00001 /* 00002 * Copyright 2004-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef _REGISTRATION_H_ 00018 #define _REGISTRATION_H_ 00019 00020 #include <list> 00021 #include <string> 00022 00023 #include <oasys/debug/Log.h> 00024 #include <oasys/serialize/Serialize.h> 00025 #include <oasys/thread/Timer.h> 00026 00027 #include "../naming/EndpointID.h" 00028 00029 namespace dtn { 00030 00031 class Bundle; 00032 00042 class Registration : public oasys::SerializableObject, public oasys::Logger { 00043 public: 00047 static const u_int32_t ADMIN_REGID = 0; 00048 static const u_int32_t LINKSTATEROUTER_REGID = 1; 00049 static const u_int32_t PING_REGID = 2; 00050 static const u_int32_t EXTERNALROUTER_REGID = 3; 00051 static const u_int32_t MAX_RESERVED_REGID = 9; 00052 00057 typedef enum { 00058 DROP, 00059 DEFER, 00060 EXEC 00061 } failure_action_t; 00062 00066 static const char* failure_action_toa(failure_action_t action); 00067 00071 Registration(const oasys::Builder&); 00072 00076 Registration(u_int32_t regid, 00077 const EndpointIDPattern& endpoint, 00078 int action, 00079 u_int32_t expiration, 00080 const std::string& script = ""); 00081 00085 virtual ~Registration(); 00086 00090 virtual void deliver_bundle(Bundle* bundle) = 0; 00091 00093 00094 u_int32_t durable_key() { return regid_; } 00095 u_int32_t regid() { return regid_; } 00096 const EndpointIDPattern& endpoint() { return endpoint_; } 00097 failure_action_t failure_action() { return static_cast<failure_action_t> 00098 (failure_action_); } 00099 const std::string& script() { return script_; } 00100 u_int32_t expiration() { return expiration_; } 00101 bool active() { return active_; } 00102 void set_active(bool a) { active_ = a; } 00103 bool expired() { return expired_; } 00104 void set_expired(bool e) { expired_ = e; } 00106 00110 void serialize(oasys::SerializeAction* a); 00111 00118 void force_expire(); 00119 00120 protected: 00124 class ExpirationTimer : public oasys::Timer { 00125 public: 00126 ExpirationTimer(Registration* reg) 00127 : reg_(reg) {} 00128 00129 void timeout(const struct timeval& now); 00130 00131 Registration* reg_; 00132 }; 00133 00134 void init_expiration_timer(); 00135 void cleanup_expiration_timer(); 00136 00137 u_int32_t regid_; 00138 EndpointIDPattern endpoint_; 00139 int failure_action_; 00140 std::string script_; 00141 u_int32_t expiration_; 00142 u_int32_t creation_time_; 00143 ExpirationTimer* expiration_timer_; 00144 bool active_; 00145 bool bound_; 00146 bool expired_; 00147 }; 00148 00152 class RegistrationList : public std::list<Registration*> {}; 00153 00154 } // namespace dtn 00155 00156 #endif /* _REGISTRATION_H_ */