[Cppunit-cvs] cppunit2/src/opentest remoteinterfaces.cpp,1.1,1.2
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-06-25 11:08:17
|
Update of /cvsroot/cppunit/cppunit2/src/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15239/src/opentest Modified Files: remoteinterfaces.cpp Log Message: Separated serialization process from call dispatching. This allows the serialization to be done by the transport layer (in a single thread). RemoteMessage can be exchanged between thread safely. Index: remoteinterfaces.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentest/remoteinterfaces.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** remoteinterfaces.cpp 24 Jun 2005 20:12:04 -0000 1.1 --- remoteinterfaces.cpp 25 Jun 2005 11:08:05 -0000 1.2 *************** *** 21,32 **** // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// // class MessageSender // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// ! void MessageSender::beginMessage( MessageId message ) { - stream().startsWriteNewMessage(); - stream() << message; } --- 21,275 ---- // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// + // class RemoteMessage + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + RemoteMessage::RemoteMessage() + { + } + + RemoteMessage::RemoteMessage( MessageId id ) + { + } + + RemoteMessage::~RemoteMessage() + { + } + + + void + RemoteMessage::serialize( Stream &stream ) + { + stream << messageId_; + doSerialize( stream ); + } + + inline RemoteMessagePtr makeRemoteMessage( MessageId id ) + { + return RemoteMessagePtr( new RemoteMessage( id ) ); + } + + inline void unserializeRemoteMessage( RemoteMessagePtr &outMessage, + MessageId id ) + { + outMessage.reset( new RemoteMessage( id ) ); + } + + + template<class TargetType> + void dispatchRemoteCall( const RemoteMessagePtr &inMessage, + TargetType *target, + void (TargetType::*method)() ) + { + (target->*method)(); + } + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // template class SimpleRemoteMessage + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + template<class DataType> + class OPENTEST_API SimpleRemoteMessage : public RemoteMessage + { + public: + SimpleRemoteMessage() + { + } + + SimpleRemoteMessage( MessageId id, const DataType &data ) + : RemoteMessage( id ) + , data_( data ) + { + } + + DataType data_; + + private: // overridden from RemoteMessage + virtual void doSerialize( Stream &stream ) + { + stream << data_; + } + }; + + template<class DataType> + RemoteMessagePtr makeSimpleRemoteMessage( MessageId id, const DataType &data ) + { + return RemoteMessagePtr( new SimpleRemoteMessage<DataType>( id, data ) ); + } + + template<class DataType> + void unserializeSimpleRemoteMessage( Stream &stream, + RemoteMessagePtr &outMessage, + MessageId id, + CppTL::Type<DataType> ) + { + typedef SimpleRemoteMessage<DataType> MessageType; + MessageType *message = new MessageType(); + outMessage.reset( message ); + stream >> message->messageId_; + stream >> message->data_; + } + + + template<class TargetType + ,class DataType + > + void dispatchSimpleRemoteCall( const RemoteMessagePtr &inMessage, + TargetType *target, + void (TargetType::*method)( const DataType & ) ) + { + typedef SimpleRemoteMessage<DataType> MessageType; + const MessageType *message = static_cast<const MessageType *>( inMessage.get() ); + (target->*method)( message->data_ ); + } + + + template<class TargetType + ,class DataType + > + void dispatchSimpleRemoteCallNoRef( const RemoteMessagePtr &inMessage, + TargetType *target, + void (TargetType::*method)( DataType ) ) + { + typedef SimpleRemoteMessage<DataType> MessageType; + const MessageType *message = static_cast<const MessageType *>( inMessage.get() ); + (target->*method)( message->data_ ); + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // template class TestIdRemoteMessage + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + template<class DataType> + class OPENTEST_API TestIdRemoteMessage : public RemoteMessage + { + public: + TestIdRemoteMessage() + { + } + + TestIdRemoteMessage( MessageId id, TestId testId, const DataType &data ) + : RemoteMessage( id ) + , testId_( testId ) + , data_( data ) + { + } + + DataType data_; + TestId testId_; + + private: // overridden from RemoteMessage + virtual void doSerialize( Stream &stream ) + { + stream << testId_ << data_; + } + }; + + template<class DataType> + RemoteMessagePtr makeTestIdRemoteMessage( MessageId id, TestId test, const DataType &data ) + { + return RemoteMessagePtr( new TestIdRemoteMessage<DataType>( id, test, data ) ); + } + + template<class DataType> + void unserializeTestIdRemoteMessage( Stream &stream, + RemoteMessagePtr &outMessage, + MessageId id, + CppTL::Type<DataType> ) + { + typedef TestIdRemoteMessage<DataType> MessageType; + MessageType *message = new MessageType(); + outMessage.reset( message ); + stream >> message->messageId_; + stream >> message->testId_; + stream >> message->data_; + } + + template<class TargetType + ,class DataType + > + void dispatchTestIdRemoteCall( const RemoteMessagePtr &inMessage, + TargetType *target, + void (TargetType::*method)( TestId, const DataType & ) ) + { + typedef TestIdRemoteMessage<DataType> MessageType; + const MessageType *message = static_cast<const MessageType *>( inMessage.get() ); + (target->*method)( message->testId_, message->data_ ); + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // RemoteMessagePtr serialization + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + + Stream & operator <<( Stream &stream, const RemoteMessagePtr &message ) + { + message->serialize( stream ); + return stream; + } + + Stream & OPENTEST_API operator >>( Stream &stream, RemoteMessagePtr &message ) + { + message.reset(); + MessageId id; + stream >> id; + switch ( id ) + { + case driverMessageSetTestDescriptions: + unserializeSimpleRemoteMessage( stream, message, id, CppTL::Type<TestDescriptions>() ); + break; + case driverMessageSetDefaultTestPlan: + unserializeSimpleRemoteMessage( stream, message, id, CppTL::Type<TestPlan>() ); + break; + case driverMessageStartTesting: + unserializeSimpleRemoteMessage( stream, message, id, CppTL::Type<TestId>() ); + break; + case driverMessageAddResultLog: + unserializeTestIdRemoteMessage( stream, message, id, CppTL::Type<ResultLog>() ); + break; + case driverMessageAddResultAssertion: + unserializeTestIdRemoteMessage( stream, message, id, CppTL::Type<ResultAssertion>() ); + break; + case driverMessageSetResultInputActualOutput: + unserializeTestIdRemoteMessage( stream, message, id, CppTL::Type<ResultInputOutput>() ); + break; + case driverMessageSetTestResult: + unserializeTestIdRemoteMessage( stream, message, id, CppTL::Type<ResultStatus>() ); + break; + case driverMessageTestPlanDone: + unserializeSimpleRemoteMessage( stream, message, id, CppTL::Type<TestId>() ); + break; + case runnerMessageRunTests: + unserializeSimpleRemoteMessage( stream, message, id, CppTL::Type<TestPlan>() ); + break; + case runnerMessageGetTestDescriptions: + case runnerMessageGetTestPlans: + case runnerMessageStopTest: + unserializeRemoteMessage( message, id ); + break; + default: + stream.setError( "Bad message type." ); + break; + } + return stream; + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// // class MessageSender // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// ! void ! MessageSender::sendMessage( const RemoteMessagePtr &message ) { } *************** *** 38,46 **** // ////////////////////////////////////////////////////////////////// void ! TestDriverProxy::setTestDescriptions( TestDescriptions &tests ) { ! beginMessage( driverMessageSetTestDescriptions ); ! stream() << tests; ! sendMessage(); } --- 281,288 ---- // ////////////////////////////////////////////////////////////////// void ! TestDriverProxy::setTestDescriptions( const TestDescriptions &tests ) { ! sendMessage( makeSimpleRemoteMessage( driverMessageSetTestDescriptions, ! tests ) ); } *************** *** 48,54 **** TestDriverProxy::setDefaultTestPlan( const TestPlan &plan ) { ! beginMessage( driverMessageSetDefaultTestPlan ); ! stream() << plan; ! sendMessage(); } --- 290,295 ---- TestDriverProxy::setDefaultTestPlan( const TestPlan &plan ) { ! sendMessage( makeSimpleRemoteMessage( driverMessageSetDefaultTestPlan, ! plan ) ); } *************** *** 56,62 **** TestDriverProxy::startTesting( TestId testPlan ) { ! beginMessage( driverMessageStartTesting ); ! stream() << testPlan; ! sendMessage(); } --- 297,302 ---- TestDriverProxy::startTesting( TestId testPlan ) { ! sendMessage( makeSimpleRemoteMessage( driverMessageStartTesting, ! testPlan ) ); } *************** *** 66,72 **** const ResultLog &log ) { ! beginMessage( driverMessageAddResultLog ); ! stream() << testPlan << log; ! sendMessage(); } --- 306,312 ---- const ResultLog &log ) { ! sendMessage( makeTestIdRemoteMessage( driverMessageAddResultLog, ! testPlan, ! log ) ); } *************** *** 75,81 **** const ResultAssertion &assertion ) { ! beginMessage( driverMessageAddResultAssertion ); ! stream() << testPlan << assertion; ! sendMessage(); } --- 315,321 ---- const ResultAssertion &assertion ) { ! sendMessage( makeTestIdRemoteMessage( driverMessageAddResultAssertion, ! testPlan, ! assertion ) ); } *************** *** 84,99 **** const ResultInputOutput &output ) { ! beginMessage( driverMessageSetResultInputActualOutput ); ! stream() << testPlan << output; ! sendMessage(); } void TestDriverProxy::setTestResult( TestId testPlan, ! ResultStatus &status ) { ! beginMessage( driverMessageSetTestResult ); ! stream() << testPlan << status; ! sendMessage(); } --- 324,339 ---- const ResultInputOutput &output ) { ! sendMessage( makeTestIdRemoteMessage( driverMessageSetResultInputActualOutput, ! testPlan, ! output ) ); } void TestDriverProxy::setTestResult( TestId testPlan, ! const ResultStatus &status ) { ! sendMessage( makeTestIdRemoteMessage( driverMessageSetTestResult, ! testPlan, ! status ) ); } *************** *** 101,107 **** TestDriverProxy::testPlanDone( TestPlanId id ) { ! beginMessage( driverMessageTestPlanDone ); ! stream() << id; ! sendMessage(); } --- 341,346 ---- TestDriverProxy::testPlanDone( TestPlanId id ) { ! sendMessage( makeSimpleRemoteMessage( driverMessageTestPlanDone, ! id ) ); } *************** *** 114,185 **** void ! TestDriverServer::processMessageStream() { ! MessageId message; ! stream() >> message; ! switch ( message ) { case driverMessageSetTestDescriptions: ! { ! TestDescriptions tests; ! stream() >> tests; ! impl_->setTestDescriptions( tests ); ! } break; case driverMessageSetDefaultTestPlan: ! { ! TestPlan plan; ! stream() >> plan; ! impl_->setDefaultTestPlan( plan ); ! } break; case driverMessageStartTesting: ! { ! TestId testPlan; ! stream() >> testPlan; ! impl_->startTesting( testPlan ); ! } break; case driverMessageAddResultLog: ! { ! TestId testPlan; ! ResultLog log; ! stream() >> testPlan >> log; ! impl_->addResultLog( testPlan, log ); ! } break; case driverMessageAddResultAssertion: ! { ! TestId testPlan; ! ResultAssertion assertion; ! stream() >> testPlan >> assertion; ! impl_->addResultAssertion( testPlan, assertion ); ! } break; case driverMessageSetResultInputActualOutput: ! { ! TestId testPlan; ! ResultInputOutput output; ! stream() >> testPlan >> output; ! impl_->setResultInputActualOutput( testPlan, output ); ! } break; case driverMessageSetTestResult: ! { ! TestId testPlan; ! ResultStatus status; ! stream() >> testPlan >> status; ! impl_->setTestResult( testPlan, status ); ! } break; case driverMessageTestPlanDone: ! { ! TestId testPlan; ! stream() >> testPlan; ! impl_->testPlanDone( testPlan ); ! } break; default: ! stream().setError( "Bad message type." ); break; } --- 353,386 ---- void ! TestDriverServer::dispatchMessage( const RemoteMessagePtr &message ) { ! switch ( message->messageId_ ) { case driverMessageSetTestDescriptions: ! dispatchSimpleRemoteCall( message, impl_, &TestDriverInterface::setTestDescriptions ); break; case driverMessageSetDefaultTestPlan: ! dispatchSimpleRemoteCall( message, impl_, &TestDriverInterface::setDefaultTestPlan ); break; case driverMessageStartTesting: ! dispatchSimpleRemoteCallNoRef( message, impl_, &TestDriverInterface::startTesting ); break; case driverMessageAddResultLog: ! dispatchTestIdRemoteCall( message, impl_, &TestDriverInterface::addResultLog ); break; case driverMessageAddResultAssertion: ! dispatchTestIdRemoteCall( message, impl_, &TestDriverInterface::addResultAssertion ); break; case driverMessageSetResultInputActualOutput: ! dispatchTestIdRemoteCall( message, impl_, &TestDriverInterface::setResultInputActualOutput ); break; case driverMessageSetTestResult: ! dispatchTestIdRemoteCall( message, impl_, &TestDriverInterface::setTestResult ); break; case driverMessageTestPlanDone: ! dispatchSimpleRemoteCallNoRef( message, impl_, &TestDriverInterface::testPlanDone ); break; default: ! // ignore message => @todo add some error handling break; } *************** *** 195,206 **** TestRunnerProxy::getTestDescriptions() { ! beginMessage( runnerMessageGetTestDescriptions ); ! sendMessage(); } void TestRunnerProxy::getTestPlans() { ! beginMessage( runnerMessageGetTestPlans ); ! sendMessage(); } --- 396,406 ---- TestRunnerProxy::getTestDescriptions() { ! sendMessage( makeRemoteMessage( runnerMessageGetTestDescriptions ) ); } + void TestRunnerProxy::getTestPlans() { ! sendMessage( makeRemoteMessage( runnerMessageGetTestPlans ) ); } *************** *** 208,221 **** TestRunnerProxy::runTests( const TestPlan &plan ) { ! beginMessage( runnerMessageRunTests ); ! stream() << plan; ! sendMessage(); } void ! TestRunnerProxy::stopTest() { ! beginMessage( runnerMessageStopTest ); ! sendMessage(); } --- 408,447 ---- TestRunnerProxy::runTests( const TestPlan &plan ) { ! sendMessage( makeSimpleRemoteMessage( runnerMessageRunTests, plan ) ); } void ! TestRunnerProxy::stopTests() { ! sendMessage( makeRemoteMessage( runnerMessageStopTest ) ); ! } ! ! ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! // class TestRunnerServer ! // ////////////////////////////////////////////////////////////////// ! // ////////////////////////////////////////////////////////////////// ! void ! TestRunnerServer::dispatchMessage( const RemoteMessagePtr &message ) ! { ! switch ( message->messageId_ ) ! { ! case runnerMessageGetTestDescriptions: ! dispatchRemoteCall( message, impl_, &TestRunnerInterface::getTestDescriptions ); ! break; ! case runnerMessageGetTestPlans: ! dispatchRemoteCall( message, impl_, &TestRunnerInterface::getTestPlans ); ! break; ! case runnerMessageRunTests: ! dispatchSimpleRemoteCall( message, impl_, &TestRunnerInterface::runTests ); ! break; ! case runnerMessageStopTest: ! dispatchRemoteCall( message, impl_, &TestRunnerInterface::stopTests ); ! break; ! default: ! // ignore message => @todo add some error handling ! break; ! } } |