Esempio n. 1
0
int CVkProto::SetStatus(int iNewStatus)
{
	if (m_iDesiredStatus == iNewStatus || iNewStatus == ID_STATUS_IDLE)
		return 0;

	int oldStatus = m_iStatus;
	m_iDesiredStatus = iNewStatus;

	if (iNewStatus == ID_STATUS_OFFLINE) {
		if ( IsOnline()) {
			SetServerStatus(ID_STATUS_OFFLINE);
			ShutdownSession();
		}

		m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
	}
	else if (m_hWorkerThread == NULL && !(m_iStatus >= ID_STATUS_CONNECTING && m_iStatus < ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES)) {
		m_iStatus = ID_STATUS_CONNECTING;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
		m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL);
	}
	else if ( IsOnline())
		SetServerStatus(iNewStatus);
	else 
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);

	return 0;
}
Esempio n. 2
0
DWORD WINAPI StatusThread(LPVOID lpParameter)
{
	int i, ctl_ret;
	wchar_t mount_rw[256];

	HWND hConfigDialog = (HWND)lpParameter;

	EnterCriticalSection(&gThreadSection);
	ConfigGetString(L"rw", mount_rw);
	SetServerStatus(ServerStarting);
	PostMessage(hConfigDialog, WM_STATUSCHANGE, 0, 0);
	
	for(i=0; i<BOOT_WAIT; i++)
	{
		ctl_ret = SendCtl(QEMU_IP_ANSI, "default", NET_TIMEOUT);
		if(GetServerStatus() != ServerStarting)
		{
			LeaveCriticalSection(&gThreadSection);
			ExitThread(1);
		}
		if(ctl_ret == 0)
			break;
	}

	if(ctl_ret == 0)
	{
		if(GetServerStatus() != ServerStarting)
		{
			LeaveCriticalSection(&gThreadSection);
			ExitThread(1);
		}
		if(wcscmp(mount_rw, L"yes") == 0)
		{
			if(SendCtl(QEMU_IP_ANSI, "rw", NET_TIMEOUT) != 0)
				MessageBox(NULL, GetString(IDS_CTL_FAILED), GetString(IDS_CAPTION), MB_ICONEXCLAMATION | MB_OK);
			gMountRw = TRUE;
		}
		if(GetServerStatus() == ServerStarting)
			SetServerStatus(ServerRunning);
	}
	else if(GetServerStatus() != ServerStopped)
		SetServerStatus(ServerUnknown);

	PostMessage(hConfigDialog, WM_STATUSCHANGE, 0, 0);
	LeaveCriticalSection(&gThreadSection);
	ExitThread(0);
	return 2L;
}
Esempio n. 3
0
void ServerStop(HWND hWnd, HWND hCaller, UINT uMsg)
{
	SERVER_STATUS status;
	if(!gServer.hProcess)
		return;

	status = GetServerStatus();
	SetServerStatus(ServerStopped);
#ifndef CONFIG_NO_ROCTL
	if(status == ServerRunning || status == ServerUnknown)
	{
		if(uMsg == WM_QUERYENDSESSION)
			SendCtl(QEMU_IP_ANSI, "ro", 1);
		else
		{
		//if(SendCtlLoop(QEMU_IP_ANSI, "ro", NET_TIMEOUT, NET_RETRY) != 0)
			if(SendCtl(QEMU_IP_ANSI, "ro", NET_TIMEOUT) != 0)
				MessageBox(NULL, GetString(IDS_ERROR_CTLRO), GetString(IDS_CAPTION), MB_ICONSTOP | MB_OK);
		}
	}
#endif
	EnumWindows(CloseServerCallback, (LPARAM)&gServer);
	if(WaitForSingleObject(gServer.hProcess, QEMU_TIMEOUT) == WAIT_TIMEOUT)
		TerminateProcess(gServer.hProcess, 0);
	CloseHandle(gServer.hThread);
	CloseHandle(gServer.hProcess);
	memset(&gServer, 0, sizeof(PROCESS_INFORMATION));
	PostMessage(hWnd, WM_STATUSCHANGE, 0, 0);
}
Esempio n. 4
0
void CVkProto::OnLoggedIn()
{
	m_bOnline = true;
	SetServerStatus(m_iDesiredStatus);

	// initialize online timer
	CallFunctionAsync(VKSetTimer, this);
}
Esempio n. 5
0
int CVkProto::SetStatus(int iNewStatus)
{
	debugLogA("CVkProto::SetStatus iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d m_hWorkerThread = %d", iNewStatus, m_iStatus, m_iDesiredStatus, m_hWorkerThread == NULL ? 0 : 1);
	if (m_iDesiredStatus == iNewStatus || iNewStatus == ID_STATUS_IDLE)
		return 0;

	int oldStatus = m_iStatus;
	m_iDesiredStatus = iNewStatus;

	if (iNewStatus == ID_STATUS_OFFLINE) {
		if (IsOnline()) {
			SetServerStatus(ID_STATUS_OFFLINE);
			debugLogA("CVkProto::SetStatus ShutdownSession");
			ShutdownSession();
		}

		m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
		debugLogA("CVkProto::SetStatus (1) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
	}
	else if (m_hWorkerThread == NULL && !IsStatusConnecting(m_iStatus)) {
		m_iStatus = ID_STATUS_CONNECTING;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
		debugLogA("CVkProto::SetStatus (2) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
		m_hWorkerThread = ForkThreadEx(&CVkProto::WorkerThread, 0, NULL);
	}
	else if (IsOnline()) {
		debugLogA("CVkProto::SetStatus (3) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
		SetServerStatus(iNewStatus);
	}
	else {
		debugLogA("CVkProto::SetStatus (4) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
		if (!IsStatusConnecting(m_iStatus))
			m_iDesiredStatus = m_iStatus;
		debugLogA("CVkProto::SetStatus (5) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
	}

	debugLogA("CVkProto::SetStatus (ret) iNewStatus = %d, m_iStatus = %d, m_iDesiredStatus = %d oldStatus = %d", iNewStatus, m_iStatus, m_iDesiredStatus, oldStatus);
	return 0;
}
Esempio n. 6
0
void CVkProto::OnLoggedIn()
{
	debugLogA("CVkProto::OnLoggedIn");
	m_bOnline = true;
	SetServerStatus(m_iDesiredStatus);

	// initialize online timer
	CallFunctionAsync(VKSetTimer, this);

	db_unset(NULL, m_szModuleName, "LastNewsReqTime");
	db_unset(NULL, m_szModuleName, "LastNotificationsReqTime");
}