Fawkes API Fawkes Development Version
qa_ipc_msg.cpp
1
2/***************************************************************************
3 * qa_ipc_msg.h - QA for IPC message queues
4 *
5 * Generated: Mon Sep 18 23:13:10 2006
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// Do not include in api reference
25///@cond QA
26
27#include <utils/ipc/msg.h>
28
29#include <stdio.h>
30#include <string.h>
31#include <unistd.h>
32
33#define QA_MTYPE 1
34
35using namespace fawkes;
36
37typedef struct
38{
39 long mtype;
40 char msg[20];
41} simple_msg_t;
42
43int
44main(int argc, char **argv)
45{
46 // Create message queue, destroy on delete
47 IPCMessageQueue *m1 = new IPCMessageQueue(".", 'A', true, true);
48
49 // Open, do not create, do not destroy
50 IPCMessageQueue *m2 = new IPCMessageQueue(".", 'A', false, false);
51
52 for (unsigned int i = 0; i < 10; ++i) {
53 simple_msg_t smsg;
54 simple_msg_t rmsg;
55 memset(&smsg, 0, sizeof(smsg));
56 memset(&rmsg, 0, sizeof(rmsg));
57
58 smsg.mtype = QA_MTYPE;
59 sprintf(smsg.msg, "%u", i);
60
61 m1->send((IPCMessageQueue::MessageStruct *)&smsg, sizeof(smsg));
62 m2->recv(QA_MTYPE, (IPCMessageQueue::MessageStruct *)&rmsg, sizeof(rmsg));
63
64 printf("Sent: %s Received: %s\n", smsg.msg, rmsg.msg);
65 }
66
67 delete m2;
68 delete m1;
69
70 return 0;
71}
72
73/// @endcond
IPC message queue.
Definition: msg.h:32
bool recv(long mtype, MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:170
bool send(MessageStruct *msg, unsigned int data_size)
Receive messages from this queue of the given message type.
Definition: msg.cpp:227
Fawkes library namespace.
This is the struct of the messages that has to be fed to send and receive methods.
Definition: msg.h:40