DDSConnection.cpp
Go to the documentation of this file.
1 #include <rms/provider/DDSConnection.h>
2 #include <rms/base/RmsRuntimeException.h>
3 #include <unistd.h>
4 #include <boost/lexical_cast.hpp>
5 
6 namespace gov {
7 
8 namespace fnal {
9 
10 namespace cd {
11 
12 namespace rms {
13 
14 namespace provider {
15 
18 
19 /**
20  * Creates a new DDSConnection given the application name and partition.
21  *
22  * @param applicationName The name of the application generating/receiving
23  * messages.
24  * @param applicationPartition The partition of the application that is
25  * generating/receiving messages.
26  */
28  const int partitionNumber) {
29  _applicationName = applicationName;
30  _partitionNumber = partitionNumber;
31 
32  char hostname[80];
33  memset(hostname, 0, 80);
34  if (gethostname(hostname, 79) == 0) {
35  _uuidGenerator = new util::UUIDGenerator(hostname);
36  std::string tmpString(hostname);
37  _myHostName = tmpString;
38  }
39  else {
40  _uuidGenerator = new util::UUIDGenerator("C++DDSConnection");
41  _myHostName = "Unknown";
42  }
43 
44  _debugFlag = 0;
45  char *debugEnvVar = getenv("RMS_DEBUG");
46  if (debugEnvVar != NULL) {
47  std::string debugString(debugEnvVar);
48  try {
49  _debugFlag = boost::lexical_cast<int>(debugString);
50  }
51  catch (boost::bad_lexical_cast &excpt) {
52  std::cerr << "*** ERROR: Invalid RMS_DEBUG value: \""
53  << debugString << "\"." << std::endl;
54  }
55  }
56 
57  boost::mutex::scoped_lock sl(_staticMutex);
59  if (_instanceCount == 1) {
60  try {
62  }
63  catch (...) {
64  std::cerr << "Unable to connect DomainParticipant in "
65  << "DDSConnection constructor." << std::endl;
66  }
67  }
68 }
69 
70 /**
71  * Destructor.
72  */
74  close();
75 
76  boost::mutex::scoped_lock sl(_staticMutex);
78  if (_instanceCount == 0) {
80  }
81 }
82 
83 /**
84  * Determine if the given destination can be reached with the DDS provider.
85  *
86  * @param dest The destination to check to see if messages can be sent to it.
87  * @return True if the destination can be reached, false otherwise.
88  */
89 bool DDSConnection::supportsDestination(const base::RmsDestination& dest) {
90  return true;
91 }
92 
93 /**
94  * Closes the connection. After calling this method, the
95  * connection should no longer be used since it will no
96  * longer be connected to the underlying provider system.
97  */
99  if (_uuidGenerator) {
100  delete _uuidGenerator;
101  _uuidGenerator = NULL;
102  }
103 }
104 
105 } // end of namespace provider
106 
107 } // end of namespace rms
108 
109 } // end of namespace cd
110 
111 } // end of namespace fnal
112 
113 } // end of namespace gov
static DPSingleton & Instance()
Definition: CETDDS.h:142
OStream cerr
Definition: OStream.cxx:7
DDSConnection(const std::string applicationName, const int partitionNumber)
bool supportsDestination(const base::RmsDestination &candidateDestination)
std::string getenv(std::string const &name)
Definition: fnal.py:1
c cd(1)
enum BeamMode string