00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _CONTACT_MANAGER_H_
00018 #define _CONTACT_MANAGER_H_
00019
00020 #include <oasys/debug/Log.h>
00021 #include <oasys/thread/SpinLock.h>
00022 #include <oasys/thread/Timer.h>
00023 #include <oasys/util/StringBuffer.h>
00024 #include <oasys/util/StringUtils.h>
00025 #include "bundling/BundleEventHandler.h"
00026
00027 namespace dtn {
00028
00029 class Contact;
00030 class ConvergenceLayer;
00031 class CLInfo;
00032 class Link;
00033 class LinkSet;
00034
00039 class ContactManager : public BundleEventHandler {
00040 public:
00044 ContactManager();
00045 virtual ~ContactManager();
00046
00050 void dump(oasys::StringBuffer* buf) const;
00051
00052
00053
00054
00055
00056
00061 bool add_new_link(const LinkRef & link);
00062
00066 void del_link(const LinkRef& link, bool wait = false,
00067 ContactEvent::reason_t reason = ContactEvent::NO_INFO);
00068
00072 bool has_link(const LinkRef& link);
00073
00078 bool has_link(const char* name);
00079
00083 LinkRef find_link(const char* name);
00084
00096 LinkRef find_link_to(ConvergenceLayer* cl,
00097 const std::string& nexthop,
00098 const EndpointID& remote_eid = EndpointID::NULL_EID(),
00099 Link::link_type_t type = Link::LINK_INVALID,
00100 u_int states = 0xffffffff);
00101
00106 const LinkSet* links();
00107
00111 oasys::Lock* lock() { return &lock_; }
00112
00113
00114
00115
00116
00117
00121 void handle_event(BundleEvent* event)
00122 {
00123 dispatch_event(event);
00124 }
00125
00129 void handle_link_created(LinkCreatedEvent* event);
00130
00134 void handle_link_available(LinkAvailableEvent* event);
00135
00139 void handle_link_unavailable(LinkUnavailableEvent* event);
00140
00144 void handle_contact_up(ContactUpEvent* event);
00145
00146
00147
00148
00149
00150
00157 LinkRef new_opportunistic_link(ConvergenceLayer* cl,
00158 const std::string& nexthop,
00159 const EndpointID& remote_eid,
00160 const std::string* link_name = NULL);
00161
00162 protected:
00163
00164 LinkSet* links_;
00165 int opportunistic_cnt_;
00166
00170 void reopen_link(const LinkRef& link);
00171
00175 class LinkAvailabilityTimer : public oasys::Timer {
00176 public:
00177 LinkAvailabilityTimer(ContactManager* cm, const LinkRef& link)
00178 : cm_(cm), link_(link.object(), "LinkAvailabilityTimer") {}
00179
00180 virtual void timeout(const struct timeval& now);
00181
00182 ContactManager* cm_;
00183 LinkRef link_;
00184 };
00185 friend class LinkAvailabilityTimer;
00186
00190 typedef std::map<LinkRef, LinkAvailabilityTimer*> AvailabilityTimerMap;
00191 AvailabilityTimerMap availability_timers_;
00192
00196 mutable oasys::SpinLock lock_;
00197 };
00198
00199
00200 }
00201
00202 #endif