IBR-DTNSuite
0.8
|
00001 /* 00002 * ConnectionManager.h 00003 * 00004 * Created on: 18.09.2009 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef CONNECTIONMANAGER_H_ 00009 #define CONNECTIONMANAGER_H_ 00010 00011 #include "Component.h" 00012 #include "net/ConvergenceLayer.h" 00013 #include "net/BundleReceiver.h" 00014 #include "core/EventReceiver.h" 00015 #include <ibrdtn/data/EID.h> 00016 #include "core/Node.h" 00017 #include <ibrcommon/Exceptions.h> 00018 00019 #include <set> 00020 00021 namespace dtn 00022 { 00023 namespace net 00024 { 00025 class NeighborNotAvailableException : public ibrcommon::Exception 00026 { 00027 public: 00028 NeighborNotAvailableException(string what = "The requested connection is not available.") throw() : ibrcommon::Exception(what) 00029 { 00030 }; 00031 }; 00032 00033 class ConnectionNotAvailableException : public ibrcommon::Exception 00034 { 00035 public: 00036 ConnectionNotAvailableException(string what = "The requested connection is not available.") throw() : ibrcommon::Exception(what) 00037 { 00038 }; 00039 }; 00040 00041 class ConnectionManager : public dtn::core::EventReceiver, public dtn::daemon::IntegratedComponent 00042 { 00043 public: 00044 ConnectionManager(); 00045 virtual ~ConnectionManager(); 00046 00047 void addConnection(const dtn::core::Node &n); 00048 void removeConnection(const dtn::core::Node &n); 00049 00050 void addConvergenceLayer(ConvergenceLayer *cl); 00051 00052 void queue(const dtn::data::EID &eid, const dtn::data::BundleID &b); 00053 00057 void raiseEvent(const dtn::core::Event *evt); 00058 00059 class ShutdownException : public ibrcommon::Exception 00060 { 00061 public: 00062 ShutdownException(string what = "System shutdown") throw() : ibrcommon::Exception(what) 00063 { 00064 }; 00065 }; 00066 00067 void open(const dtn::core::Node &node); 00068 00069 void queue(const ConvergenceLayer::Job &job); 00070 00075 const std::set<dtn::core::Node> getNeighbors(); 00076 00082 bool isNeighbor(const dtn::core::Node&); 00083 00090 const dtn::core::Node getNeighbor(const dtn::data::EID &eid); 00091 00095 virtual const std::string getName() const; 00096 00097 protected: 00102 void discovered(const dtn::core::Node &node); 00103 00104 virtual void componentUp(); 00105 virtual void componentDown(); 00106 00107 private: 00111 void queue(const dtn::core::Node &node, const ConvergenceLayer::Job &job); 00112 00116 void check_unavailable(); 00117 00121 void check_autoconnect(); 00122 00126 dtn::core::Node& getNode(const dtn::data::EID &eid); 00127 00128 // if set to true, this module will shutdown 00129 bool _shutdown; 00130 00131 // mutex for the list of convergence layers 00132 ibrcommon::Mutex _cl_lock; 00133 00134 // contains all configured convergence layers 00135 std::set<ConvergenceLayer*> _cl; 00136 00137 // mutex for the lists of nodes 00138 ibrcommon::Mutex _node_lock; 00139 00140 // contains all nodes 00141 std::list<dtn::core::Node> _nodes; 00142 00143 // next timestamp for autoconnect check 00144 size_t _next_autoconnect; 00145 }; 00146 } 00147 } 00148 00149 #endif /* CONNECTIONMANAGER_H_ */