servlib/contacts/Contact.cc
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 #ifdef HAVE_CONFIG_H
       
    18 #  include <dtn-config.h>
       
    19 #endif
       
    20 
       
    21 #include "Contact.h"
       
    22 #include "bundling/Bundle.h"
       
    23 #include "bundling/BundleDaemon.h"
       
    24 #include "bundling/BundleEvent.h"
       
    25 #include "bundling/BundleList.h"
       
    26 #include "conv_layers/ConvergenceLayer.h"
       
    27 
       
    28 namespace dtn {
       
    29 
       
    30 /**
       
    31  * Constructor
       
    32  */
       
    33 Contact::Contact(const LinkRef& link)
       
    34     : RefCountedObject("/dtn/contact/refs"),
       
    35       Logger("Contact", "/dtn/contact/%s",link->name()),
       
    36       link_(link.object(), "Contact"), cl_info_(NULL)
       
    37 {
       
    38     start_time_.get_time();
       
    39     duration_ = 0;
       
    40     bps_         = 0;
       
    41     latency_  = 0;
       
    42     
       
    43     log_info("new contact *%p", this);
       
    44 }
       
    45 
       
    46 Contact::~Contact()
       
    47 {
       
    48     ASSERT(cl_info_ == NULL);
       
    49 }
       
    50 
       
    51 /**
       
    52  * Formatting...
       
    53  */
       
    54 int
       
    55 Contact::format(char* buf, size_t sz) const
       
    56 {
       
    57     return snprintf(buf, sz, "contact %s (started %u.%u)",
       
    58                     link_->nexthop(),
       
    59                     start_time_.sec_, start_time_.usec_);
       
    60 }
       
    61 
       
    62 void
       
    63 Contact::serialize(oasys::SerializeAction *a)
       
    64 {
       
    65     a->process("start_time_sec", &start_time_.sec_);
       
    66     a->process("start_time_usec", &start_time_.usec_);
       
    67     a->process("duration", &duration_);
       
    68     a->process("bps", &bps_);
       
    69     a->process("latency", &latency_);
       
    70     a->process("link", link_.object());
       
    71 }
       
    72 
       
    73 } // namespace dtn