![]() |
VR-Link API Documentation for HLA 1.3
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *********************************************************************/ 00008 #pragma once 00009 00010 #include "vlMachineTypes.h" 00011 00012 #include <sys/types.h> 00013 #include <sys/ipc.h> 00014 #include <sys/sem.h> 00015 00017 #define DT_QCONTROL_VALID 0 00018 #define DT_QCONTROL_DEAD_SPACE 1 00019 #define DT_QCONTROL_END 2 00020 00021 #define DtSMQFrontLockSem 0 00022 #define DtSMQPacketCountSem 1 00023 00028 #define DtSMQByteCountSem 0 00029 00030 #define DtCsSemaphoresUsed 2 00031 00032 #define DtSMQDontGoYet 0 00033 #define DtSMQIAmGoingAway 1 00034 #define DtSMQYouMustGoAway 2 00035 00036 #define DtSMQExternal 0 00037 #define DtSMQInternal 1 00038 00039 #ifdef DtUSE_UTILITIES_NAMESPACE 00040 namespace DtUSE_UTILITIES_NAMESPACE 00041 { 00042 #endif 00043 00044 typedef struct Dt_Q_Elmt_Hdr 00045 { 00046 short read; 00047 short control; 00048 int size; 00049 } DtQueueElementHdr; 00050 00051 typedef struct Dt_Msg_Queue_Element 00052 { 00053 DtQueueElementHdr hdr; 00054 char data[8]; 00055 } DtMsgQueueElement; 00056 00057 00058 typedef struct Dt_Q_Hdr 00059 { 00060 DtInt32 front; 00061 DtU32 notifyReader; 00062 00063 00064 unsigned char goAway; 00065 unsigned char internal; 00066 DtU16 padding1; 00067 00068 unsigned char blockingRead; 00069 unsigned char blockingWrite; 00070 unsigned char dropOldest; 00071 unsigned char padding2; 00072 00073 } DtShmQueueHdr; 00074 00075 typedef struct Dt_Shm_Msg_Queue 00076 { 00077 DtShmQueueHdr hdr; 00078 char data[8]; 00079 } DtShmMsgQueue; 00080 00081 00082 00083 class DT_DLL_VLUTIL DtShmMsgQueueManager 00084 { 00085 friend class DtShmMsgQueueReader; 00086 friend class DtShmMsgQueueWriter; 00087 00088 public: 00089 00090 DtShmMsgQueueManager(DtShmMsgQueue *q, int size, int sem, int firstSem, 00091 bool pleaseInit, bool dropOldest); 00092 00093 virtual ~DtShmMsgQueueManager(void); 00094 00095 void setBlockingRead(bool mode) 00096 { queue->hdr.blockingRead = mode ? 1 : 0; } 00097 00098 void setBlockingWrite(bool mode) 00099 { queue->hdr.blockingWrite = mode ? 1 : 0; } 00100 00101 bool isBlockingRead() 00102 { return queue->hdr.blockingRead ? true : false; } 00103 00104 bool isBlockingWrite() 00105 { return queue->hdr.blockingWrite ? true : false; } 00106 00107 bool isDropOldest() 00108 { return queue->hdr.dropOldest ? true : false; } 00109 00110 int getGoAway() { return queue->hdr.goAway; } 00111 00112 DtU32 notifyReader(); 00113 00114 void setNotifyReader(DtU32 count) { queue->hdr.notifyReader = count; } 00115 00116 private: 00117 00118 int lockFront(int wait); 00119 void unlockFront(void); 00120 00121 void incrPacketCount(int amount); 00122 void incrByteCount(int amount); 00123 void decrByteCount(int amount); 00124 void decrPacketCount(int amount); 00125 00126 int getPhysEnd() { return physEnd; } 00127 00128 void setFront(int newFront) { queue->hdr.front = newFront; } 00129 int getFront() { return queue->hdr.front; } 00130 00131 void setGoAway(int reason) { queue->hdr.goAway = reason; } 00132 00133 void setDropOldest(bool mode) 00134 { queue->hdr.dropOldest = mode ? 1 : 0; } 00135 00136 void setInternal(int mode) { queue->hdr.internal = mode; } 00137 bool isInternal() { return queue->hdr.internal ? true : false; } 00138 00139 DtMsgQueueElement *getQueueElement(int i) 00140 { return (DtMsgQueueElement *) & queue->data[i]; } 00141 00142 00143 protected: 00144 00145 DtShmMsgQueue *queue; 00146 int physEnd; 00147 int semid; 00148 00149 struct sembuf testAndSetLock; 00150 struct sembuf clearLock; 00151 struct sembuf addBytes; 00152 struct sembuf subBytes; 00153 struct sembuf addPackets; 00154 struct sembuf subPackets; 00155 00156 00157 }; 00158 00159 #ifdef DtUSE_UTILITIES_NAMESPACE 00160 } 00161 #endif 00162