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 |
|
---|
36 |
|
---|
37 |
|
---|
38 | // **************************************************************************
|
---|
39 | /** @class DimNetwork
|
---|
40 |
|
---|
41 | @brief Implements automatic subscription to MESSAGE and STATE services
|
---|
42 |
|
---|
43 | This class derives from DimServiceInfoList, so that it has a full
|
---|
44 | overview of all commands and services existing in the current Dim
|
---|
45 | network. In addition it automatically subscribes to all available
|
---|
46 | MESSAGE and STATE services and redirects them to its MessageImp base class.
|
---|
47 |
|
---|
48 | @todo
|
---|
49 | - maybe the StateClient can be abondoned, this way it would be possible
|
---|
50 | to subscribe to only available MESSAGE and STATE services
|
---|
51 |
|
---|
52 | **/
|
---|
53 | // **************************************************************************
|
---|
54 | #include "DimServiceInfoList.h"
|
---|
55 | #include "DimErrorRedirecter.h"
|
---|
56 |
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 | class DimNetwork : public MessageImp, public DimErrorRedirecter, public DimServiceInfoList
|
---|
60 | {
|
---|
61 | private:
|
---|
62 | void DeleteClientList();
|
---|
63 |
|
---|
64 | protected:
|
---|
65 | typedef std::map<const std::string, StateClient*> ClientList;
|
---|
66 |
|
---|
67 | ClientList fClientList; /// A list with all MESSAGE services to which we subscribed
|
---|
68 |
|
---|
69 | void AddServer(const std::string &s);
|
---|
70 | void RemoveServer(const std::string &s);
|
---|
71 | void RemoveAllServers();
|
---|
72 |
|
---|
73 | public:
|
---|
74 | DimNetwork(std::ostream &out=std::cout)
|
---|
75 | : MessageImp(out), DimErrorRedirecter(static_cast<MessageImp&>(*this))
|
---|
76 | {
|
---|
77 | }
|
---|
78 | ~DimNetwork()
|
---|
79 | {
|
---|
80 | DeleteClientList();
|
---|
81 | }
|
---|
82 |
|
---|
83 | int GetCurrentState(const string &server) const;
|
---|
84 | };
|
---|
85 |
|
---|
86 |
|
---|
87 | #endif
|
---|