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 addConvergenceLayer(ConvergenceLayer *cl);
00049 
00050                         void queue(const dtn::data::EID &eid, const dtn::data::BundleID &b);
00051 
00055                         void raiseEvent(const dtn::core::Event *evt);
00056 
00057                         class ShutdownException : public ibrcommon::Exception
00058                         {
00059                         public:
00060                                 ShutdownException(string what = "System shutdown") throw() : ibrcommon::Exception(what)
00061                                 {
00062                                 };
00063                         };
00064 
00065                         void open(const dtn::core::Node &node);
00066 
00067                         void queue(const ConvergenceLayer::Job &job);
00068 
00073                         const std::set<dtn::core::Node> getNeighbors();
00074 
00080                         bool isNeighbor(const dtn::core::Node&);
00081 
00085                         virtual const std::string getName() const;
00086 
00087                 protected:
00092                         void discovered(const dtn::core::Node &node);
00093 
00097                         void check_discovered();
00098 
00099                         virtual void componentUp();
00100                         virtual void componentDown();
00101 
00102                 private:
00106                         void queue(const dtn::core::Node &node, const ConvergenceLayer::Job &job);
00107 
00108                         // if set to true, this module will shutdown
00109                         bool _shutdown;
00110 
00111                         // mutex for the list of convergence layers
00112                         ibrcommon::Mutex _cl_lock;
00113 
00114                         // contains all configured convergence layers
00115                         std::set<ConvergenceLayer*> _cl;
00116 
00117                         // mutex for the lists of nodes
00118                         ibrcommon::Mutex _node_lock;
00119 
00120                         // contains all static configured nodes
00121                         std::set<dtn::core::Node> _static_nodes;
00122 
00123                         // contains all dynamic discovered nodes
00124                         std::set<dtn::core::Node> _discovered_nodes;
00125 
00126                         // contains all connected nodes
00127                         std::set<dtn::core::Node> _connected_nodes;
00128                 };
00129         }
00130 }
00131 
00132 #endif /* CONNECTIONMANAGER_H_ */