123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- // eBus.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "eBus.h"
- //#include "Logger.h"
- #include "eBusService.h"
- #include "P2PModule.h"
- /*
- void InitEbusEnv(bool EnableLog)
- {
- return IniteBusService(EnableLog);
- }
- void QuitEbusEnv()
- {
- return QuiteBusService();
- }
- eBus::eBus(void)
- {
- //BUSC::MessageClient::OpenLogger();
- m_pBusService = (HANDLE)new eBusService();
- ((eBusService*)m_pBusService)->SetParent(this);
- }
- eBus::~eBus(void)
- {
- if (m_pP2PModule)
- {
- delete m_pP2PModule;
- m_pP2PModule = NULL;
- }
- delete (eBusService*)m_pBusService;
- }
- bool eBus::Connect(ResDataObject &connection)
- {
- try {
- do {
- bool Local;
- ResDataObject ret;
- //Local
- if (TryGetConnectOptions(connection, EBUS_CONNECTION_LOCAL, ret) == false)
- {
- //ExeptionHappen("connection::Local is not Right");
- break;
- }
- Local = ret;
- //BusId
- DString SourceID;
- if (TryGetConnectOptions(connection, EBUS_CONNECTION_BUSID, ret) == false)
- {
- //ExeptionHappen("connection::BusId is not Right");
- break;
- }
- SourceID = (const char *)ret;
- //Port
- DString Port = DString::From(BUSC::Client::GetDefStatusPort());
- if (TryGetConnectOptions(connection, EBUS_CONNECTION_PORT, ret))
- {
- Port = (const char *)ret;
- }
- //RouterIp
- DString Ip = "";
- if (TryGetConnectOptions(connection, EBUS_CONNECTION_ROUTERIP, ret))
- {
- Ip = (const char *)ret;
- }
- m_Connected = true;
- if (m_pP2PModule)
- {
- m_Connected = ((P2P_Module_Base*)m_pP2PModule)->ConnectP2P();
- }
- m_Connected &= ((eBusService*)m_pBusService)->Connect(Local, SourceID, Ip, Port);
- return m_Connected;
- } while (0);
- }
- catch (ResDataObjectExption &exp)
- {
- //exp.what()
- Logger *p = GetGlobalLogger();
- //mLog::FDEBUG( exp.what());
- }
- catch (...)
- {
- Logger *p = GetGlobalLogger();
- //mLog::FDEBUG( "Unknown Exp Happened\n");
- }
- m_Connected = false;
- return false;
- }
- bool eBus::IsConnected()
- {
- if (m_Connected)
- {
- m_Connected = ((eBusService*)m_pBusService)->IsConnected();
- }
- return m_Connected;
- }
- void eBus::InitP2P(const char *pszIp, const char *pszLocalBusId, bool AsServer)
- {
- if (AsServer)
- {
- m_pP2PModule = new P2P_Module_Server();
- }
- else
- {
- m_pP2PModule = new P2P_Module_Client();
- }
- ((P2P_Module_Server*)m_pP2PModule)->InitP2P((const char*)pszIp, (const char*)pszLocalBusId, AsServer, (PVOID)this);
- }
- void eBus::DisConnect()
- {
- ((eBusService*)m_pBusService)->DisConnect();
- if (m_pP2PModule)
- {
- ((P2P_Module_Base*)m_pP2PModule)->Disconnect();
- }
- m_Connected = false;
- }
- void eBus::Quit()
- {
- ((eBusService*)m_pBusService)->Quit();
- if (m_pP2PModule)
- {
- ((P2P_Module_Base*)m_pP2PModule)->Quit();
- }
- }
- void eBus::SetLogPath(const char *pPath)
- {
- ((eBusService*)m_pBusService)->SetLogPath(pPath);
- }
- bool eBus::SendSMPacket(const char *pTargetID, const char *pContext, unsigned long long nShareMemID)
- {
- if (((eBusService*)m_pBusService)->m_ConnectionStatus)
- {
- return ((eBusService*)m_pBusService)->SendSMPacket(pTargetID, pContext, nShareMemID, CCOS_HW_CHANNEL + 1);
- }
- //mLog::FERROR("ConnectionStatus is False");
- m_Connected = false;
- return false;
- }
- bool eBus::SendRawPacket(const char *pTargetID, const char *pContext, DWORD ChannelId)
- {
- if (((eBusService*)m_pBusService)->m_ConnectionStatus)
- {
- return ((eBusService*)m_pBusService)->SendPacket(pTargetID, pContext, ChannelId);
- }
- m_Connected = false;
- return false;
- }
- bool eBus::SendPacket(const char *pTargetID, const char *pContext, const char *pBlock, DWORD BlockSize)
- {
- if (((eBusService*)m_pBusService)->m_ConnectionStatus)
- {
- if (pBlock)
- {
- //mLog::FDEBUG("Send BlockData to :{$}",pTargetID);
- if (m_pP2PModule != NULL)
- {
- if (((P2P_Module_Base*)m_pP2PModule)->IsTargetBusId(pTargetID))
- {
- //going to p2p
- return ((P2P_Module_Base*)m_pP2PModule)->SendBlob(pContext, pBlock, BlockSize);
- }
- }
- return ((eBusService*)m_pBusService)->SendPacket(pTargetID, pContext, pBlock, BlockSize, CCOS_HW_CHANNEL + 1);
- }
- //mLog::FDEBUG("Send MsgData to :{$}", pTargetID);
- return ((eBusService*)m_pBusService)->SendPacket(pTargetID, pContext, CCOS_HW_CHANNEL);
- }
- //mLog::FDEBUG("Send Data to :{$} Failed ", pTargetID);
- m_Connected = false;
- return false;
- }
- bool eBus::TryGetConnectOptions(ResDataObject &connection, const char *pKey, ResDataObject &result)
- {
- bool ret = false;
- try {
- int Idx = connection.GetFirstOf(pKey);
- if (Idx >= 0)
- {
- result = connection[Idx];
- ret = true;
- }
- }
- //catch (ResDataObjectExption &exp)
- //{
- // //exp.what()
- // Logger *p = GetGlobalLogger();
- // //mLog::FDEBUG( exp.what());
- // result = "";
- //}
- catch (...)
- {
- Logger *p = GetGlobalLogger();
- //mLog::FDEBUG( "Unknown Exp Happened\n");
- result = "";
- }
- return ret;
- }
- void eBus::BlobDataArrived(const char *pMsg, unsigned char *pBlockData, DWORD BlockDataLen)
- {
- if (((eBusService*)m_pBusService)->m_ConnectionStatus)
- {
- ((eBusService*)m_pBusService)->BlobDataArrived(pMsg, pBlockData, BlockDataLen);
- return;
- }
- m_Connected = false;
- }
- void eBus::UnRegistThread(DWORD Tid)
- {
- ((eBusService*)m_pBusService)->UnRegistThread(Tid);
- }
- */
|