00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 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 * Link set accessor functions 00055 * 00056 *********************************************/ 00060 void add_link(Link* link); 00061 00065 void del_link(Link* link); 00066 00070 bool has_link(Link* link); 00071 00075 Link* find_link(const char* name); 00076 00088 Link* find_link_to(ConvergenceLayer* cl, 00089 const std::string& nexthop, 00090 const EndpointID& remote_eid = EndpointID::NULL_EID(), 00091 Link::link_type_t type = Link::LINK_INVALID, 00092 u_int states = 0xffffffff); 00093 00098 const LinkSet* links(); 00099 00103 oasys::Lock* lock() { return &lock_; } 00104 00105 /********************************************** 00106 * 00107 * Event handler routines 00108 * 00109 *********************************************/ 00113 void handle_event(BundleEvent* event) 00114 { 00115 dispatch_event(event); 00116 } 00117 00121 void handle_link_available(LinkAvailableEvent* event); 00122 00126 void handle_link_unavailable(LinkUnavailableEvent* event); 00127 00131 void handle_contact_up(ContactUpEvent* event); 00132 00133 /********************************************** 00134 * 00135 * Opportunistic contact routines 00136 * 00137 *********************************************/ 00144 Link* new_opportunistic_link(ConvergenceLayer* cl, 00145 const std::string& nexthop, 00146 const EndpointID& remote_eid); 00147 00148 protected: 00149 00150 LinkSet* links_; 00151 int opportunistic_cnt_; 00152 00156 void reopen_link(Link* link); 00157 00161 class LinkAvailabilityTimer : public oasys::Timer { 00162 public: 00163 LinkAvailabilityTimer(ContactManager* cm, Link* link) 00164 : cm_(cm), link_(link) {} 00165 00166 virtual void timeout(const struct timeval& now); 00167 00168 ContactManager* cm_; 00169 Link* link_; 00170 }; 00171 friend class LinkAvailabilityTimer; 00172 00176 typedef std::map<Link*, LinkAvailabilityTimer*> AvailabilityTimerMap; 00177 AvailabilityTimerMap availability_timers_; 00178 00182 mutable oasys::SpinLock lock_; 00183 }; 00184 00185 00186 } // namespace dtn 00187 00188 #endif /* _CONTACT_MANAGER_H_ */