OpenTTD Source  20241121-master-g67a0fccfad
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. More...
 
std::string CreatePayload (Reason reason, bool for_preview=false)
 
- Public Member Functions inherited from HTTPCallback
virtual ~HTTPCallback ()=default
 Silentium.
 

Static Public Member Functions

constexpr static bool IsSurveyPossible ()
 

Protected Member Functions

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

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

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.

◆ 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, Debug, ClientSettings::network, and NetworkSettings::participate_survey.


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