|
IBR-DTNSuite 0.6
|
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 00015 using namespace dtn::data; 00016 00017 namespace dtn 00018 { 00019 namespace core 00020 { 00021 class AbstractWorker : public ibrcommon::Mutex 00022 { 00023 class AbstractWorkerAsync : public ibrcommon::JoinableThread, public dtn::core::EventReceiver 00024 { 00025 public: 00026 AbstractWorkerAsync(AbstractWorker &worker); 00027 virtual ~AbstractWorkerAsync(); 00028 void shutdown(); 00029 00030 virtual void raiseEvent(const dtn::core::Event *evt); 00031 00032 protected: 00033 void run(); 00034 bool __cancellation(); 00035 00036 private: 00037 void prepareBundle(dtn::data::Bundle &bundle) const; 00038 00039 AbstractWorker &_worker; 00040 bool _running; 00041 00042 ibrcommon::Queue<dtn::data::BundleID> _receive_bundles; 00043 }; 00044 00045 public: 00046 AbstractWorker(); 00047 00048 virtual ~AbstractWorker(); 00049 00050 virtual const EID getWorkerURI() const; 00051 00052 virtual void callbackBundleReceived(const Bundle &b) = 0; 00053 00054 protected: 00055 void initialize(const string uri, bool async = false); 00056 void transmit(const Bundle &bundle); 00057 00058 EID _eid; 00059 00060 void shutdown(); 00061 00062 private: 00063 AbstractWorkerAsync _thread; 00064 }; 00065 } 00066 } 00067 00068 #endif /*ABSTRACTWORKER_H_*/