1 | #include "MessageDim.h"
|
---|
2 |
|
---|
3 | #include "tools.h"
|
---|
4 | #include "Time.h"
|
---|
5 | #include "dic.hxx"
|
---|
6 | #include <iostream>
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 | struct testType {
|
---|
10 | long v1;
|
---|
11 | long v2;
|
---|
12 | long v3;
|
---|
13 | long v4;
|
---|
14 | long v5;
|
---|
15 | long v6;
|
---|
16 | long v7;
|
---|
17 | long v8;
|
---|
18 | long v9;
|
---|
19 | long v10;
|
---|
20 | };
|
---|
21 |
|
---|
22 | struct DataLoggerStats {
|
---|
23 | long sizeWritten;
|
---|
24 | long freeSpace;
|
---|
25 | long writingRate;
|
---|
26 | };
|
---|
27 |
|
---|
28 | class StatSub : public DimClient
|
---|
29 | {
|
---|
30 | DimStampedInfo* info;
|
---|
31 | DimStampedInfo* info2;
|
---|
32 |
|
---|
33 | public:
|
---|
34 | StatSub()
|
---|
35 | {
|
---|
36 | info = new DimStampedInfo("FAD_CONTROL/START_RUN", const_cast<char*>(""), this);
|
---|
37 | info2 = new DimStampedInfo("TIME/EMPTY", const_cast<char*>(""), this);
|
---|
38 | }
|
---|
39 | void infoHandler()
|
---|
40 | {
|
---|
41 | return;
|
---|
42 | DimInfo* I = getInfo();
|
---|
43 | if (I == info2)
|
---|
44 | {
|
---|
45 | cout << "EMPTY SERVICE UPDATED. " << "Format: " << I->getFormat() << endl;
|
---|
46 | }
|
---|
47 | if (I != info)
|
---|
48 | return;
|
---|
49 | DataLoggerStats* data = reinterpret_cast<DataLoggerStats*>(I->getData());
|
---|
50 | std::cout << "size written: " << data->sizeWritten << " free space: " << data->freeSpace << " writing rate" << data->writingRate << std::endl;
|
---|
51 | }
|
---|
52 | };
|
---|
53 |
|
---|
54 | DimService * myService;
|
---|
55 |
|
---|
56 | int main(int, const char **)
|
---|
57 | {
|
---|
58 | // We could use putenv to make the Configure class change the value...
|
---|
59 | setenv("DIM_DNS_NODE", "localhost", 0);
|
---|
60 |
|
---|
61 | cout << "This is the new version of the service 21 July 2011" << endl;
|
---|
62 |
|
---|
63 | // Start a DimServer called TIME
|
---|
64 | DimServer::start("FAD_CONTROL");
|
---|
65 |
|
---|
66 | // Some info on the console
|
---|
67 | std::cout << "Offering TIME/MESSAGE...\n" << std::endl;
|
---|
68 | long emptyFormatVariable[2];
|
---|
69 | emptyFormatVariable[0] = 1;
|
---|
70 | emptyFormatVariable[1] = 2;
|
---|
71 | const char* format = "X:1;X:1";
|
---|
72 | DimService* emptyFormatService = new DimService("FAD_CONTROL/START_RUN", "X:1;X:1", emptyFormatVariable, 2*sizeof(long));
|
---|
73 | testType variable;
|
---|
74 | variable.v1 = 0;
|
---|
75 | variable.v2 = 1;
|
---|
76 | variable.v3 = 2;
|
---|
77 | variable.v4 = 3;
|
---|
78 | variable.v5 = 4;
|
---|
79 | variable.v6 = 5;
|
---|
80 | variable.v7 = 6;
|
---|
81 | variable.v8 = 7;
|
---|
82 | variable.v9 = 8;
|
---|
83 | variable.v10 = 9;
|
---|
84 | // DimDescribedService srvc("TIME/ETIENNE", "X:1;X:1;X:1;X:1;X:1;X:1;X:1;X:1;X:1;X:1", variable, "Test Service");
|
---|
85 |
|
---|
86 | StatSub stSub;
|
---|
87 | // delete emptyFormatService;
|
---|
88 | // usleep(1000000);
|
---|
89 | // emptyFormatService = new DimService("TIME/EMPTY", "X:1", &emptyFormatVariable, sizeof(long));
|
---|
90 |
|
---|
91 | cout << "Test service created" << endl;
|
---|
92 | // Setup a DimService called TIME/MESSAGE
|
---|
93 | MessageDimTX msg("TIME");
|
---|
94 | while (1)
|
---|
95 | {
|
---|
96 | // if (variable.v1 %10 == 0)
|
---|
97 | // {
|
---|
98 | // delete emptyFormatService;
|
---|
99 | // cout << "Service deleted" << endl;
|
---|
100 | // usleep(1000000);
|
---|
101 | // emptyFormatService = new DimService("TIME/EMPTY", "X:1", &emptyFormatVariable, sizeof(long));
|
---|
102 | // cout << "Service re-created" << endl;
|
---|
103 | // }
|
---|
104 |
|
---|
105 | // srvc.updateService();
|
---|
106 | emptyFormatService->updateService();
|
---|
107 | emptyFormatVariable[0]++;
|
---|
108 | emptyFormatVariable[1]++;
|
---|
109 | variable.v1++;
|
---|
110 | variable.v2++;
|
---|
111 | variable.v3++;
|
---|
112 | variable.v4++;
|
---|
113 | variable.v5++;
|
---|
114 | variable.v6++;
|
---|
115 | variable.v7++;
|
---|
116 | variable.v8++;
|
---|
117 | variable.v9++;
|
---|
118 | variable.v10++;
|
---|
119 | // wait approximately one second
|
---|
120 | usleep(1000000);
|
---|
121 | }
|
---|
122 |
|
---|
123 | return 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // **************************************************************************
|
---|
127 | /** @example logtime.cc
|
---|
128 |
|
---|
129 | This is a simple example how to log messages through the Dim network
|
---|
130 | using MessageDimTX. Here we are offering the time once a second.
|
---|
131 |
|
---|
132 | The program is stopped by CTRL-C
|
---|
133 |
|
---|
134 | */
|
---|
135 | // **************************************************************************
|
---|