1 | #ifndef FACT_DimNetwork
|
---|
2 | #define FACT_DimNetwork
|
---|
3 |
|
---|
4 | // **************************************************************************
|
---|
5 | /** @class StateClient
|
---|
6 |
|
---|
7 | @brief A simple Dim client diriving from MessageDimRX subscribing to the STATE service
|
---|
8 |
|
---|
9 | This is a simple dim client which subscribes to the MESSAGE and STATE
|
---|
10 | service of a server. It stores the last state and its time as well as
|
---|
11 | the last message sent.
|
---|
12 |
|
---|
13 | **/
|
---|
14 | // **************************************************************************
|
---|
15 | #include "MessageDim.h"
|
---|
16 | #include "Time.h"
|
---|
17 |
|
---|
18 | class StateClient : public MessageDimRX
|
---|
19 | {
|
---|
20 | private:
|
---|
21 | Time fStateTime; /// Combine into one MTime (together with value)
|
---|
22 | int fState; /// -2 not initialized, -1 not connected, 0>= state of client
|
---|
23 |
|
---|
24 | DimStampedInfo fInfoState; /// The dim service subscription
|
---|
25 |
|
---|
26 | protected:
|
---|
27 | void infoHandler();
|
---|
28 |
|
---|
29 | public:
|
---|
30 | StateClient(const std::string &name, MessageImp &imp);
|
---|
31 |
|
---|
32 | bool IsConnected() const { return fState>=0; }
|
---|
33 | int GetState() const { return fState; }
|
---|
34 |
|
---|
35 | const char *GetName() const { return const_cast<DimStampedInfo&>(fInfoState).getName(); }
|
---|
36 | };
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 | // **************************************************************************
|
---|
41 | /** @class DimNetwork
|
---|
42 |
|
---|
43 | @brief Implements automatic subscription to MESSAGE and STATE services
|
---|
44 |
|
---|
45 | This class derives from DimServiceInfoList, so that it has a full
|
---|
46 | overview of all commands and services existing in the current Dim
|
---|
47 | network. In addition it automatically subscribes to all available
|
---|
48 | MESSAGE and STATE services and redirects them to its MessageImp base class.
|
---|
49 |
|
---|
50 | @todo
|
---|
51 | - maybe the StateClient can be abondoned, this way it would be possible
|
---|
52 | to subscribe to only available MESSAGE and STATE services
|
---|
53 |
|
---|
54 | **/
|
---|
55 | // **************************************************************************
|
---|
56 | #include "DimServiceInfoList.h"
|
---|
57 | #include "DimErrorRedirecter.h"
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | class DimNetwork : public MessageImp, public DimErrorRedirecter, public DimServiceInfoListImp
|
---|
62 | {
|
---|
63 | private:
|
---|
64 | void DeleteClientList();
|
---|
65 |
|
---|
66 | protected:
|
---|
67 | typedef std::map<const std::string, StateClient*> ClientList;
|
---|
68 |
|
---|
69 | ClientList fClientList; /// A list with all MESSAGE services to which we subscribed
|
---|
70 |
|
---|
71 | void AddServer(const std::string &s);
|
---|
72 | void RemoveServer(std::string s);
|
---|
73 | void RemoveAllServers();
|
---|
74 |
|
---|
75 | public:
|
---|
76 | DimNetwork(std::ostream &out=std::cout)
|
---|
77 | : MessageImp(out), DimErrorRedirecter(static_cast<MessageImp&>(*this))
|
---|
78 | {
|
---|
79 | }
|
---|
80 | ~DimNetwork()
|
---|
81 | {
|
---|
82 | DeleteClientList();
|
---|
83 | }
|
---|
84 |
|
---|
85 | int GetCurrentState(const string &server) const;
|
---|
86 | };
|
---|
87 |
|
---|
88 |
|
---|
89 | #endif
|
---|