<!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: APIRegistration.cc Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.8 --> <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> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>APIRegistration.cc</h1><a href="APIRegistration_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 2005-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="APIRegistration_8h.html">APIRegistration.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 <a name="l00027"></a>00027 <span class="keyword">namespace </span>dtn { <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00030"></a><a class="code" href="classdtn_1_1APIRegistration.html#655c811c051e82c6ef0d1089bb6cd641">00030</a> <a class="code" href="classdtn_1_1APIRegistration.html#655c811c051e82c6ef0d1089bb6cd641" title="Constructor for deserialization.">APIRegistration::APIRegistration</a>(<span class="keyword">const</span> oasys::Builder& builder) <a name="l00031"></a>00031 : <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>(builder) <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classdtn_1_1APIRegistration.html#4932a64058476cc73138682306cd1aa6" title="Queue of bundles for the registration.">bundle_list_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1BlockingBundleList.html" title="A simple derivative to the BundleList class that hooks in an oasys Notifier, which...">BlockingBundleList</a>(logpath_); <a name="l00034"></a>00034 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a> = NULL; <a name="l00035"></a>00035 } <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00038"></a><a class="code" href="classdtn_1_1APIRegistration.html#be72e7c2e0fba7c2a3320604d34fb536">00038</a> <a class="code" href="classdtn_1_1APIRegistration.html#655c811c051e82c6ef0d1089bb6cd641" title="Constructor for deserialization.">APIRegistration::APIRegistration</a>(u_int32_t <a class="code" href="dtncat_8c.html#8eb0c3e35c1feb7baf9802f03bf42e41">regid</a>, <a name="l00039"></a>00039 <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="l00040"></a>00040 <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="l00041"></a>00041 u_int32_t <a class="code" href="dtncat_8c.html#7508c434c1f2152c7fd03381726d0a2a">session_flags</a>, <a name="l00042"></a>00042 u_int32_t <a class="code" href="dtncat_8c.html#d6057e40387509de502bdc91007d3238">expiration</a>, <a name="l00043"></a>00043 <span class="keyword">const</span> std::string& script) <a name="l00044"></a>00044 : <a class="code" href="classdtn_1_1Registration.html" title="Class used to represent an &quot;application&quot; registration, loosely defined...">Registration</a>(regid, endpoint, action, session_flags, expiration, script) <a name="l00045"></a>00045 { <a name="l00046"></a>00046 <a class="code" href="classdtn_1_1APIRegistration.html#4932a64058476cc73138682306cd1aa6" title="Queue of bundles for the registration.">bundle_list_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1BlockingBundleList.html" title="A simple derivative to the BundleList class that hooks in an oasys Notifier, which...">BlockingBundleList</a>(logpath_); <a name="l00047"></a>00047 <span class="keywordflow">if</span> (session_flags & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1ccfadd042afba693bbcf1e5980667d9">Session::CUSTODY</a>) { <a name="l00048"></a>00048 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1BlockingBundleList.html" title="A simple derivative to the BundleList class that hooks in an oasys Notifier, which...">BlockingBundleList</a>(logpath_); <a name="l00049"></a>00049 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a>->logpath_appendf(<span class="stringliteral">"/session_notify"</span>); <a name="l00050"></a>00050 } <span class="keywordflow">else</span> { <a name="l00051"></a>00051 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a> = NULL; <a name="l00052"></a>00052 } <a name="l00053"></a>00053 } <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00056"></a>00056 <span class="keywordtype">void</span> <a name="l00057"></a><a class="code" href="classdtn_1_1APIRegistration.html#176d274dfae1c74dd7f9b559f878d5d8">00057</a> <a class="code" href="classdtn_1_1APIRegistration.html#176d274dfae1c74dd7f9b559f878d5d8" title="Virtual from SerializableObject.">APIRegistration::serialize</a>(oasys::SerializeAction* a) <a name="l00058"></a>00058 { <a name="l00059"></a>00059 <a class="code" href="classdtn_1_1APIRegistration.html#176d274dfae1c74dd7f9b559f878d5d8" title="Virtual from SerializableObject.">Registration::serialize</a>(a); <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="keywordflow">if</span> (a->action_code() == oasys::Serialize::UNMARSHAL && <a name="l00062"></a>00062 (<a class="code" href="classdtn_1_1Registration.html#415f9206a338992d0803615254736061">session_flags_</a> & <a class="code" href="classdtn_1_1Session.html#a795473f389a203d6e15058da8d9498c1ccfadd042afba693bbcf1e5980667d9">Session::CUSTODY</a>)) <a name="l00063"></a>00063 { <a name="l00064"></a>00064 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a> = <span class="keyword">new</span> <a class="code" href="classdtn_1_1BlockingBundleList.html" title="A simple derivative to the BundleList class that hooks in an oasys Notifier, which...">BlockingBundleList</a>(logpath_); <a name="l00065"></a>00065 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a>->logpath_appendf(<span class="stringliteral">"/session_notify"</span>); <a name="l00066"></a>00066 } <a name="l00067"></a>00067 } <a name="l00068"></a>00068 <a name="l00069"></a>00069 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00070"></a><a class="code" href="classdtn_1_1APIRegistration.html#6dbe7c6e426a34d303a0088f17cba57f">00070</a> <a class="code" href="classdtn_1_1APIRegistration.html#6dbe7c6e426a34d303a0088f17cba57f">APIRegistration::~APIRegistration</a>() <a name="l00071"></a>00071 { <a name="l00072"></a>00072 <span class="keyword">delete</span> <a class="code" href="classdtn_1_1APIRegistration.html#4932a64058476cc73138682306cd1aa6" title="Queue of bundles for the registration.">bundle_list_</a>; <a name="l00073"></a>00073 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a>) { <a name="l00074"></a>00074 <span class="keyword">delete</span> <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a>; <a name="l00075"></a>00075 } <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <a name="l00078"></a>00078 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00079"></a>00079 <span class="keywordtype">void</span> <a name="l00080"></a><a class="code" href="classdtn_1_1APIRegistration.html#6f726b18f6b40dc2d06515e8faf73fc5">00080</a> <a class="code" href="classdtn_1_1APIRegistration.html#6f726b18f6b40dc2d06515e8faf73fc5" title="Virtual from Registration.">APIRegistration::deliver_bundle</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle) <a name="l00081"></a>00081 { <a name="l00082"></a>00082 <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>() && (<a class="code" href="classdtn_1_1Registration.html#4dc9b410fd6245bb14319bcd630dad6b">failure_action_</a> == <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198cee823ba03e506c2eabc59bf5cec8d4d7c4" title="Drop bundles.">DROP</a>)) { <a name="l00083"></a>00083 log_info(<span class="stringliteral">"deliver_bundle: "</span> <a name="l00084"></a>00084 <span class="stringliteral">"dropping bundle id %d for passive registration %d (%s)"</span>, <a name="l00085"></a>00085 bundle-><a class="code" href="classdtn_1_1Bundle.html#7031e2e5e4078445bf4ad39cdcdea3b2" title="Accessors.">bundleid</a>(), <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>, <a class="code" href="classdtn_1_1Registration.html#7b1ed5976ecd907b9ba15108fba2143d">endpoint_</a>.<a class="code" href="classdtn_1_1EndpointID.html#c9d8a72806359621f4d2850c1e78269c">c_str</a>()); <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="comment">// post an event saying we "delivered" it</span> <a name="l00088"></a>00088 <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_1BundleDeliveredEvent.html" title="Event class for local bundle delivery.">BundleDeliveredEvent</a>(bundle, <span class="keyword">this</span>)); <a name="l00089"></a>00089 <span class="keywordflow">return</span>; <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>() && (<a class="code" href="classdtn_1_1Registration.html#4dc9b410fd6245bb14319bcd630dad6b">failure_action_</a> == <a class="code" href="classdtn_1_1Registration.html#7f4eb0e60d645c02fb6f7738de198ceeab6ca7835f129fdc409b2fc31c19a192" title="Execute the specified callback procedure.">EXEC</a>)) { <a name="l00093"></a>00093 <span class="comment">// this sure seems like a security hole, but what can you</span> <a name="l00094"></a>00094 <span class="comment">// do -- it's in the spec</span> <a name="l00095"></a>00095 log_info(<span class="stringliteral">"deliver_bundle: "</span> <a name="l00096"></a>00096 <span class="stringliteral">"running script '%s' for registration %d (%s)"</span>, <a name="l00097"></a>00097 <a class="code" href="classdtn_1_1Registration.html#b58b5719ce29ebfd9daa76eb8a331877">script_</a>.c_str(), <a class="code" href="classdtn_1_1Registration.html#0df345d8c181f4380604d07c196474e2">regid_</a>, <a class="code" href="classdtn_1_1Registration.html#7b1ed5976ecd907b9ba15108fba2143d">endpoint_</a>.<a class="code" href="classdtn_1_1EndpointID.html#c9d8a72806359621f4d2850c1e78269c">c_str</a>()); <a name="l00098"></a>00098 <a name="l00099"></a>00099 system(<a class="code" href="classdtn_1_1Registration.html#b58b5719ce29ebfd9daa76eb8a331877">script_</a>.c_str()); <a name="l00100"></a>00100 <span class="comment">// fall through</span> <a name="l00101"></a>00101 } <a name="l00102"></a>00102 <a name="l00103"></a>00103 log_info(<span class="stringliteral">"deliver_bundle: queuing bundle id %d for %s delivery to %s"</span>, <a name="l00104"></a>00104 bundle-><a class="code" href="classdtn_1_1Bundle.html#7031e2e5e4078445bf4ad39cdcdea3b2" title="Accessors.">bundleid</a>(), <a name="l00105"></a>00105 <a class="code" href="classdtn_1_1Registration.html#76d7e69abd93971f58ef49eee4b9abfc" title="Accessors.">active</a>() ? <span class="stringliteral">"active"</span> : <span class="stringliteral">"deferred"</span>, <a name="l00106"></a>00106 <a class="code" href="classdtn_1_1Registration.html#7b1ed5976ecd907b9ba15108fba2143d">endpoint_</a>.<a class="code" href="classdtn_1_1EndpointID.html#c9d8a72806359621f4d2850c1e78269c">c_str</a>()); <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="keywordflow">if</span> (BundleDaemon::instance()->params_.test_permuted_delivery_) { <a name="l00109"></a>00109 <a class="code" href="classdtn_1_1APIRegistration.html#4932a64058476cc73138682306cd1aa6" title="Queue of bundles for the registration.">bundle_list_</a>-><a class="code" href="classdtn_1_1BundleList.html#ed4600017614f1193d4781e1a1a34301" title="As a testing hook, insert the given bundle into a random location in the list.">insert_random</a>(bundle); <a name="l00110"></a>00110 } <span class="keywordflow">else</span> { <a name="l00111"></a>00111 <a class="code" href="classdtn_1_1APIRegistration.html#4932a64058476cc73138682306cd1aa6" title="Queue of bundles for the registration.">bundle_list_</a>-><a class="code" href="classdtn_1_1BundleList.html#9f3efd0593739e89ed478fd4bbccd3e0" title="Add a new bundle to the back of the list.">push_back</a>(bundle); <a name="l00112"></a>00112 } <a name="l00113"></a>00113 } <a name="l00114"></a>00114 <a name="l00115"></a>00115 <span class="comment">//----------------------------------------------------------------------</span> <a name="l00116"></a>00116 <span class="keywordtype">void</span> <a name="l00117"></a><a class="code" href="classdtn_1_1APIRegistration.html#a33ea2487250a89197cddd76c12b53df">00117</a> <a class="code" href="classdtn_1_1APIRegistration.html#a33ea2487250a89197cddd76c12b53df" title="Hook for subclasses to handle a new session notification on this registration.">APIRegistration::session_notify</a>(<a class="code" href="classdtn_1_1Bundle.html" title="The internal representation of a bundle.">Bundle</a>* bundle) <a name="l00118"></a>00118 { <a name="l00119"></a>00119 log_debug(<span class="stringliteral">"session_notify *%p"</span>, bundle); <a name="l00120"></a>00120 <a class="code" href="classdtn_1_1APIRegistration.html#b4159c1472529a1a7f89c4523cd22ec7" title="Queue of subscription notification bundles.">session_notify_list_</a>-><a class="code" href="classdtn_1_1BundleList.html#9f3efd0593739e89ed478fd4bbccd3e0" title="Add a new bundle to the back of the list.">push_back</a>(bundle); <a name="l00121"></a>00121 } <a name="l00122"></a>00122 <a name="l00123"></a>00123 } <span class="comment">// namespace dtn</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Fri Jan 30 09:26:52 2009 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.8 </small></address> </body> </html>