Go to the documentation of this file.00001 #ifndef EVENTFILTER_UTILITIES_SLAVEQUEUE_H
00002 #define EVENTFILTER_UTILITIES_SLAVEQUEUE_H
00003
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #include <sys/types.h>
00007 #include <sys/ipc.h>
00008 #include <sys/msg.h>
00009 #include <errno.h>
00010 #include <string.h>
00011
00012 #include "EventFilter/Utilities/interface/MsgBuf.h"
00013
00014
00015
00016 namespace evf{
00017
00018 class SlaveQueue{
00019
00020 public:
00021
00022 SlaveQueue(unsigned int ind) : queue_id_(0)
00023 {
00024
00025
00026 queue_id_ = msgget(QUEUE_ID+ind, 0);
00027 if (queue_id_ == -1) {
00028 XCEPT_RAISE(evf::Exception, "failed to get message queue");
00029 }
00030 }
00031 ~SlaveQueue()
00032 {
00033 }
00034
00035 int post(MsgBuf &ptr)
00036 {
00037 int rc;
00038 rc = msgsnd(queue_id_,ptr.ptr_, ptr.msize(),0);
00039
00040 if(rc==-1)
00041 std::cout << "snd::Slave failed to post message - error:"
00042 << strerror(errno) << std::endl;
00043 return rc;
00044 }
00045 unsigned long rcv(MsgBuf &ptr)
00046 {
00047 unsigned long msg_type = MSQS_MESSAGE_TYPE_SLA;
00048 int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize(), - msg_type, 0);
00049 if (rc == -1 && errno != ENOMSG)
00050 {
00051 std::string serr = "rcv::Slave failed to get message from queue - error:";
00052 serr += strerror(errno);
00053 XCEPT_RAISE(evf::Exception, serr);
00054 }
00055 else if(rc == -1 && errno == ENOMSG) return MSGQ_MESSAGE_TYPE_RANGE;
00056 return msg_type;
00057 }
00058 unsigned long rcvNonBlocking(MsgBuf &ptr)
00059 {
00060 unsigned long msg_type = MSQS_MESSAGE_TYPE_SLA;
00061 int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize(), - msg_type, IPC_NOWAIT);
00062 if (rc == -1 && errno != ENOMSG)
00063 {
00064 std::string serr = "rcvnb::Slave failed to get message from queue - error:";
00065 serr += strerror(errno);
00066 XCEPT_RAISE(evf::Exception, serr);
00067 }
00068 else if(rc == -1 && errno == ENOMSG) return MSGQ_MESSAGE_TYPE_RANGE;
00069 return msg_type;
00070 }
00071 unsigned long rcvNonBlockingAny(MsgBuf &ptr)
00072 {
00073 unsigned long msg_type = 0;
00074 int rc = msgrcv(queue_id_, ptr.ptr_, ptr.msize(), msg_type, IPC_NOWAIT);
00075 if (rc == -1 && errno != ENOMSG)
00076 {
00077 std::string serr = "rcvnb::Slave failed to get message from queue - error:";
00078 serr += strerror(errno);
00079 XCEPT_RAISE(evf::Exception, serr);
00080 }
00081 else if(rc == -1 && errno == ENOMSG) return MSGQ_MESSAGE_TYPE_RANGE;
00082 return msg_type;
00083 }
00084 int id() const {return queue_id_;}
00085 private:
00086
00087 int queue_id_;
00088
00089 };
00090 }
00091 #endif