IBR-DTNSuite 0.6

daemon/src/net/ConnectionManager.h

Go to the documentation of this file.
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&) const;
00083 
00087                         virtual const std::string getName() const;
00088 
00089                 protected:
00094                         void discovered(const dtn::core::Node &node);
00095 
00096                         virtual void componentUp();
00097                         virtual void componentDown();
00098 
00099                 private:
00103                         void queue(const dtn::core::Node &node, const ConvergenceLayer::Job &job);
00104 
00108                         void check_unavailable();
00109 
00113                         void check_autoconnect();
00114 
00118                         dtn::core::Node& getNode(const dtn::data::EID &eid);
00119 
00120                         // if set to true, this module will shutdown
00121                         bool _shutdown;
00122 
00123                         // mutex for the list of convergence layers
00124                         ibrcommon::Mutex _cl_lock;
00125 
00126                         // contains all configured convergence layers
00127                         std::set<ConvergenceLayer*> _cl;
00128 
00129                         // mutex for the lists of nodes
00130                         ibrcommon::Mutex _node_lock;
00131 
00132                         // contains all nodes
00133                         std::list<dtn::core::Node> _nodes;
00134 
00135                         // next timestamp for autoconnect check
00136                         size_t _next_autoconnect;
00137                 };
00138         }
00139 }
00140 
00141 #endif /* CONNECTIONMANAGER_H_ */