TEST(CLExecutiveNameServer, GetCommunicationPtr) { CLExecutiveNameServer *p = CLExecutiveNameServer::GetInstance(); EXPECT_NE(p, (CLExecutiveNameServer *)0); EXPECT_EQ(p->GetCommunicationPtr(0), (CLMessagePoster *)0); EXPECT_EQ(p->GetCommunicationPtr(""), (CLMessagePoster *)0); CLLogger::WriteLogMsg("The Following bug is produced on purpose", 0); EXPECT_EQ(p->GetCommunicationPtr("3423"), (CLMessagePoster *)0); const char *strPipeName = "/tmp/NamedPipe_For_CLExecutiveNameServer_Test"; CLNamedPipe np(strPipeName, true); CLMessagePoster *mp = new CLMessagePoster(new CLMsgToPointerSerializer, 0, new CLDataPostChannelByNamedPipeMaintainer(strPipeName), 0); EXPECT_TRUE(mp->Initialize(new CLInitialDataPostChannelNotifier, 0).IsSuccess()); EXPECT_TRUE(p->Register("SDFdfd", mp).IsSuccess()); CLMessagePoster *qq = p->GetCommunicationPtr("SDFdfd"); EXPECT_TRUE(qq == mp); EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd").IsSuccess()); EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd").IsSuccess()); }
CLStatus CLExecutiveNameServer::PostExecutiveMessage(const char* pstrExecutiveName, CLMessage* pMessage){ if(pMessage == 0) return CLStatus(-1, 0); if((pstrExecutiveName == 0) || (strlen(pstrExecutiveName) == 0)){ delete pMessage; return CLStatus(-1, 0); } CLExecutiveNameServer* pNameServer = CLExecutiveNameServer::GetInstance(); if(pNameServer == NULL){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), CLExecutiveNameServer::GetInstance error", 0); delete pMessage; return CLStatus(-1,0); } CLExecutiveCommunication* pComm = pNameServer->GetCommunicationPtr(pstrExecutiveName); if(pComm == NULL){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->GetCommunicationPtr error", 0); delete pMessage; return CLStatus(-1,0); } CLStatus s = pComm->PostExecutiveMessage(pMessage); if(!s.IsSuccess()){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pComm->PostExecutiveMessage error", 0); CLStatus s = pNameServer->ReleaseCommunicationPtr(pstrExecutiveName); if(!s.IsSuccess()) CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->ReleaseCommunicationPtr error", 0); return CLStatus(-1,0); } CLStatus s2 = pNameServer->ReleaseCommunicationPtr(pstrExecutiveName); if(!s2.IsSuccess()) CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->ReleaseCommunicationPtr error", 0); return CLStatus(0, 0); }