📄 mainserv.c
字号:
{ int i; FILE *fp; FKINFO *p,*q,*t,*srcArray; printf("ENter func QueryFeedBack!\n"); fRecords=0; Pthread_mutex_lock( &fLock.FK_FLOCK ); Pthread_mutex_lock( &countFK_Mutex ); MergeRecords( TYPE_OF_FKXX ); /* Alloacate the memory of message array.*/ if( mesgCount <= AUTOROLLVAL_FK ) { loadedMesg.fkInfo = (FKINFO *)malloc( LEN_FKINFO * mesgCount); fp = Fopen( "FKXX.data","r+"); rewind(fp); printf("MesgCount is %d\n",mesgCount); for( i=0; i<mesgCount; i++)
if( fread( &( (loadedMesg.fkInfo)[i].fkxx), LEN_FKXX, 1, fp) != 1)
{
if( feof(fp))
{
Fclose(fp);
break;
}
perror("File read error!");
} else { (loadedMesg.fkInfo)[i].index = i+1; printf("Index is %d.\n",(loadedMesg.fkInfo)[i].index); printf("File content:FeedBack Sign %X \n",loadedMesg.fkInfo[i].fkxx.FeedBackSign ); printf(" Address of the message %d is %lX.\n",i,&loadedMesg.fkInfo[i] ); } Fclose( fp ); srcArray = loadedMesg.fkInfo; /* Search the records by the given source ID */ /* Mark the non-fixed records' pointer to NULL*/ for( p=srcArray; p< srcArray+mesgCount; p++) if( p->fkxx.srcID != queFilter.srcID ) { p = NULL; } else { fRecords++; printf("Found records' address is %X\n",*p); } printf("Found records is %d\n",fRecords); if( fRecords != 0 )/* Fixed records are found */ { t = srcArray; printf("previous head address is %X\n",srcArray); /* Build the array accrodding to the previous marks */ q = srcArray = ( FKINFO *)malloc( LEN_FKINFO * fRecords ); printf("Later head address is %X\n",srcArray); for( p=t; p< t+mesgCount; p++) if( p != NULL ) { *q = *p; printf("Found records' address is %X\n",p); printf("Found FKXX records' additional mesg %s\n",p->fkxx.AdditionalINfor); q++; } /* Release the memory of former address array */ free( t ); loadedMesg.fkInfo = srcArray; } loadedMesg.countOfMesg = fRecords; fRecords = 0; Pthread_mutex_unlock( &countFK_Mutex ); Pthread_mutex_unlock( &fLock.FK_FLOCK ); } else //AutoRollBack the supposed numbers of records { loadedMesg.fkInfo = (FKINFO *)malloc( LEN_FKINFO * AUTOROLLVAL_FK); fp = Fopen( "FKXX.data","r+"); fseek( fp, ( mesgCount-AUTOROLLVAL_FK )*LEN_FKXX, SEEK_SET ); for( i=0; i<AUTOROLLVAL_FK; i++) /******Problem here,can't use the wrapper function Fread()*******/
if( fread( &( (loadedMesg.fkInfo)[i].fkxx), LEN_FKXX, 1, fp) != 1)
{
if( feof(fp))
{
Fclose(fp);
break;
}
perror("File read error!");
} else { (loadedMesg.fkInfo)[i].index = i+1; printf("Index is %d.\n",(loadedMesg.fkInfo)[i].index); printf("File content:FeedBack Sign %X \n",loadedMesg.fkInfo[i].fkxx.FeedBackSign ); printf(" Address of the message %d is %lX.\n",i,&loadedMesg.fkInfo[i] ); } Fclose( fp ); /* Rewrite the records to file to keep the latest AUTOROLLVAL_FK numbers of records */ SaveData( INBOX, TYPE_OF_FKXX, AUTOROLLVAL_FK ); countFKXX = AUTOROLLVAL_FK; Pthread_mutex_unlock( &countFK_Mutex ); Pthread_mutex_unlock( &fLock.FK_FLOCK ); srcArray = loadedMesg.fkInfo; printf("loadedMesg.fkInfo is %X\n",loadedMesg.fkInfo ); printf("queFilter.srcID is %ld\n",queFilter.srcID ); for( p=srcArray; p< srcArray+AUTOROLLVAL_FK; p++) if( p->fkxx.srcID != queFilter.srcID ) { p->fkxx.srcID = 0; } else { fRecords++; printf("Found records' address is %X\n",p); } printf("Found records is %d\n",fRecords); if( fRecords != 0 )/* Fixed records are found */ { t = srcArray; printf("previous head address is %X\n",srcArray); /* Build the array accrodding to the previous marks */ q = srcArray = ( FKINFO *)malloc( LEN_FKINFO * fRecords ); printf("Later head address is %X\n",srcArray); for( p=t; p< t+AUTOROLLVAL_FK; p++) if( p->fkxx.srcID != 0 ) { *q = *p; printf("Found records' address is %X\n",p); printf("Found FKXX records' additional mesg %s\n",p->fkxx.AdditionalINfor); q++; } /* Release the memory of former address array */ free( t ); loadedMesg.fkInfo = srcArray; } loadedMesg.countOfMesg = fRecords; fRecords = 0; } }void **Filtrate( MESGTYPE mesgType, int megCount, FILTER filter, QueryFilter queFilter, void **arg ) { int i; LOCINFO **p,**q,**t,**srcArray; COMMINFO **x,**y,**z,**srcArray1; printf("Enter Filtrate now.\n"); fRecords = 0; if( megCount == 0) { printf("NULL records to Filtrate!\n"); loadedMesg.countOfMesg = fRecords; return; } switch( mesgType ) { case TYPE_OF_DWXX: if( arg == NULL ) err_sys("Error occurred-> Empty DWXX records in memory!"); srcArray = (LOCINFO **)arg; switch( filter ) { case BY_LOCADDRSS: printf("Enter Filtrate_BY_LOCADDRSS now.\n"); /* Search the records by the given source ID */ /* Mark the non-fixed records' pointer to NULL*/ for( p=srcArray; p< srcArray+megCount; p++) if( (*p)->dwxx.srcID != queFilter.srcID ) { *p = NULL; } else { fRecords++; printf("Found records' address is %X\n",*p); } printf("Found records is %d\n",fRecords); if( fRecords != 0 )/* Fixed records are found */ { t = srcArray; printf("previous head address is %X\n",srcArray); /* Rebuild the address array accrodding to the previous marks */ q = srcArray = malloc( LEN_P_LOCINFO * fRecords ); printf("Later head address is %X\n",srcArray); for( p=t; p< t+megCount; p++) if( *p != NULL ) { *q = *p; printf("Found records' address is %X\n",*p); q++; } /* Release the memory of former address array */ free( t ); } loadedMesg.countOfMesg = fRecords; fRecords = 0; break; case BY_LOCTIME: /* Search the records by the given time limit */ fRecords=0; /* Mark the non-fixed records' pointer to NULL*/ for( p=srcArray; p<srcArray+megCount; p++) if( ! CompareLocTime( queFilter, p )) { *p = NULL; } else fRecords++; if( fRecords != 0 )/* Fixed records are found */ { t = srcArray; /* Rebuild the address array accrodding to the previous marks */ q = srcArray = malloc( LEN_P_LOCINFO * fRecords ); for( p=t; p<t+megCount; p++) if( *p != NULL ) { *q = *p; q++; } /* Release the memory of former address array */ free( t ); } else printf("No this records!\n"); loadedMesg.countOfMesg = fRecords; fRecords = 0; break; case BY_BOTH: /* Search the records by the given time limit and source user ID */ /* Mark the non-fixed records' pointer to NULL*/ for( p=srcArray; p<srcArray+megCount; p++) if( ((*p)->dwxx.srcID) != queFilter.srcID ) { if( !CompareLocTime( queFilter, p )) { printf("The not found DESID is %X\n",(*p)->dwxx.srcID); *p = NULL; } } else { printf("The found DESID is %X,%X\n",(*p)->dwxx.srcID,queFilter.srcID); fRecords++; } printf("Found records is %d\n",fRecords); if( fRecords != 0 )/* Fixed records are found */ { t = srcArray; /* Rebuild the address array accrodding to the previous marks */ q = srcArray = malloc( LEN_P_LOCINFO * fRecords ); for( p=t; p<t+megCount; p++) if( *p != NULL ) { *q = *p; q++; } /* Release the memory of former address array */ free( t ); } else printf("No this records!\n"); loadedMesg.countOfMesg = fRecords; fRecords = 0; break; } return (void **)srcArray; break; case TYPE_OF_TXXX: srcArray1 = (COMMINFO **)arg; switch( filter ) { case BY_LOCADDRSS: /* Search the records by the given source ID */ /* Mark the non-fixed records' pointer to NULL*/ if( arg == NULL ) err_sys("Error occurred-> Empty TXXX records in memory!"); fRecords=0; for( x=srcArray1; x< srcArray1+megCount; x++) if( (*x)->txIndex.srcID != queFilter.srcID ) { *x = NULL; } else { fRecords++; printf("Found records' address is %X\n",*x); } printf("Found records is %d\n",fRecords); if( fRecords != 0 )/* Fixed records are found */ { z = srcArray1; printf("previous head address is %X\n",srcArray1); /* Rebuild the address array accrodding to the previous marks */ y = srcArray1 = malloc( LEN_P_COMMINFO * fRecords ); printf("Later head address is %X\n",srcArray1); for( x=z; x< z+megCount; x++) if( *x != NULL ) { *y = *x; printf("Found records' address is %X\n",*y); y++; } /* Release the memory of former address array */ free( z ); } loadedMesg.countOfMesg = fRecords; fRecords = 0; break; case BY_NEWEST3: /* Search the records which are the lastest 3 ones */ if( arg == NULL ) err_sys("Error occurred-> Empty TXXX records in memory!"); if( megCount >= 3) { fRecords = 3; z = srcArray1; /* Rebuild the address array accrodding to the previous marks */ y = srcArray1 = malloc( LEN_P_COMMINFO * 3 ); printf("Later head address is %X\n",srcArray1); for( i=3; i> 0; i--) { *y = *(z+megCount-i ); printf("Found records' address is %X\n",*y); y++; } /* Release the memory of former address array */ free( z ); } else { fRecords = megCount; if( fRecords != 0 )/* Fixed records are found */ { z = srcArray1; y = srcArray1 = malloc( LEN_P_COMMINFO * fRecords ); for( i=fRecords; i> 0; i--) { *y = *(z+megCount-i ); printf("Found records' address is %X\n",*y); y++; } /* Release the memory of former address array */ free( z ); } } printf("Found records is %d\n",fRecords); loadedMesg.countOfMesg = fRecords; fRecords = 0; break; case BY_AUTOFBACK: /* Search the records by the AUTOFEEDBACK message */ QueryFeedBack( megCount, queFilter); /* After loading the wanted data to memory */ /* user browser the fixed records in the window */ break; }//end of switch return (void **)srcArray1; break; }//End of switch }void *CheckSelf( void *arg ){ }void *CheckICStat( void *arg ){}void *CheckSerialComm( void *arg ){}/* The following thread func to obtain the new data of location *//* from struct->newLoc and reflush the current window's display */void *AcceptLoc( void *arg ){ locArg = (LOCARG *)arg; startLocFlag = LOCSTART; switch( locArg->locType ) { case SINGLE: Pthread_mutex_lock(&newLoc_Mutex); while ( newLoc.flag == 0 ) Pthread_cond_wait( &newLoc_cond, &newLoc_Mutex ); newLoc.flag--; newLoc.usable = TRUE; printf("After In thread AcceptLoc newLoc.usable is %d\n",newLoc.usable ); printf("win_reportOpen == %d %d\n",win_reportOpen,WIN_REPORTOPEN); if( win_locOpen == WIN_LOCOPEN || win_reportOpen == WIN_REPORTOPEN ) { //Flush the window printf("Flush the window!\n"); ShowByDaDi (J_hwndedit_loclocate ,W_hwndedit_loclocate, newLoc.dwxx.longitude , newLoc.dwxx.latitude) ;//显示"经度""纬度" ShowHighByDaDiGao (locatehight_loclocate,locateErr_loclocate , newLoc.dwxx.height, newLoc.dwxx.abnormalHeigtht, newLoc.dwxx.normalSign, newLoc.dwxx.abnormalSign);//显示"高程"""高程误差" sprintf(buffer ,"%4d-%2d-%2d %2d:%2d:%2d", newLoc.dwxx.year, newLoc.dwxx.mon, newLoc.dwxx.day, newLoc.dwxx.hour,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -