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 * This library is free software; you can redistribute it and/or 00025 * modify it under the terms of the GNU Lesser General Public 00026 * License as published by the Free Software Foundation; either 00027 * version 2.1 of the License, or (at your option) any later version. 00028 * 00029 * This library is distributed in the hope that it will be useful, 00030 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00032 * Lesser General Public License for more details. 00033 * 00034 * You should have received a copy of the GNU Lesser General Public 00035 * License along with this library; if not, write to the Free Software 00036 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00037 * 00038 ********************************************************************/ 00039 00040 /* 00041 * $Id: device.h 4247 2007-11-14 21:07:49Z thjc $ 00042 * 00043 * A device is a driver/interface pair. 00044 */ 00045 00046 #ifndef _DEVICE_H 00047 #define _DEVICE_H 00048 00049 #include <libplayercore/player.h> 00050 #include <libplayercore/message.h> 00051 00052 #define LOCALHOST_ADDR 16777343 00053 00054 // Forward declarations 00055 class Driver; 00056 00062 class Device 00063 { 00064 private: 00065 public: 00066 00071 Device(player_devaddr_t addr, Driver *driver); 00072 00074 ~Device(); 00075 00079 int Subscribe(QueuePointer &sub_queue); 00080 00084 int Unsubscribe(QueuePointer &sub_queue); 00085 00099 void PutMsg(QueuePointer &resp_queue, 00100 uint8_t type, 00101 uint8_t subtype, 00102 void* src, 00103 size_t deprecated, 00104 double* timestamp); 00105 00115 void PutMsg(QueuePointer &resp_queue, 00116 player_msghdr_t* hdr, 00117 void* src, 00118 bool copy=true); 00119 00142 Message* Request(QueuePointer &resp_queue, 00143 uint8_t type, 00144 uint8_t subtype, 00145 void* src, 00146 size_t deprecated, 00147 double* timestamp, 00148 bool threaded = true); 00149 00155 static bool MatchDeviceAddress(player_devaddr_t addr1, 00156 player_devaddr_t addr2) 00157 { 00158 // On some machines, looking up "localhost" gives you 00159 // "127.0.0.1", which packs into a 32-bit int as 16777343. On other 00160 // machines, it gives you "0.0.0.0", which packs as 0. In order to 00161 // be able to do things like play back logfiles made on any machine, 00162 // we'll treat these two addresses as identical. 00163 return(((addr1.host == addr2.host) || 00164 ((addr1.host == 0) && (addr2.host == LOCALHOST_ADDR)) || 00165 ((addr1.host == LOCALHOST_ADDR) && (addr2.host == 0))) && 00166 (addr1.robot == addr2.robot) && 00167 (addr1.interf == addr2.interf) && 00168 (addr1.index == addr2.index)); 00169 } 00170 00172 Device* next; 00173 00175 player_devaddr_t addr; 00176 00178 char drivername[PLAYER_MAX_DRIVER_STRING_LEN]; 00179 00181 Driver* driver; 00182 00184 QueuePointer InQueue; 00185 00187 QueuePointer* queues; 00188 00190 size_t len_queues; 00191 }; 00192 00193 #endif