IBR-DTN  1.0.0
AbstractWorker.h
Go to the documentation of this file.
1 /*
2  * AbstractWorker.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef ABSTRACTWORKER_H_
23 #define ABSTRACTWORKER_H_
24 
25 #include <ibrdtn/data/Bundle.h>
26 #include <ibrdtn/data/BundleID.h>
27 #include <ibrdtn/data/EID.h>
28 #include "core/EventReceiver.h"
30 #include <ibrcommon/thread/Mutex.h>
31 #include <ibrcommon/thread/Conditional.h>
32 #include <ibrcommon/thread/Thread.h>
33 #include "net/ConvergenceLayer.h"
34 
35 #include <ibrcommon/thread/Queue.h>
36 #include <set>
37 
38 using namespace dtn::data;
39 
40 namespace dtn
41 {
42  namespace core
43  {
44  class AbstractWorker : public ibrcommon::Mutex
45  {
46  class AbstractWorkerAsync : public ibrcommon::JoinableThread, public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>
47  {
48  public:
49  AbstractWorkerAsync(AbstractWorker &worker);
50  virtual ~AbstractWorkerAsync();
51 
52  void initialize();
53  void shutdown();
54 
55  virtual void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
56 
57  protected:
58  void run() throw ();
59  void __cancellation() throw ();
60 
61  private:
62  AbstractWorker &_worker;
63  bool _running;
64 
65  ibrcommon::Queue<dtn::data::BundleID> _receive_bundles;
66  };
67 
68  public:
70 
71  virtual ~AbstractWorker();
72 
73  virtual const EID getWorkerURI() const;
74 
75  virtual void callbackBundleReceived(const Bundle &b) = 0;
76 
77  protected:
78  void initialize(const std::string &uri);
79  void transmit(dtn::data::Bundle &bundle);
80 
82 
83  void shutdown();
84 
88  void subscribe(const dtn::data::EID &endpoint);
89 
93  void unsubscribe(const dtn::data::EID &endpoint);
94 
95  private:
96  AbstractWorkerAsync _thread;
97  std::set<dtn::data::EID> _groups;
98  };
99  }
100 }
101 
102 #endif /*ABSTRACTWORKER_H_*/
bool _running
Definition: dtninbox.cpp:122