ContactManager.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2005 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef _CONTACT_MANAGER_H_
00039 #define _CONTACT_MANAGER_H_
00040 
00041 #include <oasys/debug/Log.h>
00042 #include <oasys/thread/SpinLock.h>
00043 #include <oasys/thread/Timer.h>
00044 #include <oasys/util/StringBuffer.h>
00045 #include <oasys/util/StringUtils.h>
00046 #include "bundling/BundleEventHandler.h"
00047 
00048 namespace dtn {
00049 
00050 class Contact;
00051 class ConvergenceLayer;
00052 class CLInfo;
00053 class Link;
00054 class LinkSet;
00055 
00060 class ContactManager : public BundleEventHandler {
00061 public:
00065     ContactManager();
00066     virtual ~ContactManager();
00067     
00071     void dump(oasys::StringBuffer* buf) const;
00072     
00073     /**********************************************
00074      *
00075      * Link set accessor functions
00076      *
00077      *********************************************/
00081     void add_link(Link* link);
00082     
00086     void del_link(Link* link);
00087     
00091     bool has_link(Link* link);
00092 
00096     Link* find_link(const char* name);
00097 
00109     Link* find_link_to(ConvergenceLayer* cl,
00110                        const std::string& nexthop,
00111                        const EndpointID& remote_eid = EndpointID::NULL_EID(),
00112                        Link::link_type_t type = Link::LINK_INVALID,
00113                        u_int states = 0xffffffff);
00114     
00119     const LinkSet* links();
00120 
00124     oasys::Lock* lock() { return &lock_; }
00125 
00126     /**********************************************
00127      *
00128      * Event handler routines
00129      *
00130      *********************************************/
00134     void handle_event(BundleEvent* event)
00135     {
00136         dispatch_event(event);
00137     }
00138     
00142     void handle_link_available(LinkAvailableEvent* event);
00143     
00147     void handle_link_unavailable(LinkUnavailableEvent* event);
00148 
00152     void handle_contact_up(ContactUpEvent* event);
00153 
00154     /**********************************************
00155      *
00156      * Opportunistic contact routines
00157      *
00158      *********************************************/
00165     Link* new_opportunistic_link(ConvergenceLayer* cl,
00166                                  const std::string& nexthop,
00167                                  const EndpointID& remote_eid);
00168     
00169 protected:
00170     
00171     LinkSet* links_;                    
00172     int opportunistic_cnt_;             
00173 
00177     void reopen_link(Link* link);
00178 
00182     class LinkAvailabilityTimer : public oasys::Timer {
00183     public:
00184         LinkAvailabilityTimer(ContactManager* cm, Link* link)
00185             : cm_(cm), link_(link) {}
00186         
00187         virtual void timeout(const struct timeval& now);
00188 
00189         ContactManager* cm_;    
00190         Link* link_;            
00191     };
00192     friend class LinkAvailabilityTimer;
00193 
00197     typedef std::map<Link*, LinkAvailabilityTimer*> AvailabilityTimerMap;
00198     AvailabilityTimerMap availability_timers_;
00199 
00203     mutable oasys::SpinLock lock_;
00204 };
00205 
00206 
00207 } // namespace dtn
00208 
00209 #endif /* _CONTACT_MANAGER_H_ */

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1