- 论坛徽章:
- 0
|
下面就贴一下grobal_var.h:- #ifndef GROBAL_VAR_H_
- #define GROBAL_VAR_H_
- #ifdef WIN32
- #include<stdio.h>
- #include<map>
- #endif
- #ifdef LINUX
- #include<stdio.h>
- #include<map>
- #endif
- #include "ETIM/ETIM_Type.h"
- //#include "ETIM/E_P2P_API.h"
- #include "ETIM/E_P2P_API.h"
- #ifdef WIN32
- #include<windows.h>
- #endif
- #if defined(WIN32DLL) || defined (WIN32)
- #define mSecSleep(ms) Sleep(ms)
- typedef DWORD ETIM_threadid;
- #elif defined(LINUX)
- #define mSecSleep(ms) usleep(ms * 1000)
- typedef pthread_t ETIM_threadid;
- #endif
- #ifdef WIN32
- class Locker
- {
- public:
- inline Locker() { m_hMutex=CreateMutex(NULL,FALSE,NULL); }
- inline ~Locker() { CloseHandle(m_hMutex); }
- inline void Lock() { WaitForSingleObject(m_hMutex, INFINITE); }
- inline void Unlock() { ReleaseMutex(m_hMutex); }
- private:
- HANDLE m_hMutex;
- };
- #endif
- #ifdef LINUX
- #endif
- extern Locker g_lockLock;
- /*class SingletonMapClient*/
- typedef INT32 st_ClientMapKey;
- typedef struct
- {
- UCHAR ucChannel;
- st_ETIM_Session SessionInfo;
- UINT32 uConnectTime; //connect before ? seconds or mini seconds
- CHAR bUsed;
- }st_ClientMapValue;
- typedef std::pair<st_ClientMapKey, st_ClientMapValue> PairClient;
- //typedef std::map<st_ClientMapKey,st_ClientMapValue> ClientValueType;
- class SingletonMapClient
- {
- public:
- SingletonMapClient();
- virtual ~SingletonMapClient();
-
- std::map<st_ClientMapKey,st_ClientMapValue> m_mapClient; // pair<sessionhanle, st_clientMapValue>
- public:
-
- static SingletonMapClient * GetInstance();
- private:
- static SingletonMapClient * m_s_pInstance;
- static Locker m_s_lockSingle;
- };
- /*class SingletonReceiveCmd*/
- typedef INT32 st_ReceiveMapKey;
- typedef struct
- {
- UCHAR ucChannel;
- char szFilePathName[MAX_PATH];
- long lOffset;
- size_t uSize;
- ETIM_threadid dwThreadId;
- int iSending;
- }st_ReciveMapValue;
- typedef std::pair<const st_ReceiveMapKey, st_ReciveMapValue> PairReceiveCmd; //pair<sessionHandle, ReceiveMapValue>
- //typedef std::multimap<st_ReceiveMapIndex, st_ReciveMapValue> RecevieCmd_ValueType;
- class SingletonReceiveCmd
- {
- public:
- SingletonReceiveCmd();
- virtual ~SingletonReceiveCmd();
- std::multimap<st_ReceiveMapKey, st_ReciveMapValue> m_multimapReceiveCmd;
- public:
- static SingletonReceiveCmd * GetInstance();
- private:
- static SingletonReceiveCmd * m_s_pInstance;
- static Locker m_s_lockSingle;
- };
- /*a Facade Pattern for all Grobal variable*/
- class GrobalVarFacade
- {
- //GrobalVarFacade 中的每个函数都要对互斥量加锁和解锁
- public:
- GrobalVarFacade();
- virtual ~GrobalVarFacade();
- public:
- SingletonMapClient * GetSingeltonMapClientInstance();
- SingletonReceiveCmd * GetSingletonReceiveCmdInstance();
- bool AddClient(PairClient pairCli);
-
- bool FindClient(st_ClientMapKey cliIndex);
- bool DeleteClient(st_ClientMapKey cliIndex);
- UINT32 GetClientCount();
- bool GetOneReceiveCmd(st_ReceiveMapKey &key ,st_ReciveMapValue &Value);
- bool AddOrUpdateClient();
-
- private:
- static GrobalVarFacade *m_s_pInstance;
- static Locker m_s_lockGrobalVar;
- SingletonMapClient * m_p_SingletonClient;
- SingletonReceiveCmd * m_p_SingetonReceiveCmd;
- };
- #endif //#ifndef GROBAL_VAR_H_
复制代码 |
|