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