IBR-DTNSuite 0.6

daemon/src/core/Node.h

Go to the documentation of this file.
00001 
00002 #ifndef IBRDTN_DAEMON_NODE_H_
00003 #define IBRDTN_DAEMON_NODE_H_
00004 
00005 #include <string>
00006 #include <ibrdtn/data/EID.h>
00007 #include <set>
00008 #include <list>
00009 #include <iostream>
00010 
00011 namespace dtn
00012 {
00013         namespace net
00014         {
00015                 class ConvergenceLayer;
00016         }
00017 
00018         namespace core
00019         {
00023                 class Node
00024                 {
00025                 public:
00026                         enum Protocol
00027                         {
00028                                 CONN_UNSUPPORTED = -1,
00029                                 CONN_UNDEFINED = 0,
00030                                 CONN_TCPIP = 1,
00031                                 CONN_UDPIP = 2,
00032                                 CONN_LOWPAN = 3,
00033                                 CONN_BLUETOOTH = 4,
00034                                 CONN_HTTP = 5
00035                         };
00036 
00042                         enum Type
00043                         {
00044                                 NODE_UNAVAILABLE = 0,
00045                                 NODE_CONNECTED = 1,
00046                                 NODE_DISCOVERED = 2,
00047                                 NODE_STATIC = 3
00048                         };
00049 
00050                         class URI
00051                         {
00052                         public:
00053                                 URI(const Type t, const Protocol proto, const std::string &uri, const size_t timeout = 0);
00054                                 ~URI();
00055 
00056                                 const Type type;
00057                                 const Protocol protocol;
00058                                 const std::string value;
00059                                 const size_t expire;
00060 
00061                                 void decode(std::string &address, unsigned int &port) const;
00062 
00063                                 bool operator<(const URI &other) const;
00064                                 bool operator==(const URI &other) const;
00065 
00066                                 bool operator==(const Node::Protocol &p) const;
00067                                 bool operator==(const Node::Type &t) const;
00068 
00069                                 friend std::ostream& operator<<(std::ostream&, const Node::URI&);
00070                         };
00071 
00072                         class Attribute
00073                         {
00074                         public:
00075                                 Attribute(const Type t, const std::string &name, const std::string &value, const size_t timeout = 0);
00076                                 ~Attribute();
00077 
00078                                 const Type type;
00079                                 const std::string name;
00080                                 const std::string value;
00081                                 const size_t expire;
00082 
00083                                 bool operator<(const Attribute &other) const;
00084                                 bool operator==(const Attribute &other) const;
00085 
00086                                 bool operator==(const std::string &name) const;
00087 
00088                                 friend std::ostream& operator<<(std::ostream&, const Node::Attribute&);
00089                         };
00090 
00091                         static std::string toString(Node::Type type);
00092                         static std::string toString(Node::Protocol proto);
00093 
00099                         Node(const dtn::data::EID &id);
00100 
00104                         virtual ~Node();
00105 
00111                         bool has(Node::Protocol proto) const;
00112                         bool has(const std::string &name) const;
00113 
00118                         void add(const URI &u);
00119                         void add(const Attribute &attr);
00120 
00125                         void remove(const URI &u);
00126                         void remove(const Attribute &attr);
00127 
00131                         void clear();
00132 
00138                         std::list<URI> get(Node::Protocol proto) const;
00139                         std::list<URI> get(Node::Type type, Node::Protocol proto) const;
00140 
00146                         std::list<Attribute> get(const std::string &name) const;
00147 
00152                         const dtn::data::EID& getEID() const;
00153 
00157                         bool expire();
00158 
00165                         bool operator==(const Node &other) const;
00166                         bool operator<(const Node &other) const;
00167 
00168                         bool operator==(const dtn::data::EID &other) const;
00169 
00170                         const Node& operator+=(const Node &other);
00171                         const Node& operator-=(const Node &other);
00172 
00173                         std::string toString() const;
00174 
00175                         bool doConnectImmediately() const;
00176                         void setConnectImmediately(bool val);
00177 
00181                         bool isAvailable() const;
00182 
00183                         friend std::ostream& operator<<(std::ostream&, const Node&);
00184 
00185                 private:
00186                         bool _connect_immediately;
00187                         dtn::data::EID _id;
00188 
00189                         std::set<URI> _uri_list;
00190                         std::set<Attribute> _attr_list;
00191                 };
00192         }
00193 }
00194 
00195 #endif /*IBRDTN_DAEMON_NODE_H_*/