<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>DTN Reference Implementation: Registration.cc Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.6 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="main.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <h1>Registration.cc</h1><a href="Registration_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Copyright 2004-2006 Intel Corporation</span> <a name="l00003"></a>00003 <span class="comment"> * </span> <a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span> <a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span> <a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span> <a name="l00007"></a>00007 <span class="comment"> * </span> <a name="l00008"></a>00008 <span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span> <a name="l00009"></a>00009 <span class="comment"> * </span> <a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span> <a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span> <a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> <a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span> <a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span> <a name="l00015"></a>00015 <span class="comment"> */</span> <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor"># include <<a class="code" href="dtn-config_8h.html">dtn-config.h</a>></span> <a name="l00019"></a>00019 <span class="preprocessor">#endif</span> <a name="l00020"></a>00020 <span class="preprocessor"></span> <a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="Registration_8h.html">Registration.h</a>"</span> <a name="l00022"></a>00022 <span class="preprocessor">#include "<a class="code" href="bundling_2Bundle_8h.html">bundling/Bundle.h</a>"</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="BundleDaemon_8h.html">bundling/BundleDaemon.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="bundling_2BundleList_8h.html">bundling/BundleList.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="Session_8h.html">session/Session.h</a>"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="GlobalStore_8h.html">storage/GlobalStore.h</a>"</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="keyword">namespace </span>dtn { <a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00031"></a>00031 <span class="keyword">const</span> <span class="keywordtype">char</span>* <a name="l00032"></a><a class="code" href="classdtn_1_1Registration.html#0516f5465c5e68f3700751f2037a385e">00032</a> <a class="code" href="classdtn_1_1Registration.html#0516f5465c5e68f3700751f2037a385e" title="Get a string representation of a failure action.">Registration::failure_action_toa</a>(<a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee" title="Type enumerating the option requested by the registration for how to handle bundles...">failure_action_t</a> action) <a name="l00033"></a>00033 { <a name="l00034"></a>00034 <span class="keywordflow">switch</span>(action) { <a name="l00035"></a>00035 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee823ba03e506c2eabc59bf5cec8d4d7c4" title="Drop bundles.">DROP</a>: <span class="keywordflow">return</span> <span class="stringliteral">"DROP"</span>; <a name="l00036"></a>00036 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee7d49e789754ae6edd202ca69e1863c0c" title="Spool bundles until requested.">DEFER</a>: <span class="keywordflow">return</span> <span class="stringliteral">"DEFER"</span>; <a name="l00037"></a>00037 <span class="keywordflow">case</span> <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198ceeab6ca7835f129fdc409b2fc31c19a192" title="Execute the specified callback procedure.">EXEC</a>: <span class="keywordflow">return</span> <span class="stringliteral">"EXEC"</span>; <a name="l00038"></a>00038 } <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="keywordflow">return</span> <span class="stringliteral">"__INVALID__"</span>; <a name="l00041"></a>00041 } <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00044"></a><a class="code" href="classdtn_1_1Registration.html#82c89559a12c69bf90f6cd68a617c4c1">00044</a> Registration::Registration(u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, <a name="l00045"></a>00045 <span class="keyword">const</span> <a class="code" href="classdtn_1_1EndpointIDPattern.html" title="A Distinct class for endpoint patterns (i.e.">EndpointIDPattern</a>& <a class="code" href="dtnperf-server_8c.html#6d2d1c31529bee906473fcabaffff34f">endpoint</a>, <a name="l00046"></a>00046 u_int32_t <a class="code" href="dtnrecv_8c.html#54cdad81a486219f61493a49962ad684">failure_action</a>, <a name="l00047"></a>00047 u_int32_t <a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a>, <a name="l00048"></a>00048 u_int32_t <a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">expiration</a>, <a name="l00049"></a>00049 <span class="keyword">const</span> std::string& script) <a name="l00050"></a>00050 <a name="l00051"></a>00051 : <a class="code" href="classoasys_1_1Logger.html">Logger</a>(<span class="stringliteral">"Registration"</span>, <span class="stringliteral">"/dtn/registration/%d"</span>, regid), <a name="l00052"></a>00052 regid_(regid), <a name="l00053"></a>00053 endpoint_(endpoint), <a name="l00054"></a>00054 failure_action_(failure_action), <a name="l00055"></a>00055 session_flags_(session_flags), <a name="l00056"></a>00056 script_(script), <a name="l00057"></a>00057 expiration_(expiration), <a name="l00058"></a>00058 expiration_timer_(NULL), <a name="l00059"></a>00059 active_(false), <a name="l00060"></a>00060 expired_(false), <a name="l00061"></a>00061 delivery_cache_(std::string(logpath()) + <span class="stringliteral">"/delivery_cache"</span>, 1024) <a name="l00062"></a>00062 { <a name="l00063"></a>00063 <span class="keyword">struct </span>timeval now;<a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."></a> <a name="l00064"></a>00064 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."> ::gettimeofday</a>(&now, 0); <a name="l00065"></a>00065 <a class="code" href="classdtn_1_1Registration.html#9ddb283c3f06042747093e32ee0f372f">creation_time_</a> = now.tv_sec; <a name="l00066"></a>00066 <a name="l00067"></a>00067 <a class="code" href="classdtn_1_1Registration.html#589deea8aeb3ec9da9d9481b150f8a93">init_expiration_timer</a>(); <a name="l00068"></a>00068 } <a name="l00069"></a>00069 <a name="l00070"></a>00070 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00071"></a><a class="code" href="classdtn_1_1Registration.html#e04eebfcf0eda6d40e896811e8d89b17">00071</a> <a class="code" href="classdtn_1_1Registration.html#e04eebfcf0eda6d40e896811e8d89b17" title="Constructor for deserialization.">Registration::Registration</a>(<span class="keyword">const</span> oasys::Builder&) <a name="l00072"></a>00072 : <a class="code" href="classoasys_1_1Logger.html">Logger</a>(<span class="stringliteral">"Registration"</span>, <span class="stringliteral">"/dtn/registration"</span>), <a name="l00073"></a>00073 <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>(0), <a name="l00074"></a>00074 <a class="code" href="classdtn_1_1Registration.html#7b1ed5976ecd907b9ba15108fba2143d">endpoint_</a>(), <a name="l00075"></a>00075 <a class="code" href="classdtn_1_1Registration.html#4dc9b410fd6245bb14319bcd630dad6b">failure_action_</a>(<a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee7d49e789754ae6edd202ca69e1863c0c" title="Spool bundles until requested.">DEFER</a>), <a name="l00076"></a>00076 <a class="code" href="classdtn_1_1Registration.html#b58b5719ce29ebfd9daa76eb8a331877">script_</a>(), <a name="l00077"></a>00077 <a class="code" href="classdtn_1_1Registration.html#9f0d8f84cff0af6f816edd0f307ffedd">expiration_</a>(0), <a name="l00078"></a>00078 <a class="code" href="classdtn_1_1Registration.html#9ddb283c3f06042747093e32ee0f372f">creation_time_</a>(0), <a name="l00079"></a>00079 <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a>(NULL), <a name="l00080"></a>00080 <a class="code" href="classdtn_1_1Registration.html#509c946a1e8c2126ed5dc6d638a23fa7">active_</a>(false), <a name="l00081"></a>00081 <a class="code" href="classdtn_1_1Registration.html#96bdac21a90177dc1b6a5401520c74da">expired_</a>(false), <a name="l00082"></a>00082 <a class="code" href="classdtn_1_1Registration.html#8a5a7036c6a2f518b7422573c48f5614">delivery_cache_</a>(std::string(logpath()) + <span class="stringliteral">"/delivery_cache"</span>, 1024) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 } <a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00087"></a><a class="code" href="classdtn_1_1Registration.html#97dad60a7b054bad1e2c9d83b4ac659d">00087</a> <a class="code" href="classdtn_1_1Registration.html#97dad60a7b054bad1e2c9d83b4ac659d" title="Destructor.">Registration::~Registration</a>() <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <a class="code" href="classdtn_1_1Registration.html#cec2dcf7eccabf732f9d5305b6832637">cleanup_expiration_timer</a>(); <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00093"></a>00093 <span class="keywordtype">bool</span> <a name="l00094"></a><a class="code" href="classdtn_1_1Registration.html#4cc4d8035b434305b500a76ba7b7b446">00094</a> <a class="code" href="classdtn_1_1Registration.html#4cc4d8035b434305b500a76ba7b7b446" title="Deliver the bundle if it isn&#39;t a duplicate.">Registration::deliver_if_not_duplicate</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle) <a name="l00095"></a>00095 { <a name="l00096"></a>00096 <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1Registration.html#8a5a7036c6a2f518b7422573c48f5614">delivery_cache_</a>.<a class="code" href="classdtn_1_1BundleInfoCache.html#5c7594a62ad46e3b8eb9939092e2167c" title="Try to add the bundle to the cache.">add_entry</a>(bundle, <a class="code" href="classdtn_1_1EndpointID.html#31bd1844cae5e71cc2393a139c9bec4c" title="Return the special endpoint id used for the null endpoint, namely &quot;dtn:none&quot;...">EndpointID::NULL_EID</a>())) { <a name="l00097"></a>00097 log_debug(<span class="stringliteral">"suppressing duplicate delivery of bundle *%p"</span>, bundle); <a name="l00098"></a>00098 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00099"></a>00099 } <a name="l00100"></a>00100 <a name="l00101"></a>00101 log_debug(<span class="stringliteral">"delivering bundle *%p"</span>, bundle); <a name="l00102"></a>00102 <a class="code" href="classdtn_1_1Registration.html#6e66f84ad64d676654ea7ef89f24cd69" title="Abstract hook for subclasses to deliver a bundle to this registration.">deliver_bundle</a>(bundle); <a name="l00103"></a>00103 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00104"></a>00104 } <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00107"></a>00107 <span class="keywordtype">void</span> <a name="l00108"></a><a class="code" href="classdtn_1_1Registration.html#94ef089f390f2aad0e99ecfbd53b3819">00108</a> <a class="code" href="classdtn_1_1Registration.html#94ef089f390f2aad0e99ecfbd53b3819" title="Hook for subclasses to handle a new session notification on this registration.">Registration::session_notify</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle) <a name="l00109"></a>00109 { <a name="l00110"></a>00110 (void)bundle; <a name="l00111"></a>00111 PANIC(<span class="stringliteral">"generic session_notify implementation should never be called"</span>); <a name="l00112"></a>00112 } <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00115"></a>00115 <span class="keywordtype">void</span> <a name="l00116"></a><a class="code" href="classdtn_1_1Registration.html#2dfc54d1c5139cfde1f4ea714ae8e036">00116</a> <a class="code" href="classdtn_1_1Registration.html#2dfc54d1c5139cfde1f4ea714ae8e036" title="Force the registration to expire immediately.">Registration::force_expire</a>() <a name="l00117"></a>00117 { <a name="l00118"></a>00118 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1Registration.html#509c946a1e8c2126ed5dc6d638a23fa7">active_</a>); <a name="l00119"></a>00119 <a name="l00120"></a>00120 <a class="code" href="classdtn_1_1Registration.html#cec2dcf7eccabf732f9d5305b6832637">cleanup_expiration_timer</a>(); <a name="l00121"></a>00121 <a class="code" href="classdtn_1_1Registration.html#978fc4d494afebbdc602d9383b08b40c" title="Accessors.">set_expired</a>(<span class="keyword">true</span>); <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a>00124 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00125"></a>00125 <span class="keywordtype">void</span> <a name="l00126"></a><a class="code" href="classdtn_1_1Registration.html#cec2dcf7eccabf732f9d5305b6832637">00126</a> <a class="code" href="classdtn_1_1Registration.html#cec2dcf7eccabf732f9d5305b6832637">Registration::cleanup_expiration_timer</a>() <a name="l00127"></a>00127 { <a name="l00128"></a>00128 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a>) { <a name="l00129"></a>00129 <span class="comment">// try to cancel the expiration timer. if it is still pending,</span> <a name="l00130"></a>00130 <span class="comment">// then the timer will clean itself up when it eventually</span> <a name="l00131"></a>00131 <span class="comment">// fires. otherwise, assert that we have actually expired and</span> <a name="l00132"></a>00132 <span class="comment">// delete the timer itself.</span> <a name="l00133"></a>00133 <span class="keywordtype">bool</span> pending = <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a>->cancel(); <a name="l00134"></a>00134 <a name="l00135"></a>00135 <span class="keywordflow">if</span> (! pending) { <a name="l00136"></a>00136 <a class="code" href="SDNV_8cc.html#ca68c0d4ac8df0838e209fb5300f7be3">ASSERT</a>(<a class="code" href="classdtn_1_1Registration.html#96bdac21a90177dc1b6a5401520c74da">expired_</a>); <a name="l00137"></a>00137 <span class="keyword">delete</span> <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a>; <a name="l00138"></a>00138 } <a name="l00139"></a>00139 <a name="l00140"></a>00140 <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a> = NULL; <a name="l00141"></a>00141 } <a name="l00142"></a>00142 } <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00145"></a>00145 <span class="keywordtype">void</span> <a name="l00146"></a><a class="code" href="classdtn_1_1Registration.html#392bf27256b230ef7d93cc6054fbbcef">00146</a> <a class="code" href="classdtn_1_1Registration.html#392bf27256b230ef7d93cc6054fbbcef" title="Virtual from SerializableObject.">Registration::serialize</a>(oasys::SerializeAction* a) <a name="l00147"></a>00147 { <a name="l00148"></a>00148 a->process(<span class="stringliteral">"endpoint"</span>, &<a class="code" href="classdtn_1_1Registration.html#7b1ed5976ecd907b9ba15108fba2143d">endpoint_</a>); <a name="l00149"></a>00149 a->process(<span class="stringliteral">"regid"</span>, &<a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>); <a name="l00150"></a>00150 a->process(<span class="stringliteral">"failure_action"</span>, &<a class="code" href="classdtn_1_1Registration.html#4dc9b410fd6245bb14319bcd630dad6b">failure_action_</a>); <a name="l00151"></a>00151 a->process(<span class="stringliteral">"session_flags"</span>, &<a class="code" href="classdtn_1_1Registration.html#415f9206a338992d0803615254736061">session_flags_</a>); <a name="l00152"></a>00152 a->process(<span class="stringliteral">"script"</span>, &<a class="code" href="classdtn_1_1Registration.html#b58b5719ce29ebfd9daa76eb8a331877">script_</a>); <a name="l00153"></a>00153 a->process(<span class="stringliteral">"creation_time"</span>, &<a class="code" href="classdtn_1_1Registration.html#9ddb283c3f06042747093e32ee0f372f">creation_time_</a>); <a name="l00154"></a>00154 a->process(<span class="stringliteral">"expiration"</span>, &<a class="code" href="classdtn_1_1Registration.html#9f0d8f84cff0af6f816edd0f307ffedd">expiration_</a>); <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="comment">// finish constructing the object after unserialization</span> <a name="l00157"></a>00157 <span class="keywordflow">if</span> (a->action_code() == oasys::Serialize::UNMARSHAL) { <a name="l00158"></a>00158 <a class="code" href="classdtn_1_1Registration.html#589deea8aeb3ec9da9d9481b150f8a93">init_expiration_timer</a>(); <a name="l00159"></a>00159 } <a name="l00160"></a>00160 <a name="l00161"></a>00161 logpathf(<span class="stringliteral">"/dtn/registration/%d"</span>, <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>); <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <a name="l00164"></a>00164 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00165"></a>00165 <span class="keywordtype">int</span> <a name="l00166"></a><a class="code" href="classdtn_1_1Registration.html#097e2ce6dda2b9f04bb05dcb21e1eba8">00166</a> <a class="code" href="classdtn_1_1Registration.html#097e2ce6dda2b9f04bb05dcb21e1eba8" title="Virtual from Formatter.">Registration::format</a>(<span class="keywordtype">char</span>* <a class="code" href="num2sdnv_8c.html#a81cdcc7ff6987bc85c073253e32715f">buf</a>, <span class="keywordtype">size_t</span> sz)<span class="keyword"> const</span> <a name="l00167"></a>00167 <span class="keyword"></span>{ <a name="l00168"></a>00168 <span class="keywordflow">return</span> snprintf(buf, sz, <a name="l00169"></a>00169 <span class="stringliteral">"id %u: %s %s (%s%s) [expiration %d%s%s%s%s]"</span>, <a name="l00170"></a>00170 <a class="code" href="classdtn_1_1Registration.html#d1cd25dd8e4c512591849f44e7c8090b" title="Accessors.">regid</a>(), <a name="l00171"></a>00171 <a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>() ? <span class="stringliteral">"active"</span> : <span class="stringliteral">"passive"</span>, <a name="l00172"></a>00172 <a class="code" href="classdtn_1_1Registration.html#590e683ae3d0a33456e7f0fa0a2a89d5" title="Accessors.">endpoint</a>().c_str(), <a name="l00173"></a>00173 <a class="code" href="classdtn_1_1Registration.html#0516f5465c5e68f3700751f2037a385e" title="Get a string representation of a failure action.">failure_action_toa</a>(<a class="code" href="classdtn_1_1Registration.html#d887ed1ad25a6d629aa5e437a99c473b" title="Accessors.">failure_action</a>()), <a name="l00174"></a>00174 <a class="code" href="classdtn_1_1Registration.html#d887ed1ad25a6d629aa5e437a99c473b" title="Accessors.">failure_action</a>() == <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198ceeab6ca7835f129fdc409b2fc31c19a192" title="Execute the specified callback procedure.">Registration::EXEC</a> ? <a name="l00175"></a>00175 <a class="code" href="classdtn_1_1Registration.html#6db70cee1c6095d6c15f77e98187d3d3" title="Accessors.">script</a>().c_str() : <span class="stringliteral">""</span>, <a name="l00176"></a>00176 <a class="code" href="classdtn_1_1Registration.html#4370295147fca3926d7883e40d41572d" title="Accessors.">expiration</a>(), <a name="l00177"></a>00177 <a class="code" href="classdtn_1_1Registration.html#577ef221608a47ba828daad128c2b263" title="Accessors.">session_flags</a>() != 0 ? <span class="stringliteral">" session:"</span> : <span class="stringliteral">""</span>, <a name="l00178"></a>00178 (<a class="code" href="classdtn_1_1Registration.html#577ef221608a47ba828daad128c2b263" title="Accessors.">session_flags</a>() & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1ccfadd042afba693bbcf1e5980667d9">Session::CUSTODY</a>) ? <span class="stringliteral">" custody"</span> : <span class="stringliteral">""</span>, <a name="l00179"></a>00179 (<a class="code" href="classdtn_1_1Registration.html#577ef221608a47ba828daad128c2b263" title="Accessors.">session_flags</a>() & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1978e38ca305c80fe009dd50fe24a3be">Session::PUBLISH</a>) ? <span class="stringliteral">" publish"</span> : <span class="stringliteral">""</span>, <a name="l00180"></a>00180 (<a class="code" href="classdtn_1_1Registration.html#577ef221608a47ba828daad128c2b263" title="Accessors.">session_flags</a>() & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498cadd5836fef35cca7c207e710e8e13239">Session::SUBSCRIBE</a>) ? <span class="stringliteral">" subscribe"</span> : <span class="stringliteral">""</span> <a name="l00181"></a>00181 ); <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00185"></a>00185 <span class="keywordtype">void</span> <a name="l00186"></a><a class="code" href="classdtn_1_1Registration.html#589deea8aeb3ec9da9d9481b150f8a93">00186</a> <a class="code" href="classdtn_1_1Registration.html#589deea8aeb3ec9da9d9481b150f8a93">Registration::init_expiration_timer</a>() <a name="l00187"></a>00187 { <a name="l00188"></a>00188 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1Registration.html#9f0d8f84cff0af6f816edd0f307ffedd">expiration_</a> != 0) { <a name="l00189"></a>00189 <span class="keyword">struct </span>timeval when, now; <a name="l00190"></a>00190 when.tv_sec = <a class="code" href="classdtn_1_1Registration.html#9ddb283c3f06042747093e32ee0f372f">creation_time_</a> + <a class="code" href="classdtn_1_1Registration.html#9f0d8f84cff0af6f816edd0f307ffedd">expiration_</a>; <a name="l00191"></a>00191 when.tv_usec = 0;<a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."></a> <a name="l00192"></a>00192 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."></a> <a name="l00193"></a>00193 <a class="code" href="namespacedtnsim.html#372b0bd474085f20b38efbbade7ce72a" title="Override gettimeofday to return the simulator time."> ::gettimeofday</a>(&now, 0); <a name="l00194"></a>00194 <a name="l00195"></a>00195 <span class="keywordtype">long</span> <span class="keywordtype">int</span> in_how_long = <a class="code" href="dtnping_8h.html#78237999c2659b5d28c1a90a2123607f">TIMEVAL_DIFF_MSEC</a>(when, now); <a name="l00196"></a>00196 <span class="keywordflow">if</span> (in_how_long < 0) { <a name="l00197"></a>00197 log_warn(<span class="stringliteral">"scheduling IMMEDIATE expiration for registration id %d: "</span> <a name="l00198"></a>00198 <span class="stringliteral">"[creation_time %u, expiration %u, now %u]"</span>, <a name="l00199"></a>00199 <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>, <a class="code" href="classdtn_1_1Registration.html#9ddb283c3f06042747093e32ee0f372f">creation_time_</a>, expiration_, (u_int)now.tv_sec); <a name="l00200"></a>00200 } <span class="keywordflow">else</span> { <a name="l00201"></a>00201 log_debug(<span class="stringliteral">"scheduling expiration for registration id %d at %u.%u "</span> <a name="l00202"></a>00202 <span class="stringliteral">"(in %ld seconds): "</span>, <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>, <a name="l00203"></a>00203 (u_int)when.tv_sec, (u_int)when.tv_usec, <a name="l00204"></a>00204 in_how_long / 1000); <a name="l00205"></a>00205 } <a name="l00206"></a>00206 <a name="l00207"></a>00207 <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html" title="Class to implement registration expirations.">ExpirationTimer</a>(<span class="keyword">this</span>); <a name="l00208"></a>00208 <a class="code" href="classdtn_1_1Registration.html#da32c12ce215c0b00c3dd02837cd2a01">expiration_timer_</a>->schedule_at(&when); <a name="l00209"></a>00209 <a name="l00210"></a>00210 } <span class="keywordflow">else</span> { <a name="l00211"></a>00211 <a class="code" href="classdtn_1_1Registration.html#978fc4d494afebbdc602d9383b08b40c" title="Accessors.">set_expired</a>(<span class="keyword">true</span>); <a name="l00212"></a>00212 } <a name="l00213"></a>00213 } <a name="l00214"></a>00214 <a name="l00215"></a>00215 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00216"></a>00216 <span class="keywordtype">void</span> <a name="l00217"></a><a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html#42b0b5ae3b401715a861c50063986a52">00217</a> <a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html#42b0b5ae3b401715a861c50063986a52">Registration::ExpirationTimer::timeout</a>(<span class="keyword">const</span> <span class="keyword">struct</span> timeval& now) <a name="l00218"></a>00218 { <a name="l00219"></a>00219 (void)now; <a name="l00220"></a>00220 <a name="l00221"></a>00221 <a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html#d75e6e460c1cb20a1e11c4f9cfdead85">reg_</a>-><a class="code" href="classdtn_1_1Registration.html#978fc4d494afebbdc602d9383b08b40c" title="Accessors.">set_expired</a>(<span class="keyword">true</span>); <a name="l00222"></a>00222 <a name="l00223"></a>00223 <span class="keywordflow">if</span> (! <a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html#d75e6e460c1cb20a1e11c4f9cfdead85">reg_</a>-><a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>()) { <a name="l00224"></a>00224 <a class="code" href="classdtn_1_1BundleDaemon.html#370a80f7dd9fd9297e76d7f830d737a8" title="Queues the event at the tail of the queue for processing by the daemon thread.">BundleDaemon::post</a>(<span class="keyword">new</span> <a class="code" href="classdtn_1_1RegistrationExpiredEvent.html" title="Event class for registration expiration.">RegistrationExpiredEvent</a>(<a class="code" href="classdtn_1_1Registration_1_1ExpirationTimer.html#d75e6e460c1cb20a1e11c4f9cfdead85">reg_</a>)); <a name="l00225"></a>00225 } <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <a name="l00228"></a>00228 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 21 14:09:46 2008 for DTN Reference Implementation by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> </body> </html>