EpcTools
An event based multi-threaded C++ development framework.
eqpub.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __eqpub_h_included
19 #define __eqpub_h_included
20 
21 #include "eqbase.h"
22 #include "eshmem.h"
23 #include "esynch2.h"
24 
27 
28 DECLARE_ERROR_ADVANCED2(EQueuePublicError_QueueNotFound);
29 
32 
33 class EQueuePublic : public EQueueBase
34 {
35 public:
37  EQueuePublic();
39  ~EQueuePublic();
40 
44  Void init(Int queueid, EQueueBase::Mode mode);
45 
46 protected:
48  Bool isPublic() { return True; }
49  ULong &msgSize();
50  Int &msgCnt();
51  Long &msgHead();
52  Long &msgTail();
53  Bool &multipleReaders();
54  Bool &multipleWriters();
55  Int &numReaders();
56  Int &numWriters();
57  Int &refCnt();
58  pChar data();
59  Int ctrlSize();
60  Void allocDataSpace(cpStr sFile, Char cId, Int nSize);
61  Void initReadMutex();
62  Void initWriteMutex();
63  Void initSemFree(UInt initialCount);
64  Void initSemMsgs(UInt initialCount);
65 
66  EMutexData &readMutex() { return ESynchObjects::getMutex(readMutexId()); }
67  EMutexData &writeMutex() { return ESynchObjects::getMutex(writeMutexId()); }
68  ESemaphoreData &semFree() { return ESynchObjects::getSemaphore(semFreeId()); }
69  ESemaphoreData &semMsgs() { return ESynchObjects::getSemaphore(semMsgsId()); }
70 
71  virtual EQueueMessage *allocMessage(Long msgType) = 0;
72 
73  Void init(Int nMsgSize, Int nMsgCnt, Int queueId, Bool bMultipleReaders,
74  Bool bMultipleWriters, EQueueBase::Mode eMode)
75  {
76  EQueueBase::init(nMsgSize, nMsgCnt, queueId, bMultipleReaders, bMultipleWriters, eMode);
77  }
79 
80 private:
81  typedef struct
82  {
83  Int m_refCnt;
84  Int m_numReaders;
85  Int m_numWriters;
86  Bool m_multipleReaders;
87  Bool m_multipleWriters;
88 
89  ULong m_msgSize;
90  Int m_msgCnt;
91  Long m_head; // next location to write
92  Long m_tail; // next location to read
93  Int m_rmutexid;
94  Int m_wmutexid;
95  Int m_semfreeid;
96  Int m_semmsgsid;
97  } esharedqueue_ctrl_t;
98 
99  Int &readMutexId() { return m_pCtrl->m_rmutexid; }
100  Int &writeMutexId() { return m_pCtrl->m_wmutexid; }
101 
102  Int &semFreeId() { return m_pCtrl->m_semfreeid; }
103  Int &semMsgsId() { return m_pCtrl->m_semmsgsid; }
104 
105  ESharedMemory m_sharedmem;
106  esharedqueue_ctrl_t *m_pCtrl;
107  pChar m_pData;
108 };
109 
110 #endif // #define __eqpub_h_included
ESemaphoreData
Contains the data associated with a public or private semaphore.
Definition: esynch.h:268
True
#define True
True.
Definition: ebase.h:25
eshmem.h
Defines a class for access to shared memory.
EQueueBase
The message queue base class.
Definition: eqbase.h:120
EQueueMessage
Represents a message to be written to/read from a message queue.
Definition: eqbase.h:55
EQueueBase::Mode
Mode
The queue access modes.
Definition: eqbase.h:127
EQueuePublic::init
Void init(Int queueid, EQueueBase::Mode mode)
Initializes the queue object.
esynch2.h
DECLARE_ERROR_ADVANCED2
DECLARE_ERROR_ADVANCED2(EQueuePublicError_QueueNotFound)
EQueuePublic::EQueuePublic
EQueuePublic()
Default constructor.
Definition: eqpub.cpp:37
ESharedMemory
The shared memory access class.
Definition: eshmem.h:43
EQueuePublic
Definition: eqpub.h:33
EQueuePublic::~EQueuePublic
~EQueuePublic()
Class destructor.
Definition: eqpub.cpp:43
eqbase.h
Provides base class support for sending and receiving messages via a message queue.
EMutexData
Contains the data associated with a public or private mutex.
Definition: esynch.h:72