FACT++  1.0
MessageDim.cc
Go to the documentation of this file.
1 #include "MessageDim.h"
2 
3 #include "tools.h"
4 #include "Time.h"
5 
6 using namespace std;
7 
8 // **************************************************************************
23 // **************************************************************************
24 
25 // --------------------------------------------------------------------------
26 //
35 //
36 MessageDimTX::MessageDimTX(const std::string &name, std::ostream &out)
37  : DimDescribedService(name + "/MESSAGE", const_cast<char*>("C"),
38  "A general logging service providing a quality of service (severity)"
39  "|Message[string]:The message"),
40  MessageImp(out), fDebug(false),
41  fMsgQueue(std::bind(&MessageDimTX::UpdateService, this, placeholders::_1))
42 {
43  // This is a message which will never arrive because
44  // the time to establish a client-sever connection is
45  // too short.
46  Message("MessageDimTX started.");
47 }
48 
49 // --------------------------------------------------------------------------
50 //
52 //
54 {
55  // Everything here will never be sent by dim because the
56  // dim services have been stopped already. This is necessary,
57  // to have them available already during startup
58  Message("MessageDimTX shutting down ["+to_string(fMsgQueue.size())+"]");
59  fMsgQueue.wait();
60 }
61 
62 bool MessageDimTX::UpdateService(const tuple<Time,string,int> &data)
63 {
64  setData(get<1>(data));
65  setQuality(get<2>(data));
66 
67  const int rc = DimDescribedService::Update(get<0>(data));
68  if (rc==0 && fDebug)
69  Out() << " !! " << get<0>(data).GetAsStr() << " - Sending failed!" << endl;
70 
71  return true;
72 }
73 
74 // --------------------------------------------------------------------------
75 //
82 //
83 int MessageDimTX::Write(const Time &t, const string &txt, int qos)
84 {
85  MessageImp::Write(t, txt, qos);
86  fMsgQueue.emplace(t, txt, qos);
87  return 1;
88 }
89 
90 // **************************************************************************
108 // **************************************************************************
109 
110 // --------------------------------------------------------------------------
111 //
119 //
120 MessageDimRX::MessageDimRX(const std::string &name, MessageImp &imp)
121 : fMinLogLevel(0), fConnected(false), fMsg(imp),
122 fDimMessage((name+"/MESSAGE").c_str(), (void*)NULL, 0, this)
123 {
124 }
125 
126 // --------------------------------------------------------------------------
127 //
131 //
133 {
134  if (getInfo()!=&fDimMessage)
135  return;
136 
137  const string name = fDimMessage.getName();
138  const string server = name.substr(0, name.find_first_of('/'));
139 
141 
142  // The server is diconnected. Do nothing
143  if (!fConnected)
144  {
145  // We cannot print this message because it is produced by
146  // every server which doesn't have the MESSAGE service, too.
147  //fMsg.Message(server+": Disconnected.");
148  return;
149  }
150 
151  // skip all messages with a severity smaller than the minimum log level
153  return;
154 
155  const string msg = server+": "+fDimMessage.getString();
156 
157  // Make sure getTimestamp is called _before_ getTimestampMillisecs
158  // Must be in exactly this order!
159  const int tsec = fDimMessage.getTimestamp();
160  const int tms = fDimMessage.getTimestampMillisecs();
161 
162  // Write the received message to the output
163  fMsg.Write(Time(tsec, tms*1000), msg, fDimMessage.getQuality());
164 }
char * getString()
Definition: dic.hxx:108
bool fConnected
Definition: MessageDim.h:38
Queue< std::tuple< Time, std::string, int > > fMsgQueue
Definition: MessageDim.h:15
MessageDimRX(const std::string &name, MessageImp &imp)
Definition: MessageDim.cc:120
void setQuality(int quality)
Definition: discpp.cxx:1256
The base implementation of a distributed messaging system.
Definition: MessageImp.h:10
int getQuality()
Definition: diccpp.cxx:102
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
bool UpdateService(const std::tuple< Time, std::string, int > &data)
Definition: MessageDim.cc:62
int Write(const Time &t, const std::string &txt, int qos=kInfo)
Definition: MessageDim.cc:83
STL namespace.
MessageDimTX(const std::string &name, std::ostream &out=std::cout)
Definition: MessageDim.cc:36
int getTimestampMillisecs()
Definition: diccpp.cxx:114
std::ostream & Out() const
Definition: MessageImp.h:73
int getSize()
Definition: dic.hxx:100
virtual int Write(const Time &time, const std::string &txt, int qos=kMessage)
Definition: MessageImp.cc:133
bool wait(bool abrt=false)
Definition: Queue.h:186
int getTimestamp()
Definition: diccpp.cxx:107
Based on MessageImp, redirects log-output to a Dim service MESSAGE.
Definition: MessageDim.h:10
uint16_t qos
Definition: HeadersGPS.h:29
void setData(const void *ptr, size_t sz)
int fMinLogLevel
Definition: MessageDim.h:37
float data[4 *1440]
DimStampedInfo fDimMessage
Definition: MessageDim.h:44
size_t size() const
Definition: Queue.h:303
TT t
Definition: test_client.c:26
int Message(const std::string &str)
Definition: MessageImp.h:46
DimInfo * getInfo()
Definition: dic.hxx:26
MessageImp & fMsg
Definition: MessageDim.h:41
void infoHandler()
Definition: MessageDim.cc:132
char * getName()
Definition: dic.hxx:101