OpenTTD Source 20241224-master-gf74b0cf984
NetworkSurveyHandler Class Reference

Socket handler for the survey connection. More...

#include <network_survey.h>

Inheritance diagram for NetworkSurveyHandler:
HTTPCallback

Public Types

enum class  Reason { PREVIEW , LEAVE , EXIT , CRASH }
 

Public Member Functions

void Transmit (Reason reason, bool blocking=false)
 Transmit the survey.
 
std::string CreatePayload (Reason reason, bool for_preview=false)
 
- Public Member Functions inherited from HTTPCallback
virtual ~HTTPCallback ()=default
 Silentium.
 

Static Public Member Functions

static constexpr bool IsSurveyPossible ()
 

Protected Member Functions

void OnFailure () override
 An error has occurred and the connection has been closed.
 
void OnReceiveData (std::unique_ptr< char[]> data, size_t length) override
 We're receiving data.
 
bool IsCancelled () const override
 Check if there is a request to cancel the transfer.
 

Private Attributes

std::mutex mutex
 Mutex for the condition variable.
 
std::atomic< bool > transmitted
 Whether the survey has been transmitted.
 
std::condition_variable transmitted_cv
 Condition variable to inform changes to transmitted.
 

Detailed Description

Socket handler for the survey connection.

Definition at line 20 of file network_survey.h.

Member Enumeration Documentation

◆ Reason

enum class NetworkSurveyHandler::Reason
strong
Enumerator
PREVIEW 

User is previewing the survey result.

LEAVE 

User is leaving the game (but not exiting the application).

EXIT 

User is exiting the application.

CRASH 

Game crashed.

Definition at line 27 of file network_survey.h.

Member Function Documentation

◆ IsCancelled()

bool NetworkSurveyHandler::IsCancelled ( ) const
inlineoverrideprotectedvirtual

Check if there is a request to cancel the transfer.

Returns
true iff the connection is cancelled.
Note
Cancellations are never instant, and can take a bit of time to be processed. The object needs to remain valid until the OnFailure() callback is called.

Implements HTTPCallback.

Definition at line 24 of file network_survey.h.

◆ IsSurveyPossible()

static constexpr bool NetworkSurveyHandler::IsSurveyPossible ( )
inlinestaticconstexpr

Definition at line 37 of file network_survey.h.

◆ OnFailure()

void NetworkSurveyHandler::OnFailure ( )
overrideprotectedvirtual

An error has occurred and the connection has been closed.

Note
HTTP socket handler is closed/freed.

Implements HTTPCallback.

Definition at line 114 of file network_survey.cpp.

References Debug, transmitted, and transmitted_cv.

◆ OnReceiveData()

void NetworkSurveyHandler::OnReceiveData ( std::unique_ptr< char[]>  data,
size_t  length 
)
overrideprotectedvirtual

We're receiving data.

Parameters
datathe received data, nullptr when all data has been received.
lengththe amount of received data, 0 when all data has been received.
Note
When nullptr is sent the HTTP socket handler is closed/freed.

Implements HTTPCallback.

Definition at line 121 of file network_survey.cpp.

References Debug, transmitted, and transmitted_cv.

◆ Transmit()

void NetworkSurveyHandler::Transmit ( Reason  reason,
bool  blocking = false 
)

Transmit the survey.

Parameters
reasonThe reason for sending the survey.
blockingWhether to block until the survey is sent.

Definition at line 86 of file network_survey.cpp.

References _settings_client, NetworkHTTPSocketHandler::Connect(), Debug, lock, mutex, ClientSettings::network, NetworkBackgroundLoop(), NetworkSurveyUriString(), NetworkSettings::participate_survey, transmitted, and transmitted_cv.

Referenced by CrashLog::SendSurvey().

Field Documentation

◆ mutex

std::mutex NetworkSurveyHandler::mutex
private

Mutex for the condition variable.

Definition at line 43 of file network_survey.h.

Referenced by Transmit().

◆ transmitted

std::atomic<bool> NetworkSurveyHandler::transmitted
private

Whether the survey has been transmitted.

Definition at line 44 of file network_survey.h.

Referenced by OnFailure(), OnReceiveData(), and Transmit().

◆ transmitted_cv

std::condition_variable NetworkSurveyHandler::transmitted_cv
private

Condition variable to inform changes to transmitted.

Definition at line 45 of file network_survey.h.

Referenced by OnFailure(), OnReceiveData(), and Transmit().


The documentation for this class was generated from the following files: