Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

driver.h

Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000  
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *                      
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 /*
00024  * $Id: driver.h,v 1.10 2004/11/12 20:02:13 gerkey Exp $
00025  *  
00026  *  The virtual class from which all driver classes inherit.  this
00027  *  defines the API that all drivers must implement.
00028  */
00029 
00030 #ifndef _DRIVER_H
00031 #define _DRIVER_H
00032 
00033 #include <pthread.h>
00034 
00035 #include <stddef.h> /* for size_t */
00036 #include "playercommon.h"
00037 #include "playerqueue.h"
00038 
00039 extern bool debug;
00040 extern bool experimental;
00041 
00042 // Forward declarations
00043 class CLock;
00044 class ConfigFile;
00045 
00046 
00053 class Driver
00054 {
00055   private:
00056     // this mutex is used to lock data, command, and req/rep buffers/queues
00057     // TODO: could implement different mutexes for each data structure, but
00058     // is it worth it?
00059     //
00060     // NOTE: StageDevice won't use this; it declares its own inter-process
00061     // locking mechanism (and overrides locking methods)
00062     pthread_mutex_t accessMutex;
00063 
00064     // the driver's thread
00065     pthread_t driverthread;
00066 
00067     // A condition variable (and accompanying mutex) that can be used to
00068     // signal other drivers that are waiting on this one.
00069     pthread_cond_t cond;
00070     pthread_mutex_t condMutex;
00071     
00072 
00073   public:
00075     player_device_id_t device_id;
00076         
00078     int subscriptions;
00079 
00082     int entries;
00083 
00089     bool alwayson;
00090 
00093     int error;
00094 
00095   public:
00096 
00098     //
00107     Driver(ConfigFile *cf, int section, int interface, uint8_t access,
00108            size_t datasize, size_t commandsize, 
00109            size_t reqqueuelen, size_t repqueuelen);
00110 
00116     Driver(ConfigFile *cf, int section);
00117 
00119     virtual ~Driver();
00120     
00130     int AddInterface(player_device_id_t id, unsigned char access,
00131                      size_t datasize, size_t commandsize,
00132                      size_t reqqueuelen, size_t repqueuelen);
00133     
00147     int AddInterface(player_device_id_t id, unsigned char access,
00148                      void* data, size_t datasize, 
00149                      void* command, size_t commandsize, 
00150                      void* reqqueue, int reqqueuelen, 
00151                      void* repqueue, int repqueuelen);
00152 
00154     void SetError(int code) {this->error = code;}
00155 
00165     virtual int Subscribe(player_device_id_t id);
00166 
00176     virtual int Unsubscribe(player_device_id_t id);
00177 
00184     virtual int Setup() = 0;
00185 
00192     virtual int Shutdown() = 0;
00193 
00201     virtual void Prepare() {}
00202 
00203   public:
00204 
00209     void StartThread(void);
00210 
00215     void StopThread(void);
00216 
00222     virtual void Main(void);
00223 
00228     virtual void MainQuit(void);
00229 
00230   private:
00231 
00232     // Dummy main (just calls real main).  This is used to simplify
00233     // thread creation.
00234     static void* DummyMain(void *driver);
00235 
00236     // Dummy main cleanup (just calls real main cleanup).  This is
00237     // used to simplify thread termination.
00238     static void DummyMainQuit(void *driver);
00239 
00240   public:
00241     
00247     void Wait(void);
00248 
00261     void DataAvailable(void);
00262 
00263     // a static version of DataAvailable that can be used as a
00264     // callback from libraries. It calls driver->DataAvailable(). 
00265     static void DataAvailableStatic( Driver* driver );
00266 
00274     virtual void Update() {}
00275 
00276     // Note: the Get* and Put* functions MAY be overridden by the
00277     // driver itself, but then the driver is reponsible for Lock()ing
00278     // and Unlock()ing appropriately
00279 
00288     virtual void PutData(player_device_id_t id, void* src, size_t len,
00289                          struct timeval* timestamp);
00290 
00294     void PutData(void* src, size_t len, struct timeval* timestamp)
00295       { PutData(this->device_id,src,len,timestamp); }
00296 
00305     virtual size_t GetData(player_device_id_t id,
00306                            void* dest, size_t len,
00307                            struct timeval* timestamp);
00308 
00316     virtual void PutCommand(player_device_id_t id,
00317                             void* src, size_t len,
00318                             struct timeval* timestamp);
00319 
00328     virtual size_t GetCommand(player_device_id_t id,
00329                               void* dest, size_t len,
00330                               struct timeval* timestamp);
00331 
00335     size_t GetCommand(void* dest, size_t len,
00336                       struct timeval* timestamp)
00337       { return GetCommand(this->device_id,dest,len,timestamp); }
00338 
00343     virtual void ClearCommand(player_device_id_t id);
00344 
00349     void ClearCommand(void)
00350       { ClearCommand(this->device_id); }
00351 
00362     virtual int PutConfig(player_device_id_t id, void *client, 
00363                           void* src, size_t len,
00364                           struct timeval* timestamp);
00365 
00377     virtual int GetConfig(player_device_id_t id, void **client, 
00378                           void* dest, size_t len,
00379                           struct timeval* timestamp);
00380 
00384     int GetConfig(void** client, void* dest, size_t len, 
00385                   struct timeval* timestamp)
00386       { return GetConfig(this->device_id,client,dest,len,timestamp); }
00387 
00398     virtual int PutReply(player_device_id_t id, void* client, 
00399                          unsigned short type, 
00400                          void* src, size_t len,
00401                          struct timeval* timestamp);
00402 
00407     int PutReply(void* client, 
00408                  unsigned short type, 
00409                  void* src, size_t len,
00410                  struct timeval* timestamp)
00411       { return PutReply(this->device_id,client,type,src,len,timestamp); }
00412 
00416     int PutReply(player_device_id_t id, void* client, unsigned short type,
00417                  struct timeval* timestamp)
00418       { return PutReply(id,client,type,NULL,0,timestamp); }
00419 
00423     int PutReply(void* client, unsigned short type,
00424                  struct timeval* timestamp)
00425       { return PutReply(this->device_id,client,type,NULL,0,timestamp); }
00426 
00437     virtual int GetReply(player_device_id_t id, void* client, 
00438                          unsigned short* type, 
00439                          void* dest, size_t len,
00440                          struct timeval* timestamp);
00441 
00444     virtual int Request(player_device_id_t id, void* requester, 
00445                         void* request, size_t reqlen,
00446                         struct timeval* req_timestamp,
00447                         unsigned short* reptype, 
00448                         void* reply, size_t replen,
00449                         struct timeval* rep_timestamp);
00450 
00451   protected:
00452     // these methods are used to lock and unlock the various buffers and
00453     // queues; they are implemented with mutexes in Driver and overridden
00454     // in CStageDriver
00455     virtual void Lock(void);
00456     virtual void Unlock(void);
00457 
00458 };
00459 
00460 
00461 #endif

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