Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 29c369053a983cc5d8c880dc6e0a2237 > files > 60

libdtn-devel-2.6.0-2mdv2009.1.i586.rpm

<!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: BaseTLV.h 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&nbsp;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&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>BaseTLV.h</h1><a href="BaseTLV_8h.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">#ifndef _PROPHET_BASE_TLV_H_</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#define _PROPHET_BASE_TLV_H_</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stddef.h&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="keyword">namespace </span>prophet
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">template</span>&lt;<span class="keyword">class</span> TLV&gt;
<a name="l00029"></a><a class="code" href="structprophet_1_1TLVFactory.html">00029</a> <span class="keyword">struct </span><a class="code" href="structprophet_1_1TLVFactory.html">TLVFactory</a>
<a name="l00030"></a>00030 {
<a name="l00035"></a><a class="code" href="structprophet_1_1TLVFactory.html#8d7db1b16d96f90c5a186698536f9f0c">00035</a>     <span class="keyword">static</span> TLV* <a class="code" href="structprophet_1_1TLVFactory.html#8d7db1b16d96f90c5a186698536f9f0c" title="Factory method for deserializing over-the-wire TLV into in-memory class representation...">deserialize</a>(<span class="keyword">const</span> u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>)
<a name="l00036"></a>00036     {
<a name="l00037"></a>00037         TLV* t = <span class="keyword">new</span> TLV();
<a name="l00038"></a>00038         <span class="keywordflow">if</span> (t-&gt;deserialize(bp,len))
<a name="l00039"></a>00039             <span class="keywordflow">return</span> t;
<a name="l00040"></a>00040         <span class="keyword">delete</span> t;
<a name="l00041"></a>00041         <span class="keywordflow">return</span> NULL;
<a name="l00042"></a>00042     }
<a name="l00043"></a>00043 };
<a name="l00044"></a>00044 
<a name="l00058"></a><a class="code" href="classprophet_1_1BaseTLV.html">00058</a> <span class="keyword">class </span><a class="code" href="classprophet_1_1BaseTLV.html" title="The Prophet I-D (March 2006) dictates five bytecodes for router state exchange messages...">BaseTLV</a>
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060 <span class="keyword">public</span>:
<a name="l00064"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d">00064</a>     <span class="keyword">typedef</span> <span class="keyword">enum</span> {
<a name="l00065"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d7058a0458dcadab12100c4813118e7db">00065</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d7058a0458dcadab12100c4813118e7db">UNKNOWN_TLV</a>  = 0x00,
<a name="l00066"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4dcc990715f37355c47fb7f197fb5a3c">00066</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4dcc990715f37355c47fb7f197fb5a3c">HELLO_TLV</a>    = 0x01,
<a name="l00067"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d270f859e453632bfbf1638df2609b089">00067</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d270f859e453632bfbf1638df2609b089">ERROR_TLV</a>    = 0x02,
<a name="l00068"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">00068</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">RIBD_TLV</a>     = 0xA0,
<a name="l00069"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">00069</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">RIB_TLV</a>      = 0xA1,
<a name="l00070"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4678012b183261a4608ea83babc8c315">00070</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4678012b183261a4608ea83babc8c315">OFFER_TLV</a>    = 0XA2, 
<a name="l00071"></a><a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d41b6935bfc9badb7cc041dada67836e5">00071</a>         <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d41b6935bfc9badb7cc041dada67836e5">RESPONSE_TLV</a> = 0XA3,  <span class="comment">// not in spec</span>
<a name="l00072"></a>00072     } <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">prophet_tlv_t</a>;
<a name="l00073"></a>00073 
<a name="l00077"></a>00077     <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l00078"></a><a class="code" href="classprophet_1_1BaseTLV.html#508c517f1f80e0bb7fe6726ecc57ac17">00078</a>     <a class="code" href="classprophet_1_1BaseTLV.html#508c517f1f80e0bb7fe6726ecc57ac17" title="Pretty print function for prophet_tlv_t.">tlv_to_str</a>(<a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">prophet_tlv_t</a> tlv)
<a name="l00079"></a>00079     {
<a name="l00080"></a>00080         <span class="keywordflow">switch</span>(tlv) {
<a name="l00081"></a>00081             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4dcc990715f37355c47fb7f197fb5a3c">HELLO_TLV</a>:    <span class="keywordflow">return</span> <span class="stringliteral">"HELLO_TLV"</span>;
<a name="l00082"></a>00082             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09de5615891dad0b40891a124fcff00f562">RIBD_TLV</a>:     <span class="keywordflow">return</span> <span class="stringliteral">"RIBD_TLV"</span>;
<a name="l00083"></a>00083             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d1a1e57bb574af687605a82fe9f8b7f3e">RIB_TLV</a>:      <span class="keywordflow">return</span> <span class="stringliteral">"RIB_TLV"</span>;
<a name="l00084"></a>00084             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d4678012b183261a4608ea83babc8c315">OFFER_TLV</a>:    <span class="keywordflow">return</span> <span class="stringliteral">"OFFER_TLV"</span>;
<a name="l00085"></a>00085             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d41b6935bfc9badb7cc041dada67836e5">RESPONSE_TLV</a>: <span class="keywordflow">return</span> <span class="stringliteral">"RESPONSE_TLV"</span>;
<a name="l00086"></a>00086             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d270f859e453632bfbf1638df2609b089">ERROR_TLV</a>:
<a name="l00087"></a>00087             <span class="keywordflow">case</span> <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d7058a0458dcadab12100c4813118e7db">UNKNOWN_TLV</a>:
<a name="l00088"></a>00088             <span class="keywordflow">default</span>:         <span class="keywordflow">return</span> <span class="stringliteral">"Unknown TLV type"</span>;
<a name="l00089"></a>00089         }
<a name="l00090"></a>00090     }
<a name="l00091"></a>00091 
<a name="l00095"></a><a class="code" href="classprophet_1_1BaseTLV.html#e6cae3a4e862763869c53ac6130af69f">00095</a>     <span class="keyword">virtual</span> <a class="code" href="classprophet_1_1BaseTLV.html#e6cae3a4e862763869c53ac6130af69f" title="Destructor.">~BaseTLV</a>() {}
<a name="l00096"></a>00096 
<a name="l00102"></a>00102     <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="classprophet_1_1BaseTLV.html#18534e5841ee8447ca2c51cf299becd0" title="Write out TLV from in-memory representation into provided buffer, using no more than...">serialize</a>(u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>) <span class="keyword">const</span> = 0;
<a name="l00103"></a>00103 
<a name="l00105"></a><a class="code" href="classprophet_1_1BaseTLV.html#b786adb497e8ed2e726390a579483dbc">00105</a>     <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">prophet_tlv_t</a> <a class="code" href="classprophet_1_1BaseTLV.html#b786adb497e8ed2e726390a579483dbc" title="Accessors.">typecode</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a>; }
<a name="l00106"></a><a class="code" href="classprophet_1_1BaseTLV.html#85ccaab1420732e2f1e327798b8899ed">00106</a>     u_int8_t      <a class="code" href="classprophet_1_1BaseTLV.html#85ccaab1420732e2f1e327798b8899ed" title="Accessors.">flags</a>()<span class="keyword">    const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a>; }
<a name="l00107"></a><a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291">00107</a>     u_int16_t     <a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>()<span class="keyword">   const </span>{ <span class="keywordflow">return</span> <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>; }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 <span class="keyword">protected</span>:
<a name="l00111"></a>00111 
<a name="l00115"></a><a class="code" href="classprophet_1_1BaseTLV.html#01468b394d8a4aa6241ac8946afa4458">00115</a>     <a class="code" href="classprophet_1_1BaseTLV.html#01468b394d8a4aa6241ac8946afa4458" title="Constructor is protected to force use of factory.">BaseTLV</a>(<a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">prophet_tlv_t</a> <a class="code" href="classprophet_1_1BaseTLV.html#b786adb497e8ed2e726390a579483dbc" title="Accessors.">typecode</a> = <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d7058a0458dcadab12100c4813118e7db">UNKNOWN_TLV</a>,
<a name="l00116"></a>00116             u_int8_t <a class="code" href="classprophet_1_1BaseTLV.html#85ccaab1420732e2f1e327798b8899ed" title="Accessors.">flags</a> = 0, 
<a name="l00117"></a>00117             u_int16_t <a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a> = 0)
<a name="l00118"></a>00118         : <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a>(<a class="code" href="classprophet_1_1BaseTLV.html#b786adb497e8ed2e726390a579483dbc" title="Accessors.">typecode</a>), <a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a>(<a class="code" href="classprophet_1_1BaseTLV.html#85ccaab1420732e2f1e327798b8899ed" title="Accessors.">flags</a>), <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>(<a class="code" href="classprophet_1_1BaseTLV.html#5d6ab71b768b416bc457090d1189b291" title="Accessors.">length</a>) {}
<a name="l00119"></a>00119 
<a name="l00123"></a>00123     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classprophet_1_1BaseTLV.html#39a29c35a775a408b165921f61beec2d" title="Read a TLV in from transport and copy its contents into memory.">deserialize</a>(<span class="keyword">const</span> u_char* bp, <span class="keywordtype">size_t</span> <a class="code" href="num2sdnv_8c.html#fed088663f8704004425cdae2120b9b3">len</a>) = 0;
<a name="l00124"></a>00124 
<a name="l00125"></a><a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249">00125</a>     <a class="code" href="classprophet_1_1BaseTLV.html#37c3690d6040c870b40fa0436b67b09d" title="Byte codes for TLV types.">prophet_tlv_t</a>     <a class="code" href="classprophet_1_1BaseTLV.html#88263c57b5c2760ece631ce8943c6249" title="typecode for this TLV">typecode_</a>; 
<a name="l00126"></a><a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e">00126</a>     u_int8_t          <a class="code" href="classprophet_1_1BaseTLV.html#31f1ebbf538b5b28c42e49e1eef6a34e" title="TLV-specific flags.">flags_</a>;    
<a name="l00127"></a><a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823">00127</a>     <span class="keyword">mutable</span> u_int16_t <a class="code" href="classprophet_1_1BaseTLV.html#4c0a7b24b795bafb52c16b24a6188823" title="serialized length of TLV, mutable so it can be assigned by serialize() const">length_</a>;   
<a name="l00128"></a>00128 
<a name="l00129"></a>00129 }; <span class="comment">// class BaseTLV</span>
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 }; <span class="comment">// namespace prophet</span>
<a name="l00132"></a>00132 
<a name="l00133"></a>00133 <span class="preprocessor">#endif // _PROPHET_BASE_TLV_H_</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&nbsp;
<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>