OpenTTD Source 20260129-master-g2bb01bd0e4
network_survey.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef NETWORK_SURVEY_H
11#define NETWORK_SURVEY_H
12
13#include <condition_variable>
14#include <mutex>
15#include "core/http.h"
16
21protected:
22 void OnFailure() override;
23 void OnReceiveData(std::unique_ptr<char[]> data, size_t length) override;
24 bool IsCancelled() const override { return false; }
25
26public:
28 enum class Reason : uint8_t {
29 Preview,
30 Leave,
31 Exit,
32 Crash,
33 };
34
35 void Transmit(Reason reason, bool blocking = false);
36 std::string CreatePayload(Reason reason, bool for_preview = false);
37
38 constexpr static bool IsSurveyPossible()
39 {
40 return true;
41 }
42
43private:
44 std::mutex mutex;
45 std::atomic<bool> transmitted;
46 std::condition_variable transmitted_cv;
47};
48
49extern NetworkSurveyHandler _survey;
50
51#endif /* NETWORK_SURVEY_H */
Socket handler for the survey connection.
void OnFailure() override
An error has occurred and the connection has been closed.
bool IsCancelled() const override
Check if there is a request to cancel the transfer.
std::atomic< bool > transmitted
Whether the survey has been transmitted.
std::condition_variable transmitted_cv
Condition variable to inform changes to transmitted.
void OnReceiveData(std::unique_ptr< char[]> data, size_t length) override
We're receiving data.
Reason
Reason why the survey data is being sent.
@ Preview
User is previewing the survey result.
@ Leave
User is leaving the game (but not exiting the application).
@ Exit
User is exiting the application.
std::mutex mutex
Mutex for the condition variable.
void Transmit(Reason reason, bool blocking=false)
Transmit the survey.
Basic functions to send and receive HTTP packets.
Callback for when the HTTP handler has something to tell us.
Definition http.h:18