00001
00010 #include <stdlib.h>
00011 #include "MsgQInternal.h"
00012
00013
00014
00015 MSGQ_INFO_PTR MsgQInfo[MSGQ_TBL_SZ];
00016 MSGQ_INFO_LIST_PTR MsgQListHead = NULL;
00017
00018 inline unsigned int HashIndex(ULONG qName);
00019
00020
00021
00022
00023
00024
00025
00026
00027 int InstallMsqQTable(ULONG qName, int qId, int semId, int* err) {
00028
00029 MSGQ_INFO_PTR pMsgQInfo = NULL;
00030 unsigned int index;
00031
00032 if ((pMsgQInfo = MsgQTableLookup(qName)) == NULL) {
00033 pMsgQInfo = (MSGQ_INFO_PTR)malloc(sizeof(*pMsgQInfo));
00034
00035 if(pMsgQInfo != NULL) {
00036 index = HashIndex(qName);
00037
00038 pMsgQInfo->next = MsgQInfo[index];
00039 MsgQInfo[index] = pMsgQInfo;
00040 pMsgQInfo->qName = qName;
00041 pMsgQInfo->qId = qId;
00042 pMsgQInfo->semId = semId;
00043 pMsgQInfo->sendState = MSG_Q_READY;
00044 pMsgQInfo->numMsgs = 0;
00045
00046 *err = OK;
00047 return (OK);
00048 }
00049 else
00050 *err = KMsgQLibNoMemoryErr;
00051 }
00052 else
00053 *err = KMsgQLibQIdErr;
00054
00055 return(ERROR);
00056
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 inline unsigned int HashIndex(ULONG qName) {
00066 return(qName % MSGQ_TBL_SZ);
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 MSGQ_INFO* MsgQTableLookup(ULONG qName) {
00076 MSGQ_INFO_PTR pMsgQInfo = NULL;
00077
00078 for (pMsgQInfo = MsgQInfo[HashIndex(qName)]; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00079 if (qName == pMsgQInfo->qName)
00080 return(pMsgQInfo);
00081 }
00082
00083 return(NULL);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093 int RemoveFromMsqQTable(ULONG qName, int* err) {
00094 unsigned int index = 0;
00095 MSGQ_INFO_PTR prev = NULL;
00096 MSGQ_INFO_PTR pMsgQInfo = NULL;
00097
00098 index = HashIndex(qName);
00099 for (pMsgQInfo = MsgQInfo[index]; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00100 if (qName == pMsgQInfo->qName)
00101 break;
00102 prev = pMsgQInfo;
00103 }
00104
00105 if (pMsgQInfo != NULL) {
00106 if (prev == NULL)
00107 MsgQInfo[index] = pMsgQInfo->next;
00108 else
00109 prev->next = pMsgQInfo->next;
00110
00111 free((void*)pMsgQInfo);
00112 *err = OK;
00113 return (OK);
00114 }
00115 else
00116 *err = KMsgQLibQIdErr;
00117
00118 return(ERROR);
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 void AddToMsgQTable(ULONG qName) {
00128 MSGQ_INFO_LIST_PTR tempNext;
00129
00130 if (MsgQListHead != NULL) {
00131
00132 tempNext = MsgQListHead->next;
00133
00134 if ((MsgQListHead->next = (MSGQ_INFO_LIST*)malloc(sizeof(MSGQ_INFO_LIST))) != NULL) {
00135 MsgQListHead->next->next = tempNext;
00136 MsgQListHead->next->qName = qName;
00137 }
00138 else
00139 MsgQListHead->next = tempNext;
00140 }
00141 else {
00142 if ((MsgQListHead = (MSGQ_INFO_LIST*)malloc(sizeof(MSGQ_INFO_LIST))) != NULL) {
00143 MsgQListHead->next = NULL;
00144 MsgQListHead->qName = qName;
00145 }
00146 }
00147 }
00148
00149
00150
00151
00152
00153
00154 void DeleteFromMsgQTable(ULONG qName) {
00155 MSGQ_INFO_LIST_PTR prev = NULL;
00156 MSGQ_INFO_LIST_PTR pMsgQInfo = NULL;
00157
00158 for (pMsgQInfo = MsgQListHead; pMsgQInfo != NULL; pMsgQInfo = pMsgQInfo->next) {
00159 if (qName == pMsgQInfo->qName)
00160 break;
00161 prev = pMsgQInfo;
00162 }
00163
00164 if (pMsgQInfo != NULL) {
00165
00166 if( prev == NULL )
00167 MsgQListHead = MsgQListHead->next ;
00168
00169
00170 else
00171 prev->next = pMsgQInfo->next;
00172
00173
00174 free((void*) pMsgQInfo);
00175 }
00176 }