00001 00002 /*************************************************************************** 00003 * msg.h - IPC message queue 00004 * 00005 * Generated: Mon Mar 13 17:37:49 2006 (from FireVision) 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 #ifndef __UTILS_IPC_MSG_H_ 00025 #define __UTILS_IPC_MSG_H_ 00026 00027 namespace fawkes { 00028 00029 00030 class IPCMessageQueueData; 00031 00032 class IPCMessageQueue { 00033 public: 00034 00035 static const int MaxMessageSize; 00036 00037 /** This is the struct of the messages that has to be fed to send and 00038 * receive methods. 00039 */ 00040 typedef struct { 00041 long int mtype; /**< type of the message */ 00042 char mtext[1]; /**< content of the message, can be of arbitrary 00043 * size up to MaxMessageSize 00044 */ 00045 } MessageStruct; 00046 00047 IPCMessageQueue(const char *path, char id, 00048 bool create = false, 00049 bool destroy_on_delete = false); 00050 00051 IPCMessageQueue(int id, 00052 bool create = false, 00053 bool destroy_on_delete = false); 00054 00055 ~IPCMessageQueue(); 00056 00057 bool isValid(); 00058 bool recv(long mtype, MessageStruct *msg, unsigned int data_size); 00059 bool recvNext(MessageStruct *msg, unsigned int max_data_size, int *data_size); 00060 bool send(MessageStruct *msg, unsigned int data_size); 00061 00062 /** Get the message type 00063 * @param buffer the buffer of the message as returned by getMessage() 00064 * @return the message type 00065 */ 00066 static inline long 00067 mtype(char *buffer) 00068 { 00069 return (((MessageStruct *)buffer)->mtype); 00070 } 00071 00072 protected: 00073 bool destroy_on_delete; 00074 00075 private: 00076 IPCMessageQueueData *data; 00077 00078 }; 00079 00080 00081 } // end namespace fawkes 00082 00083 #endif