00001 /* 00002 * NetLinkManager.h 00003 * 00004 * Created on: 21.12.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef NETLINKMANAGER_H_ 00009 #define NETLINKMANAGER_H_ 00010 00011 #include "ibrcommon/net/LinkManager.h" 00012 #include "ibrcommon/net/vsocket.h" 00013 #include "ibrcommon/net/vinterface.h" 00014 #include "ibrcommon/thread/Mutex.h" 00015 #include "ibrcommon/thread/Conditional.h" 00016 #include "ibrcommon/thread/Thread.h" 00017 00018 //#include <netinet/in.h> 00019 #include <netlink/netlink.h> 00020 #include <netlink/attr.h> 00021 00022 #include <map> 00023 #include <set> 00024 00025 namespace ibrcommon 00026 { 00027 class NetLinkManager : public ibrcommon::LinkManager, public ibrcommon::JoinableThread 00028 { 00029 friend class LinkManager; 00030 00031 public: 00032 virtual ~NetLinkManager(); 00033 00034 const std::string getInterface(int index) const; 00035 const std::list<vaddress> getAddressList(const vinterface &iface, const vaddress::Family f); 00036 00037 void registerInterfaceEvent(const vinterface &iface, LinkManager::EventCallback*); 00038 void unregisterInterfaceEvent(const vinterface &iface, LinkManager::EventCallback*); 00039 void unregisterAllEvents(LinkManager::EventCallback *cb); 00040 00041 protected: 00042 void run(); 00043 bool __cancellation(); 00044 00045 private: 00046 NetLinkManager(); 00047 00048 class parse_exception : public Exception 00049 { 00050 public: 00051 parse_exception(string error) : Exception(error) 00052 {}; 00053 }; 00054 00055 std::map<int, std::string> read_nlmsg(int fd); 00056 00057 ibrcommon::Mutex _call_mutex; 00058 00059 struct nl_handle *_handle; 00060 struct nl_cache *_link_cache; 00061 struct nl_cache *_addr_cache; 00062 00063 bool _initialized; 00064 ibrcommon::vsocket *_sock; 00065 00066 ibrcommon::Mutex _listener_mutex; 00067 std::map<vinterface, std::set<LinkManager::EventCallback* > > _listener; 00068 }; 00069 } 00070 00071 #endif /* NETLINKMANAGER_H_ */
1.7.1