コード例 #1
0
ファイル: MainWindow.cpp プロジェクト: psychogenic/druid
void MainWindow::doQuit()
{

	if (connection.get() && connection->active())
	{
		uint8_t wait_count = 0;
		while (executing_request && wait_count++ < 3)
			PLATFORM_SLEEP(1);

		executing_request = true; // lock out other comm events

		DRUID::SerialUIUserPtr serial_user = connection->serialUser();

		doUpMenu(serial_user);  // always do it once...
		if (current_menu_depth)
		{

			uint8_t failCount = 0;
			while (current_menu_depth && (doUpMenu(serial_user) || failCount++ < 3))
			{
				;
			}

		}

		serial_user->exitProgramMode();
		executing_request = false;

	}

	Close(true);

}
コード例 #2
0
ファイル: Scheduler.cpp プロジェクト: rockfireredmoon/iceee
void PooledWorker::Work() {
	g_Logs.server->info("Starting pooled thread worker %v", mWorkerID);
	while(true) {
		g_Logs.server->debug("Waiting for work on thread %v", mWorkerID);
		TaskType t = g_Scheduler.PopPoolTask();
		t();
		PLATFORM_SLEEP(g_MainSleep);
	}
}
コード例 #3
0
ファイル: Packet.cpp プロジェクト: kgrubb/iceee
void PacketManager::ThreadMain(void) {
	bThreadActive = true;

	while (bThreadActive == true) {
		GetPackets2();
		//Debug_RunDiagnostics();
		SendPackets2();
		PLATFORM_SLEEP(1);
	}
}
コード例 #4
0
ファイル: Scenery2.cpp プロジェクト: tremblewithfear6/iceee
void SceneryManager::ThreadMain(void)
{
	bThreadActive = true;

	while(bThreadActive == true)
	{
		if(mPendingPageRequest.size() > 0)
			ProcessPageRequests();

		RunGarbageCheck();

		PLATFORM_SLEEP(1);
	}
}
コード例 #5
0
ファイル: Util.cpp プロジェクト: psychogenic/druid
UtilConnectionPackage::UtilConnectionPackage(unsigned int baud_rate,
		const DRUIDString& device) :
		is_active(false),
		io_service(NULL),
		serial_thread(NULL)
{

	static DRUID::SerialUIUserPtr nullSUserPtr;


	// create new service/serial user/thread
	io_service = new boost::asio::io_service();
	if (! io_service)
		return;


	serial_user = SerialUIUserPtr(new DRUID::SerialUIUser());

	if (! serial_user)
	{
		destroyIOService();
		return;
	}

	try {

		serial_user->connect(*io_service, baud_rate, device);

	} catch (std::exception & e)
	{
		std::cerr << "Exception caught while connecting to serial port: " << e.what() << "\n";


		destroyIOService();

		DRUID::SerialUIUserPtr emptyPtr;

		serial_user = emptyPtr;

		return;
	}

	serial_thread = new boost::thread(boost::bind(&boost::asio::io_service::run, io_service));

	if (! serial_thread)
	{

		destroyIOService();
		serial_user = nullSUserPtr;

	}

	// phew, made it!

	is_active = true;

#ifdef PLATFORM_WINDOWS
	PLATFORM_SLEEP(0.5);
#endif


}
コード例 #6
0
void SimulatorBaseThread :: RunMainLoop(void)
{
	while(isActive == true)
	{
		if(Status == Status_Ready)
		{
			//The simulator base is responsible for delegating incoming connections
			//to their Simulator object.
			//This listening port is not responsible for sending or receiving
			//data.
			Status = Status_Kick;
		}
		else if(Status == Status_Init)
		{
			if(sc.CreateSocket(HomePortStr, BindAddress) == 0)
			{
				g_Logs.simulator->info("[SimB] Server created, awaiting connection on port %v (socket:%v).", HomePort, sc.ListenSocket);
				Status = Status_Wait;
			}
			else
			{
				//Keep trying, but wait a bit longer than normal.
				PLATFORM_SLEEP(g_ErrorSleep);
			}
		}
		else if(Status == Status_Wait)
		{
			int res = sc.Accept();
			if(res == 0)
			{
				LaunchSimulatorThread();
				sc.ClientSocket = SocketClass::Invalid_Socket;
			}
			else
			{
				if(sc.disconnecting) {
					g_Logs.simulator->info("SimulatorBase shutdown.");
					Status = Status_None;
				}
				else {
					g_Logs.simulator->info("Socket error: %v", sc.GetErrorMessage());
					//This shouldn't normally fail.  Need a complete restart.
					Status = Status_Restart;
				}
			}
		}
		else if(Status == Status_Restart)
		{
			g_Logs.simulator->info("[SimB] Disconnecting server.");
			sc.ShutdownServer();
			Status = Status_Init;
			PLATFORM_SLEEP(g_ErrorSleep);
		}
		else if(Status == Status_Kick)
		{
			g_Logs.simulator->info("[SimB] Kicking client.");
			sc.DisconnectClient();
			Status = Status_Wait;  //Wait for another connection.
		}
		else
		{
			g_Logs.simulator->error("[SimB] Unknown status.");
			Status = Status_Restart;
		}
		//Keep it from burning up unnecessary CPU cycles.
		PLATFORM_SLEEP(SleepDelayNormal);
	}
}