Пример #1
0
void  HandleServNew(stRcvdMsg * pstRcvdMsg ,int8 * pi8MsgPtr,uint64 ui64ID)
{
 int8 * pi8SavePtr = NULL;
 int8 * pi8Token = NULL;
 uint64 ui64RecId = 0;
 stRecord * pstRedAdd = NULL;

 if(NULL != pi8MsgPtr)
 { 
    pi8Token = strtok_r(pi8MsgPtr , DELIMITER , &pi8SavePtr);
    if(0 == strcmp("CLIENTID",pi8Token))
    {
        pi8Token = strtok_r(NULL , DELIMITER , &pi8SavePtr);
        ui64RecId = strtol(pi8Token,NULL,0);
        if(NULL == (pstRedAdd = SearchRecord(ui64RecId)))
       {
           /*New record should be created for a new client*/
           pstRedAdd = CreateRecord(ui64RecId);
           if(NULL != pstRedAdd)
           {
               pstRedAdd->ui64RecNum = ui64RecId;
               FillRecord(pstRedAdd,pi8SavePtr);
               pstRedAdd->ui32ContentFull = 0;
           }	           
      }
      else
      {
           /*Client already exists,just update*/      
           FillRecord(pstRedAdd,pi8SavePtr); 
      }
    }
    freeMsg(pstRcvdMsg);
 }
}
Пример #2
0
	int minDis(string & orgWord,string & desWord ,int step)
	{
		int ret;

		if(record.find(desWord) != record.end() && record[desWord].find(orgWord) != record[desWord].end())
			return record[desWord][orgWord];

		if(orgWord.size() == 0 && desWord.size() == 0)
		{
			if(minSteps > step)
				minSteps = step;
		}
		if(orgWord.size() == 0)
		{
			ret = desWord.size();
			FillRecord(orgWord,desWord,ret);
			return ret	;
		}
		if(desWord.size() == 0)
		{
			ret = orgWord.size();
			FillRecord(orgWord,desWord,ret);
			return ret;
		}

		if( step > minSteps)
			return 1;

		string orgWordSub = orgWord.size()==1?string(""): orgWord.substr(1);
		string desWordSub = desWord.size()==1?string(""): desWord.substr(1);

		if(orgWord[0] == desWord[0])
		{
			int doNoneSetps = minDis( orgWordSub,desWordSub,step); 
			ret =doNoneSetps;
			FillRecord(orgWord,desWord,ret);
			return ret;
		}
		else
		{
			int addSteps = minDis(orgWord,desWordSub,step+1) + 1;
			int delSteps = minDis(orgWordSub,desWord,step+1) + 1;
			int replaceSteps = minDis( orgWordSub,desWordSub,step+1) + 1; 
			ret = min(min(delSteps,addSteps),replaceSteps);
			FillRecord(orgWord,desWord,ret);		
			return ret;
		}
	}
Пример #3
0
void  HandleServUpdate(stRcvdMsg * pstRcvdMsg ,int8 *   pi8MsgPtr)
{

stRecord * pstRedAdd = NULL;
int8 * pi8Token = NULL;
int8 * pi8SavePtr = NULL;
uint64 ui64RecId = 0;

if(NULL !=  pstRcvdMsg && (NULL != pi8MsgPtr))
{
    
  pi8Token = strtok_r(pi8MsgPtr , DELIMITER , &pi8SavePtr);
  if(0 == strcmp(pi8Token , "CLIENTID"))
  {
     pi8Token = strtok_r(NULL , DELIMITER , &pi8SavePtr);
     ui64RecId = strtol(pi8Token,NULL,0);

  /*Look for the client record and then update the client*/
     if(NULL != (pstRedAdd = SearchRecord(ui64RecId)))
     {     
        FillRecord(pstRedAdd,pi8SavePtr);
     }
  }
  freeMsg(pstRcvdMsg); 
 }
}
Пример #4
0
void HandleCliUpdate(stRcvdMsg * pstRcvdMsg , int8 * pi8MsgPtr ,uint64 ui64ID)
{
   stRecord * pstRedAdd = NULL;
   uint32 ui32BitMask = 0;
    /*Search for the record and fill the updated content*/
    if(NULL != (pstRedAdd = SearchRecord(ui64ID)))
    {     
        if((ui32BitMask = FillRecord(pstRedAdd,pi8MsgPtr)) != 0)
        {
           if(pstRedAdd->ui32ContentFull == 0)
            {
              ui32BitMask |= SERVER|NEW|CLIENTID;
              pstRedAdd->ui32ContentFull = 1;
            }
            else
            {
              ui32BitMask |= SERVER|UPDATE|CLIENTID;
            }
        }     
        PrepareCliRsp(pstRcvdMsg,pstRedAdd,ui32BitMask);   
    }
}