source: trunk/FACT++/src/logtime.cc @ 10347

Last change on this file since 10347 was 10347, checked in by tbretz, 9 years ago
Removed printing of command list from constructor; added help2man conform help-output.
File size: 3.7 KB
Line 
1#include "MessageDim.h"
2
3#include "tools.h"
4#include "Time.h"
5
6#include <iostream>
7
8class DimDescriptionService
9{
10    static int         fCount;
11    static DimService *fService;
12    static std::string fFormat;
13
14    std::string fFmt;
15
16public:
17    DimDescriptionService(const std::string &name, const std::string &format)
18    {
19        // FIXME: throw is DimServer::itsName==0
20
21        std::string n = std::string(DimServer::itsName)+"/SERVICE_DESC";
22
23        if (!fService)
24            fService = new DimService(n.c_str(), const_cast<char*>(""));
25
26        fCount++;
27
28        fFmt = name + '=' + format + '\n';
29
30        if (fFormat.find(fFmt)!=std::string::npos)
31            return;
32
33        fFormat += fFmt;
34
35        fService->setData(const_cast<char*>(fFormat.c_str()));
36        fService->updateService();
37
38    }
39    ~DimDescriptionService()
40    {
41        const size_t pos = fFormat.find(fFmt);
42        if (pos!=std::string::npos)
43            fFormat.replace(pos, fFmt.size(), "");
44
45        if (--fCount>0)
46            return;
47
48        delete fService;
49        fService=0;
50    }
51};
52
53class DimDescribedService : public DimDescriptionService, public DimService
54{
55public:
56    template<typename T>
57        DimDescribedService(const char *name, T &val, const char *desc)
58        : DimDescriptionService(name, desc), DimService(name, val)
59    {
60    }
61
62    DimDescribedService(const char *name, const char *val, const char *desc)
63        : DimDescriptionService(name, desc), DimService(name, const_cast<char*>(val)) { }
64
65    DimDescribedService(const char *name, char *format, void *structure, int size, const char *desc)
66        : DimDescriptionService(name, desc), DimService(name, format, structure, size)
67    {
68        // FIXME: compare number of ; with number of |
69    }
70};
71
72DimService *DimDescriptionService::fService = 0;
73int DimDescriptionService::fCount = 0;
74std::string DimDescriptionService::fFormat;
75
76
77int main(int, const char **)
78{
79    // We could use putenv to make the Configure class change the value...
80    setenv("DIM_DNS_NODE", "localhost", 0);
81
82    // Start a DimServer called TIME
83    DimServer::start("TIME");
84
85    // Some info on the console
86    std::cout << "Offering TIME/MESSAGE...\n" << std::endl;
87
88    short s;
89    int i;
90    long long ll;
91    float f;
92    DimDescribedService servt("TIME/TEST", "C:1;I:1;C", NULL, 0,
93                              "Char[c]:This is a char|   Int This is an int|String[s]:This is a string");
94
95    DimDescribedService servs("TIME/SHORT",     s,  "[a]");
96    DimDescribedService servx("TIME/LONGLONG",  ll, ": This is my long long");
97    DimDescribedService servi("TIME/INT",       i,  "MyInt{mi}");
98    DimDescribedService servf("TIME/FLOAT",     f,  "   MyFloat  :   This is my float");
99    DimDescribedService servc("TIME/TIME", const_cast<char*>(""), "MyTime[T]:This is my time");
100
101    DimCommand cmd("TIME/CMD", "I:2;F:2");
102
103    DimDescriptionService des("TIME/CMD", "range[addr]:From DAC to DAC|values[DAC]:DAC values to be set");
104
105    // Setup a DimService called TIME/MESSAGE
106    MessageDimTX msg("TIME");
107    while (1)
108    {
109        // Send current time
110        msg.Message(Time().GetAsStr());
111//        servx.Update();
112        /*
113        servs.updateService();
114        servi.updateService();
115        servf.updateService();
116        servc.updateService();
117         */
118        // wait approximately one second
119        usleep(100000);
120    }
121
122    return 0;
123}
124
125// **************************************************************************
126/** @example logtime.cc
127
128This is a simple example how to log messages through the Dim network
129using MessageDimTX. Here we are offering the time once a second.
130
131The program is stopped by CTRL-C
132
133*/
134// **************************************************************************
Note: See TracBrowser for help on using the repository browser.