PageRenderTime 15ms CodeModel.GetById 10ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TServerMS/Database/DBMessageHandler.h

http://awoe.googlecode.com/
C++ Header | 69 lines | 48 code | 14 blank | 7 comment | 1 complexity | 80148f403d804a39f2d092df3f4b0aa1 MD5 | raw file
 1/////////////////////////////////////////////////////////////////////
 2// DBMessageHandler.h
 3//
 4//
 5// 11/16/2010
 6//
 7/////////////////////////////////////////////////////////////////////
 8
 9#ifndef __PERSISTMSGHANDLER_H__
10#define __PERSISTMSGHANDLER_H__
11
12#include <map>
13#include "Message/MsgHandlerIf.h"
14#include "Database/DBMysql.h"
15#include "Service/Service.h"
16
17class MsgHandlerInitDataDB  : public IMsgHandlerInitData
18{
19public:
20	MsgHandlerInitDataDB(Service* pSvcLgc):wpSvcLgc(pSvcLgc){}
21	Service* wpSvcLgc;
22	string db_server;
23	string db_name;
24	string db_user;
25	string db_password;
26	short db_port;
27};
28
29
30
31class DBMessage;
32class PersistService;
33class DBMessageHandler : public IMsgHandler
34{
35	friend PersistService;
36public:
37	DBMessageHandler( );
38	virtual ~DBMessageHandler( );
39
40	virtual bool initialize(IMsgHandlerInitData* data) ;
41
42	virtual bool handleMsg( IMsg * message );
43private:
44	virtual void addSubHandler(int nMsgCate, int nMsgID, IMsgHandler* pHandler);
45	virtual void rmvSubHandler(int nMsgCate, int nMsgID);
46private:
47	typedef std::map< int, IMsgHandler* > MessageMap;
48	typedef std::map< int, IMsgHandler* >::iterator MessageMapIter;
49	typedef std::map< int, IMsgHandler* >::const_iterator MessageMapConstIter;
50
51	static MessageMap ms_MessageMap;
52
53protected:
54	static DBMysql m_DBMysql;
55
56	static Service*	m_wpSvcLgc;
57};
58
59extern INT64	sqlResult;
60
61#define SQL_QUERY( sql, ... )						\
62	do												\
63	{												\
64		char strSQL[ 1024 ];							\
65		sprintf_s( strSQL, 1024, sql, __VA_ARGS__ );	\
66		sqlResult = m_DBMysql.Query( strSQL );		\
67	} while ( 0 );
68
69#endif // __PERSISTMSGHANDLER_H__