virtual CLStatus Initialize(CLMessageLoopManager *pMessageLoop, void* pContext)
	{
		EXPECT_EQ((long)pContext, 3);

		pMessageLoop->Register(1, (CallBackForMessageLoop)(&CLPipeQueue_CLThreadForMsgLoop::On_1));
		pMessageLoop->Register(2, (CallBackForMessageLoop)(&CLPipeQueue_CLThreadForMsgLoop::On_2));

		CLSharedExecutiveCommunicationByNamedPipe *queue = new CLSharedExecutiveCommunicationByNamedPipe(test_pipe_name);
		EXPECT_TRUE(queue->RegisterSerializer(1, new CLMsg1ForCLThreadForMsgLoop_Serializer).IsSuccess());
		EXPECT_TRUE(queue->RegisterSerializer(2, new CLMsg2ForCLThreadForMsgLoop_Serializer).IsSuccess());

		EXPECT_TRUE(CLExecutiveNameServer::GetInstance()->Register(test_pipe_name, queue).IsSuccess());

		CLMessage *p = new CLMsg1ForCLThreadForMsgLoop;
		EXPECT_TRUE(CLExecutiveNameServer::PostExecutiveMessage(test_pipe_name, p).IsSuccess());

		p = new CLMsg2ForCLThreadForMsgLoop;
		EXPECT_TRUE(CLExecutiveNameServer::PostExecutiveMessage(test_pipe_name, p).IsSuccess());

		EXPECT_TRUE(CLExecutiveNameServer::GetInstance()->ReleaseCommunicationPtr(test_pipe_name).IsSuccess());

		return CLStatus(0, 0);
	}
Example #2
0
int main()
{
	try
	{
		if(!CLLibExecutiveInitializer::Initialize().IsSuccess())
		{
			cout << "Initialize error" << endl;
			return 0;
		}

		CLSharedExecutiveCommunicationByNamedPipe *pSender = new CLSharedExecutiveCommunicationByNamedPipe("test_pipe");
		pSender->RegisterSerializer(TEST_MESSAGE_ID, new CLTestMsgSerializer);
		pSender->RegisterSerializer(QUIT_MESSAGE_ID, new CLQuitMsgSerializer);

		CLExecutiveNameServer::GetInstance()->Register("test_pipe", pSender);

		CLTestMsg *pTestMsg = new CLTestMsg;
		pTestMsg->i = 3;
		pTestMsg->j = 4;
		CLExecutiveNameServer::PostExecutiveMessage("test_pipe", pTestMsg);

		CLQuitMsg *pQuitMsg = new CLQuitMsg;
		CLExecutiveNameServer::PostExecutiveMessage("test_pipe", pQuitMsg);

		CLExecutiveNameServer::GetInstance()->ReleaseCommunicationPtr("test_pipe");
		
		throw CLStatus(0, 0);
	}
	catch(CLStatus& s)
	{
		if(!CLLibExecutiveInitializer::Destroy().IsSuccess())
			cout << "Destroy error" << endl;

		return 0;
	}
}