LocalhostConnection.cpp
Go to the documentation of this file.
1 #include <rms/provider/LocalhostConnection.h>
2 
3 namespace gov {
4 
5 namespace fnal {
6 
7 namespace cd {
8 
9 namespace rms {
10 
11 namespace provider {
12 
13 /**
14  * Create a new LocalhostConnection.
15  *
16  * @param applicationName The name of the application generating/receiving
17  * messages.
18  * @param applicationPartition The partition of the application that is
19  * generating/receiving messages.
20  */
22  const int applicationPartition) {
23  _messageSource.setProperty(base::RmsDestination::TARGET_PROPERTY_NAME, applicationName);
24  _messageSource.setPartitionProperty(applicationPartition);
25 
26  char hostname[32];
27  if (gethostname(hostname, 31) == 0) {
28  _uuidGenerator = new util::UUIDGenerator(hostname);
29  }
30  else {
31  _uuidGenerator = new util::UUIDGenerator("C++LocalhostConnection");
32  }
33 }
34 
35 /**
36  * Determine whether this provider supports a particular destination.
37  *
38  * @return True as this provider supports all destinations.
39  */
40 bool LocalhostConnection::supportsDestination(const base::RmsDestination& candidateDestination) {
41  return true;
42 }
43 
44 /**
45  * Send a string to a particular destination.
46  *
47  * @param dest The destination to send a message to.
48  * @param messageString The string to send.
49  */
50 void LocalhostConnection::sendString(const base::RmsDestination& dest,
51  const std::string& messageString) {
52  ListenerContainer aListener;
53  boost::shared_ptr<std::string> messagePtr (new std::string(messageString));
54 
55  for (unsigned int i = 0; i < _destinationList.size(); i++) {
56  aListener.setDestination(_destinationList.at(i).getDestination());
57  aListener.setListener(_destinationList.at(i).getListener());
58 
59  if (aListener.getDestination().equals(dest)) {
60  aListener.getListener()->textReceived(messagePtr);
61  }
62  }
63 }
64 
65 /**
66  * Send an RmsMessage to a particular destination.
67  *
68  * @param dest The destination to send a message to.
69  * @param message The RmsMessage to send.
70  */
71 void LocalhostConnection::sendMessage(const base::RmsDestination &dest,
72  const base::RmsMessage& message) {
73  sendString(dest, message.serialize());
74 }
75 
76 /**
77  * Register a listener with this provider.
78  *
79  * @param dest The destination that the listener is interested in
80  * @param listener A reference to the listener object.
81  */
82 void LocalhostConnection::addListener(const base::RmsDestination& dest,
83  ProviderListener *listener) {
84  ListenerContainer newListener(dest, listener);
85 
86  _destinationList.push_back(newListener);
87 }
88 
89 /**
90  * Remove a listener from this provider.
91  *
92  * @param dest The destination to remove.
93  * @param listener The listener to remove.
94  *
95  * @bug implement
96  */
97 void LocalhostConnection::removeListener(const base::RmsDestination& dest, ProviderListener *listener) {
98  return;
99 }
100 
101 /**
102  * Ping a destination to see if it is up.
103  *
104  * @return This always returns true.
105  */
106 bool LocalhostConnection::ping(const base::RmsDestination& pingDestination) {
107  return true;
108 }
109 
110 /**
111  * Close this provider, and free any resources it may have allocated.
112  */
114  return;
115 }
116 
117 } // end of namespace provider
118 
119 } // end of namespace rms
120 
121 } // end of namespace cd
122 
123 } // end of namespace fnal
124 
125 } // end of namespace gov
void addListener(const base::RmsDestination &dest, ProviderListener *listener)
void removeListener(const base::RmsDestination &dest, ProviderListener *listener)
bool supportsDestination(const base::RmsDestination &candidateDestination)
Definition: fnal.py:1
static const std::string TARGET_PROPERTY_NAME
bool ping(const base::RmsDestination &pingDestination)
void sendMessage(const base::RmsDestination &dest, const base::RmsMessage &message)
c cd(1)
LocalhostConnection(const std::string applicationName, const int applicationPartition)
void sendString(const base::RmsDestination &dest, const std::string &messageString)
virtual void textReceived(boost::shared_ptr< std::string > messageText)=0
enum BeamMode string