📄 dbproxy.cc
字号:
//DBProxy.cc
/*/////////////////////////////////////////////////////////////////
李亦
liease@163.com 4040719
2006-7-18
/*/////////////////////////////////////////////////////////////////
#include "rpg/cmd/DBProxy.h"
#include "rpg/cmd/DBAccess.h"
#include "rpg/cmd/RPGCommand.h"
//#include "rpg/RPGDataMan.h"
namespace RPG
{
DBProxy* g_pDBProxy = NULL;
IMPLEMENT_CONOBJECT(DBProxy);
/////////////////////////////////////////////////////////////////
// class DBProxy 构造函数 /析构函数
DBProxy::DBProxy(/*RPGCommand* pCommand*/)
{
//AssertWarn(pCommand,"RPGCommand实例引用不能为NULL");
//m_pRPGCommand = pCommand;
//m_pClassName = "DBProxy";
setModDynamicFields(true);
setModStaticFields(true);
}
DBProxy::~DBProxy()
{
}
void DBProxy::initPersistFields()
{
Parent::initPersistFields();
}
//void DBProxy::consoleInit()
//{
//}
//void DBProxy::run(S32 arg)
//{
// //派发指令任务到各DBAccess
// //把指令结果解析到DataMan
//}
void DBProxy::Initialize(CSTR pScriptName)
{
AssertWarn(g_pDBProxy == NULL, "DBProxy实例已经创建了,不可创建第2个。");
g_pDBProxy = new DBProxy(/*g_pRPGCommand*/);
g_pDBProxy->registerObject(pScriptName);
}
void DBProxy::Destroy()
{
if(g_pDBProxy)
{
g_pDBProxy->DestroyProxy();
//g_pDBProxy->deleteObject();
g_pDBProxy = NULL;
}
}
void DBProxy::DestroyProxy()
{
DBAccess* pAccess;
for(S32 n=size()-1; n >= 0 ; n--)
{
pAccess = dynamic_cast<DBAccess*>((*this)[n]);
if(pAccess)
{
pAccess->StopProcess();
#ifdef RPGCMD_USE_THREAD
if(pAccess->waitForExit())
#endif
{
removeObject(pAccess);
pAccess->deleteObject();
}
}
}
StopProcess();
#ifdef RPGCMD_USE_THREAD
if(waitForExit())
#endif
deleteObject();
}
#ifndef RPGCMD_USE_THREAD
void DBProxy::run()
{
U32 n;
DBAccess* pAccess;
for(n=0; n<size(); n++)
{
pAccess = dynamic_cast<DBAccess*>((*this)[n]);
if(pAccess == NULL)
continue;
pAccess->Process();
}
RPGCmdProcess::Process();
}
#endif
//void DBProxy::OnStopProcess()
//{
// deleteObject();
//}
//void DBProxy::Process()
//{
//}
S32 DBProxy::OnSendingTask(GCMDTASK* pTask)
{
U32 n;
DBAccess* pAccess;
U32 nSize;
//把DBProxy的任务,克隆到可用的DBAccess中去
nSize = size();
if(nSize == 0)
return TO_FAILED;
for(n=0; n<nSize; n++)
{
pAccess = dynamic_cast<DBAccess*>((*this)[n]);
if(pAccess == NULL)
continue;
if(pAccess->GhostTask(pTask))
return TO_OK;
}
return TO_FAILED;
}
//void DBProxy::OnTaskFinished(GCMDTASK* pTask,TaskStates state)
//{
//}
S32 DBProxy::OnRespondeTask(GCMDTASK* pTask)
{
Con::printf("DBProxy CMD: %d",pTask->dwCmd);
//把数据转移到RPGCommand结果队列中去
g_pRPGCommand->ResultTask(pTask);
return TO_MOVE;
}
};//namespace RPG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -