// -*- C++ -*- // // $Id$ #include "Writer.h" #include "QuoterTypeSupportC.h" #include #include const int num_instances_per_writer = 1; const int num_quotes = 10; Writer::Writer(::DDS::DataWriter_ptr writer) : writer_ (::DDS::DataWriter::_duplicate (writer)), finished_instances_ (0), timeout_writes_ (0) { } void Writer::start () { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer::start \n"))); // Lanuch num_instances_per_writer threads. // Each thread writes one instance which uses the thread id as the // key value. if (activate (THR_NEW_LWP | THR_JOINABLE, num_instances_per_writer) == -1) { cerr << "Writer::start(): activate failed" << endl; exit(1); } } void Writer::end () { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer::end \n"))); wait (); } int Writer::svc () { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer::svc begins.\n"))); ::DDS::InstanceHandleSeq handles; try { while (1) { // To Do: Wait until there are matched subscriptions using // the writer's get_matched_subscriptions method and the handles // variable. // End: Wait until there are matched subscriptions using // the writer_'s get_matched_subscriptions method and the handles // variable. } // To Do: Narrow 'writer_' to a Quoter data writer // End: Narrow 'writer_' to a Quoter data writer // To Do: Create some Quoter object, // register them with the infrastructure // (via the quoter_dw's _cxx_register() method), and // modify the data values as desired, and write them out. // Use CORBA::string_dup to copy strings. // End: Create a Quoter object (or objects), // register it (or them) with the infrastructure // (via the quoter_dw's _cxx_register() method), and // modify the data values as desired, and write them out. // Use CORBA::string_dup to copy strings. } catch (CORBA::Exception& e) { cerr << "Exception caught in svc:" << endl << e << endl; } while (1) { // To Do: Wait until there are no longer any matched subscriptions // End: Wait until there are no longer any matched subscriptions } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) Writer::svc finished.\n"))); finished_instances_ ++; return 0; } bool Writer::is_finished () const { return finished_instances_ == num_instances_per_writer; } int Writer::get_timeout_writes () const { return timeout_writes_.value (); }