Esempio n. 1
0
/*----------------------------------------------------------------------
|       NPT_PosixQueue::Abort
+---------------------------------------------------------------------*/
void
NPT_PosixQueue::Abort()
{
    pthread_cond_t abort_condition;
    pthread_cond_init(&abort_condition, NULL);

    struct timespec timed;
    GetTimeOut(20, timed);

    // acquire mutex
    if (pthread_mutex_lock(&m_Mutex)) {
        return;
    }

    // tell other threads that they should exit immediately
    m_Aborting = true;

    // notify clients
    pthread_cond_broadcast(&m_CanPopCondition);
    pthread_cond_broadcast(&m_CanPushCondition);

    // wait for all waiters to exit
    while (m_PoppersWaitingCount > 0 || m_PushersWaitingCount > 0) {
        pthread_cond_timedwait(&abort_condition,
                               &m_Mutex,
                               &timed);
    }
    
    pthread_mutex_unlock(&m_Mutex);
}
Esempio n. 2
0
int CConnectionSettingsAdvanced::DoModal(CConnectionSettings *pConnSettings)
   {
      int      nRetVal;

      ASSERT(pConnSettings);
      if(pConnSettings == NULL)
         return IDCANCEL;

      m_pConnSettings = pConnSettings;
      SetAppTitle(m_pConnSettings->GetName());
      SetAppFileName(m_pConnSettings->GetAppFileName());
      SetTimeOut(m_pConnSettings->GetTimeOut());
      SetFirstCheck(m_pConnSettings->GetFirstCheck());
      m_bUsesDialup = m_pConnSettings->WatchForDialup();
      m_bRestoreAutodial = m_pConnSettings->RestoreAutodial();

      nRetVal = CDialog::DoModal();

      if(nRetVal == IDOK)
         {
            m_pConnSettings->SetTimeOut(GetTimeOut());
            m_pConnSettings->SetFirstCheck(GetFirstCheck());
            m_pConnSettings->SetName(GetAppTitle());
            m_pConnSettings->SetAppFileName(GetAppFileName());
            m_pConnSettings->SetWatchForDialup(m_bUsesDialup);
            m_pConnSettings->SetRestoreAutodial(m_bRestoreAutodial);
            m_pConnSettings->SaveSettings();
         }
      return nRetVal;
   }
Esempio n. 3
0
FCarlaServer::ErrorCode FCarlaServer::SendSceneDescription(
    const FString &MapName,
    const TArray<APlayerStart *> &AvailableStartSpots,
    const TArray<USensorDescription *> &SensorDescriptions,
    const bool bBlocking)
{
  carla_scene_description scene;
  // Encode map name.
  const auto MapNameBuffer = FCarlaEncoder::Encode(MapName);
  scene.map_name = MapNameBuffer.Get();
  // Encode start spots.
  TArray<carla_transform> Transforms;
  FCarlaEncoder::Encode(AvailableStartSpots, Transforms);
  scene.player_start_spots = (Transforms.Num() > 0 ? Transforms.GetData() : nullptr);;
  scene.number_of_player_start_spots = Transforms.Num();
  // Encode sensors.
  TArray<TUniquePtr<const char[]>> SensorNames; // This holds the memory while we send it.
  TArray<carla_sensor_definition> Sensors;
  FCarlaEncoder::Encode(SensorDescriptions, Sensors, SensorNames);
  scene.sensors = (Sensors.Num() > 0 ? Sensors.GetData() : nullptr);;
  scene.number_of_sensors = Sensors.Num();
  // Send scene description.
  UE_LOG(LogCarlaServer, Log, TEXT("Sending %d available start positions"), scene.number_of_player_start_spots);
  UE_LOG(LogCarlaServer, Log, TEXT("Sending %d sensor descriptions"), scene.number_of_sensors);
  return ParseErrorCode(carla_write_scene_description(Server, scene, GetTimeOut(TimeOut, bBlocking)));
}
Esempio n. 4
0
//
/// Sets the percentage done for the gauge control. If the splash screen does not
/// have a gauge control, this doesn't do anything.
//
void
TSplashWindow::SetPercentDone(int percent)
{
  if (HasStyle(MakeGauge) && IsWindow()) {
    if (GetGauge())
      GetGauge()->SetValue(percent);

    if (percent > PercentThreshold) {
      // Set up the timer
      //
      if (GetTimeOut() != 0)
        SetTimer(TimerId, GetTimeOut());
    }
    // and last
    if (GetGauge())
      GetApplication()->PumpWaitingMessages();
  }
}
Esempio n. 5
0
FCarlaServer::ErrorCode FCarlaServer::ReadEpisodeStart(uint32 &StartPositionIndex, const bool bBlocking)
{
  carla_episode_start values;
  auto ec = ParseErrorCode(carla_read_episode_start(Server, values, GetTimeOut(TimeOut, bBlocking)));
  if (Success == ec) {
    StartPositionIndex = values.player_start_spot_index;
    UE_LOG(LogCarlaServer, Log, TEXT("Episode start received: { StartIndex = %d }"), StartPositionIndex);
  }
  return ec;
}
Esempio n. 6
0
/*----------------------------------------------------------------------
|       NPT_PosixQueue::Push
+---------------------------------------------------------------------*/
NPT_Result
NPT_PosixQueue::Push(NPT_QueueItem* item, NPT_Timeout timeout)
{
    struct timespec timed;
    if (timeout != NPT_TIMEOUT_INFINITE) {
        NPT_CHECK(GetTimeOut(timeout, timed));
    }

    // lock the mutex that protects the list
    if (pthread_mutex_lock(&m_Mutex)) {
        return NPT_FAILURE;
    }

    NPT_Result result = NPT_SUCCESS;
    // check that we have not exceeded the max
    if (m_MaxItems) {
        while (m_Items.GetItemCount() >= m_MaxItems) {
            // wait until we can push
            ++m_PushersWaitingCount;
            if (timeout == NPT_TIMEOUT_INFINITE) {
                pthread_cond_wait(&m_CanPushCondition, &m_Mutex);
                --m_PushersWaitingCount;
            } else {
                int wait_res = pthread_cond_timedwait(&m_CanPushCondition, 
                                                      &m_Mutex, 
                                                      &timed);
                --m_PushersWaitingCount;
                if (wait_res == ETIMEDOUT) {
                    result = NPT_ERROR_TIMEOUT;
                    break;
                }
            }

            if (m_Aborting) {
                result = NPT_ERROR_INTERRUPTED;
                break;
            }
        }
    }

    // add the item to the list
    if (result == NPT_SUCCESS) {
        m_Items.Add(item);

        // wake up any thread that may be waiting to pop
        if (m_PoppersWaitingCount) { 
            pthread_cond_broadcast(&m_CanPopCondition);
        }
    }

    // unlock the mutex
    pthread_mutex_unlock(&m_Mutex);

    return result;
}
Esempio n. 7
0
//
/// Before the window closes, and if the mouse has been captured, this releases it now.
//
void
TSplashWindow::CleanupWindow()
{
  if (CapturedMouse) {
    ReleaseCapture();
    CapturedMouse = false;
  }

  if (GetTimeOut() != 0)
    KillTimer(TimerId);
}
Esempio n. 8
0
FCarlaServer::ErrorCode FCarlaServer::ReadNewEpisode(FString &IniFile, const bool bBlocking)
{
  carla_request_new_episode values;
  auto ec = ParseErrorCode(carla_read_request_new_episode(Server, values, GetTimeOut(TimeOut, bBlocking)));
  if (Success == ec) {
    FCarlaEncoder::Decode(values, IniFile);
    UE_LOG(LogCarlaServer, Log, TEXT("Received new episode"));
#ifdef CARLA_SERVER_EXTRA_LOG
    UE_LOG(LogCarlaServer, Log, TEXT("Received CarlaSettings.ini:\n%s"), *IniFile);
#endif // CARLA_SERVER_EXTRA_LOG
  }
  return ec;
}
Esempio n. 9
0
/*----------------------------------------------------------------------
|       NPT_PosixQueue::Peek
+---------------------------------------------------------------------*/
NPT_Result
NPT_PosixQueue::Peek(NPT_QueueItem*& item, NPT_Timeout timeout)
{
    struct timespec timed;
    if (timeout != NPT_TIMEOUT_INFINITE) {
        NPT_CHECK(GetTimeOut(timeout, timed));
    }

    // lock the mutex that protects the list
    if (pthread_mutex_lock(&m_Mutex)) {
        return NPT_FAILURE;
    }

    NPT_Result result = NPT_SUCCESS;
    NPT_List<NPT_QueueItem*>::Iterator head = m_Items.GetFirstItem();
    if (timeout) {
        while (!head) {
            // no item in the list, wait for one
            ++m_PoppersWaitingCount;
            if (timeout == NPT_TIMEOUT_INFINITE) {
                pthread_cond_wait(&m_CanPopCondition, &m_Mutex);
                --m_PoppersWaitingCount;
            } else {
                int wait_res = pthread_cond_timedwait(&m_CanPopCondition, 
                                                      &m_Mutex, 
                                                      &timed);
                --m_PoppersWaitingCount;
                if (wait_res == ETIMEDOUT) {
                    result = NPT_ERROR_TIMEOUT;
                    break;
                }
            }

            if (m_Aborting) {
                result = NPT_ERROR_INTERRUPTED;
                break;
            }

            head = m_Items.GetFirstItem();
        }
    } else {
        if (!head) result = NPT_ERROR_LIST_EMPTY;
    }

    item = head?*head:NULL;

    // unlock the mutex
    pthread_mutex_unlock(&m_Mutex);

    return result;
}
Esempio n. 10
0
/*----------------------------------------------------------------------
|       NPT_PosixQueue::Pop
+---------------------------------------------------------------------*/
NPT_Result
NPT_PosixQueue::Pop(NPT_QueueItem*& item, NPT_Timeout timeout)
{
    struct timespec timed;
    if (timeout != NPT_TIMEOUT_INFINITE) {
        NPT_CHECK(GetTimeOut(timeout, timed));
    }

    // lock the mutex that protects the list
    if (pthread_mutex_lock(&m_Mutex)) {
        return NPT_FAILURE;
    }

    NPT_Result result;
    if (timeout) {
        while ((result = m_Items.PopHead(item)) == NPT_ERROR_LIST_EMPTY) {
            // no item in the list, wait for one
            ++m_PoppersWaitingCount;
            if (timeout == NPT_TIMEOUT_INFINITE) {
                pthread_cond_wait(&m_CanPopCondition, &m_Mutex);
                --m_PoppersWaitingCount;
            } else {
                int wait_res = pthread_cond_timedwait(&m_CanPopCondition, 
                                                      &m_Mutex, 
                                                      &timed);
                --m_PoppersWaitingCount;
                if (wait_res == ETIMEDOUT) {
                    result = NPT_ERROR_TIMEOUT;
                    break;
                }
            }
            
            if (m_Aborting) {
                result = NPT_ERROR_INTERRUPTED;
                break;
            }
        }
    } else {
        result = m_Items.PopHead(item);
    }
    
    // wake up any thread that my be waiting to push
    if (m_MaxItems && (result == NPT_SUCCESS) && m_PushersWaitingCount) {
        pthread_cond_broadcast(&m_CanPushCondition);
    }

    // unlock the mutex
    pthread_mutex_unlock(&m_Mutex);
 
    return result;
}
Esempio n. 11
0
CHttp::CHttp ()

{
	m_url = m_Protocol = m_HostName = m_UserName = m_Password = m_FileName = NULL;
	m_Port = 0;

	m_contenttype = NULL;

	m_proxyport = 0;
	m_isproxy = false;
	m_proxy = m_proxyuser = m_proxypwd =NULL;

	m_challenge = false;
	m_challengename = m_challengepwd = NULL;

	m_HttpOpenRequest = m_InternetConnect = m_InternetSession = NULL;
	
	m_timeout = GetTimeOut();
}
Esempio n. 12
0
FCarlaServer::ErrorCode FCarlaServer::ReadControl(FVehicleControl &Control, const bool bBlocking)
{
  carla_control values;
  auto ec = ParseErrorCode(carla_read_control(Server, values, GetTimeOut(TimeOut, bBlocking)));
  if (Success == ec) {
#ifdef CARLA_SERVER_EXTRA_LOG
    UE_LOG(
        LogCarlaServer,
        Log,
        TEXT("Read control (%s): { Steer = %f, Throttle = %f, Brake = %f, Handbrake = %s, Reverse = %s }"),
        (bBlocking ? TEXT("Sync") : TEXT("Async")),
        values.steer,
        values.throttle,
        values.brake,
        (values.hand_brake ? TEXT("True") : TEXT("False")),
        (values.reverse ? TEXT("True") : TEXT("False")));
#endif // CARLA_SERVER_EXTRA_LOG
    FCarlaEncoder::Decode(values, Control);
  } else if ((!bBlocking) && (TryAgain == ec)) {
    UE_LOG(LogCarlaServer, Warning, TEXT("No control received from the client this frame!"));
  }
  return ec;
}
Esempio n. 13
0
VOID RunLoader(VOID)
{
    ULONG_PTR SectionId;
    ULONG     OperatingSystemCount;
    OperatingSystemItem* OperatingSystemList;
    PCSTR*    OperatingSystemDisplayNames;
    ULONG     DefaultOperatingSystem;
    LONG      TimeOut;
    ULONG     SelectedOperatingSystem;
    ULONG     i;

    if (!MachInitializeBootDevices())
    {
        UiMessageBoxCritical("Error when detecting hardware.");
        return;
    }

#ifdef _M_IX86
    /* Load additional SCSI driver (if any) */
    if (LoadBootDeviceDriver() != ESUCCESS)
    {
        UiMessageBoxCritical("Unable to load additional boot device drivers.");
    }
#endif

    if (!IniFileInitialize())
    {
        UiMessageBoxCritical("Error initializing .ini file.");
        return;
    }

    /* Debugger main initialization */
    DebugInit(TRUE);

    if (!IniOpenSection("FreeLoader", &SectionId))
    {
        UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
        return;
    }

    TimeOut = GetTimeOut();

    /* UI main initialization */
    if (!UiInitialize(TRUE))
    {
        UiMessageBoxCritical("Unable to initialize UI.");
        return;
    }

    OperatingSystemList = InitOperatingSystemList(&OperatingSystemCount);
    if (!OperatingSystemList)
    {
        UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
        goto Reboot;
    }

    if (OperatingSystemCount == 0)
    {
        UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
        goto Reboot;
    }

    DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemList, OperatingSystemCount);

    /* Create list of display names */
    OperatingSystemDisplayNames = FrLdrTempAlloc(sizeof(PCSTR) * OperatingSystemCount, 'mNSO');
    if (!OperatingSystemDisplayNames)
        goto Reboot;

    for (i = 0; i < OperatingSystemCount; i++)
    {
        OperatingSystemDisplayNames[i] = OperatingSystemList[i].LoadIdentifier;
    }

    /* Find all the message box settings and run them */
    UiShowMessageBoxesInSection("FreeLoader");

    for (;;)
    {
        /* Redraw the backdrop */
        UiDrawBackdrop();

        /* Show the operating system list menu */
        if (!UiDisplayMenu("Please select the operating system to start:",
                           "For troubleshooting and advanced startup options for "
                               "ReactOS, press F8.",
                           TRUE,
                           OperatingSystemDisplayNames,
                           OperatingSystemCount,
                           DefaultOperatingSystem,
                           TimeOut,
                           &SelectedOperatingSystem,
                           FALSE,
                           MainBootMenuKeyPressFilter))
        {
            UiMessageBox("Press ENTER to reboot.");
            goto Reboot;
        }

        TimeOut = -1;

        /* Load the chosen operating system */
        LoadOperatingSystem(&OperatingSystemList[SelectedOperatingSystem]);
    }

Reboot:
    UiUnInitialize("Rebooting...");
    return;
}
Esempio n. 14
0
FCarlaServer::ErrorCode FCarlaServer::SendEpisodeReady(const bool bBlocking)
{
  UE_LOG(LogCarlaServer, Log, TEXT("Ready to play, notifying client"));
  const carla_episode_ready values = {true};
  return ParseErrorCode(carla_write_episode_ready(Server, values, GetTimeOut(TimeOut, bBlocking)));
}
//--------------------------------------------------------------------------------
int CTextSocket::Receive(CString& sText)
	{
	// if we have something queued then just return it
	if(m_buffer.GetCount() > 0)
		{
		POSITION pos = m_buffer.GetHeadPosition();
		if(pos == NULL)
			return 0;
		sText = m_buffer.GetAt(pos);
		m_buffer.RemoveAt(pos);
		return sText.GetLength();
		}

	sText.Empty();
	DWORD nStart = ::GetTickCount();

	for(;;)
		{
		int nLen = CSmallSocket::Receive(sText.GetBuffer(1024), 1024);
		sText.ReleaseBuffer(nLen == -1 ? 0 : nLen);

		if(nLen == 0)
			return 0;

		if(nLen == SOCKET_ERROR)
			{
			DWORD nNow = ::GetTickCount();
			// check for tickcount wrap around - happens every 49.7 days
			// of continuous running - see GetTickCount
			if(nNow < nStart)
				{
				nStart = ::GetTickCount();
				continue;
				}

			// see if we've timed out
			if((nStart + GetTimeOut()) <= nNow)
				return 0;

			if(::WSAGetLastError() == WSAEWOULDBLOCK)
				{
				::Sleep(100);
				continue;
				}
			else
				return SOCKET_ERROR;
			}

		for(int i = 0; i < sText.GetLength(); i++)
			{
			TCHAR cCur = sText[i];
			switch(cCur)
				{
				case '\r':
					m_buffer.AddTail(m_sCurLine);
					m_sCurLine.Empty();
					break;
				case '\n':
					break;
				default:
					m_sCurLine += cCur;
					break;
				}
			}

		sText.Empty();
		return 0;
		}
	}