コード例 #1
0
ファイル: ITEScreenWatch.cpp プロジェクト: hjgode/ITE_xml_rpc
int _tmain(int argc, _TCHAR* argv[])
{
	DWORD dwXmlRpcThreadID;
	PROCESS_INFORMATION pi;
	HANDLE hXMLRpcClientThread;
	bool ThreadCreated=false;

	LogLevel=1;
	Log(1,L"ITEScreenWatch V 0.1");

	MyGetIpAdress();	// read IP into g_pLocalIP

	InitScreenContent();

	CreateProcess(L"\\Program Files\\Intermec\\ITE\\intermte.exe", L"", NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi); 
	Sleep(10000);
	hWndITEWindow = FindWindow(_T("IntermTE"), _T("ITE"));
	if (hWndITEWindow==NULL)
	{
		Log(1,L"FindWindows ITE failes");
	}
	else
	{
		hXMLRpcClientThread=CreateThread(NULL, 0, XMLRpcClientThread, (VOID *)0, 0,&dwXmlRpcThreadID);
		if (hXMLRpcClientThread == NULL)
		{
			Log(1,L"CreateThread failed");
		}
		else
		{
			Log(1,L"CreateThread OK");
			ThreadCreated=true;
		}
	}
	
	Log(1,L"Waiting for TE exit");
	do{
		WaitForSingleObject(pi.hProcess,INFINITE);
	}while((FindWindow(_T("IntermTE"), _T("ITE")))!=NULL);

	Log(1,L"ITE Exit");

	if (ThreadCreated)
	{
		s.exit();
		s.shutdown();
	}
	//Sleep(2000);
	TerminateThread(hXMLRpcClientThread,1);
	//Log(L"Wait Thread end");
	//WaitForSingleObject(hXMLRpcClientThread,INFINITE);
	Sleep(1000);
	
	closeMsgQueue(g_hMsgQueue);

	Log(1,L"Program Exit");
	return 0;
}
コード例 #2
0
ファイル: mmaster.cpp プロジェクト: viniciusah/ros_mmaster
int main(int argc, char **argv)
{

  ros::init(argc, argv, "mmaster", ros::init_options::AnonymousName);

  if (!mmaster.readAddressMaster())
  {
	cout << "There is no ROS_MASTER environment variable. Exiting ..." << endl;
	exit(1);
  }

  mmaster.getIPAddress();
  
  srand(time(NULL));
  mmaster.setPort((rand() % 64512) + 1024);    // choose a random a port between 1024 and 65536																																									// ports below 1024 requires root privileges and
			// max port number is 65536
 
//  XmlRpc::setVerbosity(3);

  thread_exit = false;
  
  boost::thread xml_rpc_server_thread(xml_rpc_server_listen);
 
  // Set false on first call to test later if I choose a port not used
  mmaster.alreadyAddMyAddress(false);
  boost::thread update_mmaster_addresses_thread(update_mmaster_addresses);

  #ifdef DEBUG
  cout << "main: Vou entrar no laço de leitura do teclado" << endl;
  #endif

  string keyboard_input;
  
  while(true)
    {
    cin >> keyboard_input;
    if (keyboard_input == "exit")
      {
		  cout << "main: Finishing this master" << endl; 
		  break;
      }
    if (keyboard_input == "print")
      {
         mmaster.printServerInfo();
      }
    }

  thread_exit = true;

  // Shutdown XML RPC Server
  s.shutdown();

  ros::NodeHandle node_handle;
  string mmaster_addresses;

  ROS_INFO("Consulting param /mmaster_addresses");

  // Get updated list from parameter server
  node_handle.getParam("/mmaster_addresses", mmaster_addresses);

  // TODO
  // send a notification to others masters to notify that i am leaving

  mmaster_addresses = mmaster.removeMyAddress(mmaster_addresses);

  if (mmaster_addresses != "")
    {
    // Remove my address from parameter server
    node_handle.setParam("/mmaster_addresses", mmaster_addresses);
    }
  else
    // I am the last server, remove the param
    node_handle.deleteParam("/mmaster_addresses");

  return 0;
}