IBR-DTNSuite  0.12
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 
51  void initialize();
52  void shutdown();
53 
54  virtual void raiseEvent(const dtn::core::Event *evt) throw ();
55 
56  protected:
57  void run() throw ();
58  void __cancellation() throw ();
59 
60  private:
61  void prepareBundle(dtn::data::Bundle &bundle) const;
62 
63  AbstractWorker &_worker;
64  bool _running;
65 
67  };
68 
69  public:
71 
72  virtual ~AbstractWorker();
73 
74  virtual const EID getWorkerURI() const;
75 
76  virtual void callbackBundleReceived(const Bundle &b) = 0;
77 
78  protected:
79  void initialize(const std::string &uri);
80  void transmit(const Bundle &bundle);
81 
83 
84  void shutdown();
85 
89  void subscribe(const dtn::data::EID &endpoint);
90 
94  void unsubscribe(const dtn::data::EID &endpoint);
95 
96  private:
97  AbstractWorkerAsync _thread;
98  std::set<dtn::data::EID> _groups;
99  };
100  }
101 }
102 
103 #endif /*ABSTRACTWORKER_H_*/