示例#1
0
AplPacket *
apl_packet_deserialize(uint8_t *data, size_t length)
{
    if(length < APL_PACKET_HEADER_LENGTH) {
        APL_ERROR("Cannot deserialize, packet is not large enough for header");
        return NULL;
    }

    AplPacket *packet = apl_alloc(APL_PACKET_HEADER_LENGTH);
    memcpy(packet, data, APL_PACKET_HEADER_LENGTH);

    if(length < packet->size) {
        APL_ERROR("Cannot deserialize, packet size exceeds buffer size");
        free(packet);
        return NULL;
    }

    APL_TRACE("Deserialized packet of %zu bytes of type %" PRIu64,
        packet->size, packet->type);
    return packet;
}
示例#2
0
DWORD RunCommand( LPTSTR Command, LPCTSTR CurrentDirectory /*= NULL*/ )
{
   STARTUPINFO si;
   PROCESS_INFORMATION pi;

   ZeroMemory( &si, sizeof(si) );
   si.cb = sizeof(si);
   ZeroMemory( &pi, sizeof(pi) );

   // Start the child process. 
   if( !CreateProcess( NULL, // No module name (use command line). 
      Command,          // Command line. 
      NULL,             // Process handle not inheritable. 
      NULL,             // Thread handle not inheritable. 
      FALSE,            // Set handle inheritance to FALSE. 
      0,                // No creation flags. 
      NULL,             // Use parent's environment block. 
      CurrentDirectory, // Starting directory. 
      &si,              // Pointer to STARTUPINFO structure.
      &pi )             // Pointer to PROCESS_INFORMATION structure.
      ) 
   {
      APL_THROW( 
         _T("Error on executing command '") << ConvertToBuf<std::basic_string<TCHAR> >(Command)
         << _T("' with starting dir '") << (CurrentDirectory == NULL ? std::basic_string<TCHAR>(_T("NULL")) : ConvertToBuf<std::basic_string<TCHAR> >(CurrentDirectory)) 
         << _T("': ") << GetDWErrorInfo( GetLastError() )
      );      
   }

   DWORD ExitCode;

   APL_ERROR( WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED );
   APL_ERROR( GetExitCodeProcess(pi.hProcess, &ExitCode) );       
   APL_ERROR( CloseHandle(pi.hProcess) );
   APL_ERROR( CloseHandle(pi.hThread) );

   return ExitCode;
}
示例#3
0
文件: main.c 项目: Photonios/appalone
int
main(int argc, char **argv)
{
    /* catch ctrl + c */
    apl_signal(SIGINT, on_program_exit);
    
    if(argc <= 1) {
        APL_ERROR("Usage is: apl-host [video file]\n");
        return 1;
    }

    AplHost *host = apl_host_connect(APL_CENTRAL_SERVER_HOST,
        APL_CENTRAL_SERVER_PORT);

    if(!host) {
        return 1;
    }

    apl_host_new_pool(host);
    apl_host_free(&host);

    return 0;
}
示例#4
0
void ExecutePreRunFile( const TCHAR *FilePath )
{
#if 0
   SHELLEXECUTEINFO ShExecInfo;
   
   TCHAR FullPath[MAX_PATH], FileDir[MAX_PATH];
   LPTSTR FileName;

   APL_ERROR( GetFullPathName(FilePath, MAX_PATH, FullPath, &FileName) != 0 );

   memcpy( FileDir, FullPath, (FileName - FullPath) * sizeof(*FileDir) );
   FileDir[FileName - FullPath] = _T('\0');

   ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
   ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
   ShExecInfo.hwnd = NULL;     o
   ShExecInfo.lpVerb = NULL;
   ShExecInfo.lpFile = FullPath;
   
#ifdef DEBUG
   ShExecInfo.lpParameters = _T( "DEBUG" );
#else
   ShExecInfo.lpParameters = _T( "RELEASE" );
#endif

   ShExecInfo.lpDirectory = FileDir;
   ShExecInfo.nShow = nShowCmd;
   ShExecInfo.hInstApp = NULL;

   cout << "Запуск файла " << FullPath;
   if( ShellExecuteEx(&ShExecInfo) != TRUE )
   {
      cout << "ERROR: " << GetDWErrorInfo( GetLastError() );
      throw TSilentException();
   }

   if( ShExecInfo.hProcess != NULL )
   {
      DWORD ExitCode;

      APL_ERROR( WaitForSingleObject(ShExecInfo.hProcess, INFINITE) != WAIT_FAILED );
      APL_ERROR( GetExitCodeProcess(ShExecInfo.hProcess, &ExitCode) );       
      APL_ERROR( CloseHandle(ShExecInfo.hProcess) != 0 );

      if( ExitCode != 0 )
      {
         cout << " ERROR ExitCode != 0!"<< endl;
         throw TSilentException();
      }
      else
         cout << " OK!" << endl;
   }
   else
      cout << " OK (no hProcess)!" << endl;
#else

   #ifdef DEBUG
      #define CMD_LINE _T( " DEBUG" )
   #else
      #define CMD_LINE _T( " RELEASE" )
   #endif

   TCHAR FullPath[MAX_PATH], FileDir[MAX_PATH];
   LPTSTR FileName;

   APL_ERROR( GetFullPathName(FilePath, MAX_PATH, FullPath, &FileName) != 0 );

   memcpy( FileDir, FullPath, (FileName - FullPath) * sizeof(*FileDir) );
   FileDir[FileName - FullPath] = _T('\0');
   
   lstrcat( FullPath, CMD_LINE );

   std::cout << "Запуск файла: " << FullPath << std::endl << APL_LINE;

   DWORD ExitCode = RunCommand( FullPath, FileDir );
   std::cout << APL_LINE;

   if( ExitCode != 0)
   {
      std::cout << " ERROR ExitCode: " << ExitCode << std::endl;
      throw TSilentException();
   }
   else
      std::cout << "OK!" << std::endl << std::endl;

#endif
}