并行处理之引用计数与状态的使用(二)

2014-11-24 07:30:33 · 作者: · 浏览: 37
onnObj)部分代码如下:
// 返回值及错误码
enum TRFCResult
{crSuccess = 1, // 成功
crFailure = 0, // 失败
crUnknown = -1, // 未知错误
crNotExist = -2, // 不存在(如: AConnObj)
crNotStart = -3, // 服务器未启动
crNotConnect = -4, // 连接未打开
crNonsupport = -5, // 不支持
crVersion = -6, // 版本太低
crPassword = -7, // 密码错误
crIsExisted = -8, // 已存在
crIsIllegal = -9, // 不合法
crAttrInvalid = -10, // 属性无效
crStateInvalid = -11, // 状态无效
crHandleInvalid = -12, // 句柄无效
crAccessIllegal = -13}; // 存取非法
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* TRFConnObj - 客户端连接对象类 */
class TRFConnObj
{
public:
TRFConnObj(TRFConnEvent* AEventObj = NULL, const char* AHost = NULL,
long APort = 0, const char* APassword = NULL);
virtual ~TRFConnObj();
// 属性
void* Data() const { return FData; }
TRCConnection* ConnObj() const { return FConnObj; }
TRFConnEvent* EventObj() const { return FEventObj; }
Longword CallTimeout() const { return FCallTimeout; }
TObjState State() const { return FState; }
KYString RFVersion() const { return FRFInfo.Version; }
TDateTime RFStartTime() const { return FRFInfo.StartTime; }
TDateTime RFDateTime();
// 设置属性
void SetData(void* AData) { FData = AData; }
void SetCallTimeout(Longword ATimeout);
// 打开/关闭连接
long Open();
void Close(bool ANeedWait = false);
// 读取/设置文件属性
long GetFileAttr(const char* AFileName, long* Attrib);
long SetFileAttr(const char* AFileName, long Attrib);
// 文件存在/删除/移动文件或目录
long FileExisted(const char* AFileName);
long DeleteFile(const char* AFileName);
long MoveFile(const char* AOldName, const char* ANewName);
// 目录存在/创建/删除
long DirExisted(const char* APathName);
long CreateDir(const char* APathName, bool AForced = false);
long RemoveDir(const char* APathName, bool AForced = false);
// 磁盘操作相关函数
long DriveType(const char* ADrive, long* AType);
long DiskSpace(const char* APath, __int64* ATotalSpace,
__int64* AFreeSpace);
protected:
// 状态锁
void Lock() const { FLock->Enter(); }
void Unlock() const { FLock->Leave(); }
// 对象次数增减
long IncObjTimes() { return InterlockedIncrement(&FObjTimes); }
long DecObjTimes() { return InterlockedDecrement(&FObjTimes); }
// 引用计数增减
bool IncRefCount_Valid();
bool IncRefCount();
void DecRefCount();
// 读取 RF 的信息
void GetRFInfo();
void GetRFDateTime();
// 存取 RF 属性方法
long GetRFInt(long Attrib, long& AValue);
long GetRFStr(long Attrib, KYString& AValue);
long SetRFInt(long Attrib, long AValue);
long SetRFSt