FACT++  1.0
DimDescriptionService.cc
Go to the documentation of this file.
1 // **************************************************************************
33 // **************************************************************************
34 #include "DimDescriptionService.h"
35 
36 #include <stdexcept>
37 
38 #include "dis.hxx"
39 #include "Time.h"
40 
41 using namespace std;
42 
45 std::string DimDescriptionService::fData = "";
46 
48 
49 // --------------------------------------------------------------------------
50 //
70 //
71 DimDescriptionService::DimDescriptionService(const std::string &name, const std::string &desc)
72 {
73  string server = DimServer::itsName ? DimServer::itsName : "";
74  if (server.empty())
75  {
76  const size_t p = name.find_first_of('/');
77  if (p==string::npos)
78  throw logic_error("Could not determine server name");
79 
80  server = name.substr(0, p);
81  }
82 
83  if (desc.find_first_of('\n')!=string::npos)
84  throw logic_error("Description for "+name+" contains '\\n'");
85 
86  if (!fService)
87  {
88  fService = new DimService((server+"/SERVICE_DESC").c_str(), const_cast<char*>(""));
89  fData =
90  server + "/SERVICE_DESC"
91  "=Descriptions of services or commands and there arguments"
92  "|Description[string]:For a detailed "
93  "explanation of the descriptive string see the class reference "
94  "of DimDescriptionService.\n" +
95  server + "/CLIENT_LIST"
96  "=Native Dim service: A list of all connected clients\n" +
97  server + "/VERSION_NUMBER"
98  "=Native Dim service: Version number of Dim in use"
99  "|DimVer[int]:Version*100+Release (e.g. V19r17 = 1917)\n" +
100  server + "/EXIT"
101  "=This is a native Dim command: Exit program"
102  "remotely. FACT++ programs use the given number as return code."
103  "|Rc[int]:Return code, under normal circumstances this should be 0 or 1 (42 will call exit() directly, 0x42 will call abort() directly.\n" +
104  server + "/SERVICE_LIST"
105  "=Native Dim service: List of services, commands and formats"
106  "|ServiceList[string]:For details see the Dim manual.\n";
107  }
108 
109 
110  fCount++;
111 
112  fDescription = name + '=' + desc;
113 
114  if (fData.find(fDescription+'\n')!=std::string::npos)
115  return;
116 
117  fData += fDescription + '\n';
118 
119  const Time t;
120  fService->setTimestamp(t.Time_t(), t.ms());
121  fService->setData(const_cast<char*>(fData.c_str()));
122  fService->updateService();
123 }
124 
125 
126 // --------------------------------------------------------------------------
127 //
131 //
133 {
134  const size_t pos = fData.find(fDescription+'\n');
135  if (pos!=std::string::npos)
136  fData.replace(pos, fDescription.size()+1, "");
137 
138  if (--fCount>0)
139  return;
140 
141  delete fService;
142  fService=0;
143 }
144 
146 {
147  setTimestamp(t.Time_t(), t.ms());
148 }
149 
151 {
152  setTime(Time());
153 }
154 
156 {
157  setTime(t);
158  return updateService();
159 }
160 
162 {
163  return Update(Time());
164 }
165 
167 {
168  return Update(data.data());
169 }
170 
172 {
173  setData(data);
174  return Update();
175 }
unsigned int ms() const
Definition: Time.h:102
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
static DimService * fService
Counter to count the number of instatiations.
STL namespace.
time_t Time_t() const
Definition: Time.cc:213
DimDescriptionService(const std::string &name, const std::string &format)
Local storage for the applied description.
float data[4 *1440]
TT t
Definition: test_client.c:26
static char * itsName
Definition: dis.hxx:92
static std::set< std::string > fServices
static std::string fData
Pointer to the DimService distributing the desscriptions.
uint16_t fData[21]
Definition: HeadersFTM.h:193