// 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); } */