servlib/contacts/Contact.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2004-2006 Intel Corporation
       
     3  * 
       
     4  *    Licensed under the Apache License, Version 2.0 (the "License");
       
     5  *    you may not use this file except in compliance with the License.
       
     6  *    You may obtain a copy of the License at
       
     7  * 
       
     8  *        http://www.apache.org/licenses/LICENSE-2.0
       
     9  * 
       
    10  *    Unless required by applicable law or agreed to in writing, software
       
    11  *    distributed under the License is distributed on an "AS IS" BASIS,
       
    12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13  *    See the License for the specific language governing permissions and
       
    14  *    limitations under the License.
       
    15  */
       
    16 
       
    17 #ifndef _CONTACT_H_
       
    18 #define _CONTACT_H_
       
    19 
       
    20 #include <oasys/debug/DebugUtils.h>
       
    21 #include <oasys/debug/Formatter.h>
       
    22 #include <oasys/serialize/Serialize.h>
       
    23 #include <oasys/util/Ref.h>
       
    24 #include <oasys/util/RefCountedObject.h>
       
    25 #include <oasys/util/Time.h>
       
    26 
       
    27 namespace dtn {
       
    28 
       
    29 class Bundle;
       
    30 class ConvergenceLayer;
       
    31 class CLInfo;
       
    32 class Link;
       
    33 
       
    34 // re-defined from Link.h
       
    35 typedef oasys::Ref<Link> LinkRef;
       
    36 
       
    37 /**
       
    38  * Encapsulation of an active connection to a next-hop DTN contact.
       
    39  * This is basically a repository for any state about the contact
       
    40  * opportunity including start time, estimations for bandwidth or
       
    41  * latency, etc.
       
    42  *
       
    43  * It also contains the CLInfo slot for the convergence layer to put
       
    44  * any state associated with the active connection.
       
    45  *
       
    46  * Since the contact object may be used by multiple threads in the
       
    47  * case of a connection-oriented convergence layer, and because the
       
    48  * object is intended to be deleted when the contact opportunity ends,
       
    49  * all object instances are reference counted and will be deleted when
       
    50  * the last reference is removed.
       
    51  */
       
    52 class Contact : public oasys::RefCountedObject,
       
    53                 public oasys::Logger,
       
    54                 public oasys::SerializableObject
       
    55 {
       
    56 public:
       
    57     /**
       
    58      * Constructor
       
    59      */
       
    60     Contact(const LinkRef& link);
       
    61 
       
    62 private:
       
    63     /**
       
    64      * Destructor -- private since the class is reference counted and
       
    65      * therefore is never explicitly deleted.
       
    66      */ 
       
    67     virtual ~Contact();
       
    68     friend class oasys::RefCountedObject;
       
    69 
       
    70 public:
       
    71     /**
       
    72      * Store the convergence layer state associated with the contact.
       
    73      */
       
    74     void set_cl_info(CLInfo* cl_info)
       
    75     {
       
    76         ASSERT((cl_info_ == NULL && cl_info != NULL) ||
       
    77                (cl_info_ != NULL && cl_info == NULL));
       
    78         
       
    79         cl_info_ = cl_info;
       
    80     }
       
    81     
       
    82     /**
       
    83      * Accessor to the convergence layer info.
       
    84      */
       
    85     CLInfo* cl_info() { return cl_info_; }
       
    86     
       
    87     /**
       
    88      * Accessor to the link
       
    89      */
       
    90     const LinkRef& link() { return link_; }
       
    91 
       
    92     /**
       
    93      * Virtual from formatter
       
    94      */
       
    95     int format(char* buf, size_t sz) const;
       
    96 
       
    97     /**
       
    98      * Virtual from SerializableObject
       
    99      */
       
   100     virtual void serialize( oasys::SerializeAction *a );
       
   101 
       
   102 
       
   103     /// @{ Accessors
       
   104     const oasys::Time& start_time() const { return start_time_; }
       
   105     u_int32_t          duration()   const { return duration_; }
       
   106     u_int32_t          bps()        const { return bps_; }
       
   107     u_int32_t          latency()    const { return latency_; }
       
   108 
       
   109     void set_start_time(const oasys::Time& t) { start_time_ = t; }
       
   110     void set_duration(u_int32_t duration)     { duration_ = duration; }
       
   111     void set_bps(u_int32_t bps)               { bps_ = bps; }
       
   112     void set_latency(u_int32_t latency)       { latency_ = latency; }
       
   113     /// @}
       
   114     
       
   115 protected:
       
   116     /// Time when the contact begin
       
   117     oasys::Time start_time_;
       
   118 
       
   119     /// Contact duration (0 if unknown)
       
   120     u_int32_t duration_;
       
   121 
       
   122     /// Approximate bandwidth
       
   123     u_int32_t bps_;
       
   124     
       
   125     /// Approximate latency
       
   126     u_int32_t latency_;
       
   127 
       
   128     LinkRef link_ ; 	///< Parent link on which this contact exists
       
   129     
       
   130     CLInfo* cl_info_;	///< convergence layer specific info
       
   131 };
       
   132 
       
   133 /**
       
   134  * Typedef for a reference on a contact.
       
   135  */
       
   136 typedef oasys::Ref<Contact> ContactRef;
       
   137 
       
   138 } // namespace dtn
       
   139 
       
   140 #endif /* _CONTACT_H_ */