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 class IPCMessageQueueData;
30 
32 {
33 public:
34  static const int MaxMessageSize;
35 
36  /** This is the struct of the messages that has to be fed to send and
37  * receive methods.
38  */
39  typedef struct
40  {
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, bool create = false, bool destroy_on_delete = false);
48 
49  IPCMessageQueue(int id, bool create = false, bool destroy_on_delete = false);
50 
52 
53  bool isValid();
54  bool recv(long mtype, MessageStruct *msg, unsigned int data_size);
55  bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size);
56  bool send(MessageStruct *msg, unsigned int data_size);
57 
58  /** Get the message type
59  * @param buffer the buffer of the message as returned by getMessage()
60  * @return the message type
61  */
62  static inline long
63  mtype(char *buffer)
64  {
65  return (((MessageStruct *)buffer)->mtype);
66  }
67 
68 protected:
70 
71 private:
72  IPCMessageQueueData *data;
73 };
74 
75 } // end namespace fawkes
76 
77 #endif
IPC message queue.
Definition: msg.h:32
bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size)
Receive messages from this queue of any type.
Definition: msg.cpp:202
~IPCMessageQueue()
Destructor.
Definition: msg.cpp:113
bool recv(long mtype, MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:170
static const int MaxMessageSize
Maximum size of a message.
Definition: msg.h:34
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:128
static long mtype(char *buffer)
Get the message type.
Definition: msg.h:63
bool destroy_on_delete
destroy this message queue on delete?
Definition: msg.h:69
bool send(MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:227
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:73
Fawkes library namespace.
This is the struct of the messages that has to be fed to send and receive methods.
Definition: msg.h:40
long int mtype
type of the message
Definition: msg.h:41