TEST(CLProtocolDataPoster, PostProtocolData_Features_Test)
{
	CLProtocolDataPoster *pd = new CLProtocolDataPoster;

	CLEvent e;
	CLNamedPipe *preader = new CLNamedPipe("/tmp/NamedPipe_for_CLProtocolDataPosterTest", true);
	CLNamedPipe *pwriter = new CLNamedPipe("/tmp/NamedPipe_for_CLProtocolDataPosterTest", false);
	EXPECT_TRUE(pd->SetParameters(new CLDataPosterByNamedPipe(pwriter), new CLDataPostResultNotifier(false), &e).IsSuccess());

	CLIOVectors *piov = new CLIOVectors;
	long i = 32;
	EXPECT_TRUE(piov->PushBack((char *)(&i), 8).IsSuccess());
	CLStatus s1 = pd->PostProtocolData(piov);
	EXPECT_TRUE(s1.IsSuccess());

	EXPECT_TRUE(e.Wait().IsSuccess());

	long j = 0;
	CLIOVectors iov1;
	EXPECT_TRUE(iov1.PushBack((char *)(&j), 8).IsSuccess());
	EXPECT_TRUE(preader->Read(iov1).IsSuccess());
	EXPECT_EQ(j, 32);

	delete pwriter;
	delete preader;
}
CLStatus CLThreadForMsgLoop::Run(void *pContext)
{
	if(m_pCoordinator == 0)
		return CLStatus(-1, 0);
	CLEvent event;
	CLThreadInitialFinishedNotifier notifier(&event);
	SLExecutiveInitialParameter para;//打包通知变量和运行参数
	para.pContext = pContext;
	para.pNotifier = &notifier;

	CLStatus s = m_pCoordinator->Run(&para);
	if(!s.IsSuccess())
	{
		CLLogger::WriteLogMesg("In CLThreadForMsgLoop::Run(), m_pThread->Run error", 0);
		m_bWaitForDeath = false;
		m_pCoordinator = 0;
		return CLStatus(-1, 0);
	}
	CLStatus s1 = event.Wait();
	if(!s1.IsSuccess())
		CLLogger::WriteLogMesg("In CLThreadForMsgLoop::Run(), event.Wait error", 0);
	if(notifier.IsInitialSuccess())
		return CLStatus(0,0);
	else
		return CLStatus(-1,0);

}
Exemplo n.º 3
0
int main_ss()
{
    CLEvent *pEvent = (CLEvent *) new CLEvent();
    CLCoordinator *pCoordinator = new CLRegularCoordinator();
    //CLExecutiveFunctionProvider * printer = new CLParaPrinter();
    CLMyFunction *myfunc = new CLMyFunction();
    CLExecutive *pThread = new CLThread(pCoordinator,true);
    pCoordinator->SetExecObjects(pThread,myfunc);
    cout <<"Status Code: "<<pCoordinator->Run((void*)pEvent).m_clReturnCode<<endl;

    pEvent->Wait();
    cout << "main thread: i received signal." << endl;
    pCoordinator->WaitForDeath();
    //pCoordinator->WaitForDeath();
    return 0;
}
TEST(CLProtocolDataPoster, STL_PostProtocolData_Features_Test)
{
	CLProtocolDataPoster *pd = new CLProtocolDataPoster;
	CLEvent e;
	CLSTLqueue *q = new CLSTLqueue;
	
	EXPECT_TRUE(pd->SetParameters(new CLDataPosterBySTLqueue(q), new CLDataPostResultNotifier(false), &e).IsSuccess());

	CLIOVectors *piov = new CLIOVectors;
	long i = 32;
	EXPECT_TRUE(piov->PushBack((char *)(&i), 8).IsSuccess());
	CLStatus s1 = pd->PostProtocolData(piov);
	EXPECT_TRUE(s1.IsSuccess());

	EXPECT_TRUE(e.Wait().IsSuccess());

	long j = 0;
	CLIOVectors iov1;
	EXPECT_TRUE(iov1.PushBack((char *)(&j), 8).IsSuccess());
	EXPECT_TRUE(q->PopData(iov1).IsSuccess());
	EXPECT_EQ(j, 32);

	delete q;
}