?? sharememory.cpp
字號:
else { // initialize semaphore, set value = 1 struct sembuf *pSemBuffer; pSemBuffer = (sembuf *) new sembuf; if(NULL == pSemBuffer) { { ShmLog("17"); throw C_SHMException(); } } for(int i=0;i < m_pBlockInfo->uiSemTotalNumber;i++) { memset(pSemBuffer,0,sizeof(sembuf)); pSemBuffer->sem_num = i; pSemBuffer->sem_op = 0; pSemBuffer->sem_flg = SEM_UNDO; semop(m_iSemID,pSemBuffer,1); } /* #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } for(int i=0;i < m_pBlockInfo->uiSemTotalNumber;i++) { fprintf(fp,"GetShmSemID{ ucInitialFalg = %d }\n",ucInitialFlag); } fclose(fp); #endif */ if(pSemBuffer != NULL) { delete pSemBuffer; pSemBuffer = NULL; } } } #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"GetShmSemID{ ucInitialFalg = %d }\n",ucInitialFlag); fclose(fp); #endif } // get config value of business area information void C_ShareMemory::GetAreaConfig() { CConfigXml ShmConfig; char sName[XML_NAME_LEN]; char sValue[XML_VALUE_LEN]; string sTemp; #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"before Load m_pConfigFileName=%s\n", m_pConfigFileName); fclose(fp); #endif if( !ShmConfig.Load(m_pConfigFileName) ) { ShmLog("18"); throw C_SHMException(); } printf("SHM----->\n"); #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"after Load m_pConfigFileName=%s\n", m_pConfigFileName); fclose(fp); #endif // get config information of business area m_pBlockInfo->pAreaInfo = new S_AreaInfo[ m_pBlockInfo->uiBusinessAreaNumber ]; if(NULL == m_pBlockInfo->pAreaInfo) { { ShmLog("19"); throw C_SHMException(); } } memset(m_pBlockInfo->pAreaInfo,0,(m_pBlockInfo->uiBusinessAreaNumber) * sizeof(S_AreaInfo)); for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { // get config value of business area ID memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.AreaID",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("20"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->uiAreaID = atoi(sValue); // get config value of business area size memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.AreaSize",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("21"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->ulAreaSize = atol(sValue); // calculate offset of the business area start address // from block start address if(0 == i) { (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset = m_pBlockInfo->ulControlAreaSize; } else { (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset = (m_pBlockInfo->pAreaInfo + i - 1)->ulAddressOffset \ + (m_pBlockInfo->pAreaInfo + i - 1)->ulAreaSize; } // get config value of business index area size memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.AreaIndexSize",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("22"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->ulAreaIndexSize = atol(sValue); // get config value of data item size memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.DataItemSize",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("23"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->ulItemSize = atol(sValue); // get config value of data item number memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.DataItemNumber",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("24"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->ulItemNumber = atol(sValue); // calculate start address of index array, // namely business index area start address /* (m_pBlockInfo->pAreaInfo + i)->pIndex = \ (unsigned long *) (m_pBlockStartAddress + (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset); */ (m_pBlockInfo->pAreaInfo + i)->pIndex = new unsigned long[(m_pBlockInfo->pAreaInfo + i)->ulItemNumber]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pIndex) { ShmLog("24_"); throw C_SHMException(); } memset((m_pBlockInfo->pAreaInfo + i)->pIndex,0, \ (m_pBlockInfo->pAreaInfo + i)->ulItemNumber * sizeof(unsigned long)); // initialize index array for(unsigned long j=0;j < (m_pBlockInfo->pAreaInfo + i)->ulItemNumber;j++) { *((m_pBlockInfo->pAreaInfo + i)->pIndex + j) = \ (unsigned long)m_pBlockStartAddress \ + (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset \ + (m_pBlockInfo->pAreaInfo + i)->ulAreaIndexSize \ + j * (m_pBlockInfo->pAreaInfo + i)->ulItemSize; } // initialize update flag (m_pBlockInfo->pAreaInfo + i)->pUpdateFlag = (unsigned char *)( m_pBlockStartAddress \ + (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset ); for(unsigned long j=0;j < (m_pBlockInfo->pAreaInfo + i)->ulItemNumber;j++) { *( (m_pBlockInfo->pAreaInfo + i)->pUpdateFlag + j ) = 0; } // get config value of queue number memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.QueueNumber",i); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("25"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber = atoi(sValue); // get config information of queue (m_pBlockInfo->pAreaInfo + i)->pQueueInfo = new S_QueueInfo[ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber ]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pQueueInfo) { { ShmLog("26"); throw C_SHMException(); } } memset((m_pBlockInfo->pAreaInfo + i)->pQueueInfo,0, \ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo)); int j=0; for(;j < (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber;j++) { // get config value of queue ID memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.QueueInfo_%d.QueueID",i,j); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("27"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->uiQueueID = atoi(sValue); // initialize queue /*((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue = \ (S_Queue *) ( (char *)( (m_pBlockInfo->pAreaInfo + i)->pIndex ) \ + ( (m_pBlockInfo->pAreaInfo + i)->ulItemNumber ) * sizeof(unsigned long) \ + j * sizeof(S_Queue) \ + j * ( (m_pBlockInfo->pAreaInfo + i)->ulItemNumber ) * sizeof(unsigned long) ); */ ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue = new S_Queue; if(NULL == ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue) { ShmLog("27_"); throw C_SHMException(); } memset(((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue,0,sizeof(S_Queue)); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pFront = \ (unsigned long *) (m_pBlockStartAddress + (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset \ + (m_pBlockInfo->pAreaInfo + i)->ulItemNumber \ + j * ( 2 + (m_pBlockInfo->pAreaInfo + i)->ulItemNumber + 1 ) * sizeof(unsigned long) ); *( ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pFront ) = 0; ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pRear = \ ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pFront + 1; ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->ulMaxSize = \ (m_pBlockInfo->pAreaInfo + i)->ulItemNumber + 1; /*((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pQueue = (unsigned long *) \ ( (char *)((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue + sizeof(S_Queue) ); */ ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pQueue = \ ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pFront + 2; // vacancy memory maintenance queue if(0 == ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->uiQueueID) { *( ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pRear ) = \ (m_pBlockInfo->pAreaInfo + i)->ulItemNumber; for(unsigned long k=0;k < (m_pBlockInfo->pAreaInfo + i)->ulItemNumber;k++) { *(((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pQueue + k + 1) = k; } } else { *( ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pRear ) = 0; } // get config value of front concurrent flag memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.QueueInfo_%d.FrontConcurrent",i,j); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("28"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->ucFrontConcurrent = (unsigned char)atoi(sValue); // get config value of front semaphore memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.QueueInfo_%d.FrontSemaphore",i,j); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("29"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->uiFrontSemNumber = atoi(sValue); // get config value of rear concurrent flag memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.QueueInfo_%d.RearConcurrent",i,j); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("30"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->ucRearConcurrent = (unsigned char)atoi(sValue); // get config value of rear semaphore memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.QueueInfo_%d.RearSemaphore",i,j); if( !ShmConfig.GetValue(sName,sTemp) ) { ShmLog("31"); throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->uiRearSemNumber = atoi(sValue); } /* // get config value of update array number memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.AreaInfo.UpdateArrayNumber",i); if( !ShmConfig.GetValue(sName,sTemp) ) {ShmLog("31_");throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber = atoi(sValue); // get config information of update array (m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo = \ new S_UpdateArrayInfo[ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber ]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -