Ejemplo n.º 1
0
void CuDlgReplicationStaticPageActivity::UpdateIncoming (LPRAISEDREPLICDBE pData)
{
	int iColumn   = -1;
	int iColumnDB = -1;
	int iColumnTB = -1;
	enum {SU_INSERT = 1, SU_UPDATE, SU_DELETE, SU_TOTAL, SU_TRANSACTION};
	enum {DB_INSERT = 1, DB_UPDATE, DB_DELETE, DB_TOTAL, DB_TRANSACTION};
	enum {TB_INSERT = 2, TB_UPDATE, TB_DELETE, TB_TOTAL};
	
	switch (pData->EventType)
	{
	case REPLIC_DBE_IN_INSERT:
		iColumn  = SU_INSERT;
		iColumnDB= DB_INSERT;
		iColumnTB= TB_INSERT;
		break;
	case REPLIC_DBE_IN_UPDATE:
		iColumn  = SU_UPDATE;
		iColumnDB= DB_UPDATE;
		iColumnTB= TB_UPDATE;
		break;
	case REPLIC_DBE_IN_DELETE:
		iColumn  = SU_DELETE;
		iColumnDB= DB_DELETE;
		iColumnTB= TB_DELETE;
		break;
	case REPLIC_DBE_IN_TRANSACTION:
		iColumn  = SU_TRANSACTION;
		iColumnDB= DB_TRANSACTION;
		break;
	default:
		iColumn = -1;
		break;
	}
	if (iColumn != -1 && iColumn != SU_TRANSACTION)
	{
		UpdateSummary  (iColumn,   MODE_INCOMING);	
		UpdateDatabase (iColumnDB, pData, MODE_INCOMING);
		UpdateTable    (iColumnTB, pData, MODE_INCOMING);
		UpdateDbTotal  (iColumnDB, pData);
		UpdateTbTotal  (iColumnTB, pData);
	}
	else
	if (iColumn == SU_TRANSACTION)
	{
		UpdateSummary  (iColumn,   MODE_INCOMING);	
		UpdateDatabase (iColumnDB, pData, MODE_INCOMING);
		UpdateDbTotal  (iColumnDB, pData);
	}
}
Ejemplo n.º 2
0
// Decide proper action and perform the job.
void Action::TakeAction(){
	// Do action following message type
	Packet pkt;
	std::string result;
	std::string temp;

	switch(m_GivenPkt.m_MsgType){

	case AP_REGISTRATION_REQUEST:
		InsertDatabase();
		SendResponseMessage(AP_REGISTRATION_RESPONSE, pkt);
		break;

	//case AP_REGISTRATION_RESPONSE:
		//break;

	case AP_STATE_UPDATE_REQUEST:
		UpdateDatabase();
		SendResponseMessage(AP_STATE_UPDATE_RESPONSE, pkt);
		break;

	//case AP_STATE_UPDATE_RESPONSE:
		//break;

	case AP_LIST_REQUEST:
		result = m_db->GetResult("select ID, IP, SSID from AP_Information;");

		//Parse the result by '|' mark
		//and make pkt context
		while(true)
		{
			temp = result.substr(0,result.find('|'));
			result.erase(0,result.find('|')+1);
			pkt.AddValue(AP_ID, temp);

			temp = result.substr(0,result.find('|'));
			result.erase(0,result.find('|')+1);
			pkt.AddValue(AP_IP, temp);

			temp = result.substr(0,result.find('|'));
			result.erase(0,result.find('|')+1);
			pkt.AddValue(AP_SSID, temp);

			if(result.length() < 1) break;
		}
		SendResponseMessage(AP_LIST_RESPONSE, pkt);
		break;

	default:
		break;
	}
}
Ejemplo n.º 3
0
//异步读操作完成后read_handler触发
void RWHandler::read_handler(const boost::system::error_code& ec, boost::shared_ptr<std::vector<char> > str)
{
	if (ec)
	{
		//std::cout << "read" << dataToSendIndex << std::endl;
		if (readCount > 0)
			readCount--;
		else
			HandleError(ec);
		
		return;
	}
	else
	{
		//从接收到的信息中获取请求命令
		char command[30] = { 0 };
		int i;
		for (i = 2; i < 30; i++)
		{
			if ((*str)[i] == '|')
				break;
			command[i - 2] = (*str)[i];
		}
		//客户端请求初始化项目信息
		if (strcmp(&(*str)[2], INIT_APPKEYS_INFO) == 0)
		{
			boost::system::error_code ec;
			string sendStr = ETX + (*str)[1];
			write(m_sock, buffer(sendStr, sendStr.size()), ec);
			Sleep(500);

			sendStr = "";
			GenerateSendData(sendStr, projectConfigureInfoInJson);
			write(m_sock, buffer(sendStr, sendStr.size()), ec);
			std::cout << "ProjectConfigure finish!" << std::endl;
			HandleRead();
		}
		//客户端请求初始化异常数据时调用
		else if (strcmp(command, INIT_CRASH_INFO) == 0)
		{
			readCount--;
			initErrorInfo = true;
			TransferDataToJson(crashInfo, &(*str)[i + 1]);
			dataToSendIndex = 0;
			offSet = 0;

			boost::system::error_code ec;
			string sendStr = ETX + (*str)[1] + "Receive";
			write(m_sock, buffer(sendStr, sendStr.size()), ec);
			Sleep(500);

			HandleWrite();
		}
		//客户端发送获取开发者信息时
		else if (strcmp(&(*str)[2], INIT_DEVELOPER_INFO) == 0)
		{
			readCount--;
			initDeveloper = true;
			GetDeveloperInfo(developerInfo);
			offSet = 0;

			boost::system::error_code ec;
			string sendStr = ETX + (*str)[1] + "Receive";
			write(m_sock, buffer(sendStr, sendStr.size()), ec);
			Sleep(500);

			HandleWrite();
		}
		//收到确认返回时,根据返回执行不同的操作
		else if ((*str)[0] == ETX[0])
		{
			//std::cout << "接收消息:" << &(*str)[0] << std::endl;
			//收到返回,设置重发为false
			isReSend = false;
			if (initErrorInfo)
			{
				//int sendId = (*str)[1] - '0';
				if ((offSet + OFFSET) > crashInfo[dataToSendIndex].size())
				{
					std::cout << dataToSendIndex << "发送完成!" << std::endl;
					++dataToSendIndex;
					//判断是否还有下一条异常,如果有则继续发送,无则关闭连接
					if (dataToSendIndex < crashInfo.size())
					{
						offSet = 0;
						HandleWrite();
					}
					else
					{
						boost::system::error_code ec;
						string sendStr;
						GenerateSendData(sendStr, "SendFinish");
						write(m_sock, buffer(sendStr, sendStr.size()), ec);
						initErrorInfo = false;
					}
				}
				else
				{
					offSet = offSet + OFFSET;
					HandleWrite();
				}
			}
			else if (initDeveloper)
			{
				//int sendId = (*str)[1] - '0';
				if ((offSet + OFFSET) > developerInfo.size())
				{
					std::cout << "开发者信息发送完成!" << std::endl;
					boost::system::error_code ec;
					string sendStr;
					GenerateSendData(sendStr, "SendFinish");
					write(m_sock, buffer(sendStr, sendStr.size()), ec);
					initDeveloper = false;
				}
				else
				{
					offSet = offSet + OFFSET;
					HandleWrite();
				}
			}
			HandleRead();
		}
		//客户端返回更新内容,如分配给哪个用户,异常是否已解决时调用
		else if(strcmp(command, UPDATE_CRASH_INFO) == 0)
		{
			std::cout << "接收消息:" << &(*str)[0] << std::endl;
			UpdateDatabase(&(*str)[i + 1]);
			boost::system::error_code ec;
			string sendStr = ETX + (*str)[1];
			write(m_sock, buffer(sendStr, sendStr.size()), ec);
			readCount++;
			HandleRead();
		}
		//其他情况
		else
		{
			std::cout << "接收消息:" << &(*str)[0] << std::endl;
			HandleRead();
		}
	}
}
Ejemplo n.º 4
0
int main(void) 
{
  int choice;
  int ret;

  ret = eXdbmInit();
  if(ret==-1) {
    ErrorMessage();
    return(EXIT_FAILURE);
  }

  choice=-1;

  while(choice!=12) {
    choice = MainMenu();
    switch(choice) {
    case 1 : 
      OpenDatabase();
      break;

    case 2 :
      NewDatabase();
      break;

    case 3 : 
      CloseDatabase();
      break;

    case 4 :
      UpdateDatabase();
      break;

    case 5 : 
      BackupDatabase();
      break;

    case 6 :
      ReloadDatabase();
      break;

    case 7 :
      PrintDatabase();
      break;

    case 8 :
      PrintValues();
      break;

    case 9 :
      AddEntry();
      break;

    case 10:
      ChangeEntry();
      break;

    case 11 :
      DeleteEntry();
      break;
      
    }
  }

  printf("\n\nBye bye ...\n");

  return(1);
}
Ejemplo n.º 5
0
/*********主函数**********/
void main (void)
{
	delay(100);						//上电延时
	Init_ADXL345();                 //初始化ADXL345
	Init_UART();					//初始化串口通信
   	SpaceCreate(A);					//坐标系建立
	delay(200);
	OPTION=9;
	while( 1 )            			//循环
	{ 
		
		switch(OPTION)
		{
		case 1:
			STATUS_PRE=-1;
			STATUS_NOW=-1;
			STATUS_HISTORY[0]=0;
			STATUS_HISTORY[1]=0;
			STATUS_HISTORY[2]=0;
			OPTION=2;
		case 2:					  
			UpdateDatabase( DATABASE, A );
			AnalyzeDatabase( DATABASE, SET, ZArray);
			STATUS_HISTORY[0]=STATUS_HISTORY[1];
			STATUS_HISTORY[1]=STATUS_HISTORY[2];
			if ( isStill(SET) )
			{	
				STATUS_HISTORY[2]=StillStatus(SET);	
			}
			else
			{
				STATUS_HISTORY[2]=MovingStatus(ZArray);
			}
			if(STATUS_HISTORY[0]==STATUS_HISTORY[1]&&STATUS_HISTORY[2]==STATUS_HISTORY[1])
				STATUS_NOW=STATUS_HISTORY[2];
			else
				STATUS_NOW=STATUS_PRE;
			Send2PhoneMotion(STATUS_NOW, STATUS_PRE);
			STATUS_PRE=STATUS_NOW;
			break;
		case 3:
			temp=0;
			result=0;
			prestatus=0;
			OPTION=4;
		case 4:
			UpdateDatabase( DATABASE, A );
			AnalyzeDatabase( DATABASE, SET, ZArray);
			if ( isStill(SET) )
			{
				break;
			}
			result=Count( ZArray );
			if( prestatus==0 )
				prestatus=result/10;
			else if( prestatus!=result/10 )
			{
				temp=prestatus;
				prestatus=result/10;
				result=temp*10+result%10;
			}
			Send2PhoneSteps(result);
			break;
		case 9:
			break;
		}		
	}


}