ManaPlus
ipc.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2014-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef NET_IPC_H
23 #define NET_IPC_H
24 
25 #include "localconsts.h"
26 
27 PRAGMACLANG6GCC(GCC diagnostic push)
28 PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast")
29 #include "net/sdltcpnet.h"
30 PRAGMACLANG6GCC(GCC diagnostic pop)
31 
32 #include "utils/vector.h"
33 
34 #include <string>
35 
36 class IPC final
37 {
38  public:
42  IPC();
43 
45 
46 
49  ~IPC();
50 
51  bool init();
52 
53  unsigned short getPort() const A_WARN_UNUSED
54  { return mPort; }
55 
56  void flush();
57 
58  static int acceptLoop(void *ptr);
59 
60  static void start();
61 
62  static void stop();
63 
64  private:
65  void setPort(const unsigned short port)
66  { mPort = port; }
67 
68  unsigned int mNumReqs;
70  STD_VECTOR<std::string> mDelayedCommands;
71  SDL_Thread *mThread;
72  SDL_mutex *mMutex;
73  unsigned short mPort;
74  volatile bool mThreadLocked;
75  bool mListen;
76 };
77 
78 extern IPC *ipc;
79 
80 #endif // NET_IPC_H
Definition: ipc.h:37
IPC()
Definition: ipc.cpp:39
unsigned short mPort
Definition: ipc.h:73
bool mListen
Definition: ipc.h:75
unsigned int mNumReqs
Definition: ipc.h:68
~IPC()
Definition: ipc.cpp:51
SDL_Thread * mThread
Definition: ipc.h:71
unsigned short getPort() const
Definition: ipc.h:53
static int acceptLoop(void *ptr)
Definition: ipc.cpp:91
static void stop()
Definition: ipc.cpp:154
TcpNet::Socket mSocket
Definition: ipc.h:69
void setPort(const unsigned short port)
Definition: ipc.h:65
void flush()
Definition: ipc.cpp:190
bool init()
Definition: ipc.cpp:65
SDL_mutex * mMutex
Definition: ipc.h:72
static void start()
Definition: ipc.cpp:163
volatile bool mThreadLocked
Definition: ipc.h:74
std::vector< std::string > mDelayedCommands
Definition: ipc.h:70
IPC * ipc
Definition: ipc.cpp:37
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define PRAGMACLANG6GCC(str)
Definition: localconsts.h:240
::TCPsocket Socket
Definition: sdltcpnet.h:38