lifomcom.h

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 <libplayercore/playercore.h>
00031 
00032 
00033 /*
00034  * This device is designed for exchanging information between clients.
00035  * A client sends a message of a given "type" and "channel". This 
00036  * device stores adds the message to that channel's stack.
00037  * A second client can then request data of a given "type" and "channel"
00038  * if Pop is called the last piece of data added to the buffer is returned
00039  * and then deleted.
00040  * If Read is called the last piece of data added is returned, and left there
00041  * This is a filo, or a stack first in last out -
00042  * This way if were reading drive command for example we can be sure to
00043  * get a "STOP" and interupt a "FWD" before it's been read.
00044  * Player's "configuration"-style message passing is used.
00045  */
00046 
00047 
00048 
00049 class LifoMCom : public Driver 
00050 {
00051 private:
00052 
00053     class Buffer {
00054     private:
00055         player_mcom_data_t dat[MCOM_N_BUFS];
00056         int top;
00057       int capacity;
00058     public:
00059         int type;
00060         char channel[MCOM_CHANNEL_LEN];
00061         Buffer();
00062         ~Buffer();
00063         void Push(player_mcom_data_t newdat);
00064         player_mcom_data_t Pop();
00065         player_mcom_data_t Read();
00066         void Clear();
00067         void print();
00068       void SetCapacity(int cap);
00069       int GetCapacity() { return capacity; }
00070     };
00071 
00072     struct Link{
00073         Buffer buf;
00074         Link* next;
00075     };
00076 
00077     class LinkList {
00078     private:
00079         Link * top;
00080     public:
00081         LinkList();
00082         ~LinkList();
00083         void Push(player_mcom_data_t d,int type, char channel[MCOM_CHANNEL_LEN]);
00084         player_mcom_data_t Pop(int type, char channel[MCOM_CHANNEL_LEN]);
00085         player_mcom_data_t Read(int type,char channel[MCOM_CHANNEL_LEN]);
00086         void Clear(int type,char channel[MCOM_CHANNEL_LEN]);
00087       void SetCapacity(int type, char channel[MCOM_CHANNEL_LEN], 
00088                        unsigned char cap);
00089       Link * FindLink(int type, char channel[MCOM_CHANNEL_LEN]);
00090     };
00091 
00092     LinkList Data;
00093 
00094 public:
00095 
00096 
00097     // Called when we recieve a config request; overrides Driver::PutConfig
00098 /*    virtual int PutConfig(player_device_id_t id, void *client, 
00099                           void* src, size_t len,
00100                           struct timeval* timestamp);*/
00101 
00102     // These do nothing but are abstract in Driver, so here they are
00103     // Process incoming messages from clients 
00104     int ProcessMessage(ClientData * client, player_msghdr * hdr, uint8_t * data, uint8_t * resp_data, size_t * resp_len);
00105 
00106     // Constructor
00107     LifoMCom(ConfigFile* cf, int section);
00108 
00109     virtual int Setup() {
00110         printf("startup...\n");
00111         return 0;
00112     }
00113 
00114     virtual int Shutdown() {
00115         printf("shutdown ...\n");
00116         return 0;
00117     }
00118 };
00119 
00120 
00121 
00122 
00123 Driver* LifoMCom_Init(char* interface, ConfigFile* cf, int section);
00124 
00125 // a driver registration function
00126 void LifoMCom_Register(DriverTable* table);
00127 
00128 
00129 
00130 #endif //ifdef _MCOMDEVICE_HH_
00131 

Last updated 12 September 2005 21:38:45