IBR-DTNSuite  0.10
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"
29 #include <ibrcommon/thread/Mutex.h>
32 #include "net/ConvergenceLayer.h"
33 
34 #include <ibrcommon/thread/Queue.h>
35 #include <set>
36 
37 using namespace dtn::data;
38 
39 namespace dtn
40 {
41  namespace core
42  {
44  {
45  class AbstractWorkerAsync : public ibrcommon::JoinableThread, public dtn::core::EventReceiver
46  {
47  public:
48  AbstractWorkerAsync(AbstractWorker &worker);
49  virtual ~AbstractWorkerAsync();
50  void shutdown();
51 
52  virtual void raiseEvent(const dtn::core::Event *evt) throw ();
53 
54  protected:
55  void run() throw ();
56  void __cancellation() throw ();
57 
58  private:
59  void prepareBundle(dtn::data::Bundle &bundle) const;
60 
61  AbstractWorker &_worker;
62  bool _running;
63 
65  };
66 
67  public:
69 
70  virtual ~AbstractWorker();
71 
72  virtual const EID getWorkerURI() const;
73 
74  virtual void callbackBundleReceived(const Bundle &b) = 0;
75 
76  protected:
77  void initialize(const std::string &uri, const dtn::data::Number &cbhe, bool async);
78  void transmit(const Bundle &bundle);
79 
81 
82  void shutdown();
83 
87  void subscribe(const dtn::data::EID &endpoint);
88 
92  void unsubscribe(const dtn::data::EID &endpoint);
93 
94  private:
95  AbstractWorkerAsync _thread;
96  std::set<dtn::data::EID> _groups;
97  };
98  }
99 }
100 
101 #endif /*ABSTRACTWORKER_H_*/