int main(int argc, char** argv){ Logger::set_level(LogDebug); Logger::set_output(new OutputPolicyFile("log.txt")); Engine* the_engine = new RandyEngine; GTPReader the_reader(*the_engine); }
int main (int argc, char *argv[]) { int status = 0; try { ACE_DEBUG((LM_INFO," %P|%t %T subscriber main\n")); ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. parse_args (argc, argv); ::DDS::DomainParticipant_var dp = dpf->create_participant(TEST_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil()); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: create_participant failed.\n"))); return 1 ; } // Register the type supports switch (1 << DATA_SIZE) { case 128: { ::Mine::Pt128TypeSupportImpl* pt128ts_servant = new ::Mine::Pt128TypeSupportImpl(); PortableServer::ServantBase_var safe_servant = pt128ts_servant; ::Mine::Pt128TypeSupport_var pt128ts = TAO::DCPS::servant_to_reference (pt128ts_servant); if (::DDS::RETCODE_OK != pt128ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT (" %P|%t ERROR: Failed to register the Pt128TypeSupport."))); return 1; } } break; case 512: { ::Mine::Pt512TypeSupportImpl* pt512ts_servant = new ::Mine::Pt512TypeSupportImpl(); PortableServer::ServantBase_var safe_servant = pt512ts_servant; ::Mine::Pt512TypeSupport_var pt512ts = TAO::DCPS::servant_to_reference (pt512ts_servant); if (::DDS::RETCODE_OK != pt512ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT (" %P|%t ERROR:Failed to register the Pt512TypeSupport."))); return 1; } } break; case 2048: { ::Mine::Pt2048TypeSupportImpl* pt2048ts_servant = new ::Mine::Pt2048TypeSupportImpl(); PortableServer::ServantBase_var safe_servant = pt2048ts_servant; ::Mine::Pt2048TypeSupport_var pt2048ts = TAO::DCPS::servant_to_reference (pt2048ts_servant); if (::DDS::RETCODE_OK != pt2048ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT (" %P|%t ERROR: Failed to register the Pt2048TypeSupport."))); return 1; } } break; case 8192: { ::Mine::Pt8192TypeSupportImpl* pt8192ts_servant = new ::Mine::Pt8192TypeSupportImpl(); PortableServer::ServantBase_var safe_servant = pt8192ts_servant; ::Mine::Pt8192TypeSupport_var pt8192ts = TAO::DCPS::servant_to_reference (pt8192ts_servant); if (::DDS::RETCODE_OK != pt8192ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT (" %P|%t ERROR: Failed to register the Pt8192TypeSupport."))); return 1; } } }; ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCE; topic_qos.resource_limits.max_instances = MAX_INSTANCES; topic_qos.resource_limits.max_samples = MAX_SAMPLES; topic_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; ::DDS::Topic_var topic = dp->create_topic (TEST_TOPIC, TEST_TYPE, topic_qos, ::DDS::TopicListener::_nil()); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(TEST_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, ::DDS::SubscriberListener::_nil()); if (CORBA::is_nil (sub.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: create_subscriber failed.\n")), 1); } // Initialize the transport if (0 != ::init_reader_tranport() ) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: init_transport failed!\n")), 1); } // Attach the subscriber to the transport. ::TAO::DCPS::SubscriberImpl* sub_impl = ::TAO::DCPS::reference_to_servant< ::TAO::DCPS::SubscriberImpl, ::DDS::Subscriber_ptr> (sub.in ()); if (0 == sub_impl) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: Failed to obtain servant ::TAO::DCPS::SubscriberImpl\n")), 1); } TAO::DCPS::AttachStatus attach_status = sub_impl->attach_transport(reader_transport_impl.in()); if (attach_status != TAO::DCPS::ATTACH_OK) { // We failed to attach to the transport for some reason. const char* status_str = ""; switch (attach_status) { case TAO::DCPS::ATTACH_BAD_TRANSPORT: status_str = "ATTACH_BAD_TRANSPORT"; break; case TAO::DCPS::ATTACH_ERROR: status_str = "ATTACH_ERROR"; break; case TAO::DCPS::ATTACH_INCOMPATIBLE_QOS: status_str = "ATTACH_INCOMPATIBLE_QOS"; break; default: status_str = "Unknown Status"; break; } ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: Failed to attach to the transport. ") ACE_TEXT("AttachStatus == %s\n"), status_str), 1); } // Create the Datareaders ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); sub->copy_from_topic_qos (dr_qos, topic_qos); ::DDS::DataReader_var the_dr = sub->create_datareader(description.in (), dr_qos, ::DDS::DataReaderListener::_nil()); if (CORBA::is_nil (the_dr.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT(" %P|%t ERROR: create_datareader failed.\n")), 1); } Reader the_reader(sub.in (), the_dr.in (), num_datawriters, NUM_SAMPLES, DATA_SIZE); status = the_reader.svc(); // clean up subscriber objects sub->delete_contained_entities() ; dp->delete_subscriber(sub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheTransportFactory->release(); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("( %P|%t ERROR: TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } // Note: The TransportImpl reference SHOULD be deleted before exit from // main if the concrete transport libraries are loaded dynamically. // Otherwise cleanup after main() will encount access vilation. reader_transport_impl = 0; writer_transport_impl = 0; return status; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { int status = 0; try { ACE_DEBUG((LM_INFO,"(%P|%t) %T subscriber main\n")); ::DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(argc, argv); // let the Service_Participant (in above line) strip out -DCPSxxx parameters // and then get application specific parameters. status = parse_args (argc, argv); if (status) return status; ::DDS::DomainParticipant_var dp = dpf->create_participant(TEST_DOMAIN, PARTICIPANT_QOS_DEFAULT, ::DDS::DomainParticipantListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (dp.in ())) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: create_participant failed.\n"))); return 1 ; } ::Xyz::Pt128TypeSupport_var pt128ts; ::Xyz::Pt512TypeSupport_var pt512ts; ::Xyz::Pt2048TypeSupport_var pt2048ts; ::Xyz::Pt8192TypeSupport_var pt8192ts; // Register the type supports switch (DATA_SIZE) { case 128: { pt128ts = new ::Xyz::Pt128TypeSupportImpl(); if (::DDS::RETCODE_OK != pt128ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Failed to register the Pt128TypeSupport."))); return 1; } } break; case 512: { pt512ts = new ::Xyz::Pt512TypeSupportImpl(); if (::DDS::RETCODE_OK != pt512ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR:Failed to register the Pt512TypeSupport."))); return 1; } } break; case 2048: { pt2048ts = new ::Xyz::Pt2048TypeSupportImpl(); if (::DDS::RETCODE_OK != pt2048ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Failed to register the Pt2048TypeSupport."))); return 1; } } break; case 8192: { pt8192ts = new ::Xyz::Pt8192TypeSupportImpl(); if (::DDS::RETCODE_OK != pt8192ts->register_type(dp.in (), TEST_TYPE)) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Failed to register the Pt8192TypeSupport."))); return 1; } } }; ::DDS::TopicQos topic_qos; dp->get_default_topic_qos(topic_qos); topic_qos.resource_limits.max_samples_per_instance = MAX_SAMPLES_PER_INSTANCE; topic_qos.resource_limits.max_instances = MAX_INSTANCES; topic_qos.resource_limits.max_samples = MAX_SAMPLES; topic_qos.reliability.kind = ::DDS::RELIABLE_RELIABILITY_QOS; topic_qos.reliability.max_blocking_time.sec = max_mili_sec_blocking / 1000; topic_qos.reliability.max_blocking_time.nanosec = (max_mili_sec_blocking % 1000) * 1000*1000; topic_qos.history.kind = ::DDS::KEEP_ALL_HISTORY_QOS; ::DDS::Topic_var topic = dp->create_topic (TEST_TOPIC, TEST_TYPE, topic_qos, ::DDS::TopicListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (topic.in ())) { return 1 ; } ::DDS::TopicDescription_var description = dp->lookup_topicdescription(TEST_TOPIC); if (CORBA::is_nil (description.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: lookup_topicdescription failed.\n")), 1); } // Create the subscriber ::DDS::Subscriber_var sub = dp->create_subscriber(SUBSCRIBER_QOS_DEFAULT, ::DDS::SubscriberListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (sub.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: create_subscriber failed.\n")), 1); } // Create the Datareaders ::DDS::DataReaderQos dr_qos; sub->get_default_datareader_qos (dr_qos); sub->copy_from_topic_qos (dr_qos, topic_qos); ::DDS::DataReader_var the_dr = sub->create_datareader(description.in (), dr_qos, ::DDS::DataReaderListener::_nil(), ::OpenDDS::DCPS::DEFAULT_STATUS_MASK); if (CORBA::is_nil (the_dr.in ())) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: create_datareader failed.\n")), 1); } Reader the_reader(sub.in (), the_dr.in (), num_datawriters, NUM_SAMPLES, DATA_SIZE); status = the_reader.svc(); // clean up subscriber objects sub->delete_contained_entities() ; dp->delete_subscriber(sub.in ()); dp->delete_topic(topic.in ()); dpf->delete_participant(dp.in ()); TheServiceParticipant->shutdown (); } catch (const TestException&) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: TestException caught in main.cpp. "))); return 1; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in main.cpp:"); return 1; } return status; }