50 #if defined (PLAYER_STATIC)
51 #define PLAYERCORE_EXPORT
52 #elif defined (playercore_EXPORTS)
53 #define PLAYERCORE_EXPORT __declspec (dllexport)
55 #define PLAYERCORE_EXPORT __declspec (dllimport)
58 #define PLAYERCORE_EXPORT
63#include <libplayerinterface/player.h>
96 bool operator == (
void * pointer);
100 bool operator != (
void * pointer);
164 return(((type < 0) || (hdr->
type == (uint8_t)type)) &&
165 ((subtype < 0) || (hdr->
subtype == (uint8_t)subtype)) &&
181 return(((type < 0) || (hdr->
type == (uint8_t)type)) &&
182 ((subtype < 0) || (hdr->
subtype == (uint8_t)subtype)));
248 int host, robot, interf, index;
253 int _type,
int _subtype,
int _replace) :
254 host(_host), robot(_robot), interf(_interf), index(_index),
255 type(_type), subtype(_subtype), replace(_replace), next(NULL) {}
259 return(((this->host < 0) ||
260 ((uint32_t)this->host == hdr->
addr.
host)) &&
261 ((this->robot < 0) ||
262 ((uint32_t)this->robot == hdr->
addr.
robot)) &&
263 ((this->interf < 0) ||
264 ((uint16_t)this->interf == hdr->
addr.
interf)) &&
265 ((this->index < 0) ||
266 ((uint16_t)this->index == hdr->
addr.
index)) &&
268 ((uint8_t)this->type == hdr->
type)) &&
269 ((this->subtype < 0) ||
270 ((uint8_t)this->subtype == hdr->
subtype)));
273 bool Equivalent (
int _host,
int _robot,
int _interf,
int _index,
int _type,
int _subtype)
275 return (host == _host && robot == _robot && interf ==_interf && index == _index &&
276 type == _type && subtype == _subtype);
345 bool Empty() {
return(this->head == NULL); }
369 void SetReplace(
bool _Replace) { this->Replace = _Replace; };
377 int _type,
int _subtype,
int _replace);
384 int _type,
int _subtype,
int _replace);
403 void SetFilter(
int host,
int robot,
int interf,
int index,
404 int type,
int subtype);
406 void SetPull (
bool _pull) { this->pull = _pull; }
416 void Lock() {pthread_mutex_lock(&lock);};
418 void Unlock() {pthread_mutex_unlock(&lock);};
445 int filter_host, filter_robot, filter_interf,
446 filter_index, filter_type, filter_subtype;
This class is a helper for maintaining doubly-linked queues of Messages.
Definition message.h:219
Message * msg
The message stored in this queue element.
Definition message.h:227
~MessageQueueElement()
Destroy a queue element.
MessageQueueElement * next
Pointer to next queue element.
Definition message.h:232
MessageQueueElement * prev
Pointer to previous queue element.
Definition message.h:230
MessageQueueElement()
Create a queue element with NULL prev and next pointers.
A doubly-linked queue of messages.
Definition message.h:338
void SetFilter(int host, int robot, int interf, int index, int type, int subtype)
Set filter values.
size_t GetLength(void)
Get current length of queue, in elements.
void ClearFilter(void)
Clear (i.e., turn off) message filter.
bool pull
Flag for if in pull mode.
Definition message.h:449
void PushBack(Message &msg, bool haveLock)
Push a message at the back of the queue, without checking replacement rules or size limits.
bool data_delivered
Flag that data was sent (in PULL mode)
Definition message.h:454
size_t Maxlen
Maximum length of queue in elements.
Definition message.h:429
MessageQueueElement * head
Head of the queue.
Definition message.h:423
Message * Pop()
Pop a message off the queue.
~MessageQueue()
Destroy a message queue.
void AddReplaceRule(const player_devaddr_t &device, int _type, int _subtype, int _replace)
Add a replacement rule to the list.
bool Filter(Message &msg)
Check whether a message passes the current filter.
bool Wait(double TimeOut=0.0)
Wait on this queue.
MessageQueueElement * tail
Tail of the queue.
Definition message.h:425
MessageReplaceRule * replaceRules
Singly-linked list of replacement rules.
Definition message.h:431
bool drop_count
Count of the number of messages discarded due to queue overflow.
Definition message.h:456
void SetDataRequested(bool d, bool haveLock)
Set the data_requested flag.
void SetReplace(bool _Replace)
Set the Replace flag, which governs whether data and command messages of the same subtype from the sa...
Definition message.h:369
pthread_mutex_t lock
Mutex to control access to the queue, via Lock() and Unlock().
Definition message.h:427
bool Empty()
Check whether a queue is empty.
Definition message.h:345
void Unlock()
Unlock the mutex associated with this queue.
Definition message.h:418
pthread_cond_t cond
A condition variable that can be used to signal, via DataAvailable(), other threads that are Wait()in...
Definition message.h:440
void Lock()
Lock the mutex associated with this queue.
Definition message.h:416
bool Push(Message &msg)
Push a message onto the queue.
void SetPull(bool _pull)
Set the pull flag.
Definition message.h:406
bool data_requested
Flag for data was requested (in PULL mode), but none has yet been delivered.
Definition message.h:452
bool filter_on
Current filter values.
Definition message.h:444
MessageQueue(bool _Replace, size_t _Maxlen)
Create an empty message queue.
bool Replace
When a (data or command) message doesn't match a rule in replaceRules, should we replace it?
Definition message.h:434
pthread_mutex_t condMutex
Mutex to go with condition variable cond.
Definition message.h:442
void Remove(MessageQueueElement *el)
Remove element el from the queue, and rearrange pointers appropriately.
void DataAvailable(void)
Signal that new data is available.
void AddReplaceRule(int _host, int _robot, int _interf, int _index, int _type, int _subtype, int _replace)
Add a replacement rule to the list.
int CheckReplace(player_msghdr_t *hdr)
Check whether a message with the given header should replace any existing message of the same signatu...
size_t Length
Current length of queue, in elements.
Definition message.h:436
void PushFront(Message &msg, bool haveLock)
Put it at the front of the queue, without checking replacement rules or size limits.
We keep a singly-linked list of (addr,type,subtype,replace) tuples.
Definition message.h:244
Reference-counted message objects.
Definition message.h:133
Message(const struct player_msghdr &Header, void *data, bool copy=true)
Create a new message.
void * GetPayload()
Get pointer to payload.
Definition message.h:188
QueuePointer Queue
queue to which any response to this message should be directed
Definition message.h:197
unsigned int GetDataSize()
Size of message data.
Definition message.h:190
bool Compare(Message &other)
Compare type, subtype, device, and device_index.
~Message()
Destroy message, dec ref counts and delete data if ref count == 0.
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition message.h:159
uint8_t * Data
Pointer to the message data.
Definition message.h:210
Message(const struct player_msghdr &Header, void *data, QueuePointer &_queue, bool copy=true)
Create a new message with an associated queue.
Message(const Message &rhs)
Copy pointers from existing message and increment refcount.
player_msghdr_t Header
message header
Definition message.h:208
player_msghdr_t * GetHeader()
Get pointer to header.
Definition message.h:186
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype)
Helper for message processing.
Definition message.h:177
pthread_mutex_t * Lock
Used to lock access to Data.
Definition message.h:212
void DecRef()
Decrement ref count.
unsigned int * RefCount
Reference count.
Definition message.h:200
An autopointer for the message queue.
Definition message.h:74
void DecRef()
Decrement ref count.
MessageQueue * Queue
The queue we are pointing to.
Definition message.h:107
MessageQueue * get() const
retrieve underlying object for use, may return a null pointer
QueuePointer(bool _Replace, size_t _Maxlen)
Create an empty message queue and an auto pointer to it.
~QueuePointer()
Destroy our reference to the message queue.
pthread_mutex_t * Lock
Used to lock access to refcount.
Definition message.h:113
QueuePointer(const QueuePointer &CopyFrom)
Create a new reference to a message queue.
QueuePointer()
Create a NULL autopointer;.
unsigned int * RefCount
Reference count.
Definition message.h:110
A device address.
Definition player.h:146
uint16_t index
Which device of that interface.
Definition player.h:155
uint32_t robot
The "robot" or device collection in which the device resides.
Definition player.h:151
uint32_t host
The "host" on which the device resides.
Definition player.h:148
uint16_t interf
The interface provided by the device; must be one of PLAYER_*_CODE.
Definition player.h:153
Generic message header.
Definition player.h:162
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition player.h:166
uint8_t subtype
Message subtype; interface specific.
Definition player.h:168
player_devaddr_t addr
Device to which this message pertains.
Definition player.h:164