IBR-DTNSuite  0.8
daemon/src/api/ExtendedApiHandler.h
Go to the documentation of this file.
00001 /*
00002  * ExtendedApiHandler.h
00003  *
00004  *  Created on: 10.10.2011
00005  *      Author: morgenro,roettger
00006  */
00007 
00008 #ifndef EXTENDEDAPIHANDLER_H_
00009 #define EXTENDEDAPIHANDLER_H_
00010 
00011 #include "api/Registration.h"
00012 #include "core/Node.h"
00013 #include "api/ClientHandler.h"
00014 
00015 #include <ibrdtn/data/Bundle.h>
00016 #include <ibrcommon/thread/Thread.h>
00017 #include <ibrcommon/thread/Queue.h>
00018 #include <ibrcommon/net/tcpstream.h>
00019 
00020 
00021 namespace dtn
00022 {
00023         namespace api
00024         {
00025                 class ExtendedApiHandler : public ProtocolHandler
00026                 {
00027                 public:
00028                         enum STATUS_CODES
00029                         {
00030                                 API_STATUS_NOTIFY_COMMON = 600,
00031                                 API_STATUS_NOTIFY_NEIGHBOR = 601,
00032                                 API_STATUS_NOTIFY_BUNDLE = 602
00033                         };
00034 
00035                         ExtendedApiHandler(ClientHandler &client, ibrcommon::tcpstream &stream);
00036                         virtual ~ExtendedApiHandler();
00037 
00038                         virtual void run();
00039                         virtual void finally();
00040                         virtual void __cancellation();
00041 
00042                         bool good() const;
00043 
00044 //                      void eventNodeAvailable(const dtn::core::Node &node);
00045 //                      void eventNodeUnavailable(const dtn::core::Node &node);
00046 
00047                 private:
00048                         class Sender : public ibrcommon::JoinableThread
00049                         {
00050                         public:
00051                                 Sender(ExtendedApiHandler &conn);
00052                                 virtual ~Sender();
00053 
00054                         protected:
00055                                 void run();
00056                                 void finally();
00057                                 void __cancellation();
00058 
00059                         private:
00060                                 ExtendedApiHandler &_handler;
00061                         } *_sender;
00062 
00063                         static void sayBundleID(ostream &stream, const dtn::data::BundleID &id);
00064                         static dtn::data::BundleID readBundleID(const std::vector<std::string>&, const size_t start);
00065 
00066                         void processIncomingBundle(dtn::data::Bundle &b);
00067 
00068                         ibrcommon::Mutex _write_lock;
00069 
00070                         dtn::data::Bundle _bundle_reg;
00071 
00072                         dtn::data::EID _endpoint;
00073                         ibrcommon::Queue<dtn::data::BundleID> _bundle_queue;
00074                 };
00075         }
00076 }
00077 
00078 #endif /* EXTENDEDAPICONNECTION_H_ */