servlib/bundling/CustodySignal.h
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 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 _CUSTODYSIGNAL_H_
       
    18 #define _CUSTODYSIGNAL_H_
       
    19 
       
    20 #define __STDC_FORMAT_MACROS
       
    21 #include <inttypes.h>
       
    22 
       
    23 #include "Bundle.h"
       
    24 #include "BundleProtocol.h"
       
    25 
       
    26 namespace dtn {
       
    27 
       
    28 /**
       
    29  * Utility class to format and parse custody signal bundles.
       
    30  */
       
    31 class CustodySignal {
       
    32 public:
       
    33     /**
       
    34      * The reason codes are defined in the bundle protocol class.
       
    35      */
       
    36     typedef BundleProtocol::custody_signal_reason_t reason_t;
       
    37 
       
    38     /**
       
    39      * Struct to hold the payload data of the custody signal.
       
    40      */
       
    41     struct data_t {
       
    42         u_int8_t        admin_type_;
       
    43         u_int8_t        admin_flags_;
       
    44         bool            succeeded_;
       
    45         u_int8_t        reason_;
       
    46         u_int64_t       orig_frag_offset_;
       
    47         u_int64_t       orig_frag_length_;
       
    48         BundleTimestamp custody_signal_tv_;
       
    49         BundleTimestamp orig_creation_tv_;
       
    50         EndpointID      orig_source_eid_;
       
    51     };
       
    52 
       
    53     /**
       
    54      * Constructor-like function to create a new custody signal bundle.
       
    55      */
       
    56     static void create_custody_signal(Bundle*           bundle,
       
    57                                       const Bundle*     orig_bundle,
       
    58                                       const EndpointID& source_eid,
       
    59                                       bool              succeeded,
       
    60                                       reason_t          reason);
       
    61 
       
    62     /**
       
    63      * Parsing function for custody signal bundles.
       
    64      */
       
    65     static bool parse_custody_signal(data_t* data,
       
    66                                      const u_char* bp, u_int len);
       
    67 
       
    68     /**
       
    69      * Pretty printer for custody signal reasons.
       
    70      */
       
    71     static const char* reason_to_str(u_int8_t reason);
       
    72 };
       
    73 
       
    74 } // namespace dtn
       
    75 
       
    76 #endif /* _CUSTODYSIGNAL_H_ */