servlib/routing/ProphetNode.cc
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 /*
       
     2  *    Copyright 2007 Baylor University
       
     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 "ProphetNode.h"
       
    22 
       
    23 namespace dtn {
       
    24 
       
    25 ProphetNode::ProphetNode(const prophet::NodeParams* params)
       
    26     : prophet::Node(params)
       
    27 {
       
    28 }
       
    29 
       
    30 ProphetNode::ProphetNode(const ProphetNode& node)
       
    31     : prophet::Node(node),
       
    32       oasys::SerializableObject(node),
       
    33       remote_eid_(node.remote_eid_)
       
    34 {
       
    35 }
       
    36 
       
    37 ProphetNode::ProphetNode(const prophet::Node& node)
       
    38     : prophet::Node(node),
       
    39       oasys::SerializableObject(),
       
    40       remote_eid_(node.dest_id())
       
    41 {
       
    42 }
       
    43 
       
    44 ProphetNode::ProphetNode(const oasys::Builder&)
       
    45     : prophet::Node(),
       
    46       oasys::SerializableObject()
       
    47 {
       
    48 }
       
    49 
       
    50 void
       
    51 ProphetNode::serialize(oasys::SerializeAction* a)
       
    52 {
       
    53     a->process("age",&age_);
       
    54     a->process("custody",&custody_);
       
    55     a->process("relay",&relay_);
       
    56     a->process("internet_gw",&internet_gateway_);
       
    57 
       
    58     // serialize into 8 bits, much like RIBTLV
       
    59     u_int8_t p_value_pass = 0;
       
    60 
       
    61     // if reading from disk into memory
       
    62     if (a->action_code() == oasys::Serialize::UNMARSHAL)
       
    63     {
       
    64         a->process("remote_eid",&remote_eid_);
       
    65         set_dest_id(remote_eid_.c_str());
       
    66 
       
    67         a->process("p_value",&p_value_pass);
       
    68         p_value_ = ((p_value_pass & 0xff) + 0.0) / (255.0);
       
    69     }
       
    70     // else writing to disk from memory
       
    71     else
       
    72     {
       
    73         remote_eid_.assign(dest_id_);
       
    74         a->process("remote_eid",&remote_eid_);
       
    75 
       
    76         p_value_pass = (u_int8_t) ( (int) (p_value_ * (255.0)) ) & 0xff;
       
    77         a->process("p_value",&p_value_pass);
       
    78     }
       
    79 }
       
    80 
       
    81 }; // dtn