source: trunk/FACT++/src/DimNetwork.h@ 11439

Last change on this file since 11439 was 10481, checked in by tbretz, 13 years ago
Used DimInfo by mistake instead of DimStampedInfo.
File size: 2.5 KB
Line 
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
9This is a simple dim client which subscribes to the MESSAGE and STATE
10service of a server. It stores the last state and its time as well as
11the last message sent.
12
13**/
14// **************************************************************************
15#include "MessageDim.h"
16#include "Time.h"
17
18class StateClient : public MessageDimRX
19{
20private:
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
26protected:
27 void infoHandler();
28
29public:
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
45This class derives from DimServiceInfoList, so that it has a full
46overview of all commands and services existing in the current Dim
47network. In addition it automatically subscribes to all available
48MESSAGE 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
59using namespace std;
60
61class DimNetwork : public MessageImp, public DimErrorRedirecter, public DimServiceInfoList
62{
63private:
64 void DeleteClientList();
65
66protected:
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(const std::string &s);
73 void RemoveAllServers();
74
75public:
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
Note: See TracBrowser for help on using the repository browser.