IBR-DTNSuite  0.8
daemon/src/api/ApiServer.h
Go to the documentation of this file.
00001 /*
00002  * ApiServer.h
00003  *
00004  *  Created on: 24.06.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef APISERVER_H_
00009 #define APISERVER_H_
00010 
00011 #include "Component.h"
00012 #include "api/Registration.h"
00013 #include "api/ClientHandler.h"
00014 #include "core/EventReceiver.h"
00015 #include <ibrcommon/net/vinterface.h>
00016 #include <ibrcommon/net/tcpserver.h>
00017 #include <ibrcommon/thread/Mutex.h>
00018 #include <ibrcommon/thread/Timer.h>
00019 
00020 #include <set>
00021 #include <list>
00022 
00023 namespace dtn
00024 {
00025         namespace api
00026         {
00027                 class ApiServer : public dtn::daemon::IndependentComponent, public dtn::core::EventReceiver, public ApiServerInterface, public ibrcommon::TimerCallback
00028                 {
00029                 public:
00030                         ApiServer(const ibrcommon::File &socket);
00031                         ApiServer(const ibrcommon::vinterface &net, int port = 4550);
00032                         virtual ~ApiServer();
00033 
00037                         virtual const std::string getName() const;
00038 
00039                         void freeRegistration(Registration &reg);
00040 
00041                         void raiseEvent(const dtn::core::Event *evt);
00042 
00043                         void processIncomingBundle(const dtn::data::EID &source, dtn::data::Bundle &bundle);
00044 
00053                         Registration& getRegistration(const std::string &handle);
00054 
00061                         virtual size_t timeout(ibrcommon::Timer*);
00062 
00063                 protected:
00064                         void __cancellation();
00065 
00066                         virtual void connectionUp(ClientHandler *conn);
00067                         virtual void connectionDown(ClientHandler *conn);
00068 
00069                         void componentUp();
00070                         void componentRun();
00071                         void componentDown();
00072 
00073                 private:
00074 
00078                         void startGarbageCollector();
00084                         size_t nextRegistrationExpiry();
00085 
00086                         ibrcommon::tcpserver _srv;
00087                         bool _shutdown;
00088                         std::list<Registration> _registrations;
00089                         std::list<ClientHandler*> _connections;
00090                         ibrcommon::Mutex _connection_lock;
00091                         ibrcommon::Mutex _registration_lock;
00092                         ibrcommon::Timer _garbage_collector;
00093                 };
00094         }
00095 }
00096 
00097 #endif /* APISERVER_H_ */