📄 util.h
字号:
/**
* util.h
*
* Short Message Abstractive Library.(SMAL)
*
* Copyright 2003-2006 北京风起水流软件工作室
*
* http://www.zealware.com
*
* princetoad@gmail.com
*
*/
#ifndef _SMAL_UTIL_H_
#define _SMAL_UTIL_H_
#include <smal.h>
//#include <common/logqueue.h>
#include <common/const.h>
#include <winsock2.h>
//##ModelId=46B5D43E03BB
class MySync
{
public:
/**@name Operations */
//@{
/**Block until the synchronisation object is available
*/
//##ModelId=46B5D43E03BC
virtual void Wait() = 0;
/**Signal that the synchronisation object is available
*/
//##ModelId=46B5D43E03BE
virtual void Signal() = 0;
//@}
};
//##ModelId=46B5D43E03C6
class MyCriticalSection : public MySync
{
public:
/**@name Construction */
//@{
/**Create a new critical section object .
*/
//##ModelId=46B5D43E03D0
MyCriticalSection();
//##ModelId=46B5D43E03D1
MyCriticalSection(const MyCriticalSection &);
/**Destroy the critical section object
*/
//##ModelId=46B5D43E03D3
~MyCriticalSection();
//@}
/**@name Operations */
//@{
/** Enter the critical section by waiting for exclusive access.
*/
//##ModelId=46B5D43E03DA
void Wait();
//##ModelId=46B5D43E03DB
inline void Enter()
{ Wait(); }
/** Leave the critical section by unlocking the mutex
*/
//##ModelId=46B5D43E03DC
void Signal();
//##ModelId=46B5D43E03E4
inline void Leave()
{ Signal(); }
//@}
private:
//##ModelId=46B5D43E03E5
MyCriticalSection & operator=(const MyCriticalSection &) { return *this; }
//##ModelId=46B5D43E03E7
CRITICAL_SECTION criticalSection;
};
///////////////////////////////////////////////////////////////////////////////
//
/** 常用结构体定义
*/
/** 线程信息结构体
*/
//##ModelId=46B5D43F0006
struct thread_info
{
//##ModelId=46B5D43F0010
DWORD m_pThreadId;
//##ModelId=46B5D43F0011
HANDLE m_hThread;
//##ModelId=46B5D43F0012
bool m_bBusyWorking;
//##ModelId=46B5D43F0013
thread_info() { m_hThread=0; m_bBusyWorking=false; }
};
/** 服务器端操作
*/
//##ModelId=46B5D43F001A
struct client_conn {
//##ModelId=46B5D43F0026
SOCKET hClient;
//##ModelId=46B5D43F002A
char sIcpid[MAX_PATH];
//##ModelId=46B5D43F002E
char sSpid[MAX_PATH];
//##ModelId=46B5D43F0030
ConnectionType type;
//##ModelId=46B5D43F0038
int nVersion;
//##ModelId=46B5D43F0039
client_conn() {
hClient = 0;
memset(sIcpid, 0, MAX_PATH);
memset(sSpid, 0, MAX_PATH);
nVersion = 0;
type = e_SendAndRecv;
}
};
///////////////////////////////////////////////////////////////////////////////
// 全局公共函数
//
/**
获得日期时间函数
格式"%04d-%02d-%02d %02d:%02d:%02d", 即YYYY-MM-DD hh:mm:ss:mss,主要用于记录日志的记录的时间戳
*/
void GetDateTime(char * strValue);
/**
转换64位无符号整数的网络字节序
*/
#define hton64(i) ( ((unsigned __int64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
#define ntoh64 hton64
int AsciiToBcd( unsigned char *lpAscii, unsigned char *lpBcd, int nLength);
void BcdToAscii( unsigned char *lpAscii, unsigned char *lpBcd, int nLength);
void ConvertMsgId( char * dst_msgid, unsigned char* uc_msgid );
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -