OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
sys_update_checker.h
1/*
2===========================================================================
3Copyright (C) 2025 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25#include "sys_local.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31 void Sys_UpdateChecker_Init();
32 void Sys_UpdateChecker_Process();
33 void Sys_UpdateChecker_Shutdown();
34
35#ifdef __cplusplus
36}
37#endif
38
39#ifdef __cplusplus
40
41# include <thread>
42# include <shared_mutex>
43# include <chrono>
44# include <condition_variable>
45
46class UpdateCheckerThread
47{
48public:
49 UpdateCheckerThread();
50 ~UpdateCheckerThread();
51
52 void Init();
53 void Shutdown();
54 bool IsRoutineActive() const;
55
56private:
57 void ShutdownThread();
58
59 void InitClient();
60 void ShutdownClient();
61
62 bool ParseVersionNumber(const char *value, int& major, int& minor, int& patch) const;
63 void RequestThread();
64 void DoRequest();
65
66private:
67 void *handle;
68 std::mutex clientWakeMutex;
69 std::condition_variable clientWake;
70 std::thread *osThread;
71 qboolean requestThreadIsActive;
72 qboolean shouldBeActive;
73};
74
75class UpdateChecker
76{
77public:
78 UpdateChecker();
79 ~UpdateChecker();
80
81 void Init();
82 void Process();
83 void Shutdown();
84
85 bool CheckNewVersion() const;
86 bool CheckNewVersion(int& major, int& minor, int& patch) const;
87 void SetLatestVersion(int major, int minor, int patch);
88
89private:
90 void CheckInitClientThread();
91 bool CanHaveRequestThread() const;
92
93private:
94 //
95 // Version information
96 //
97 int lastMajor;
98 int lastMinor;
99 int lastPatch;
100 bool versionChecked;
101
102 std::chrono::time_point<std::chrono::steady_clock> nextMessageTime;
103
104 UpdateCheckerThread *thread;
105};
106
107extern UpdateChecker updateChecker;
108
109#endif