• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/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 "ClientHandler.h"
00013 #include "ibrcommon/net/tcpserver.h"
00014 #include "ibrcommon/net/NetInterface.h"
00015 #include <ibrdtn/data/MetaBundle.h>
00016 #include <ibrcommon/thread/Queue.h>
00017 
00018 #include <queue>
00019 #include <list>
00020 
00021 namespace dtn
00022 {
00023         namespace daemon
00024         {
00025                 class ApiServer : public dtn::daemon::IndependentComponent, public ApiServerInterface
00026                 {
00027                 public:
00028                         ApiServer(const ibrcommon::File &socket);
00029                         ApiServer(ibrcommon::NetInterface net, int port = 4550);
00030                         virtual ~ApiServer();
00031 
00035                         virtual const std::string getName() const;
00036 
00037                 protected:
00038                         bool __cancellation();
00039                         void shutdown();
00040 
00041                         virtual void connectionUp(ClientHandler *conn);
00042                         virtual void connectionDown(ClientHandler *conn);
00043 
00044                         void componentUp();
00045                         void componentRun();
00046                         void componentDown();
00047 
00048                 private:
00049                         class Task
00050                         {
00051                         public:
00052                                 virtual ~Task() {};
00053                         };
00054 
00055                         class ProcessBundleTask : public Task
00056                         {
00057                         public:
00058                                 ProcessBundleTask(const dtn::data::MetaBundle&);
00059                                 ~ProcessBundleTask();
00060                                 const dtn::data::MetaBundle bundle;
00061                         };
00062 
00063                         class TransferBundleTask : public Task
00064                         {
00065                         public:
00066                                 TransferBundleTask(const dtn::data::BundleID&, const size_t id);
00067                                 ~TransferBundleTask();
00068                                 const dtn::data::BundleID bundle;
00069                                 const size_t id;
00070                         };
00071 
00072                         class QueryBundleTask : public Task
00073                         {
00074                         public:
00075                                 QueryBundleTask(const size_t id);
00076                                 ~QueryBundleTask();
00077                                 const size_t id;
00078                         };
00079 
00080                         class RemoveBundleTask : public Task
00081                         {
00082                         public:
00083                                 RemoveBundleTask(const dtn::data::BundleID&);
00084                                 ~RemoveBundleTask();
00085                                 const dtn::data::BundleID bundle;
00086                         };
00087 
00088                         class Distributor : public ibrcommon::JoinableThread, public dtn::core::EventReceiver
00089                         {
00090                         public:
00091                                 Distributor();
00092                                 ~Distributor();
00093 
00094                                 void add(ClientHandler *obj);
00095                                 void remove(ClientHandler *obj);
00096                                 void shutdown();
00097 
00101                                 void raiseEvent(const dtn::core::Event *evt);
00102 
00103                                 ibrcommon::Mutex _lock;
00104                                 std::list<ClientHandler*> _connections;
00105 
00106                         protected:
00110                                 void run();
00111 
00112                                 bool __cancellation();
00113 
00114                                 ibrcommon::Queue<ApiServer::Task*> _tasks;
00115                         };
00116 
00117                         ibrcommon::tcpserver _tcpsrv;
00118                         Distributor _dist;
00119 
00120                         size_t _next_connection_id;
00121                 };
00122         }
00123 }
00124 
00125 #endif /* APISERVER_H_ */

Generated on Thu Nov 11 2010 09:49:46 for IBR-DTNSuite by  doxygen 1.7.1