OpenDDS  Snapshot(2023/04/28-20:55)
SPMonitorImpl.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "SPMonitorImpl.h"
9 #include "MonitorFactoryImpl.h"
10 #include "monitorC.h"
11 #include "monitorTypeSupportImpl.h"
14 #include <dds/DdsDcpsInfrastructureC.h>
15 
17 
18 namespace OpenDDS {
19 namespace DCPS {
20 
21 
23  Service_Participant* /*sp*/)
24  : monitor_factory_(monitor_factory)
25 {
26  char host[256];
27  ACE_OS::hostname(host, 256);
28  hostname_ = host;
29  pid_ = ACE_OS::getpid();
30 }
31 
33 {
34 }
35 
36 void
38 {
39  if (CORBA::is_nil(this->sp_writer_.in())) {
40  this->sp_writer_ = this->monitor_factory_->get_sp_writer();
41  }
42 
43  // If the SP writer is not available, it is too soon to report
44  if (!CORBA::is_nil(this->sp_writer_.in())) {
46  report.host = this->hostname_.c_str();
47  report.pid = this->pid_;
48  DDS::DomainParticipantFactory_var pf = TheParticipantFactory;
49 
51  if (!pi) {
52  ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) SPMonitorImpl::report():")
53  ACE_TEXT(" failed to obtain DomainParticipantFactoryImpl.\n")));
54  return;
55  }
56 
57  const DomainParticipantFactoryImpl::DPMap& participants = pi->participants();
58  CORBA::ULong length = 0;
59  for (DomainParticipantFactoryImpl::DPMap::const_iterator mapIter = participants.begin();
60  mapIter != participants.end();
61  ++mapIter) {
62  for (DomainParticipantFactoryImpl::DPSet::const_iterator iter = mapIter->second.begin();
63  iter != mapIter->second.end();
64  ++iter) {
65  report.domain_participants.length(length+1);
66  report.domain_participants[length] = (*iter)->get_id();
67  length++;
68  }
69  }
70  length = 0;
71  // TODO: Redo the transport-related monitor publishing here...
72  //const TransportFactory::ImplMap& transports =
73  // TransportFactory::instance()->get_transport_impl_map();
74  //report.transports.length(static_cast<CORBA::ULong>(transports.size()));
75  //for (TransportFactory::ImplMap::const_iterator mapIter = transports.begin();
76  // mapIter != transports.end();
77  // ++mapIter) {
78  // report.transports[length++] = mapIter->first;
79  //}
80  this->sp_writer_->write(report, DDS::HANDLE_NIL);
81  }
82 }
83 
84 } // namespace DCPS
85 } // namespace OpenDDS
86 
#define ACE_ERROR(X)
const InstanceHandle_t HANDLE_NIL
SPMonitorImpl(MonitorFactoryImpl *monitor_factory, Service_Participant *sp)
Implements the OpenDDS::DCPS::DomainParticipantFactory interfaces.
ServiceParticipantReportDataWriter_ptr get_sp_writer()
ACE_CDR::ULong ULong
int hostname(char name[], size_t maxnamelen)
ACE_TEXT("TCP_Factory")
OpenDDS::DCPS::ServiceParticipantReportDataWriter_var sp_writer_
Definition: SPMonitorImpl.h:35
Full implementation of the MonitorFactoryImpl.
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define TheParticipantFactory
LM_ERROR
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
pid_t getpid(void)
DPMap participants() const
Make a copy of the participants map for reading.
Boolean is_nil(T x)
MonitorFactoryImpl * monitor_factory_
Definition: SPMonitorImpl.h:34