?? sharememory.cpp
字號:
{ {ShmLog("_31_");throw C_SHMException(); } } memset((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo,0, \ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo)); for(int k=0;k < (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber;k++) { // get config value of update array ID memset(sName,0,XML_NAME_LEN); memset(sValue,0,XML_VALUE_LEN); sprintf(sName,"ShareMemory.BusinessArea_%d.UpdateArray.UpdateArray_%d",i,k); if( !ShmConfig.GetValue(sName,sTemp) ) {ShmLog("31*");throw C_SHMException(); } strcpy(sValue,sTemp.c_str()); ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->uiUpdateArrayID = atoi(sValue); // initialize counter of update array ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->pCounter = \ (unsigned long *)( (char *)( (m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j - 1)->pQueue->pQueue \ + (m_pBlockInfo->pAreaInfo + i)->ulItemNumber * sizeof(unsigned long) \ + k * (1 + (m_pBlockInfo->pAreaInfo + i)->ulItemNumber) * sizeof(unsigned long) ); *( ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->pCounter ) = 0; // initialize start address of update array ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->pUpdateArray = \ ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->pCounter + 1; }*/ } } // initialize config information of share memory block void C_ShareMemory::InitConfig(const unsigned char ucInitialFlag) { char *pTemp = NULL; #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"InitConfig{ ucInitialFalg = %d }\n",ucInitialFlag); fclose(fp); #endif if(1 == ucInitialFlag) { // initialize and save config information to control information area #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"Before memset{ m_pBlockInfo->ulShmTotalSize = %d }\n",m_pBlockInfo->ulShmTotalSize); fclose(fp); #endif memset(m_pBlockStartAddress,0,m_pBlockInfo->ulShmTotalSize); #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"After memset{ m_pBlockInfo->ulShmTotalSize = %d }\n",m_pBlockInfo->ulShmTotalSize); fclose(fp); #endif GetAreaConfig(); // get config value of business area information #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"After getAreaConfig\n"); fclose(fp); #endif // save config information to control information area // save block config information, S_BlockInfo memcpy(m_pBlockStartAddress,m_pBlockInfo,sizeof(S_BlockInfo)); #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"After memcpy{ sizeof(S_BlockInfo) = %d }\n",sizeof(S_BlockInfo)); fclose(fp); #endif // save area config information, S_AreaInfo memcpy(m_pBlockStartAddress + sizeof(S_BlockInfo),m_pBlockInfo->pAreaInfo, \ m_pBlockInfo->uiBusinessAreaNumber * sizeof(S_AreaInfo)); #ifdef DEBUG_SHM if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"After memcpy{ m_pBlockInfo->uiBusinessAreaNumber * sizeof(S_AreaInfo) = %d }\n",m_pBlockInfo->uiBusinessAreaNumber * sizeof(S_AreaInfo)); fclose(fp); #endif // save queue config information, S_QueueInfo pTemp = m_pBlockStartAddress + sizeof(S_BlockInfo) + m_pBlockInfo->uiBusinessAreaNumber * sizeof(S_AreaInfo); for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { memcpy(pTemp,(m_pBlockInfo->pAreaInfo + i)->pQueueInfo, \ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo) ); pTemp = pTemp + (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo); } /*// save update array config information, S_UpdateArrayInfo for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { memcpy(pTemp,(m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo, \ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo) ); pTemp = pTemp + (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo); } */ pTemp = NULL; // set initialized flag = 1 memset(m_pBlockStartAddress,1,1); #ifdef DEBUG_SHM { if( (fp = fopen(gsLogFileName,"a+") ) == NULL) { printf("open %s failed!\n",gsLogFileName); exit(-1); } fprintf(fp,"<Wirte Initialize Information>\n"); S_BlockInfo suBlockInfo; memset(&suBlockInfo,0,sizeof(S_BlockInfo)); memcpy(&suBlockInfo,m_pBlockStartAddress,sizeof(S_BlockInfo)); fprintf(fp,"Share Memory Initialize Flag:%d\n",suBlockInfo.ucInitializeFlag); fprintf(fp,"Share Memory Key:%ld\n",suBlockInfo.ulShmKey); fprintf(fp,"Share Memory Size:%ld\n",suBlockInfo.ulShmTotalSize); fprintf(fp,"Semaphore Number:%d\n",suBlockInfo.uiSemTotalNumber); fprintf(fp,"Control Area Size:%ld\n",suBlockInfo.ulControlAreaSize); fprintf(fp,"Business Area Number:%d\n",suBlockInfo.uiBusinessAreaNumber); // output of business area information S_AreaInfo suAreaInfo; S_QueueInfo suQueueInfo; /* S_UpdateArrayInfo suUpdateArrayInfo;*/ pTemp = m_pBlockStartAddress + sizeof(S_BlockInfo) + suBlockInfo.uiBusinessAreaNumber * sizeof(S_AreaInfo); for(int i=0;i < suBlockInfo.uiBusinessAreaNumber;i++) { fprintf(fp,"\n<Business Area %d Information>\n",i); memset(&suAreaInfo,0,sizeof(S_AreaInfo)); memcpy(&suAreaInfo,m_pBlockStartAddress + sizeof(S_BlockInfo) + i * sizeof(S_AreaInfo),sizeof(S_AreaInfo)); // output of area information fprintf(fp,"<Area Information>\n"); fprintf(fp,"Area ID:%d\n",suAreaInfo.uiAreaID); fprintf(fp,"Area Size:%ld\n",suAreaInfo.ulAreaSize); fprintf(fp,"Area Index Size:%ld\n",suAreaInfo.ulAreaIndexSize); fprintf(fp,"Data Item Size:%ld\n",suAreaInfo.ulItemSize); fprintf(fp,"Data Item Number:%ld\n",suAreaInfo.ulItemNumber); fprintf(fp,"Queue Number:%d\n",suAreaInfo.uiQueueNumber); /*fprintf(fp,"Update Array Number:%d\n",suAreaInfo.uiUpdateArrayNumber);*/ // output of queue information for(int j=0;j < suAreaInfo.uiQueueNumber;j++) { fprintf(fp,"<Queue %d Information>\n",j); memset(&suQueueInfo,0,sizeof(S_QueueInfo)); memcpy(&suQueueInfo,pTemp,sizeof(S_QueueInfo)); pTemp = pTemp + sizeof(S_QueueInfo); fprintf(fp,"Queue ID:%d\n",suQueueInfo.uiQueueID); fprintf(fp,"Front Concurrent:%d\n",suQueueInfo.ucFrontConcurrent); fprintf(fp,"Front Semaphore:%d\n",suQueueInfo.uiFrontSemNumber); fprintf(fp,"Rear Concurrent:%d\n",suQueueInfo.ucRearConcurrent); fprintf(fp,"Rear Semaphore:%d\n",suQueueInfo.uiRearSemNumber); /*fprintf(fp,"Queue Address:0x%0x\n",suQueueInfo.pQueue);*/ fprintf(fp,"Front:%ld\n",*(suQueueInfo.pQueue->pFront)); fprintf(fp,"Rear:%ld\n",*(suQueueInfo.pQueue->pRear)); fprintf(fp,"MaxSize:%ld\n",suQueueInfo.pQueue->ulMaxSize); fprintf(fp,"Queue Address:0x%0x\n",suQueueInfo.pQueue->pQueue); } /* // output of update array information if(suAreaInfo.uiUpdateArrayNumber > 0) fprintf(fp,"<Update Array Information>\n"); for(int j=0;j < suAreaInfo.uiUpdateArrayNumber;j++) { fprintf(fp,"Update Array %d\n",j); memset(&suUpdateArrayInfo,0,sizeof(S_UpdateArrayInfo)); memcpy(&suUpdateArrayInfo,pTemp,sizeof(S_UpdateArrayInfo)); pTemp = pTemp + sizeof(S_UpdateArrayInfo); fprintf(fp,"Update Array ID:%d \n",suUpdateArrayInfo.uiUpdateArrayID); fprintf(fp,"Counter:%ld\n",*(suUpdateArrayInfo.pCounter)); fprintf(fp,"Update Array Address:0x%0x\n",suUpdateArrayInfo.pUpdateArray); }*/ } fclose(fp); } #endif } else { // get config information from control information area and initialize // check initialized flag, if not initialized, // sleep and wait until initialized int i=0; for(;i < 60;i++) { if(1 == *( (unsigned char *) m_pBlockStartAddress )) break; else sleep(1); } if(60 == i) { ShmLog("32_"); throw C_SHMException(); } // read config information from control information area // read block config information, S_BlockInfo memset(m_pBlockInfo,0,sizeof(S_BlockInfo)); memcpy(m_pBlockInfo,m_pBlockStartAddress,sizeof(S_BlockInfo)); // read area config information, S_AreaInfo m_pBlockInfo->pAreaInfo = new S_AreaInfo[ (m_pBlockInfo->uiBusinessAreaNumber) ]; if(NULL == m_pBlockInfo->pAreaInfo) { { ShmLog("32"); throw C_SHMException(); } } memset(m_pBlockInfo->pAreaInfo,0,(m_pBlockInfo->uiBusinessAreaNumber) * sizeof(S_AreaInfo)); memcpy(m_pBlockInfo->pAreaInfo,m_pBlockStartAddress + sizeof(S_BlockInfo), \ (m_pBlockInfo->uiBusinessAreaNumber) * sizeof(S_AreaInfo)); pTemp = m_pBlockStartAddress + sizeof(S_BlockInfo) \ + (m_pBlockInfo->uiBusinessAreaNumber) * sizeof(S_AreaInfo); // read queue config information, S_QueueInfo for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { (m_pBlockInfo->pAreaInfo + i)->pQueueInfo = new \ S_QueueInfo[ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber ]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pQueueInfo) { { ShmLog("33"); throw C_SHMException(); } } memset((m_pBlockInfo->pAreaInfo + i)->pQueueInfo,0, \ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo)); memcpy((m_pBlockInfo->pAreaInfo + i)->pQueueInfo,pTemp, \ (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo)); pTemp = pTemp + (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber * sizeof(S_QueueInfo); } /* // read update array config information, S_QueueInfo for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { (m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo = new \ S_UpdateArrayInfo[ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber ]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo) { {ShmLog("33__");throw C_SHMException(); } } memset((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo,0, \ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo)); memcpy((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo,pTemp, \ (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo)); pTemp = pTemp + (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber * sizeof(S_UpdateArrayInfo); } */ // initialize index array,queue,update array in business area by new m_pBlockStartAddress for(int i=0;i < m_pBlockInfo->uiBusinessAreaNumber;i++) { // initialize index array by new m_pBlockStartAddress (m_pBlockInfo->pAreaInfo + i)->pIndex = new \ unsigned long[ (m_pBlockInfo->pAreaInfo + i)->ulItemNumber ]; if(NULL == (m_pBlockInfo->pAreaInfo + i)->pIndex) { ShmLog("__33"); throw C_SHMException(); } 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 by new m_pBlockStartAddress (m_pBlockInfo->pAreaInfo + i)->pUpdateFlag = (unsigned char *)( m_pBlockStartAddress \ + (m_pBlockInfo->pAreaInfo + i)->ulAddressOffset ); // initialize queue by new m_pBlockStartAddress int j=0; for(;j < (m_pBlockInfo->pAreaInfo + i)->uiQueueNumber;j++) { ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue = new S_Queue; if(NULL == ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue) { ShmLog("__33__"); 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->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 = \ ((m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j)->pQueue->pFront + 2; } /*// initialize update array by new m_pBlockStartAddress for(int k=0;k < (m_pBlockInfo->pAreaInfo + i)->uiUpdateArrayNumber;k++) { // initialize counter of update array ((m_pBlockInfo->pAreaInfo + i)->pUpdateArrayInfo + k)->pCounter = \ (unsigned long *)( (char *)( (m_pBlockInfo->pAreaInfo + i)->pQueueInfo + j - 1)->pQueue->pQueue \
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -