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

Last change on this file since 10413 was 10396, checked in by tbretz, 14 years ago
File size: 2.4 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
36
37
38// **************************************************************************
39/** @class DimNetwork
40
41@brief Implements automatic subscription to MESSAGE and STATE services
42
43This class derives from DimServiceInfoList, so that it has a full
44overview of all commands and services existing in the current Dim
45network. In addition it automatically subscribes to all available
46MESSAGE 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
57using namespace std;
58
59class DimNetwork : public MessageImp, public DimErrorRedirecter, public DimServiceInfoList
60{
61private:
62 void DeleteClientList();
63
64protected:
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
73public:
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
Note: See TracBrowser for help on using the repository browser.