00001
00002
00003
00004
00005
00006
00007
00008 #include "MonitorFactoryImpl.h"
00009 #include "monitorC.h"
00010 #include "monitorTypeSupportImpl.h"
00011 #include "SPMonitorImpl.h"
00012 #include "DPMonitorImpl.h"
00013 #include "TopicMonitorImpl.h"
00014 #include "PublisherMonitorImpl.h"
00015 #include "SubscriberMonitorImpl.h"
00016 #include "DWMonitorImpl.h"
00017 #include "DWPeriodicMonitorImpl.h"
00018 #include "DRMonitorImpl.h"
00019 #include "DRPeriodicMonitorImpl.h"
00020 #include "TransportMonitorImpl.h"
00021 #include "dds/DCPS/Service_Participant.h"
00022 #include "dds/DCPS/DomainParticipantImpl.h"
00023 #include <dds/DdsDcpsInfrastructureC.h>
00024 #include <dds/DdsDcpsPublicationC.h>
00025 #include <dds/DCPS/Marked_Default_Qos.h>
00026 #include <dds/DCPS/transport/framework/TransportRegistry.h>
00027
00028 namespace OpenDDS {
00029 namespace DCPS {
00030
00031
00032
00033 MonitorFactoryImpl::MonitorFactoryImpl()
00034 {
00035 }
00036
00037
00038 MonitorFactoryImpl::~MonitorFactoryImpl()
00039 {
00040 }
00041
00042 OpenDDS::DCPS::Monitor*
00043 MonitorFactoryImpl::create_sp_monitor(Service_Participant* sp)
00044 {
00045 return new SPMonitorImpl(this, sp);
00046 }
00047
00048 Monitor*
00049 MonitorFactoryImpl::create_dp_monitor(DomainParticipantImpl* dp)
00050 {
00051 if (dp->get_domain_id() == MONITOR_DOMAIN_ID) {
00052 return 0;
00053 }
00054 return new DPMonitorImpl(dp, this->dp_writer_);
00055 }
00056
00057 ServiceParticipantReportDataWriter_ptr
00058 MonitorFactoryImpl::get_sp_writer()
00059 {
00060 return ServiceParticipantReportDataWriter::_duplicate(this->sp_writer_);
00061 }
00062
00063 OpenDDS::DCPS::Monitor*
00064 MonitorFactoryImpl::create_topic_monitor(TopicImpl* topic)
00065 {
00066 return new TopicMonitorImpl(topic, this->topic_writer_);
00067 }
00068
00069 OpenDDS::DCPS::Monitor*
00070 MonitorFactoryImpl::create_publisher_monitor(PublisherImpl* pub)
00071 {
00072 return new PublisherMonitorImpl(pub, this->pub_writer_);
00073 }
00074
00075 OpenDDS::DCPS::Monitor*
00076 MonitorFactoryImpl::create_subscriber_monitor(SubscriberImpl* sub)
00077 {
00078 return new SubscriberMonitorImpl(sub, this->sub_writer_);
00079 }
00080
00081 OpenDDS::DCPS::Monitor*
00082 MonitorFactoryImpl::create_data_writer_monitor(DataWriterImpl* dw)
00083 {
00084 return new DWMonitorImpl(dw, this->dw_writer_);
00085 }
00086
00087 OpenDDS::DCPS::Monitor*
00088 MonitorFactoryImpl::create_data_writer_periodic_monitor(DataWriterImpl* dw)
00089 {
00090 return new DWPeriodicMonitorImpl(dw, this->dw_per_writer_);
00091 }
00092
00093 OpenDDS::DCPS::Monitor*
00094 MonitorFactoryImpl::create_data_reader_monitor(DataReaderImpl* dr)
00095 {
00096 return new DRMonitorImpl(dr, this->dr_writer_);
00097 }
00098
00099 OpenDDS::DCPS::Monitor*
00100 MonitorFactoryImpl::create_data_reader_periodic_monitor(DataReaderImpl* dr)
00101 {
00102 return new DRPeriodicMonitorImpl(dr, this->dr_per_writer_);
00103 }
00104
00105 OpenDDS::DCPS::Monitor*
00106 MonitorFactoryImpl::create_transport_monitor(TransportImpl* transport)
00107 {
00108 return new TransportMonitorImpl(transport, this->transport_writer_);
00109 }
00110
00111 DDS::DataWriter_ptr
00112 MonitorFactoryImpl::create_data_writer(DDS::DomainParticipant_ptr participant,
00113 DDS::Publisher_ptr publisher,
00114 const char* type_name,
00115 const char* topic_name,
00116 const DDS::DataWriterQos& dw_qos)
00117 {
00118 DDS::Topic_var topic =
00119 participant->create_topic(topic_name,
00120 type_name,
00121 TOPIC_QOS_DEFAULT,
00122 DDS::TopicListener::_nil(),
00123 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
00124 if (CORBA::is_nil(topic)) {
00125 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::create_data_writer(): Failed to create topic, name = %s\n", topic_name));
00126 }
00127 DDS::DataWriter_var writer =
00128 publisher->create_datawriter(topic.in(),
00129 dw_qos,
00130 DDS::DataWriterListener::_nil(),
00131 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
00132 if (CORBA::is_nil(writer)) {
00133 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::create_data_writer(): Failed to create data writer\n"));
00134 }
00135
00136 return writer._retn();
00137 }
00138
00139 void
00140 MonitorFactoryImpl::initialize()
00141 {
00142 DDS::DomainParticipantFactory_var dpf =
00143 TheServiceParticipant->get_domain_participant_factory();
00144 DDS::DomainParticipant_var participant =
00145 dpf->create_participant(MONITOR_DOMAIN_ID,
00146 PARTICIPANT_QOS_DEFAULT,
00147 DDS::DomainParticipantListener::_nil(),
00148 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
00149 if (CORBA::is_nil(participant.in())) {
00150 ACE_DEBUG((LM_DEBUG,
00151 ACE_TEXT("ERROR: %N:%l: MonitorFactoryImpl::initialize() -")
00152 ACE_TEXT(" create_participant failed!\n")));
00153 }
00154
00155 DDS::Publisher_var publisher =
00156 participant->create_publisher(PUBLISHER_QOS_DEFAULT,
00157 DDS::PublisherListener::_nil(),
00158 OpenDDS::DCPS::DEFAULT_STATUS_MASK);
00159
00160 static const std::string config_name = TransportRegistry::DEFAULT_INST_PREFIX
00161 + std::string("MonitorBITTransportConfig");
00162 OpenDDS::DCPS::TransportConfig_rch config =
00163 TheTransportRegistry->get_config (config_name);
00164 if (config.is_nil ())
00165 {
00166 config = TransportRegistry::instance()->create_config(config_name);
00167
00168 std::string inst_name = TransportRegistry::DEFAULT_INST_PREFIX
00169 + std::string("FederationBITTCPTransportInst");
00170 TransportInst_rch inst =
00171 TransportRegistry::instance()->create_inst(inst_name, "tcp");
00172 config->instances_.push_back(inst);
00173 }
00174
00175 TransportRegistry::instance()->bind_config(config, publisher.in());
00176
00177 DDS::DataWriter_var writer;
00178 DDS::DataWriterQos dw_qos;
00179 publisher->get_default_datawriter_qos(dw_qos);
00180 dw_qos.durability.kind = DDS::TRANSIENT_LOCAL_DURABILITY_QOS;
00181
00182 OpenDDS::DCPS::ServiceParticipantReportTypeSupport_var sp_ts =
00183 new OpenDDS::DCPS::ServiceParticipantReportTypeSupportImpl();
00184 ::DDS::ReturnCode_t ret = sp_ts->register_type(participant.in(), "");
00185 if (DDS::RETCODE_OK == ret) {
00186 CORBA::String_var sp_type_name = sp_ts->get_type_name();
00187 writer = create_data_writer(participant.in(),
00188 publisher.in(),
00189 sp_type_name.in(),
00190 SERVICE_PARTICIPANT_MONITOR_TOPIC,
00191 dw_qos);
00192 this->sp_writer_ =
00193 OpenDDS::DCPS::ServiceParticipantReportDataWriter::_narrow(writer.in());
00194 if (CORBA::is_nil(this->sp_writer_)) {
00195 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow sp_writer\n"));
00196 }
00197 } else {
00198 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sp_ts\n"));
00199 }
00200
00201 OpenDDS::DCPS::DomainParticipantReportTypeSupport_var dp_ts =
00202 new OpenDDS::DCPS::DomainParticipantReportTypeSupportImpl();
00203 ret = dp_ts->register_type(participant.in(), "");
00204 if (DDS::RETCODE_OK == ret) {
00205 CORBA::String_var dp_type_name = dp_ts->get_type_name();
00206 writer = create_data_writer(participant.in(),
00207 publisher.in(),
00208 dp_type_name.in(),
00209 DOMAIN_PARTICIPANT_MONITOR_TOPIC,
00210 dw_qos);
00211 this->dp_writer_ =
00212 OpenDDS::DCPS::DomainParticipantReportDataWriter::_narrow(writer.in());
00213 if (CORBA::is_nil(this->dp_writer_)) {
00214 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dp_writer\n"));
00215 }
00216 } else {
00217 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dp_ts\n"));
00218 }
00219
00220 OpenDDS::DCPS::TopicReportTypeSupport_var topic_ts =
00221 new OpenDDS::DCPS::TopicReportTypeSupportImpl();
00222 ret = topic_ts->register_type(participant.in(), "");
00223 if (DDS::RETCODE_OK == ret) {
00224 CORBA::String_var topic_type_name = topic_ts->get_type_name();
00225 writer = create_data_writer(participant.in(),
00226 publisher.in(),
00227 topic_type_name.in(),
00228 TOPIC_MONITOR_TOPIC,
00229 dw_qos);
00230 this->topic_writer_ =
00231 OpenDDS::DCPS::TopicReportDataWriter::_narrow(writer.in());
00232 if (CORBA::is_nil(this->topic_writer_)) {
00233 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow topic_writer\n"));
00234 }
00235 } else {
00236 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register topic_ts\n"));
00237 }
00238
00239 OpenDDS::DCPS::PublisherReportTypeSupport_var pub_ts =
00240 new OpenDDS::DCPS::PublisherReportTypeSupportImpl();
00241 ret = pub_ts->register_type(participant.in(), "");
00242 if (DDS::RETCODE_OK == ret) {
00243 CORBA::String_var pub_type_name = pub_ts->get_type_name();
00244 writer = create_data_writer(participant.in(),
00245 publisher.in(),
00246 pub_type_name.in(),
00247 PUBLISHER_MONITOR_TOPIC,
00248 dw_qos);
00249 this->pub_writer_ =
00250 OpenDDS::DCPS::PublisherReportDataWriter::_narrow(writer.in());
00251 if (CORBA::is_nil(this->pub_writer_)) {
00252 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow pub_writer\n"));
00253 }
00254 } else {
00255 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register pub_ts\n"));
00256 }
00257
00258 OpenDDS::DCPS::SubscriberReportTypeSupport_var sub_ts =
00259 new OpenDDS::DCPS::SubscriberReportTypeSupportImpl();
00260 ret = sub_ts->register_type(participant.in(), "");
00261 if (DDS::RETCODE_OK == ret) {
00262 CORBA::String_var sub_type_name = sub_ts->get_type_name();
00263 writer = create_data_writer(participant.in(),
00264 publisher.in(),
00265 sub_type_name.in(),
00266 SUBSCRIBER_MONITOR_TOPIC,
00267 dw_qos);
00268 this->sub_writer_ =
00269 OpenDDS::DCPS::SubscriberReportDataWriter::_narrow(writer.in());
00270 if (CORBA::is_nil(this->sub_writer_)) {
00271 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow sub_writer\n"));
00272 }
00273 } else {
00274 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sub_ts\n"));
00275 }
00276
00277 OpenDDS::DCPS::DataWriterReportTypeSupport_var dw_ts =
00278 new OpenDDS::DCPS::DataWriterReportTypeSupportImpl();
00279 ret = dw_ts->register_type(participant.in(), "");
00280 if (DDS::RETCODE_OK == ret) {
00281 CORBA::String_var dw_type_name = dw_ts->get_type_name();
00282 writer = create_data_writer(participant.in(),
00283 publisher.in(),
00284 dw_type_name.in(),
00285 DATA_WRITER_MONITOR_TOPIC,
00286 dw_qos);
00287 this->dw_writer_ =
00288 OpenDDS::DCPS::DataWriterReportDataWriter::_narrow(writer.in());
00289 if (CORBA::is_nil(this->dw_writer_)) {
00290 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dw_writer\n"));
00291 }
00292 } else {
00293 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register sp_ts\n"));
00294 }
00295
00296 OpenDDS::DCPS::DataWriterPeriodicReportTypeSupport_var dw_per_ts =
00297 new OpenDDS::DCPS::DataWriterPeriodicReportTypeSupportImpl();
00298 ret = dw_per_ts->register_type(participant.in(), "");
00299 if (DDS::RETCODE_OK == ret) {
00300 CORBA::String_var dw_per_type_name = dw_per_ts->get_type_name();
00301 writer = create_data_writer(participant.in(),
00302 publisher.in(),
00303 dw_per_type_name.in(),
00304 DATA_WRITER_PERIODIC_MONITOR_TOPIC,
00305 dw_qos);
00306 this->dw_per_writer_ =
00307 OpenDDS::DCPS::DataWriterPeriodicReportDataWriter::_narrow(writer.in());
00308 if (CORBA::is_nil(this->dw_per_writer_)) {
00309 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dw_per_writer\n"));
00310 }
00311 } else {
00312 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dw_per_ts\n"));
00313 }
00314
00315 OpenDDS::DCPS::DataReaderReportTypeSupport_var dr_ts =
00316 new OpenDDS::DCPS::DataReaderReportTypeSupportImpl();
00317 ret = dr_ts->register_type(participant.in(), "");
00318 if (DDS::RETCODE_OK == ret) {
00319 CORBA::String_var dr_type_name = dr_ts->get_type_name();
00320 writer = create_data_writer(participant.in(),
00321 publisher.in(),
00322 dr_type_name.in(),
00323 DATA_READER_MONITOR_TOPIC,
00324 dw_qos);
00325 this->dr_writer_ =
00326 OpenDDS::DCPS::DataReaderReportDataWriter::_narrow(writer.in());
00327 if (CORBA::is_nil(this->dr_writer_)) {
00328 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dr_writer\n"));
00329 }
00330 } else {
00331 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dr_ts\n"));
00332 }
00333
00334 OpenDDS::DCPS::DataReaderPeriodicReportTypeSupport_var dr_per_ts =
00335 new OpenDDS::DCPS::DataReaderPeriodicReportTypeSupportImpl();
00336 ret = dr_per_ts->register_type(participant.in(), "");
00337 if (DDS::RETCODE_OK == ret) {
00338 CORBA::String_var dr_per_type_name = dr_per_ts->get_type_name();
00339 writer = create_data_writer(participant.in(),
00340 publisher.in(),
00341 dr_per_type_name.in(),
00342 DATA_READER_PERIODIC_MONITOR_TOPIC,
00343 dw_qos);
00344 this->dr_per_writer_ =
00345 OpenDDS::DCPS::DataReaderPeriodicReportDataWriter::_narrow(writer.in());
00346 if (CORBA::is_nil(this->dr_per_writer_)) {
00347 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow dr_per_writer\n"));
00348 }
00349 } else {
00350 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register dr_per_ts\n"));
00351 }
00352
00353 OpenDDS::DCPS::TransportReportTypeSupport_var transport_ts =
00354 new OpenDDS::DCPS::TransportReportTypeSupportImpl();
00355 ret = transport_ts->register_type(participant.in(), "");
00356 if (DDS::RETCODE_OK == ret) {
00357 CORBA::String_var transport_type_name = transport_ts->get_type_name();
00358 writer = create_data_writer(participant.in(),
00359 publisher.in(),
00360 transport_type_name.in(),
00361 TRANSPORT_MONITOR_TOPIC,
00362 dw_qos);
00363 this->transport_writer_ =
00364 OpenDDS::DCPS::TransportReportDataWriter::_narrow(writer.in());
00365 if (CORBA::is_nil(this->transport_writer_)) {
00366 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to narrow transport_writer\n"));
00367 }
00368 } else {
00369 ACE_DEBUG((LM_DEBUG, "MonitorFactoryImpl::initialize(): Failed to register transport_ts\n"));
00370 }
00371 }
00372
00373 int
00374 MonitorFactoryImpl::service_initialize()
00375 {
00376 return ACE_Service_Config::process_directive(ace_svc_desc_MonitorFactoryImpl);
00377 }
00378
00379 }
00380 }
00381
00382 using namespace OpenDDS::DCPS;
00383
00384 ACE_FACTORY_DEFINE (OpenDDS_monitor, MonitorFactoryImpl)
00385 ACE_STATIC_SVC_DEFINE (MonitorFactoryImpl,
00386 ACE_TEXT ("OpenDDS_Monitor"),
00387 ACE_SVC_OBJ_T,
00388 &ACE_SVC_NAME (MonitorFactoryImpl),
00389 ACE_Service_Type::DELETE_THIS |
00390 ACE_Service_Type::DELETE_OBJ,
00391 0)
00392