device.h
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2000
* Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/********************************************************************
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
********************************************************************/
/*
* $Id: device.h 8462 2009-12-16 00:27:55Z gbiggs $
*
* A device is a driver/interface pair.
*/
#ifndef _DEVICE_H
#define _DEVICE_H
#if defined (WIN32)
#if defined (PLAYER_STATIC)
#define PLAYERCORE_EXPORT
#elif defined (playercore_EXPORTS)
#define PLAYERCORE_EXPORT __declspec (dllexport)
#else
#define PLAYERCORE_EXPORT __declspec (dllimport)
#endif
#else
#define PLAYERCORE_EXPORT
#endif
#include <libplayerinterface/player.h>
#include <libplayercore/message.h>
#define LOCALHOST_ADDR 16777343
// Forward declarations
class Driver;
class PLAYERCORE_EXPORT Device
{
public:
Device(player_devaddr_t addr, Driver *driver);
~Device();
int Subscribe(QueuePointer &sub_queue);
int Unsubscribe(QueuePointer &sub_queue);
void PutMsg(QueuePointer &resp_queue,
uint8_t type,
uint8_t subtype,
void* src,
size_t deprecated,
double* timestamp);
void PutMsg(QueuePointer &resp_queue,
player_msghdr_t* hdr,
void* src,
bool copy=true);
Message* Request(QueuePointer &resp_queue,
uint8_t type,
uint8_t subtype,
void* src,
size_t deprecated,
double* timestamp,
bool threaded = true);
Message* TimedRequest(QueuePointer &resp_queue,
uint8_t type,
uint8_t subtype,
void* src,
double timeout = 0,
double* timestamp = NULL,
bool threaded = true);
static bool MatchDeviceAddress(player_devaddr_t addr1,
player_devaddr_t addr2)
{
// On some machines, looking up "localhost" gives you
// "127.0.0.1", which packs into a 32-bit int as 16777343. On other
// machines, it gives you "0.0.0.0", which packs as 0. In order to
// be able to do things like play back logfiles made on any machine,
// we'll treat these two addresses as identical.
return(((addr1.host == addr2.host) ||
((addr1.host == 0) && (addr2.host == LOCALHOST_ADDR)) ||
((addr1.host == LOCALHOST_ADDR) && (addr2.host == 0))) &&
(addr1.robot == addr2.robot) &&
(addr1.interf == addr2.interf) &&
(addr1.index == addr2.index));
}
Device* next;
player_devaddr_t addr;
char drivername[PLAYER_MAX_DRIVER_STRING_LEN];
QueuePointer InQueue;
QueuePointer* queues;
size_t len_queues;
Driver* driver;
private:
pthread_mutex_t accessMutex;
void Lock(void);
void Unlock(void);
};
#endif
Device::queues
QueuePointer * queues
Linked list of subscribed queues.
Definition: device.h:231
player_devaddr::interf
uint16_t interf
The interface provided by the device; must be one of PLAYER_*_CODE.
Definition: player.h:149
player_msghdr
Generic message header.
Definition: player.h:157
PLAYER_MAX_DRIVER_STRING_LEN
#define PLAYER_MAX_DRIVER_STRING_LEN
Maximum length for a driver name.
Definition: player.h:68
Device::len_queues
size_t len_queues
Length of queues.
Definition: device.h:234
Message
Reference-counted message objects.
Definition: message.h:132
player_devaddr
A device address.
Definition: player.h:141
player_devaddr::host
uint32_t host
The "host" on which the device resides.
Definition: player.h:144
Device::driver
Driver * driver
Pointer to the underlying driver.
Definition: device.h:237
Device
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:74
QueuePointer
An autopointer for the message queue.
Definition: message.h:73
Device::addr
player_devaddr_t addr
Address for this device.
Definition: device.h:221
player_devaddr::robot
uint32_t robot
The "robot" or device collection in which the device resides.
Definition: player.h:147
Driver
Base class for all drivers.
Definition: driver.h:108
Device::MatchDeviceAddress
static bool MatchDeviceAddress(player_devaddr_t addr1, player_devaddr_t addr2)
Compare two addresses.
Definition: device.h:201
Device::InQueue
QueuePointer InQueue
Pointer to the underlying driver's queue.
Definition: device.h:228
Device::accessMutex
pthread_mutex_t accessMutex
Mutex used to lock access, via Lock() and Unlock(), to device internals, like the list of subscribed ...
Definition: device.h:242
Device::next
Device * next
Next entry in the device table (this is a linked-list)
Definition: device.h:218
player_devaddr::index
uint16_t index
Which device of that interface.
Definition: player.h:151

Last updated 12 September 2005 21:38:45