IBR-DTN  1.0.0
ApiServer.h
Go to the documentation of this file.
1 /*
2  * ApiServer.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef APISERVER_H_
23 #define APISERVER_H_
24 
25 #include "Component.h"
26 #include "api/Registration.h"
27 #include "api/ClientHandler.h"
28 #include "core/EventReceiver.h"
29 #include "storage/BundleSeeker.h"
31 #include <ibrcommon/net/vinterface.h>
32 #include <ibrcommon/net/socket.h>
33 #include <ibrcommon/thread/Mutex.h>
34 #include <ibrcommon/thread/Timer.h>
35 
36 #include <set>
37 #include <list>
38 
39 namespace dtn
40 {
41  namespace api
42  {
43  class ApiServer : public dtn::daemon::IndependentComponent, public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>, public ApiServerInterface, public ibrcommon::TimerCallback
44  {
45  static const std::string TAG;
46 
47  public:
48  ApiServer(const ibrcommon::File &socket);
49  ApiServer(const ibrcommon::vinterface &net, int port = 4550);
50  virtual ~ApiServer();
51 
55  virtual const std::string getName() const;
56 
57  void freeRegistration(Registration &reg);
58 
59  void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
60 
69  Registration& getRegistration(const std::string &handle);
70 
77  virtual size_t timeout(ibrcommon::Timer*);
78 
79  protected:
80  void __cancellation() throw ();
81 
82  virtual void connectionUp(ClientHandler *conn);
83  virtual void connectionDown(ClientHandler *conn);
84 
85  void componentUp() throw ();
86  void componentRun() throw ();
87  void componentDown() throw ();
88 
89  private:
90 
94  void startGarbageCollector();
100  size_t nextRegistrationExpiry();
101 
102  ibrcommon::vsocket _sockets;
103  bool _shutdown;
104 
105  typedef std::list<Registration*> registration_list;
106  registration_list _registrations;
107 
108  typedef std::list<ClientHandler*> client_list;
109  client_list _connections;
110 
111  ibrcommon::Mutex _connection_lock;
112  ibrcommon::Mutex _registration_lock;
113  ibrcommon::Timer _garbage_collector;
114  };
115  }
116 }
117 
118 #endif /* APISERVER_H_ */
virtual void connectionUp(ClientHandler *conn)
Definition: ApiServer.cpp:303
virtual const std::string getName() const
Definition: ApiServer.cpp:298
virtual void connectionDown(ClientHandler *conn)
Definition: ApiServer.cpp:309
virtual size_t timeout(ibrcommon::Timer *)
Definition: ApiServer.cpp:264
ApiServer(const ibrcommon::File &socket)
Definition: ApiServer.cpp:45
virtual ~ApiServer()
Definition: ApiServer.cpp:96
void raiseEvent(const dtn::routing::QueueBundleEvent &evt)
Definition: ApiServer.cpp:353
Registration & getRegistration(const std::string &handle)
Definition: ApiServer.cpp:244
void freeRegistration(Registration &reg)
Definition: ApiServer.cpp:327