property.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2000
4  * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 /********************************************************************
23  *
24  * This library is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU Lesser General Public
26  * License as published by the Free Software Foundation; either
27  * version 2.1 of the License, or (at your option) any later version.
28  *
29  * This library is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32  * Lesser General Public License for more details.
33  *
34  * You should have received a copy of the GNU Lesser General Public
35  * License along with this library; if not, write to the Free Software
36  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37  *
38  ********************************************************************/
39 
40 #ifndef __PROPERTY_H
41 #define __PROPERTY_H
42 
43 #if defined (WIN32)
44  #if defined (PLAYER_STATIC)
45  #define PLAYERCORE_EXPORT
46  #elif defined (playercore_EXPORTS)
47  #define PLAYERCORE_EXPORT __declspec (dllexport)
48  #else
49  #define PLAYERCORE_EXPORT __declspec (dllimport)
50  #endif
51 #else
52  #define PLAYERCORE_EXPORT
53 #endif
54 
55 class ConfigFile;
56 class Driver;
57 
59 class PLAYERCORE_EXPORT Property
60 {
61  public:
62  Property (void);
63  Property (const char *newKey, bool readOnly);
64  virtual ~Property (void);
65 
66  // Accessor functions
67  virtual const char* GetKey (void) const { return key; }
68  virtual void SetKey (const char *newKey);
69  virtual void GetValueToMessage (void *data) const = 0;
70  virtual void SetValueFromMessage (const void *data) = 0;
71 
72  virtual bool KeyIsEqual (const char *rhs);
73 
74  // Config file read method
75  virtual bool ReadConfig (ConfigFile *cf, int section) = 0;
76 
77  protected:
78  char *key; // Key for this property
79  bool readonly; // true if this property is read-only
80 };
81 
84 
86 class PLAYERCORE_EXPORT BoolProperty : public Property
87 {
88  public:
89  BoolProperty (const char *newKey, bool newValue, bool readOnly);
91  BoolProperty (const char *newKey, bool newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
92 
93  bool GetValue (void) const { return value; }
94  void SetValue (bool newValue);
95  void GetValueToMessage (void *data) const;
96  void SetValueFromMessage (const void *data);
97 
98  // Config file read method
99  virtual bool ReadConfig (ConfigFile *cf, int section);
100 
101  // Operators
102  operator bool (void) { return value; }
103  const BoolProperty& operator= (const BoolProperty &rhs);
104  bool operator= (bool rhs);
105 
106  private:
107  bool value;
108 };
109 
112 
114 class PLAYERCORE_EXPORT IntProperty : public Property
115 {
116  public:
117  IntProperty (const char *newKey, int newValue, bool readOnly);
119  IntProperty (const char *newKey, int newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
120 
121  int GetValue (void) const { return value; }
122  void SetValue (int newValue);
123  void GetValueToMessage (void *data) const;
124  void SetValueFromMessage (const void *data);
125 
126  // Config file read method
127  virtual bool ReadConfig (ConfigFile *cf, int section);
128 
129  // Operators
130  operator int (void) { return value; }
131  const IntProperty& operator= (const IntProperty &rhs);
132  int operator= (int rhs);
133 
134  private:
135  int value;
136 };
137 
140 
142 class PLAYERCORE_EXPORT DoubleProperty : public Property
143 {
144  public:
145  DoubleProperty (const char *newKey, double newValue, bool readOnly);
147  DoubleProperty (const char *newKey, double newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
148 
149  double GetValue (void) const { return value; }
150  void SetValue (double newValue);
151  void GetValueToMessage (void *data) const;
152  void SetValueFromMessage (const void *data);
153 
154  // Config file read method
155  virtual bool ReadConfig (ConfigFile *cf, int section);
156 
157  // Operators
158  operator double (void) { return value; }
159  const DoubleProperty& operator= (const DoubleProperty &rhs);
160  double operator= (double rhs);
161 
162  private:
163  double value;
164 };
165 
168 
170 class PLAYERCORE_EXPORT StringProperty : public Property
171 {
172  public:
173  StringProperty (const char *newKey, const char *newValue, bool readOnly);
175  StringProperty (const char *newKey, const char *newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
176  ~StringProperty (void);
177 
178  const char* GetValue (void) const { return value; }
179  void SetValue (const char *newValue);
180  void GetValueToMessage (void *data) const;
181  void SetValueFromMessage (const void *data);
182 
183  // Config file read method
184  virtual bool ReadConfig (ConfigFile *cf, int section);
185 
186  // Operators
187  operator const char* (void) { return value; }
188  const StringProperty& operator= (const StringProperty &rhs);
189  const char* operator= (const char* rhs);
190 
191  private:
192  char *value;
193 };
194 
197 
199 typedef struct PropertyNode
200 {
201  char *key;
202  Property *property;
203  struct PropertyNode *next;
204 } PropertyNode;
205 
207 class PLAYERCORE_EXPORT PropertyBag
208 {
209  public:
210  PropertyBag (void);
211  ~PropertyBag (void);
212 
213  bool AddProperty (const char *key, Property *property);
214  Property* GetProperty (const char *key);
215 
216  private:
217  PropertyNode *firstProperty;
218 };
219 
220 #endif // __PROPERTY_H
Definition: dbconn.h:140
double vminx
Vector-based version of the map (call playerc_map_get_vector() to fill this in).
Definition: playerc.h:2556
String Property Class.
Definition: property.h:171
double resolution
Map resolution, m/cell.
Definition: playerc.h:2540
PLAYERC_EXPORT int playerc_log_set_read_rewind(playerc_log_t *device)
Rewind playback.
PLAYERC_EXPORT int playerc_map_subscribe(playerc_map_t *device, int access)
Subscribe to the map device.
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
PLAYERC_EXPORT int playerc_client_read_nonblock(playerc_client_t *client)
Read and process a packet (nonblocking)
playerc_device_info_t devinfos[PLAYER_MAX_DEVICES]
List of available (but not necessarily subscribed) devices.
Definition: playerc.h:552
Boolean property class.
Definition: property.h:87
PLAYERC_EXPORT int playerc_client_connect(playerc_client_t *client)
Connect to the server.
PLAYERC_EXPORT void playerc_map_destroy(playerc_map_t *device)
Destroy a map proxy.
Definition: dbconn.h:164
double y1
Endpoints [m].
Definition: player.h:300
StringProperty(const char *newKey, const char *newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
PLAYERC_EXPORT int playerc_log_set_write_state(playerc_log_t *device, int state)
Start/stop logging.
Generic message header.
Definition: player.h:162
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
double x1
Endpoints [m].
Definition: player.h:298
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition: player.h:166
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:75
const char * ReadString(int section, const char *name, const char *value)
Read a string value.
PLAYERC_EXPORT const char * playerc_error_str(void)
Retrieve the last error (as a descriptive string).
PLAYERC_EXPORT int playerc_map_unsubscribe(playerc_map_t *device)
Un-subscribe from the map device.
PLAYERC_EXPORT int playerc_log_set_filename(playerc_log_t *device, const char *fname)
Change name of log file to write to.
Property base class.
Definition: property.h:60
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:168
PLAYERC_EXPORT int playerc_map_get_vector(playerc_map_t *device)
Get the vector map, which is stored in the proxy.
PLAYERC_EXPORT int playerc_client_peek(playerc_client_t *client, int timeout)
Test to see if there is pending data.
PLAYERC_EXPORT playerc_map_t * playerc_map_create(playerc_client_t *client, int index)
Create a map proxy.
virtual void Main(void)=0
Main method for driver thread.
const char * ReadTupleString(int section, const char *name, int index, const char *value)
Read a string from a tuple field.
char drivername[PLAYER_MAX_DRIVER_STRING_LEN]
The driver name.
Definition: playerc.h:500
int ReadInt(int section, const char *name, int value)
Read an integer value.
PLAYERC_EXPORT int playerc_log_subscribe(playerc_log_t *device, int access)
Subscribe to the log device.
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
PLAYERC_EXPORT void playerc_client_destroy(playerc_client_t *client)
Destroy a client object.
Definition: camera.h:150
#define PLAYER_MSGTYPE_RESP_ACK
A positive response message.
Definition: player.h:112
Definition: dbconn.h:78
#define PLAYER_WARN2(msg, a, b)
Error message macros.
Definition: error.h:91
double x0
Endpoints [m].
Definition: player.h:294
PLAYERC_EXPORT playerc_log_t * playerc_log_create(playerc_client_t *client, int index)
Create a log proxy.
IntProperty(const char *newKey, int newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
Property bag class: stores registered properties.
Definition: property.h:208
DoubleProperty(const char *newKey, double newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
#define PLAYER_MAX_DEVICES
The maximum number of devices the server will support.
Definition: player.h:74
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
Definition: dbconn.h:106
#define PLAYER_MSGTYPE_RESP_NACK
A negative response message.
Definition: player.h:125
Integer property class.
Definition: property.h:115
BoolProperty(const char *newKey, bool newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
#define PLAYERC_DATAMODE_PUSH
The valid data delivery modes.
Definition: playerc.h:110
char * cells
Occupancy for each cell.
Definition: playerc.h:2552
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
int GetTupleCount(int section, const char *name)
Get the number of values in a tuple.
PLAYERC_EXPORT void playerc_log_destroy(playerc_log_t *device)
Destroy a log proxy.
PLAYERC_EXPORT int playerc_client_disconnect(playerc_client_t *client)
Disconnect from the server.
Class for loading configuration file information.
Definition: configfile.h:197
virtual int Setup()
Initialize the driver.
Definition: driver.h:386
PLAYERC_EXPORT playerc_client_t * playerc_client_create(playerc_mclient_t *mclient, const char *host, int port)
Create a client object.
A device address.
Definition: player.h:146
An autopointer for the message queue.
Definition: message.h:74
Client object data.
Definition: playerc.h:507
Double property class.
Definition: property.h:143
PLAYERC_EXPORT int playerc_client_datamode(playerc_client_t *client, uint8_t mode)
Change the server's data delivery mode.
Map proxy data.
Definition: playerc.h:2535
#define PLAYER_ERROR1(msg, a)
Error message macros.
Definition: error.h:82
Property node structure.
Definition: property.h:200
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:81
double y0
Endpoints [m].
Definition: player.h:296
Base class for drivers which oeprate with a thread.
Definition: driver.h:553
player_devaddr_t addr
Player id of the device.
Definition: playerc.h:497
double timestamp
Time associated with message contents (seconds since epoch)
Definition: player.h:170
PLAYERC_EXPORT int playerc_log_unsubscribe(playerc_log_t *device)
Un-subscribe from the log device.
PLAYERC_EXPORT void * playerc_client_read(playerc_client_t *client)
Read data from the server (blocking).
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
PLAYERC_EXPORT int playerc_client_set_replace_rule(playerc_client_t *client, int interf, int index, int type, int subtype, int replace)
Set a replace rule for the client queue on the server.
Log proxy data.
Definition: playerc.h:2475
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
PLAYERC_EXPORT int playerc_map_get_map(playerc_map_t *device)
Get the map, which is stored in the proxy.
virtual int Shutdown()
Finalize the driver.
Definition: driver.h:393
Base class for all drivers.
Definition: driver.h:109
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
PLAYERC_EXPORT int playerc_client_get_devlist(playerc_client_t *client)
Get the list of available device ids.
int width
Map size, in cells.
Definition: playerc.h:2543
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76
PLAYERC_EXPORT int playerc_log_get_state(playerc_log_t *device)
Get logging/playback state.
T max(T a, T b)
Return the maximum of a, b.
Definition: utility.h:126
#define PLAYERC_MAP_INDEX(dev, i, j)
Convert from a cell position to a map index.
Definition: playerc.h:2563
double origin[2]
Map origin, in meters (i.e., the real-world coordinates of cell 0,0)
Definition: playerc.h:2546
PLAYERC_EXPORT int playerc_client_requestdata(playerc_client_t *client)
Request a round of data.
PLAYERC_EXPORT int playerc_log_set_read_state(playerc_log_t *device, int state)
Start/stop playback.