IBR-DTN  1.0.0
DiscoveryAgent.h
Go to the documentation of this file.
1 /*
2  * DiscoveryAgent.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 DISCOVERYAGENT_H_
23 #define DISCOVERYAGENT_H_
24 
25 #include "Configuration.h"
26 #include "Component.h"
27 #include "core/EventReceiver.h"
28 #include "core/Node.h"
29 #include "core/TimeEvent.h"
30 #include "core/GlobalEvent.h"
31 #include "net/DiscoveryBeacon.h"
33 #include "net/DiscoveryService.h"
34 
35 #include <ibrdtn/data/Number.h>
36 #include <ibrcommon/net/vinterface.h>
37 
38 #include <list>
39 
40 namespace dtn
41 {
42  namespace net
43  {
44  class DiscoveryAgent : public dtn::core::EventReceiver<dtn::core::TimeEvent>, public dtn::core::EventReceiver<dtn::core::GlobalEvent>, public dtn::daemon::IntegratedComponent
45  {
46  public:
48  virtual ~DiscoveryAgent();
49 
53  void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
54  void raiseEvent(const dtn::core::GlobalEvent &evt) throw ();
55 
56  void onBeaconReceived(const DiscoveryBeacon &beacon);
57 
58  void registerService(const ibrcommon::vinterface &iface, dtn::net::DiscoveryBeaconHandler *handler);
60 
61  void unregisterService(const ibrcommon::vinterface &iface, const dtn::net::DiscoveryBeaconHandler *handler);
63 
65 
66  protected:
67  virtual void componentUp() throw ();
68  virtual void componentDown() throw ();
69 
70  virtual const std::string getName() const;
71 
72  private:
73  void onAdvertise();
74 
76 
77  bool _enabled;
78  uint16_t _sn;
79  dtn::data::Timestamp _adv_next;
80  unsigned int _beacon_period;
81 
82  ibrcommon::Mutex _provider_lock;
83 
84  typedef std::list<dtn::net::DiscoveryBeaconHandler*> handler_list;
85  typedef std::map<ibrcommon::vinterface, handler_list> handler_map;
86  typedef std::pair<ibrcommon::vinterface, handler_list> handler_map_entry;
87 
88  handler_map _providers;
89 
90  const ibrcommon::vinterface _any_iface;
91  };
92  }
93 }
94 
95 #endif /* DISCOVERYAGENT_H_ */
DiscoveryBeacon obtainBeacon() const
void raiseEvent(const dtn::core::TimeEvent &evt)
void unregisterService(const ibrcommon::vinterface &iface, const dtn::net::DiscoveryBeaconHandler *handler)
virtual void componentDown()
virtual const std::string getName() const
void onBeaconReceived(const DiscoveryBeacon &beacon)
void registerService(const ibrcommon::vinterface &iface, dtn::net::DiscoveryBeaconHandler *handler)