device.h

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: device.h,v 1.12 2006/03/08 23:08:56 gerkey Exp $
00025  *
00026  * A device is a driver/interface pair.
00027  */
00028 
00029 #ifndef _DEVICE_H
00030 #define _DEVICE_H
00031 
00032 #include <libplayercore/player.h>
00033 #include <libplayercore/message.h>
00034 
00035 #define LOCALHOST_ADDR 16777343
00036 
00037 // Forward declarations
00038 class Driver;
00039 
00045 class Device
00046 {
00047   private:
00048   public:
00049   
00054     Device(player_devaddr_t addr, Driver *driver);
00055 
00057     ~Device();
00058 
00062     int Subscribe(MessageQueue* sub_queue);
00063 
00067     int Unsubscribe(MessageQueue* sub_queue);
00068 
00082     void PutMsg(MessageQueue* resp_queue,
00083                 uint8_t type, 
00084                 uint8_t subtype,
00085                 void* src, 
00086                 size_t len,
00087                 double* timestamp);
00088 
00097     void PutMsg(MessageQueue* resp_queue,
00098                 player_msghdr_t* hdr,
00099                 void* src);
00100 
00123     Message* Request(MessageQueue* resp_queue,
00124                      uint8_t type,
00125                      uint8_t subtype,
00126                      void* src,
00127                      size_t len,
00128                      double* timestamp,
00129                      bool threaded = true);
00130 
00136     static bool MatchDeviceAddress(player_devaddr_t addr1,
00137                                    player_devaddr_t addr2)
00138     {
00139       // On some machines, looking up "localhost" gives you
00140       // "127.0.0.1", which packs into a 32-bit int as 16777343.  On other
00141       // machines, it gives you "0.0.0.0", which packs as 0.  In order to
00142       // be able to do things like play back logfiles made on any machine,
00143       // we'll treat these two addresses as identical.
00144       return(((addr1.host == addr2.host) ||
00145               ((addr1.host == 0) && (addr2.host == LOCALHOST_ADDR)) ||
00146               ((addr1.host == LOCALHOST_ADDR) && (addr2.host == 0))) &&
00147              (addr1.robot == addr2.robot) &&
00148              (addr1.interf == addr2.interf) &&
00149              (addr1.index == addr2.index));
00150     }
00151 
00153     Device* next;
00154 
00156     player_devaddr_t addr;
00157 
00159     char drivername[PLAYER_MAX_DRIVER_STRING_LEN];
00160 
00162     Driver* driver;
00163 
00165     MessageQueue** queues;
00166 
00168     size_t len_queues;
00169 };
00170 
00171 #endif

Last updated 12 September 2005 21:38:45