IBR-DTNSuite  0.8
daemon/src/core/AbstractWorker.h
Go to the documentation of this file.
00001 #ifndef ABSTRACTWORKER_H_
00002 #define ABSTRACTWORKER_H_
00003 
00004 #include <ibrdtn/data/Bundle.h>
00005 #include <ibrdtn/data/BundleID.h>
00006 #include <ibrdtn/data/EID.h>
00007 #include "core/EventReceiver.h"
00008 #include <ibrcommon/thread/Mutex.h>
00009 #include <ibrcommon/thread/Conditional.h>
00010 #include <ibrcommon/thread/Thread.h>
00011 #include "net/ConvergenceLayer.h"
00012 
00013 #include <ibrcommon/thread/Queue.h>
00014 #include <set>
00015 
00016 using namespace dtn::data;
00017 
00018 namespace dtn
00019 {
00020         namespace core
00021         {
00022                 class AbstractWorker : public ibrcommon::Mutex
00023                 {
00024                         class AbstractWorkerAsync : public ibrcommon::JoinableThread, public dtn::core::EventReceiver
00025                         {
00026                         public:
00027                                 AbstractWorkerAsync(AbstractWorker &worker);
00028                                 virtual ~AbstractWorkerAsync();
00029                                 void shutdown();
00030 
00031                                 virtual void raiseEvent(const dtn::core::Event *evt);
00032 
00033                         protected:
00034                                 void run();
00035                                 void __cancellation();
00036 
00037                         private:
00038                                 void prepareBundle(dtn::data::Bundle &bundle) const;
00039 
00040                                 AbstractWorker &_worker;
00041                                 bool _running;
00042 
00043                                 ibrcommon::Queue<dtn::data::BundleID> _receive_bundles;
00044                         };
00045 
00046                         public:
00047                                 AbstractWorker();
00048 
00049                                 virtual ~AbstractWorker();
00050 
00051                                 virtual const EID getWorkerURI() const;
00052 
00053                                 virtual void callbackBundleReceived(const Bundle &b) = 0;
00054 
00055                         protected:
00056                                 void initialize(const string uri, const size_t cbhe, bool async);
00057                                 void transmit(const Bundle &bundle);
00058 
00059                                 EID _eid;
00060 
00061                                 void shutdown();
00062 
00066                                 void subscribe(const dtn::data::EID &endpoint);
00067 
00071                                 void unsubscribe(const dtn::data::EID &endpoint);
00072 
00073                         private:
00074                                 AbstractWorkerAsync _thread;
00075                                 std::set<dtn::data::EID> _groups;
00076                 };
00077         }
00078 }
00079 
00080 #endif /*ABSTRACTWORKER_H_*/