ANNA Suite  2020b
Multipurpose development suite for Telco applications
Server.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_comm_Server_hpp
10 #define anna_comm_Server_hpp
11 
12 #include <vector>
13 #include <algorithm>
14 
15 #include <anna/config/defines.hpp>
16 
17 #include <anna/comm/Resource.hpp>
18 
19 namespace anna {
20 
21 namespace xml {
22 class Node;
23 }
24 
25 namespace comm {
26 
27 class Host;
28 class TransportFactory;
29 class Service;
30 class Message;
31 class INetAddress;
32 class ClientSocket;
33 class ServerAllocator;
34 class ReceiverFactory;
35 
53 class Server : public Resource {
54 public:
55  typedef std::vector <Service*> Services;
56  typedef Services::iterator iterator;
57  typedef Services::const_iterator const_iterator;
58 
62  virtual ~Server();
63 
68  const Host* getHost() const { return &a_host; }
69 
74  const ClientSocket* getClientSocket() const { return a_clientSocket; }
75 
80  int getRemotePort() const { return a_remotePort; }
81 
87  bool autoRecovery() const { return a_autoRecovery; }
88 
94  void setAutoRecovery(bool autoRecovery = true) ;
95 
104  bool isAvailable() const noexcept(false);
105 
110  TransportFactory* getTransportFactory() { return a_transportFactory; }
111 
118  const Millisecond &getMaxConnectionDelay() const { return a_msMaxConnectionDelay; }
119 
126  const Millisecond &getMaxWriteDelay() const { return a_msMaxWriteDelay; }
127 
132  ReceiverFactory* getReceiverFactory() { return a_receiverFactory; }
133 
139  void setMaxConnectionDelay(const Millisecond &msMaxConnectionDelay)
140  {
141  a_msMaxConnectionDelay = msMaxConnectionDelay;
142  }
143 
150  void setMaxWriteDelay(const Millisecond &msMaxWriteDelay) { a_msMaxWriteDelay = msMaxWriteDelay; }
151 
157  void setReceiverFactory(ReceiverFactory& receiverFactory) ;
158 
163  bool getIgnoreIncomingMessages() const { return a_ignoreIncomingMessages; }
164 
169  void setIgnoreIncomingMessages(const bool ignoreIncomingMessages) { a_ignoreIncomingMessages = ignoreIncomingMessages; }
170 
176  void attach(Service* service)
177  noexcept(false) {
178  if(std::find(begin(), end(), service) == end())
179  a_services.push_back(service);
180  }
181 
186  void connect() noexcept(false);
187 
196  ClientSocket* send(Message& message) noexcept(false);
197 
206  ClientSocket* send(Message* message) noexcept(false);
207 
212  void reset() noexcept(false);
213 
218  const_iterator begin() const { return a_services.begin(); }
219 
224  const_iterator end() const { return a_services.end(); }
225 
230  iterator begin() { return a_services.begin(); }
231 
236  iterator end() { return a_services.end(); }
237 
242  std::string asString() const ;
243 
249  xml::Node* asXML(xml::Node* parent) const noexcept(false);
250 
257  static Service* service(iterator& ii) { return *ii; }
258 
265  static const Service* service(const_iterator& ii) { return *ii; }
266 
271  static const char* className() { return "anna::comm::Server"; }
272 
273 protected:
285  Server(const std::string& name, const Host& host, const int remotePort, const bool autoRecovery, TransportFactory* transportFactory);
286 
287 private:
288  const Host& a_host;
289  const int a_remotePort;
290  const bool a_autoRecovery;
291  Services a_services;
292  TransportFactory* a_transportFactory;
293  ClientSocket* a_clientSocket;
294  Millisecond a_msMaxConnectionDelay;
295  Millisecond a_msMaxWriteDelay;
296  ReceiverFactory* a_receiverFactory;
297  bool a_ignoreIncomingMessages;
298  int a_sequence;
299 
300  virtual ClientSocket* allocateClientSocket(const INetAddress&, TransportFactory*) const ;
301 
302  friend class Host;
303  friend class ServerAllocator;
304 };
305 
306 }
307 }
308 
309 #endif
Definition: INetAddress.hpp:34
std::vector< Service * > Services
Definition: Server.hpp:55
iterator end()
Definition: Server.hpp:236
int getRemotePort() const
Definition: Server.hpp:80
Definition: Millisecond.hpp:24
const_iterator end() const
Definition: Server.hpp:224
static Service * service(iterator &ii)
Definition: Server.hpp:257
TransportFactory * getTransportFactory()
Definition: Server.hpp:110
Definition: Server.hpp:53
ReceiverFactory * getReceiverFactory()
Definition: Server.hpp:132
Definition: Node.hpp:56
Services::const_iterator const_iterator
Definition: Server.hpp:57
const_iterator begin() const
Definition: Server.hpp:218
Definition: ServerAllocator.hpp:29
static const char * className()
Definition: Server.hpp:271
Definition: ClientSocket.hpp:38
void setIgnoreIncomingMessages(const bool ignoreIncomingMessages)
Definition: Server.hpp:169
Definition: Host.hpp:46
Services::iterator iterator
Definition: Server.hpp:56
iterator begin()
Definition: Server.hpp:230
const Millisecond & getMaxWriteDelay() const
Definition: Server.hpp:126
Definition: Message.hpp:26
static const Service * service(const_iterator &ii)
Definition: Server.hpp:265
const ClientSocket * getClientSocket() const
Definition: Server.hpp:74
xml::Node Node
Definition: Node.hpp:21
Definition: ReceiverFactory.hpp:53
void attach(Service *service) noexcept(false)
Definition: Server.hpp:176
const Millisecond & getMaxConnectionDelay() const
Definition: Server.hpp:118
Definition: Resource.hpp:25
Definition: app.hpp:12
void setMaxWriteDelay(const Millisecond &msMaxWriteDelay)
Definition: Server.hpp:150
const Host * getHost() const
Definition: Server.hpp:68
Definition: TransportFactory.hpp:30
bool autoRecovery() const
Definition: Server.hpp:87
void setMaxConnectionDelay(const Millisecond &msMaxConnectionDelay)
Definition: Server.hpp:139
bool getIgnoreIncomingMessages() const
Definition: Server.hpp:163
Definition: Service.hpp:28