Fawkes API  Fawkes Development Version
msg.h
1 
2 /***************************************************************************
3  * msg.h - IPC message queue
4  *
5  * Generated: Mon Mar 13 17:37:49 2006 (from FireVision)
6  * Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __UTILS_IPC_MSG_H_
25 #define __UTILS_IPC_MSG_H_
26 
27 namespace fawkes {
28 
29 
30 class IPCMessageQueueData;
31 
33  public:
34 
35  static const int MaxMessageSize;
36 
37  /** This is the struct of the messages that has to be fed to send and
38  * receive methods.
39  */
40  typedef struct {
41  long int mtype; /**< type of the message */
42  char mtext[1]; /**< content of the message, can be of arbitrary
43  * size up to MaxMessageSize
44  */
45  } MessageStruct;
46 
47  IPCMessageQueue(const char *path, char id,
48  bool create = false,
49  bool destroy_on_delete = false);
50 
51  IPCMessageQueue(int id,
52  bool create = false,
53  bool destroy_on_delete = false);
54 
56 
57  bool isValid();
58  bool recv(long mtype, MessageStruct *msg, unsigned int data_size);
59  bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size);
60  bool send(MessageStruct *msg, unsigned int data_size);
61 
62  /** Get the message type
63  * @param buffer the buffer of the message as returned by getMessage()
64  * @return the message type
65  */
66  static inline long
67  mtype(char *buffer)
68  {
69  return (((MessageStruct *)buffer)->mtype);
70  }
71 
72  protected:
74 
75  private:
76  IPCMessageQueueData *data;
77 
78 };
79 
80 
81 } // end namespace fawkes
82 
83 #endif
bool send(MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:236
bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size)
Receive messages from this queue of any type.
Definition: msg.cpp:211
Fawkes library namespace.
bool isValid()
Check if the message queue is valid If the queue could not be opened yet (for example if you gave cre...
Definition: msg.cpp:136
~IPCMessageQueue()
Destructor.
Definition: msg.cpp:120
bool destroy_on_delete
destroy this message queue on delete?
Definition: msg.h:73
IPCMessageQueue(const char *path, char id, bool create=false, bool destroy_on_delete=false)
Create or open a message queue If a message key with the given identification criteria exists it is o...
Definition: msg.cpp:77
IPC message queue.
Definition: msg.h:32
static const int MaxMessageSize
Maximum size of a message.
Definition: msg.h:35
long int mtype
type of the message
Definition: msg.h:41
This is the struct of the messages that has to be fed to send and receive methods.
Definition: msg.h:40
bool recv(long mtype, MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:179
static long mtype(char *buffer)
Get the message type.
Definition: msg.h:67