Example #1
0
void CFileSender::DoSend()
{
	m_bRun = true;
	int nRead = 0;

	m_bStopbyServer = false;
	int nWriteCount = 100; 
	SendMessage(m_ParentHwnd, WM_SETSENDING, 1, 0);
	SendMessage(m_ParentHwnd, WM_SETSTOPBYMYSEFLT, 0, 0);
	while (nRead < m_pFile->GetLength())
	{
		if (m_bRun == false)
		{
			QueryStatus();
			if (!PackAndSendRequest(CMD_PARAM_TRANSFILE_C2S_STOP))
			{
				SendMessage(m_ParentHwnd, WM_SETSENDING, 0, 0);
				return;
			}
			break;
		}

		if (nWriteCount ++ >= 100)
		{
			nWriteCount = 0; 
			if (!QueryStatus()) 
			{
				SendMessage(m_ParentHwnd, WM_SETSENDING, 0, 0);
				return ; 
			}
		}

		if (!PackAndSendRequest(CMD_PARAM_TRANSFILE_C2S_DATA))
		{
			SendMessage(m_ParentHwnd, WM_SETSENDING, 0, 0);
			return;
		}

		FileData fileData;

		int nCount = m_pFile->Read(fileData.Buf, 4096);
		fileData.nLength = nCount;

		if (!WriteExact(m_Socket, (char*)(&fileData), sizeof(fileData)))
		{
			MessageBox(m_ParentHwnd, "发送本地文件数据失败!", "提示", MB_OK | MB_ICONEXCLAMATION);
			return;
		}

		nRead += nCount;

		
		
		SendMessage(m_ParentHwnd, WM_FILE_SENDFILETOSERVER_PROGRESS_MESSAGE, (WPARAM)(nRead), 0);
	}
}
BOOL CNTScmService::WaitForServiceStatus(DWORD dwTimeout, DWORD dwWaitForStatus, DWORD dwPollingInterval)
{
  //wait for our desired status
  DWORD dwTimeWaited = 0;
  SERVICE_STATUS ss;
  for (;;)
  {
    if (!QueryStatus(ss))
      break;

    //if this is the status we were waiting for then we're done
    if (ss.dwCurrentState == dwWaitForStatus)
      return TRUE;

    //Do the wait
    Sleep(dwPollingInterval);

    //check for timeout
    dwTimeWaited += dwPollingInterval;
    if ((dwTimeout != INFINITE) && (dwTimeWaited > dwTimeout))
    {
      SetLastError(ERROR_TIMEOUT);
      break;
    }
  }
  return FALSE;
}
BOOL CNTScmService::AcceptShutdown(BOOL& bShutdown)
{
  //Validate our parameters
  ATLASSERT(m_hService != NULL);
  
  SERVICE_STATUS ServiceStatus;
  BOOL bSuccess = QueryStatus(ServiceStatus);
  if (bSuccess)
    bShutdown = ((ServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN) != 0);

  return bSuccess;
}
BOOL CNTScmService::AcceptPauseContinue(BOOL& bPauseContinue)
{
  //Validate our parameters
  ATLASSERT(m_hService != NULL);
  
  SERVICE_STATUS ServiceStatus;
  BOOL bSuccess = QueryStatus(ServiceStatus);
  if (bSuccess)
    bPauseContinue = ((ServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) != 0);

  return bSuccess;
}
BOOL CNTScmService::AcceptStop(BOOL& bStop)
{
  //Validate our parameters
  ASSERT(m_hService != NULL);
  
  SERVICE_STATUS ServiceStatus;
  BOOL bSuccess = QueryStatus(ServiceStatus);
  if (bSuccess)
    bStop = ((ServiceStatus.dwControlsAccepted & SERVICE_ACCEPT_STOP) != 0);

  return bSuccess;
}
Example #6
0
void CFileSender::OnThreadStop()
{
	if (m_pFile != NULL)
	{
		SendMessage(m_ParentHwnd, WM_FILE_SENDFILETOSERVER_FINISH_MESSAGE, (WPARAM)(&(m_pFile->GetFileName())), 0);
		m_pFile->Close();
		delete m_pFile;
		m_pFile = NULL;
	}

	if (QueryStatus() && !m_bStopbyServer) {
		PackAndSendRequest(CMD_PARAM_TRANSFILE_C2S_FINISH);
	}
	//PackAndSendRequest(CMD_PARAM_TRANSFILE_C2S_STOP);
	SendMessage(m_ParentHwnd, WM_SETSENDING, 0, 0);
	SendMessage(m_ParentHwnd, WM_FILE_FILETOSERVERSTOP_MESSAGE, 0, 0);	
	SendMessage(m_ParentHwnd, WM_FILE_SENDFILETOSERVER_FINISHED_MESSAGE, 0, 0);//refresh list
}
Example #7
0
// 查询油量检测盒状态请求
int COil::Deal3712(byte *v_szData, int v_dwDataLen)
{
	char szResType = 0x00;		// 默认为油耗盒已连接,油浮子已连接

	// 油耗盒连接状态
	if( !m_bComConnect )
		szResType |= 0x01;

	// 油浮子连接状态
	if( QueryStatus() )
		szResType |= 0x02;

	// 向中心应答
	char szbuf[1024] = {0};
	int  ilen = 0;
	g_objSms.MakeSmsFrame(&szResType, 1, 0x37, 0x52, szbuf,sizeof(szbuf),ilen,CVT_8TO7);
	g_objSock.SOCKSNDSMSDATA(szbuf,ilen,LV12,DATASYMB_SMSBACKUP);

	return 0;
}