<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <!-- $Id: header.html 8799 2010-06-28 04:12:42Z jpgr87 $ --> <HEAD> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=utf-8"> <meta name="keywords" content="stage, robot, simulation, player, player/stage"> <link href="doxygen.css" rel="stylesheet" type="text/css"> <style type="text/css"> .floatright { float: right; margin: 0 0 1em 1em; } body { font-family: sans-serif; #font-family: Geneva, Verdana, Helvetica, Arial, sans-serif; background-color: #FFF; color:#000; } a:link { color: #A00; } a:visited { color: #800; } a { text-decoration: none; } a:hover { text-decoration: underline; } .timestamp { text-align:right; background-color: #DDD; font-size:75%;} h1 { font-size:160%; } h2 { font-size:110%; #color: #FFF; #background-color: #666; #padding:3px; } h3 { text-align:left; } img { border: 0; } ul.menu { position:relative; left:-2.5em; margin-bottom:0px; margin-top:0px; } ul.menu1 { position:relative; left:-2.1em; margin-bottom:0px; margin-top:0px; } li.menu { list-style-type: none; position:relative; #left:-0.5em; } #sidebar { position: absolute; left:0px; padding:2em; top:0em; width:12em;} #content { position: absolute; left:12em; top:0em; padding-left:3em; padding-right:3em; padding-bottom:2em; margin-top:1em; margin-right:2em; } div.box { background-color:#EEE; border: 1px solid #000; padding: 0.5ex 0.4em 0.5ex 0.6em; margin:1em; } div.title { font-weight:bold; background-color:#eee; margin-bottom:2px;} div.topbar { position: absolute; top:0px; left:9em; margin:1em; } </style> <TITLE>Player Manual</TITLE> </HEAD> <body> <div id="sidebar"> <h2 style="text-align:center;"> <a href="index.html"> <img width=140 src="http://playerstage.sourceforge.net/images/player_button_v3.png" alt="Player logo"><br></a> </h2> <div class="box"> <div class=title>Player</div> <ul class=menu> <li class=menu><a href="index.html">Frontpage</a> <li class=menu><a href="modules.html">Contents</a> </ul> </div> <div class="box"> <div class=title>User</div> <ul class=menu> <li class=menu><a href="install.html">Installation</a> <li class=menu><a href="start.html">Quick start</a> <li class=menu><a href="supported_hardware.html">Supported devices</a> <li class=menu><a href="group__tutorials.html">Tutorials</a> <li class=menu><a href="group__utils.html">Utilities</a> <li class=menu><a href="group__clientlibs.html">Client libraries</a> <li class=menu><a href="http://playerstage.sourceforge.net/wiki/Basic_FAQ">FAQ</a> <li class=menu><a href="help.html">Help</a> </ul> </div> <div class=box> <div class="title">Developer</div> <ul class=menu> <li class=menu><a href="architecture.html">Architecture</a> <li class=menu><a href="group__libplayercore.html">libplayercore</a> <ul class=menu1> <li class=menu><a href="group__interfaces.html">interfaces</a></li> </ul> <li class=menu><a href="group__libplayerdrivers.html">libplayerdrivers</a> <ul class=menu1> <li class=menu><a href="group__drivers.html">drivers</a></li> </ul> <li class=menu><a href="group__libplayercommon.html">libplayercommon</a> <li class=menu><a href="group__libplayerutils.html">libplayerutils</a> <li class=menu><a href="group__libplayersd.html">libplayersd</a> <li class=menu><a href="group__libplayertcp.html">libplayertcp</a> <li class=menu><a href="group__libplayerxdr.html">libplayerxdr</a> <li class=menu><a href="todo.html">TODO</a> </ul> </div> <div class=box> <!-- <a href="http://sourceforge.net"><img border=0 src="http://sourceforge.net/sflogo.php?group_id=42445&type=1"></a> --> <div class="title">Online</div> <a href="http://playerstage.sourceforge.net">Homepage</a><br> <a href="http://sourceforge.net/project/showfiles.php?group_id=42445">Download</a><br> <a href="http://sourceforge.net/projects/playerstage">Project</a><br> <a href="http://sourceforge.net/tracker/?group_id=42445">Bugs</a><br> <a href="http://sourceforge.net/mail/?group_id=42445">Help</a> </div> </div> <div id="content" > <!-- Generated by Doxygen 1.7.1 --> <div class="header"> <div class="headertitle"> <h1>message.h</h1> </div> </div> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * Player - One Hell of a Robot Server</span> <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2000</span> <a name="l00004"></a>00004 <span class="comment"> * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard</span> <a name="l00005"></a>00005 <span class="comment"> *</span> <a name="l00006"></a>00006 <span class="comment"> *</span> <a name="l00007"></a>00007 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span> <a name="l00008"></a>00008 <span class="comment"> * it under the terms of the GNU General Public License as published by</span> <a name="l00009"></a>00009 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span> <a name="l00010"></a>00010 <span class="comment"> * (at your option) any later version.</span> <a name="l00011"></a>00011 <span class="comment"> *</span> <a name="l00012"></a>00012 <span class="comment"> * This program is distributed in the hope that it will be useful,</span> <a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <a name="l00015"></a>00015 <span class="comment"> * GNU General Public License for more details.</span> <a name="l00016"></a>00016 <span class="comment"> *</span> <a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU General Public License</span> <a name="l00018"></a>00018 <span class="comment"> * along with this program; if not, write to the Free Software</span> <a name="l00019"></a>00019 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00020"></a>00020 <span class="comment"> *</span> <a name="l00021"></a>00021 <span class="comment"> */</span> <a name="l00022"></a>00022 <span class="comment">/********************************************************************</span> <a name="l00023"></a>00023 <span class="comment"> *</span> <a name="l00024"></a>00024 <span class="comment"> * This library is free software; you can redistribute it and/or</span> <a name="l00025"></a>00025 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span> <a name="l00026"></a>00026 <span class="comment"> * License as published by the Free Software Foundation; either</span> <a name="l00027"></a>00027 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span> <a name="l00028"></a>00028 <span class="comment"> *</span> <a name="l00029"></a>00029 <span class="comment"> * This library is distributed in the hope that it will be useful,</span> <a name="l00030"></a>00030 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00031"></a>00031 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00032"></a>00032 <span class="comment"> * Lesser General Public License for more details.</span> <a name="l00033"></a>00033 <span class="comment"> *</span> <a name="l00034"></a>00034 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span> <a name="l00035"></a>00035 <span class="comment"> * License along with this library; if not, write to the Free Software</span> <a name="l00036"></a>00036 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span> <a name="l00037"></a>00037 <span class="comment"> *</span> <a name="l00038"></a>00038 <span class="comment"> ********************************************************************/</span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="comment">/*</span> <a name="l00041"></a>00041 <span class="comment"> * Desc: Message class and message queues</span> <a name="l00042"></a>00042 <span class="comment"> * CVS: $Id: message.h 8004 2009-07-13 14:03:44Z thjc $</span> <a name="l00043"></a>00043 <span class="comment"> * Author: Toby Collett - Jan 2005</span> <a name="l00044"></a>00044 <span class="comment"> */</span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="preprocessor">#ifndef MESSAGE_H</span> <a name="l00047"></a>00047 <span class="preprocessor"></span><span class="preprocessor">#define MESSAGE_H</span> <a name="l00048"></a>00048 <span class="preprocessor"></span> <a name="l00049"></a>00049 <span class="preprocessor">#if defined (WIN32)</span> <a name="l00050"></a>00050 <span class="preprocessor"></span><span class="preprocessor"> #if defined (PLAYER_STATIC)</span> <a name="l00051"></a>00051 <span class="preprocessor"></span><span class="preprocessor"> #define PLAYERCORE_EXPORT</span> <a name="l00052"></a>00052 <span class="preprocessor"></span><span class="preprocessor"> #elif defined (playercore_EXPORTS)</span> <a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor"> #define PLAYERCORE_EXPORT __declspec (dllexport)</span> <a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor"> #else</span> <a name="l00055"></a>00055 <span class="preprocessor"></span><span class="preprocessor"> #define PLAYERCORE_EXPORT __declspec (dllimport)</span> <a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor"> #endif</span> <a name="l00057"></a>00057 <span class="preprocessor"></span><span class="preprocessor">#else</span> <a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor"> #define PLAYERCORE_EXPORT</span> <a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#endif</span> <a name="l00060"></a>00060 <span class="preprocessor"></span> <a name="l00061"></a>00061 <span class="preprocessor">#include <pthread.h></span> <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="preprocessor">#include <libplayerinterface/player.h></span> <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="keyword">class </span><a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a>; <a name="l00066"></a>00066 <a name="l00073"></a><a class="code" href="classQueuePointer.html">00073</a> <span class="keyword">class </span>PLAYERCORE_EXPORT <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> <a name="l00074"></a>00074 { <a name="l00075"></a>00075 <span class="keyword">public</span>: <a name="l00077"></a>00077 <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a>(); <a name="l00079"></a>00079 <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a>(<span class="keywordtype">bool</span> _Replace, <span class="keywordtype">size_t</span> _Maxlen); <a name="l00081"></a>00081 ~<a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a>(); <a name="l00083"></a>00083 <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a>(<span class="keyword">const</span> <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> & CopyFrom); <a name="l00084"></a>00084 <a name="l00086"></a>00086 <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> & operator = (<span class="keyword">const</span> <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> & rhs); <a name="l00088"></a>00088 <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a> * operator -> (); <a name="l00090"></a>00090 <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a> * <span class="keyword">get</span>() <span class="keyword">const</span>; <a name="l00092"></a>00092 <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a> & operator * (); <a name="l00094"></a>00094 <span class="keywordtype">bool</span> operator == (<span class="keyword">const</span> <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> & rhs); <a name="l00096"></a>00096 <span class="keywordtype">bool</span> operator == (<span class="keywordtype">void</span> * pointer); <a name="l00098"></a>00098 <span class="keywordtype">bool</span> operator != (<span class="keyword">const</span> <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> & rhs); <a name="l00100"></a>00100 <span class="keywordtype">bool</span> operator != (<span class="keywordtype">void</span> * pointer); <a name="l00101"></a>00101 <a name="l00102"></a>00102 <span class="keyword">private</span>: <a name="l00104"></a>00104 <span class="keywordtype">void</span> DecRef(); <a name="l00105"></a>00105 <a name="l00107"></a><a class="code" href="classQueuePointer.html#a39d01b30999959c773b2fc2e6da38b53">00107</a> <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a> * Queue; <a name="l00108"></a>00108 <a name="l00110"></a><a class="code" href="classQueuePointer.html#af709d845716d474503d0bbf564a97ca3">00110</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> * RefCount; <a name="l00111"></a>00111 <a name="l00113"></a><a class="code" href="classQueuePointer.html#abf724f2525c002316ee6374d25c7f81f">00113</a> pthread_mutex_t * Lock; <a name="l00114"></a>00114 }; <a name="l00115"></a>00115 <a name="l00116"></a>00116 <a name="l00117"></a>00117 <a name="l00132"></a><a class="code" href="classMessage.html">00132</a> <span class="keyword">class </span>PLAYERCORE_EXPORT <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a> <a name="l00133"></a>00133 { <a name="l00134"></a>00134 <span class="keyword">public</span>: <a name="l00137"></a>00137 <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr</a> & Header, <a name="l00138"></a>00138 <span class="keywordtype">void</span>* data, <a name="l00139"></a>00139 <span class="keywordtype">bool</span> copy = <span class="keyword">true</span>); <a name="l00140"></a>00140 <a name="l00143"></a>00143 <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr</a> & Header, <a name="l00144"></a>00144 <span class="keywordtype">void</span>* data, <a name="l00145"></a>00145 <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> &_queue, <a name="l00146"></a>00146 <span class="keywordtype">bool</span> copy = <span class="keyword">true</span>); <a name="l00147"></a>00147 <a name="l00149"></a>00149 <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>(<span class="keyword">const</span> <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a> & rhs); <a name="l00150"></a>00150 <a name="l00152"></a>00152 ~<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>(); <a name="l00153"></a>00153 <a name="l00159"></a><a class="code" href="classMessage.html#a5fd1734509a7520a64186c2653207751">00159</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> MatchMessage(<a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a>* hdr, <a name="l00160"></a>00160 <span class="keywordtype">int</span> type, <a name="l00161"></a>00161 <span class="keywordtype">int</span> subtype, <a name="l00162"></a>00162 <a class="code" href="structplayer__devaddr.html" title="A device address.">player_devaddr_t</a> addr) <a name="l00163"></a>00163 { <a name="l00164"></a>00164 <span class="keywordflow">return</span>(((type < 0) || (hdr-><a class="code" href="structplayer__msghdr.html#a1c20e2f82ad8f6164f7cf31d940255fb" title="Message type; must be one of PLAYER_MSGTYPE_*.">type</a> == (uint8_t)type)) && <a name="l00165"></a>00165 ((subtype < 0) || (hdr-><a class="code" href="structplayer__msghdr.html#aeba88246e5ba9d3d6c1f2b60c329352b" title="Message subtype; interface specific.">subtype</a> == (uint8_t)subtype)) && <a name="l00166"></a>00166 (hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a7514f8e66c9532d235cc4258a7102af5" title="The &quot;host&quot; on which the device resides.">host</a> == addr.<a class="code" href="structplayer__devaddr.html#a7514f8e66c9532d235cc4258a7102af5" title="The &quot;host&quot; on which the device resides.">host</a>) && <a name="l00167"></a>00167 (hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a5bfc4826407c3a01f4ae884ffcef00c7" title="The &quot;robot&quot; or device collection in which the device resides.">robot</a> == addr.<a class="code" href="structplayer__devaddr.html#a5bfc4826407c3a01f4ae884ffcef00c7" title="The &quot;robot&quot; or device collection in which the device resides.">robot</a>) && <a name="l00168"></a>00168 (hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#ac6a1d9efc69d7dee301aba2ef4b5948d" title="The interface provided by the device; must be one of PLAYER_*_CODE.">interf</a> == addr.<a class="code" href="structplayer__devaddr.html#ac6a1d9efc69d7dee301aba2ef4b5948d" title="The interface provided by the device; must be one of PLAYER_*_CODE.">interf</a>) && <a name="l00169"></a>00169 (hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a2814dc42b4162c8451876312fc85f0a8" title="Which device of that interface.">index</a> == addr.<a class="code" href="structplayer__devaddr.html#a2814dc42b4162c8451876312fc85f0a8" title="Which device of that interface.">index</a>)); <a name="l00170"></a>00170 } <a name="l00171"></a>00171 <a name="l00177"></a><a class="code" href="classMessage.html#ac3af22b7bba221b52c2dbafb2cb617dd">00177</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> MatchMessage(<a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a>* hdr, <a name="l00178"></a>00178 <span class="keywordtype">int</span> type, <a name="l00179"></a>00179 <span class="keywordtype">int</span> subtype) <a name="l00180"></a>00180 { <a name="l00181"></a>00181 <span class="keywordflow">return</span>(((type < 0) || (hdr-><a class="code" href="structplayer__msghdr.html#a1c20e2f82ad8f6164f7cf31d940255fb" title="Message type; must be one of PLAYER_MSGTYPE_*.">type</a> == (uint8_t)type)) && <a name="l00182"></a>00182 ((subtype < 0) || (hdr-><a class="code" href="structplayer__msghdr.html#aeba88246e5ba9d3d6c1f2b60c329352b" title="Message subtype; interface specific.">subtype</a> == (uint8_t)subtype))); <a name="l00183"></a>00183 } <a name="l00184"></a>00184 <a name="l00186"></a><a class="code" href="classMessage.html#a657c46003857b54271a84c414eba5500">00186</a> <a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a> * <a class="code" href="classMessage.html#a657c46003857b54271a84c414eba5500" title="Get pointer to header.">GetHeader</a>() {<span class="keywordflow">return</span> &Header;}; <a name="l00188"></a><a class="code" href="classMessage.html#ae8f055a9308a86946a8a281599d3e2f0">00188</a> <span class="keywordtype">void</span>* <a class="code" href="classMessage.html#ae8f055a9308a86946a8a281599d3e2f0" title="Get pointer to payload.">GetPayload</a>() {<span class="keywordflow">return</span> (<span class="keywordtype">void</span>*)Data;}; <a name="l00190"></a><a class="code" href="classMessage.html#a2f855967b8363918119bdbf5d2eb0a49">00190</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classMessage.html#a2f855967b8363918119bdbf5d2eb0a49" title="Size of message data.">GetDataSize</a>() {<span class="keywordflow">return</span> Header.<a class="code" href="structplayer__msghdr.html#a27ef3166ee2eacc5e694e5a20f6fe5b6" title="Size in bytes of the payload to follow.">size</a>;}; <a name="l00192"></a>00192 <span class="keywordtype">bool</span> Compare(<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a> &other); <a name="l00194"></a>00194 <span class="keywordtype">void</span> DecRef(); <a name="l00195"></a>00195 <a name="l00197"></a><a class="code" href="classMessage.html#a2865801b0cc762b21af76f5c39b3824a">00197</a> <a class="code" href="classQueuePointer.html" title="An autopointer for the message queue.">QueuePointer</a> Queue; <a name="l00198"></a>00198 <a name="l00200"></a><a class="code" href="classMessage.html#af8bcd20674be9b09f4ab73187dd418cc">00200</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> * RefCount; <a name="l00201"></a>00201 <a name="l00202"></a>00202 <span class="keyword">private</span>: <a name="l00203"></a>00203 <span class="keywordtype">void</span> CreateMessage(<span class="keyword">const</span> <span class="keyword">struct</span> <a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr</a> & Header, <a name="l00204"></a>00204 <span class="keywordtype">void</span>* data, <a name="l00205"></a>00205 <span class="keywordtype">bool</span> copy = <span class="keyword">true</span>); <a name="l00206"></a>00206 <a name="l00208"></a><a class="code" href="classMessage.html#a92bf92d94e3afea26e791a6fe5e394ef">00208</a> <a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a> Header; <a name="l00210"></a><a class="code" href="classMessage.html#a8363310ff515fc2fe74fa58019cc3d7f">00210</a> uint8_t * Data; <a name="l00212"></a><a class="code" href="classMessage.html#ad4d3e0ba54202520c6f441c3384f9054">00212</a> pthread_mutex_t * Lock; <a name="l00213"></a>00213 }; <a name="l00214"></a>00214 <a name="l00218"></a><a class="code" href="classMessageQueueElement.html">00218</a> <span class="keyword">class </span>PLAYERCORE_EXPORT <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a> <a name="l00219"></a>00219 { <a name="l00220"></a>00220 <span class="keyword">public</span>: <a name="l00222"></a>00222 <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a>(); <a name="l00224"></a>00224 ~<a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a>(); <a name="l00225"></a>00225 <a name="l00227"></a><a class="code" href="classMessageQueueElement.html#a0369e614acead970005c97dd9ba2f5b8">00227</a> <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>* msg; <a name="l00228"></a>00228 <span class="keyword">private</span>: <a name="l00230"></a><a class="code" href="classMessageQueueElement.html#a67f66f3e3c37fd950cce7eddc09478fe">00230</a> <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a> * prev; <a name="l00232"></a><a class="code" href="classMessageQueueElement.html#a403493de1cc8a8615c00379d221992c1">00232</a> <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a> * next; <a name="l00233"></a>00233 <a name="l00234"></a>00234 <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a>; <a name="l00235"></a>00235 }; <a name="l00236"></a>00236 <a name="l00243"></a><a class="code" href="classMessageReplaceRule.html">00243</a> <span class="keyword">class </span>PLAYERCORE_EXPORT <a class="code" href="classMessageReplaceRule.html" title="We keep a singly-linked list of (addr,type,subtype,replace) tuples.">MessageReplaceRule</a> <a name="l00244"></a>00244 { <a name="l00245"></a>00245 <span class="keyword">private</span>: <a name="l00246"></a>00246 <span class="comment">// The address to match (not using a player_devaddr_t so that we can</span> <a name="l00247"></a>00247 <span class="comment">// use -1 to indicate don't care)</span> <a name="l00248"></a>00248 <span class="keywordtype">int</span> host, robot, interf, index; <a name="l00249"></a>00249 <span class="comment">// The type and subtype to match (-1 is don't care)</span> <a name="l00250"></a>00250 <span class="keywordtype">int</span> type, subtype; <a name="l00251"></a>00251 <span class="keyword">public</span>: <a name="l00252"></a>00252 <a class="code" href="classMessageReplaceRule.html" title="We keep a singly-linked list of (addr,type,subtype,replace) tuples.">MessageReplaceRule</a>(<span class="keywordtype">int</span> _host, <span class="keywordtype">int</span> _robot, <span class="keywordtype">int</span> _interf, <span class="keywordtype">int</span> _index, <a name="l00253"></a>00253 <span class="keywordtype">int</span> _type, <span class="keywordtype">int</span> _subtype, <span class="keywordtype">int</span> _replace) : <a name="l00254"></a>00254 host(_host), robot(_robot), interf(_interf), index(_index), <a name="l00255"></a>00255 type(_type), subtype(_subtype), replace(_replace), next(NULL) {} <a name="l00256"></a>00256 <a name="l00257"></a>00257 <span class="keywordtype">bool</span> Match(<a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a>* hdr) <a name="l00258"></a>00258 { <a name="l00259"></a>00259 <span class="keywordflow">return</span>(((this->host < 0) || <a name="l00260"></a>00260 ((uint32_t)this->host == hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a7514f8e66c9532d235cc4258a7102af5" title="The &quot;host&quot; on which the device resides.">host</a>)) && <a name="l00261"></a>00261 ((this->robot < 0) || <a name="l00262"></a>00262 ((uint32_t)this->robot == hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a5bfc4826407c3a01f4ae884ffcef00c7" title="The &quot;robot&quot; or device collection in which the device resides.">robot</a>)) && <a name="l00263"></a>00263 ((this->interf < 0) || <a name="l00264"></a>00264 ((uint16_t)this->interf == hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#ac6a1d9efc69d7dee301aba2ef4b5948d" title="The interface provided by the device; must be one of PLAYER_*_CODE.">interf</a>)) && <a name="l00265"></a>00265 ((this->index < 0) || <a name="l00266"></a>00266 ((uint16_t)this->index == hdr-><a class="code" href="structplayer__msghdr.html#aefb4cbdabb4aa6cb01fd56ba7b2aeafb" title="Device to which this message pertains.">addr</a>.<a class="code" href="structplayer__devaddr.html#a2814dc42b4162c8451876312fc85f0a8" title="Which device of that interface.">index</a>)) && <a name="l00267"></a>00267 ((this->type < 0) || <a name="l00268"></a>00268 ((uint8_t)this->type == hdr-><a class="code" href="structplayer__msghdr.html#a1c20e2f82ad8f6164f7cf31d940255fb" title="Message type; must be one of PLAYER_MSGTYPE_*.">type</a>)) && <a name="l00269"></a>00269 ((this->subtype < 0) || <a name="l00270"></a>00270 ((uint8_t)this->subtype == hdr-><a class="code" href="structplayer__msghdr.html#aeba88246e5ba9d3d6c1f2b60c329352b" title="Message subtype; interface specific.">subtype</a>))); <a name="l00271"></a>00271 } <a name="l00272"></a>00272 <a name="l00273"></a>00273 <span class="keywordtype">bool</span> Equivalent (<span class="keywordtype">int</span> _host, <span class="keywordtype">int</span> _robot, <span class="keywordtype">int</span> _interf, <span class="keywordtype">int</span> _index, <span class="keywordtype">int</span> _type, <span class="keywordtype">int</span> _subtype) <a name="l00274"></a>00274 { <a name="l00275"></a>00275 <span class="keywordflow">return</span> (host == _host && robot == _robot && interf ==_interf && index == _index && <a name="l00276"></a>00276 type == _type && subtype == _subtype); <a name="l00277"></a>00277 } <a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="comment">// To replace, or not to replace</span> <a name="l00280"></a>00280 <span class="comment">// That is the question</span> <a name="l00281"></a>00281 <span class="keywordtype">int</span> replace; <a name="l00282"></a>00282 <span class="comment">// Next rule in the list</span> <a name="l00283"></a>00283 <a class="code" href="classMessageReplaceRule.html" title="We keep a singly-linked list of (addr,type,subtype,replace) tuples.">MessageReplaceRule</a>* next; <a name="l00284"></a>00284 }; <a name="l00285"></a>00285 <a name="l00337"></a><a class="code" href="classMessageQueue.html">00337</a> <span class="keyword">class </span>PLAYERCORE_EXPORT <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a> <a name="l00338"></a>00338 { <a name="l00339"></a>00339 <span class="keyword">public</span>: <a name="l00341"></a>00341 <a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a>(<span class="keywordtype">bool</span> _Replace, <span class="keywordtype">size_t</span> _Maxlen); <a name="l00343"></a>00343 ~<a class="code" href="classMessageQueue.html" title="A doubly-linked queue of messages.">MessageQueue</a>(); <a name="l00345"></a><a class="code" href="classMessageQueue.html#a8746df2213e0bb5e8c86cc5fb99717c2">00345</a> <span class="keywordtype">bool</span> <a class="code" href="classMessageQueue.html#a8746df2213e0bb5e8c86cc5fb99717c2" title="Check whether a queue is empty.">Empty</a>() { <span class="keywordflow">return</span>(this->head == NULL); } <a name="l00348"></a>00348 <span class="keywordtype">bool</span> Push(<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>& msg); <a name="l00349"></a>00349 <a name="l00354"></a>00354 <span class="keywordtype">void</span> PushFront(<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a> & msg, <span class="keywordtype">bool</span> haveLock); <a name="l00355"></a>00355 <a name="l00360"></a>00360 <span class="keywordtype">void</span> PushBack(<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a> & msg, <span class="keywordtype">bool</span> haveLock); <a name="l00361"></a>00361 <a name="l00365"></a>00365 <a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>* Pop(); <a name="l00369"></a><a class="code" href="classMessageQueue.html#a785d982d955cbe025ecc68d3b1348aa8">00369</a> <span class="keywordtype">void</span> <a class="code" href="classMessageQueue.html#a785d982d955cbe025ecc68d3b1348aa8" title="Set the Replace flag, which governs whether data and command messages of the same subtype from the sa...">SetReplace</a>(<span class="keywordtype">bool</span> _Replace) { this->Replace = _Replace; }; <a name="l00376"></a>00376 <span class="keywordtype">void</span> AddReplaceRule(<span class="keywordtype">int</span> _host, <span class="keywordtype">int</span> _robot, <span class="keywordtype">int</span> _interf, <span class="keywordtype">int</span> _index, <a name="l00377"></a>00377 <span class="keywordtype">int</span> _type, <span class="keywordtype">int</span> _subtype, <span class="keywordtype">int</span> _replace); <a name="l00383"></a>00383 <span class="keywordtype">void</span> AddReplaceRule(<span class="keyword">const</span> <a class="code" href="structplayer__devaddr.html" title="A device address.">player_devaddr_t</a> &device, <a name="l00384"></a>00384 <span class="keywordtype">int</span> _type, <span class="keywordtype">int</span> _subtype, <span class="keywordtype">int</span> _replace); <a name="l00387"></a>00387 <span class="keywordtype">int</span> CheckReplace(<a class="code" href="structplayer__msghdr.html" title="Generic message header.">player_msghdr_t</a>* hdr); <a name="l00394"></a>00394 <span class="keywordtype">bool</span> Wait(<span class="keywordtype">double</span> TimeOut=0.0); <a name="l00397"></a>00397 <span class="keywordtype">void</span> DataAvailable(<span class="keywordtype">void</span>); <a name="l00399"></a>00399 <span class="keywordtype">bool</span> Filter(<a class="code" href="classMessage.html" title="Reference-counted message objects.">Message</a>& msg); <a name="l00401"></a>00401 <span class="keywordtype">void</span> ClearFilter(<span class="keywordtype">void</span>); <a name="l00403"></a>00403 <span class="keywordtype">void</span> SetFilter(<span class="keywordtype">int</span> host, <span class="keywordtype">int</span> robot, <span class="keywordtype">int</span> interf, <span class="keywordtype">int</span> index, <a name="l00404"></a>00404 <span class="keywordtype">int</span> type, <span class="keywordtype">int</span> subtype); <a name="l00406"></a><a class="code" href="classMessageQueue.html#ac481e113aae4391d8d74e25e241269b0">00406</a> <span class="keywordtype">void</span> <a class="code" href="classMessageQueue.html#ac481e113aae4391d8d74e25e241269b0" title="Set the pull flag.">SetPull</a> (<span class="keywordtype">bool</span> _pull) { this->pull = _pull; } <a name="l00407"></a>00407 <a name="l00409"></a>00409 <span class="keywordtype">size_t</span> GetLength(<span class="keywordtype">void</span>); <a name="l00410"></a>00410 <a name="l00412"></a>00412 <span class="keywordtype">void</span> SetDataRequested(<span class="keywordtype">bool</span> d, <span class="keywordtype">bool</span> haveLock); <a name="l00413"></a>00413 <a name="l00414"></a>00414 <span class="keyword">private</span>: <a name="l00416"></a><a class="code" href="classMessageQueue.html#a93197b9bd74d7e9fa5e71939eceb62e8">00416</a> <span class="keywordtype">void</span> <a class="code" href="classMessageQueue.html#a93197b9bd74d7e9fa5e71939eceb62e8" title="Lock the mutex associated with this queue.">Lock</a>() {pthread_mutex_lock(&lock);}; <a name="l00418"></a><a class="code" href="classMessageQueue.html#a90ef77759dd90d9811dbbdcf73778b98">00418</a> <span class="keywordtype">void</span> <a class="code" href="classMessageQueue.html#a90ef77759dd90d9811dbbdcf73778b98" title="Unlock the mutex associated with this queue.">Unlock</a>() {pthread_mutex_unlock(&lock);}; <a name="l00421"></a>00421 <span class="keywordtype">void</span> Remove(<a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a>* el); <a name="l00423"></a><a class="code" href="classMessageQueue.html#a2ec72e814490a8974c9f6d21eb5b7663">00423</a> <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a>* head; <a name="l00425"></a><a class="code" href="classMessageQueue.html#a5a7e0e994a2457ee73b7283efa54583c">00425</a> <a class="code" href="classMessageQueueElement.html" title="This class is a helper for maintaining doubly-linked queues of Messages.">MessageQueueElement</a>* tail; <a name="l00427"></a><a class="code" href="classMessageQueue.html#a85231d6ff82ddbda5ff09ff3a5ce162f">00427</a> pthread_mutex_t lock; <a name="l00429"></a><a class="code" href="classMessageQueue.html#a2389db3ab46ceb5c4e718ae35271904a">00429</a> <span class="keywordtype">size_t</span> Maxlen; <a name="l00431"></a><a class="code" href="classMessageQueue.html#a6b4e1ca9827f50ff13c80aed3011631c">00431</a> <a class="code" href="classMessageReplaceRule.html" title="We keep a singly-linked list of (addr,type,subtype,replace) tuples.">MessageReplaceRule</a>* replaceRules; <a name="l00434"></a><a class="code" href="classMessageQueue.html#ad69ab7d8969fc437d7cfa40be01b8fc2">00434</a> <span class="keywordtype">bool</span> Replace; <a name="l00436"></a><a class="code" href="classMessageQueue.html#af1b304b73cebe7980479a3a1cd85f2ea">00436</a> <span class="keywordtype">size_t</span> Length; <a name="l00440"></a><a class="code" href="classMessageQueue.html#a926c7aa691bfa676fc95c7bac068db1c">00440</a> pthread_cond_t cond; <a name="l00442"></a><a class="code" href="classMessageQueue.html#adbdac9cbde00e9c91233177a9f24e10b">00442</a> pthread_mutex_t condMutex; <a name="l00444"></a><a class="code" href="classMessageQueue.html#ad0ed11d0d4a5f7392be539058e352f7d">00444</a> <span class="keywordtype">bool</span> filter_on; <a name="l00445"></a>00445 <span class="keywordtype">int</span> filter_host, filter_robot, filter_interf, <a name="l00446"></a>00446 filter_index, filter_type, filter_subtype; <a name="l00449"></a><a class="code" href="classMessageQueue.html#a17bdbcec1c31748e1fa1b77e9a2ac576">00449</a> <span class="keywordtype">bool</span> pull; <a name="l00452"></a><a class="code" href="classMessageQueue.html#acfa7b736cfe1791f6f618a178ed211bb">00452</a> <span class="keywordtype">bool</span> data_requested; <a name="l00454"></a><a class="code" href="classMessageQueue.html#a2262d819a55d5a20c3e2e7dcff31b7e0">00454</a> <span class="keywordtype">bool</span> data_delivered; <a name="l00456"></a><a class="code" href="classMessageQueue.html#a6f01c62f001b1cb8a2980a783317f74f">00456</a> <span class="keywordtype">bool</span> drop_count; <a name="l00457"></a>00457 }; <a name="l00458"></a>00458 <a name="l00459"></a>00459 <a name="l00460"></a>00460 <a name="l00461"></a>00461 <a name="l00462"></a>00462 <span class="preprocessor">#endif</span> </pre></div></div> </div> <!-- render the modification time of the source file --> <div class="timestamp"> <hr> <table style="width:100%;"> <tr> <td style="text-align:left;"> Last updated 12 September 2005 21:38:45 <!-- <td style="text-align:right;"> <a href="http://validator.w3.org/check/referer"><img style="vertical-align:middle;border:0;width:88px;height:31px" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> <a href="http://jigsaw.w3.org/css-validator/"> <img style="vertical-align:middle;border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"> </a> --> </tr> </table> </div> </tr> </table> </BODY> </HTML>