T_KRRecord *kr_input_process(T_KRInput *ptInput, T_KRRequest *ptRequest) { char *msgid = ptRequest->msgid; int msgsrc = ptRequest->msgsrc; char *msgfmt = ptRequest->msgfmt; size_t msglen = ptRequest->msglen; char *msgbuf = ptRequest->msgbuf; T_KRInputDefine *ptInputDefine = kr_input_get_define(ptInput, msgsrc); if (ptInputDefine == NULL) { KR_LOG(KR_LOGERROR, "kr_input_get_define [%d] error!", msgsrc); return NULL; } T_KRInputHandle *ptInputHandle = kr_input_define_get_handle(ptInputDefine, msgfmt, ptInput->ptInputModule); if (ptInputHandle == NULL) { KR_LOG(KR_LOGERROR, "kr_input_define_get_handle [%s] error!", msgfmt); return NULL; } T_KRRecord *ptRecord = kr_record_new(ptInput, msgsrc); if (ptRecord == NULL) { KR_LOG(KR_LOGERROR, "kr_record_new [%s] error!", msgsrc); return NULL; } int iResult = kr_input_handle_process(ptInputHandle, ptInputDefine, msglen, msgbuf, ptRecord); if (iResult != 0) { KR_LOG(KR_LOGERROR, "kr_input_handle_process [%s] error!", msgid); kr_record_free(ptRecord); return NULL; } return ptRecord; }
T_KRRecord* kr_record_new(T_KRTable *ptTable) { /*get current record address*/ size_t ulCurrRecOffset = ptTable->uiRecordLoc*ptTable->iRecordSize; char *psCurrRecAddr = &ptTable->pRecordBuff[ulCurrRecOffset]; /*delete and free old record*/ T_KRRecord *ptRecord = (T_KRRecord *)psCurrRecAddr; if (ptRecord->ptTable != NULL) { kr_record_delete(ptRecord); kr_record_free(ptRecord); } /*create and set new record*/ memset(psCurrRecAddr, 0x00, ptTable->iRecordSize); ptRecord->pfFree = NULL; ptRecord->ptTable = ptTable; ptRecord->pRecBuf = psCurrRecAddr+sizeof(T_KRRecord); /*move record location to the next*/ ptTable->uiRecordLoc = (++ptTable->uiRecordLoc)%ptTable->lKeepValue; return ptRecord; }