Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

lifomcom.h

Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000  Brian Gerkey   &  Kasper Stoy
00004  *                      gerkey@usc.edu    kaspers@robotics.usc.edu
00005  *
00006  *  LifoMCom device by Matthew Brewer <mbrewer@andrew.cmu.edu> (updated for 1.3 by 
00007  *  Reed Hedges <reed@zerohour.net>) at the Laboratory for Perceptual 
00008  *  Robotics, Dept. of Computer Science, University of Massachusetts,
00009  *  Amherst.
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU General Public License
00022  *  along with this program; if not, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #ifndef _MCOMDEVICE_HH_
00028 #define _MCOMDEVICE_HH_
00029 
00030 #include <player.h>
00031 #include <driver.h>
00032 #include <drivertable.h>
00033 
00034 
00035 /*
00036  * This device is designed for exchanging information between clients.
00037  * A client sends a message of a given "type" and "channel". This 
00038  * device stores adds the message to that channel's stack.
00039  * A second client can then request data of a given "type" and "channel"
00040  * if Pop is called the last piece of data added to the buffer is returned
00041  * and then deleted.
00042  * If Read is called the last piece of data added is returned, and left there
00043  * This is a filo, or a stack first in last out -
00044  * This way if were reading drive command for example we can be sure to
00045  * get a "STOP" and interupt a "FWD" before it's been read.
00046  * Player's "configuration"-style message passing is used.
00047  */
00048 
00049 
00050 
00051 class LifoMCom : public Driver 
00052 {
00053 private:
00054 
00055     class Buffer {
00056     private:
00057         player_mcom_data_t dat[MCOM_N_BUFS];
00058         int top;
00059       int capacity;
00060     public:
00061         int type;
00062         char channel[MCOM_CHANNEL_LEN];
00063         Buffer();
00064         ~Buffer();
00065         void Push(player_mcom_data_t newdat);
00066         player_mcom_data_t Pop();
00067         player_mcom_data_t Read();
00068         void Clear();
00069         void print();
00070       void SetCapacity(int cap);
00071       int GetCapacity() { return capacity; }
00072     };
00073 
00074     struct Link{
00075         Buffer buf;
00076         Link* next;
00077     };
00078 
00079     class LinkList {
00080     private:
00081         Link * top;
00082     public:
00083         LinkList();
00084         ~LinkList();
00085         void Push(player_mcom_data_t d,int type, char channel[MCOM_CHANNEL_LEN]);
00086         player_mcom_data_t Pop(int type, char channel[MCOM_CHANNEL_LEN]);
00087         player_mcom_data_t Read(int type,char channel[MCOM_CHANNEL_LEN]);
00088         void Clear(int type,char channel[MCOM_CHANNEL_LEN]);
00089       void SetCapacity(int type, char channel[MCOM_CHANNEL_LEN], 
00090                        unsigned char cap);
00091       Link * FindLink(int type, char channel[MCOM_CHANNEL_LEN]);
00092     };
00093 
00094     LinkList Data;
00095 
00096 public:
00097 
00098     // Constructor
00099     LifoMCom(ConfigFile* cf, int section);
00100 
00101     // Called when we recieve a config request; overrides Driver::PutConfig
00102     virtual int PutConfig(player_device_id_t id, void *client, 
00103                           void* src, size_t len,
00104                           struct timeval* timestamp);
00105 
00106     // These do nothing but are abstract in Driver, so here they are
00107     virtual int Setup() {
00108         printf("startup...\n");
00109         return 0;
00110     }
00111 
00112     virtual int Shutdown() {
00113         printf("shutdown ...\n");
00114         return 0;
00115     }
00116 };
00117 
00118 
00119 
00120 
00121 Driver* LifoMCom_Init(char* interface, ConfigFile* cf, int section);
00122 
00123 // a driver registration function
00124 void LifoMCom_Register(DriverTable* table);
00125 
00126 
00127 
00128 #endif //ifdef _MCOMDEVICE_HH_
00129 

Generated on Tue May 3 14:15:34 2005 for Player by doxygen 1.3.6