00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _FORWARDINGINFO_H_
00018 #define _FORWARDINGINFO_H_
00019
00020 #include <string>
00021 #include <sys/time.h>
00022 #include <oasys/serialize/Serialize.h>
00023 #include "CustodyTimer.h"
00024
00025 namespace dtn {
00026
00037 class ForwardingInfo : public oasys::SerializableObject{
00038 public:
00042 typedef enum {
00043 INVALID_ACTION = 0,
00044 FORWARD_ACTION,
00045 COPY_ACTION
00046 } action_t;
00047
00048 static inline const char* action_to_str(action_t action)
00049 {
00050 switch(action) {
00051 case INVALID_ACTION: return "INVALID";
00052 case FORWARD_ACTION: return "FORWARD";
00053 case COPY_ACTION: return "COPY";
00054 default:
00055 NOTREACHED;
00056 }
00057 }
00058
00062 typedef enum {
00063 NONE,
00064 IN_FLIGHT,
00065 TRANSMITTED,
00066 TRANSMIT_FAILED,
00067 CANCELLED,
00068 CUSTODY_TIMEOUT,
00069 } state_t;
00070
00071 static const char* state_to_str(state_t state)
00072 {
00073 switch(state) {
00074 case NONE: return "NONE";
00075 case IN_FLIGHT: return "IN_FLIGHT";
00076 case TRANSMITTED: return "TRANSMITTED";
00077 case TRANSMIT_FAILED: return "TRANSMIT_FAILED";
00078 case CANCELLED: return "CANCELLED";
00079 case CUSTODY_TIMEOUT: return "CUSTODY_TIMEOUT";
00080 default:
00081 NOTREACHED;
00082 }
00083 }
00084
00088 ForwardingInfo()
00089 : state_(NONE),
00090 action_(INVALID_ACTION),
00091 clayer_(""),
00092 nexthop_(""),
00093 custody_timer_() {}
00094
00095
00096
00097
00098 ForwardingInfo(const oasys::Builder&)
00099 : state_(NONE),
00100 action_(INVALID_ACTION),
00101 clayer_(""),
00102 nexthop_(""),
00103 custody_timer_() {}
00104
00108 ForwardingInfo(state_t state,
00109 action_t action,
00110 const std::string& clayer,
00111 const std::string& nexthop,
00112 const CustodyTimerSpec& custody_timer)
00113 : state_(NONE),
00114 action_(action),
00115 clayer_(clayer),
00116 nexthop_(nexthop),
00117 custody_timer_(custody_timer)
00118 {
00119 set_state(state);
00120 }
00121
00125 void set_state(state_t new_state)
00126 {
00127 state_ = new_state;
00128 ::gettimeofday(×tamp_, 0);
00129 }
00130
00131 virtual void serialize( oasys::SerializeAction *a );
00132
00133 int state_;
00134 int action_;
00135 std::string clayer_;
00136 std::string nexthop_;
00137 struct timeval timestamp_;
00138 CustodyTimerSpec custody_timer_;
00139 };
00140
00141 }
00142
00143 #endif