DCSModulesAPI  1.0.0
DCS sub project containing all the control modules as libraries.
internal.h
Go to the documentation of this file.
1 #pragma once
2 #include "../../DCS_Utils/include/DCS_ModuleUtils.h"
3 #include "../../DCS_Core/include/DCS_ModuleCore.h"
4 #include "DCS_ModuleNetwork.h"
5 #include "../config/registry.h"
6 
7 #define _WINSOCK_DEPRECATED_NO_WARNINGS
8 #include <WinSock2.h>
9 #include <ws2tcpip.h>
10 
11 #include <atomic>
12 #include <queue>
13 
29 #define _GET_F_NAME() __FUNCTION__
30 
34 #define GET_F_NAME() _GET_F_NAME()
35 
41 #define DCS_EMIT_NAMED_EVT(name, data, size) DCS::Network::Message::EmitEvent(name, data, size)
42 
48 #define DCS_EMIT_EVT(data, size) DCS::Network::Message::EmitEvent(DCS::Registry::GetEvent(GET_F_NAME()), data, size)
49 
50 namespace DCS
51 {
52  namespace Network
53  {
59  {
60  WSADATA wsa;
61  };
62 
63  inline static bool is_inited = false;
64 
69  DCS_INTERNAL_TEST WSADATA InitWinSock();
70 
75  DCS_INTERNAL_TEST void CleanupWinSock();
76 
81  DCS_INTERNAL_TEST SOCKET CreateServerSocket(i32 listen_port);
82 
87  DCS_INTERNAL_TEST SOCKET CreateClientSocket(const char *host, i32 port);
88 
93  DCS_INTERNAL_TEST void ServerListen(SOCKET server);
94 
99  DCS_INTERNAL_TEST SOCKET ServerAcceptConnection(SOCKET server);
100 
105  DCS_INTERNAL_TEST void CloseSocketConnection(SOCKET client);
106 
111  DCS_INTERNAL_TEST bool ValidateSocket(SOCKET s);
112 
117  DCS_INTERNAL_TEST i32 ReceiveData(SOCKET client, unsigned char *buffer, i32 buff_len);
118 
123  DCS_INTERNAL_TEST i32 SendData(SOCKET client, const unsigned char *buffer, i32 buff_len);
124 
132  DCS_INTERNAL_TEST i32 SendPriorityData(SOCKET client, const unsigned char *buffer, i32 buff_len);
133 
141  DCS_INTERNAL_TEST void GetSocketIpAddress(SOCKET s, char* buffer);
142 
143  namespace Message
144  {
145 
146 #define MESSAGE_XTRA_SPACE 9
147 #pragma pack(push, 1)
148 
153  {
154  u8 op;
155  u64 id; // used for sync call message identify
156  i64 size;
157  u8 *ptr;
158  };
159 #pragma pack(pop)
160 
161  extern std::mutex message_m;
162  extern std::condition_variable lsync;
163  extern DefaultMessage lmessage;
164 
169  enum class DCS_INTERNAL_TEST InternalOperation
170  {
171  NO_OP = 0,
176  EVT_SUB = 7,
178  EVT_UNSUB = 9,
179  OP_ERROR,
180  CON_VALID,
181  DATA
182  };
183 
189  DCS_INTERNAL_TEST Registry::SVReturn WaitForId(u64 id);
190 
195  DCS_INTERNAL_TEST void SetMsgIdCondition(DefaultMessage &msg);
196 
201  DCS_INTERNAL_TEST void NotifyPromise(DefaultMessage &msg);
202 
208  DCS_INTERNAL_TEST DefaultMessage Alloc(i32 size);
209 
214  DCS_INTERNAL_TEST void SetCopyIdAndCode(DefaultMessage &msg, u8 *data);
215 
221  DCS_INTERNAL_TEST void SetCopyId(DefaultMessage &msg, u8 opcode, u64 id, u8 *data);
222 
227  DCS_INTERNAL_TEST void SetNew(DefaultMessage &msg, u8 opcode, u8 *data);
228 
233  DCS_INTERNAL_TEST DefaultMessage Copy(DefaultMessage &msg);
234 
239  DCS_INTERNAL_TEST void Delete(DefaultMessage &msg);
240 
245  DCS_INTERNAL_TEST void ScheduleTransmission(DefaultMessage msg);
246 
251  DCS_INTERNAL_TEST void EmitEvent(u8 EVT_ID, u8 *evtData, i32 size);
252  }
253  }
254 }
SYNC_REQUEST
Request a synchronous function call to the server, waiting for the result.
Definition: internal.h:172
SYNC_RESPONSE
Send back a sync response to the client.
Definition: internal.h:174
CON_VALID
Server connection validity message.
Definition: internal.h:178
NO_OP
Ping the server only.
Definition: internal.h:171
Definition: internal.h:152
EVT_SUB
Subscribe to a server-side event.
Definition: internal.h:176
signed long i32
Equivalent to int_32t.
Definition: DCS_ModuleUtils.h:53
EVT_UNSUB
Unsubscribe from a previously subscribed event.
Definition: internal.h:178
Exposes Network functionalities of the API to the end user.
ASYNC_REQUEST
Request an asynchronous function call to the server.
Definition: internal.h:173
Definition: registry.h:70
ASYNC_RESPONSE
Send back an async response to the client.
Definition: internal.h:175
#define DCS_INTERNAL_TEST
Defines the export interface acessible via the dll-interface applicable for internal functions only...
Definition: exports.h:137
EVT_RESPONSE
Send event response to the client.
Definition: internal.h:177
unsigned long long u64
Equivalent to uint_64t.
Definition: DCS_ModuleUtils.h:52
unsigned char u8
Equivalent to uint_8t.
Definition: DCS_ModuleUtils.h:58
signed long long i64
Equivalent to int_64t.
Definition: DCS_ModuleUtils.h:51
OP_ERROR
Send an error to the client/server.
Definition: internal.h:178