<!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: ProphetBundleList.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>ProphetBundleList.cc</h1><a href="ProphetBundleList_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 2007 Baylor University</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><span class="preprocessor">#include "<a class="code" href="ProphetBundleList_8h.html">ProphetBundleList.h</a>"</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="keyword">namespace </span>dtn <a name="l00023"></a>00023 { <a name="l00024"></a>00024 <a name="l00025"></a>00025 <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a> <a name="l00026"></a>00026 <a class="code" href="classdtn_1_1ProphetBundleList.html#dddcafe94a1c15642c5ba0ed7477e39e" title="pointer to NULL">ProphetBundleList::NULL_BUNDLE</a>(<span class="stringliteral">"ProphetBundleList"</span>); <a name="l00027"></a>00027 <a name="l00028"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#a1f03d3edf7a36b42e681e5871e6584f">00028</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#a1f03d3edf7a36b42e681e5871e6584f" title="Constructor.">ProphetBundleList::ProphetBundleList</a>(<a class="code" href="classprophet_1_1Repository_1_1BundleCoreRep.html" title="Reduced interface into BundleCore to provide logging, drop_bundle signal, and answer...">prophet::Repository::BundleCoreRep</a>* core) <a name="l00029"></a>00029 : list_(core) {} <a name="l00030"></a>00030 <a name="l00031"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#4feecb35ac50989491b04f8128c5805d">00031</a> ProphetBundleList::~ProphetBundleList() <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classdtn_1_1ProphetBundleList.html#2b4739ca3d5359c9937384ccc551bfcc" title="Drop all prophet::Bundle*&#39;s from list.">clear</a>(); <a name="l00034"></a>00034 } <a name="l00035"></a>00035 <a name="l00036"></a>00036 <span class="keywordtype">void</span> <a name="l00037"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#726b948b41a5e24b7f2f18689dd1b107">00037</a> <a class="code" href="dtnperf-client_8c.html#517b0f7cbe789371f38fd9f87f8c807b">ProphetBundleList::add</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a>& b) <a name="l00038"></a>00038 { <a name="l00039"></a>00039 <a class="code" href="classdtn_1_1ProphetBundle.html" title="Unification class that ties together Prophet&#39;s metadata view with DTN&#39;s complete...">ProphetBundle</a>* pb = <span class="keyword">new</span> <a class="code" href="classdtn_1_1ProphetBundle.html" title="Unification class that ties together Prophet&#39;s metadata view with DTN&#39;s complete...">ProphetBundle</a>(b); <a name="l00040"></a>00040 <span class="keywordflow">if</span> (!<a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#1cafd561e6fe753ab2c47e9ac0147610" title="Add bundle to Repository, incrementing current utilization by Bundle&#39;s storage...">add</a>(pb)) <a name="l00041"></a>00041 <span class="keyword">delete</span> pb; <a name="l00042"></a>00042 } <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="keywordtype">void</span> <a name="l00045"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#2bcc467a69db02507fd03596b135e0a5">00045</a> <a class="code" href="dtnperf-client_8c.html#517b0f7cbe789371f38fd9f87f8c807b">ProphetBundleList::add</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* b) <a name="l00046"></a>00046 { <a name="l00047"></a>00047 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#1cafd561e6fe753ab2c47e9ac0147610" title="Add bundle to Repository, incrementing current utilization by Bundle&#39;s storage...">add</a>(b)) <a name="l00048"></a>00048 <span class="keywordflow">return</span>; <a name="l00049"></a>00049 <a name="l00050"></a>00050 <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* pb = <span class="keyword">const_cast<</span><a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>*<span class="keyword">></span>(b); <a name="l00051"></a>00051 <span class="keyword">delete</span> pb; <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="keywordtype">void</span> <a name="l00055"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#b705f40015a645a80f402cca6299f455">00055</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#b705f40015a645a80f402cca6299f455" title="Remove mapping for dtn::BundleRef from list.">ProphetBundleList::del</a>(<span class="keyword">const</span> <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a>& b) <a name="l00056"></a>00056 { <a name="l00057"></a>00057 <a class="code" href="classdtn_1_1ProphetBundleList.html#5396313837c1ac4ec7b167e72f3bb021">const_iterator</a> i; <a name="l00058"></a>00058 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff" title="Given destination ID and creation ts, return prophet::Bundle*.">find</a>(b->dest().str(), <a name="l00059"></a>00059 b->creation_ts().seconds_, <a name="l00060"></a>00060 b->creation_ts().seqno_, i)) <a name="l00061"></a>00061 { <a name="l00062"></a>00062 <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* bundle = <span class="keyword">const_cast<</span><a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>*<span class="keyword">></span>(*i); <a name="l00063"></a>00063 <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#85630acc1cb2251b14f9e315545ce672" title="Remove arbitrary Bundle from Repository, and decrement current utilization accordingly...">del</a>(*i); <a name="l00064"></a>00064 <span class="keyword">delete</span> bundle; <a name="l00065"></a>00065 } <a name="l00066"></a>00066 } <a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="keywordtype">void</span> <a name="l00069"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#fa90103559f89d4def5b50dee07d49ca">00069</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#b705f40015a645a80f402cca6299f455" title="Remove mapping for dtn::BundleRef from list.">ProphetBundleList::del</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* b) <a name="l00070"></a>00070 { <a name="l00071"></a>00071 <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* bundle = <span class="keyword">const_cast<</span><a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>*<span class="keyword">></span>(b); <a name="l00072"></a>00072 <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#85630acc1cb2251b14f9e315545ce672" title="Remove arbitrary Bundle from Repository, and decrement current utilization accordingly...">del</a>(bundle); <a name="l00073"></a>00073 <span class="keyword">delete</span> bundle; <a name="l00074"></a>00074 } <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* <a name="l00077"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff">00077</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff" title="Given destination ID and creation ts, return prophet::Bundle*.">ProphetBundleList::find</a>(<span class="keyword">const</span> std::string& dst, <a name="l00078"></a>00078 u_int creation_ts, <a name="l00079"></a>00079 u_int seqno)<span class="keyword"> const</span> <a name="l00080"></a>00080 <span class="keyword"></span>{ <a name="l00081"></a>00081 <a class="code" href="classdtn_1_1ProphetBundleList.html#5396313837c1ac4ec7b167e72f3bb021">const_iterator</a> i; <a name="l00082"></a>00082 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff" title="Given destination ID and creation ts, return prophet::Bundle*.">find</a>(dst,creation_ts,seqno,i)) <a name="l00083"></a>00083 <span class="keywordflow">return</span> *i; <a name="l00084"></a>00084 <span class="keywordflow">return</span> NULL; <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <a name="l00087"></a>00087 <span class="keyword">const</span> <a class="code" href="namespacedtn.html#87094f3b26b9f1d469e616d311ae57b1" title="Class definition for a Bundle reference.">BundleRef</a>& <a name="l00088"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#07853b9e4a046a0503ad68d28d44f330">00088</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#07853b9e4a046a0503ad68d28d44f330" title="Given a prophet object, return dtn::BundleRef&amp;.">ProphetBundleList::find_ref</a>(<span class="keyword">const</span> <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* b)<span class="keyword"> const</span> <a name="l00089"></a>00089 <span class="keyword"></span>{ <a name="l00090"></a>00090 <span class="keywordflow">if</span> (b != NULL) <a name="l00091"></a>00091 { <a name="l00092"></a>00092 <a class="code" href="classdtn_1_1ProphetBundleList.html#5396313837c1ac4ec7b167e72f3bb021">const_iterator</a> i; <a name="l00093"></a>00093 <span class="keywordflow">if</span> (<a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff" title="Given destination ID and creation ts, return prophet::Bundle*.">find</a>(b-><a class="code" href="classprophet_1_1Bundle.html#81f0a95589809a157829bacb4d3c5989" title="Accessors.">destination_id</a>(), <a name="l00094"></a>00094 b-><a class="code" href="classprophet_1_1Bundle.html#df5ff9aa8aba7ddd7a741d6143fe3d88" title="Accessors.">creation_ts</a>(), <a name="l00095"></a>00095 b-><a class="code" href="classprophet_1_1Bundle.html#8f4fad2c83696237207ba7a19acb9ca4" title="Accessors.">sequence_num</a>(),i)) <a name="l00096"></a>00096 <span class="keywordflow">return</span> <span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classdtn_1_1ProphetBundle.html" title="Unification class that ties together Prophet&#39;s metadata view with DTN&#39;s complete...">ProphetBundle</a>*<span class="keyword">></span>(*i)->ref(); <a name="l00097"></a>00097 } <a name="l00098"></a>00098 <span class="keywordflow">return</span> <a class="code" href="classdtn_1_1ProphetBundleList.html#dddcafe94a1c15642c5ba0ed7477e39e" title="pointer to NULL">NULL_BUNDLE</a>; <a name="l00099"></a>00099 } <a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="keywordtype">void</span> <a name="l00102"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#2b4739ca3d5359c9937384ccc551bfcc">00102</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#2b4739ca3d5359c9937384ccc551bfcc" title="Drop all prophet::Bundle*&#39;s from list.">ProphetBundleList::clear</a>() <a name="l00103"></a>00103 { <a name="l00104"></a>00104 <span class="keywordflow">while</span> (!<a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#c1554cd2ad11330f6fe1635971244497" title="Return boolean indicating whether Repository has any bundles.">empty</a>()) <a name="l00105"></a>00105 { <a name="l00106"></a>00106 <a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>* b = <span class="keyword">const_cast<</span><a class="code" href="classprophet_1_1Bundle.html" title="Facade interface between Prophet router and host implmentation&#39;s Bundle representation...">prophet::Bundle</a>*<span class="keyword">></span>( <a name="l00107"></a>00107 <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#2bc7391d0e5755776242f21f1069f962" title="Fetch const reference to internal list of Bundles (there is no guarantee of meaningful...">get_bundles</a>().<a class="code" href="classdtn_1_1BundleList.html#3ff5877316c9c9c08b161b977e48b701" title="Peek at the first bundle on the list.">front</a>()); <a name="l00108"></a>00108 <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#85630acc1cb2251b14f9e315545ce672" title="Remove arbitrary Bundle from Repository, and decrement current utilization accordingly...">del</a>(b); <a name="l00109"></a>00109 <span class="comment">// clean up memory from Facade wrapper</span> <a name="l00110"></a>00110 <span class="keyword">delete</span> b; <a name="l00111"></a>00111 } <a name="l00112"></a>00112 } <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="keywordtype">bool</span> <a name="l00115"></a><a class="code" href="classdtn_1_1ProphetBundleList.html#ba5df7e072d627a9bba6f070a59ee9c7">00115</a> <a class="code" href="classdtn_1_1ProphetBundleList.html#196550ca5bcb79b25eee907682c66dff" title="Given destination ID and creation ts, return prophet::Bundle*.">ProphetBundleList::find</a>(<span class="keyword">const</span> std::string& dst, <a name="l00116"></a>00116 u_int creation_ts, u_int seqno, <a class="code" href="classdtn_1_1ProphetBundleList.html#5396313837c1ac4ec7b167e72f3bb021">const_iterator</a>& i)<span class="keyword"> const</span> <a name="l00117"></a>00117 <span class="keyword"></span>{ <a name="l00118"></a>00118 i = <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#2bc7391d0e5755776242f21f1069f962" title="Fetch const reference to internal list of Bundles (there is no guarantee of meaningful...">get_bundles</a>().<a class="code" href="classdtn_1_1BundleList.html#24cd371acd62f2f9725ff3f92b55badf" title="Iterator used to iterate through the list.">begin</a>(); <a name="l00119"></a>00119 <span class="keywordflow">while</span> (i != <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#2bc7391d0e5755776242f21f1069f962" title="Fetch const reference to internal list of Bundles (there is no guarantee of meaningful...">get_bundles</a>().<a class="code" href="classdtn_1_1BundleList.html#19f95941fe436d25ba49ae0b2d8bf2c1" title="Iterator used to mark the end of the list.">end</a>()) <a name="l00120"></a>00120 { <a name="l00121"></a>00121 <span class="keywordflow">if</span> ((*i)->creation_ts() == creation_ts && <a name="l00122"></a>00122 (*i)->sequence_num() == seqno && <a name="l00123"></a>00123 (*i)->destination_id() == dst) <span class="keywordflow">break</span>; <a name="l00124"></a>00124 i++; <a name="l00125"></a>00125 } <a name="l00126"></a>00126 <a name="l00127"></a>00127 <span class="keywordflow">if</span> (i == <a class="code" href="classdtn_1_1ProphetBundleList.html#afaf34b35417829fa77955e0e5411730" title="collection of ProphetBundle&#39;s">list_</a>.<a class="code" href="classprophet_1_1Repository.html#2bc7391d0e5755776242f21f1069f962" title="Fetch const reference to internal list of Bundles (there is no guarantee of meaningful...">get_bundles</a>().<a class="code" href="classdtn_1_1BundleList.html#19f95941fe436d25ba49ae0b2d8bf2c1" title="Iterator used to mark the end of the list.">end</a>()) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="keywordflow">return</span> ((*i)->creation_ts() == creation_ts && <a name="l00130"></a>00130 (*i)->sequence_num() == seqno && <a name="l00131"></a>00131 (*i)->destination_id() == dst); <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 }; <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>