FACT++  1.0
DimNetwork.cc
Go to the documentation of this file.
1 #include "DimNetwork.h"
2 
3 StateClient::StateClient(const std::string &name, MessageImp &imp) :
4  MessageDimRX(name, imp), fState(-2),
5  fInfoState((name + "/STATE").c_str(), (void*)NULL, 0, this)
6 {
7 }
8 
9 // --------------------------------------------------------------------------
10 //
13 //
15 {
16  DimInfo *curr = getInfo(); // get current DimInfo address
17  if (!curr)
18  return;
19 
20  if (curr==&fInfoState)
21  {
22  const bool disconnected = fInfoState.getSize()==0;
23 
24  // Make sure getTimestamp is called _before_ getTimestampMillisecs
25  const int tsec = fInfoState.getTimestamp();
26  const int tms = fInfoState.getTimestampMillisecs();
27 
28  fState = disconnected ? -2 : fInfoState.getQuality();
29  fStateTime = Time(tsec, tms*1000);
30 
31  const string name = fInfoState.getName();
32 
33  fMsg.StateChanged(fStateTime, name.substr(0, name.length()-6),
34  disconnected ? "" : fInfoState.getString(), fState);
35 
36  return;
37  }
38 
40 }
41 
42 // ==========================================================================
43 
44 // --------------------------------------------------------------------------
45 //
47 //
49 {
50  for (ClientList::iterator i=fClientList.begin();
51  i!=fClientList.end(); i++)
52  delete i->second;
53 
54  fClientList.clear();
55 }
56 
57 // --------------------------------------------------------------------------
58 //
67 //
68 void DimNetwork::AddServer(const string &s)
69 {
71  if (s=="DIM_DNS")
72  return;
73 
74  // Check if this server is already in the list.
75  // This should never happen if Dim works reliable
76  const ClientList::iterator v = fClientList.find(s);
77  if (v!=fClientList.end())
78  {
79  stringstream err;
80  err << "Server '" << s << "' in list not as it ought to be.";
81  throw runtime_error(err.str());
82  }
83 
84  // Add the new server to the server list
85  fClientList[s] = new StateClient(s, *this);
86 }
87 
88 // --------------------------------------------------------------------------
89 //
98 //
100 {
102  if (s=="DIM_DNS")
103  return;
104 
105  const ClientList::iterator v = fClientList.find(s);
106  if (v==fClientList.end())
107  {
108  stringstream err;
109  err << "Server '" << s << "' not in list as it ought to be.";
110  throw runtime_error(err.str());
111  }
112 
113  // Remove the server from the server list
114  delete v->second;
115 
116  fClientList.erase(v);
117 }
118 
119 // --------------------------------------------------------------------------
120 //
125 {
127  DeleteClientList();
128 }
129 
130 // --------------------------------------------------------------------------
131 //
138 int DimNetwork::GetCurrentState(const string &server) const
139 {
140  const ClientList::const_iterator v = fClientList.find(server);
141  return v==fClientList.end() ? -2 : v->second->GetState();
142 }
char * getString()
Definition: dic.hxx:108
void DeleteClientList()
Delete all StateClient objects from teh list and clear the list.
Definition: DimNetwork.cc:48
int i
Definition: db_dim_client.c:21
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
int getQuality()
Definition: diccpp.cxx:102
void StateChanged(const Time &time, const std::string &server, const std::string &msg, int state)
Definition: MessageImp.cc:64
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
int GetCurrentState(const string &server) const
Definition: DimNetwork.cc:138
DimStampedInfo fInfoState
-2 not initialized, -1 not connected, 0>= state of client
Definition: DimNetwork.h:24
Definition: dic.hxx:31
uint16_t fState
State of the FTM central state machine.
Definition: HeadersFTM.h:189
int getTimestampMillisecs()
Definition: diccpp.cxx:114
int getSize()
Definition: dic.hxx:100
void RemoveServer(std::string s)
Definition: DimNetwork.cc:99
Time fStateTime
Definition: DimNetwork.h:21
void AddServer(const std::string &s)
A list with all MESSAGE services to which we subscribed.
Definition: DimNetwork.cc:68
int getTimestamp()
Definition: diccpp.cxx:107
virtual void RemoveServer(std::string s)
StateClient(const std::string &name, MessageImp &imp)
Definition: DimNetwork.cc:3
Based on MessageImp, subscribes to a MESSAGE service in the Dim network.
Definition: MessageDim.h:34
DimInfo * getInfo()
Definition: dic.hxx:26
void infoHandler()
The dim service subscription.
Definition: DimNetwork.cc:14
MessageImp & fMsg
Definition: MessageDim.h:41
void RemoveAllServers()
Definition: DimNetwork.cc:124
int fState
Combine into one MTime (together with value)
Definition: DimNetwork.h:22
virtual void RemoveAllServers()
void infoHandler()
Definition: MessageDim.cc:132
char * getName()
Definition: dic.hxx:101
virtual void AddServer(const std::string &s)