qa_ipc_msg.cpp

00001 
00002 /***************************************************************************
00003  *  qa_ipc_msg.h - QA for IPC message queues
00004  *
00005  *  Generated: Mon Sep 18 23:13:10 2006
00006  *  Copyright  2005-2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 // Do not include in api reference
00025 ///@cond QA
00026 
00027 #include <utils/ipc/msg.h>
00028 
00029 #include <stdio.h>
00030 #include <unistd.h>
00031 #include <string.h>
00032 
00033 #define QA_MTYPE 1
00034 
00035 using namespace fawkes;
00036 
00037 typedef struct {
00038   long mtype;
00039   char msg[20];
00040 } simple_msg_t;
00041 
00042 int
00043 main( int argc, char **argv )
00044 {
00045   // Create message queue, destroy on delete
00046   IPCMessageQueue *m1 = new IPCMessageQueue(".", 'A', true, true);
00047 
00048   // Open, do not create, do not destroy
00049   IPCMessageQueue *m2 = new IPCMessageQueue(".", 'A', false, false);
00050 
00051   for (unsigned int i = 0; i < 10; ++i) {
00052     simple_msg_t smsg;
00053     simple_msg_t rmsg;
00054     memset(&smsg, 0, sizeof(smsg));
00055     memset(&rmsg, 0, sizeof(rmsg));
00056 
00057     smsg.mtype = QA_MTYPE;
00058     sprintf(smsg.msg, "%u", i);
00059 
00060     m1->send((IPCMessageQueue::MessageStruct *)&smsg, sizeof(smsg));
00061     m2->recv(QA_MTYPE, (IPCMessageQueue::MessageStruct *)&rmsg, sizeof(rmsg));
00062 
00063     printf("Sent: %s     Received: %s\n", smsg.msg, rmsg.msg);
00064   }
00065 
00066   delete m2;
00067   delete m1;
00068 
00069   return 0;
00070 }
00071 
00072 
00073 
00074 /// @endcond

Generated on Tue Feb 22 13:31:27 2011 for Fawkes API by  doxygen 1.4.7