RetroArch
rpc_connection.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "connection.h"
4 #include "serialization.h"
5 
6 // I took this from the buffer size libuv uses for named pipes; I suspect ours would usually be much
7 // smaller.
8 constexpr size_t MaxRpcFrameSize = 64 * 1024;
9 
10 struct RpcConnection {
11  enum class ErrorCode : int {
12  Success = 0,
13  PipeClosed = 1,
14  ReadCorrupt = 2,
15  };
16 
17  enum class Opcode : uint32_t {
18  Handshake = 0,
19  Frame = 1,
20  Close = 2,
21  Ping = 3,
22  Pong = 4,
23  };
24 
28  };
29 
30  struct MessageFrame : public MessageFrameHeader {
32  };
33 
34  enum class State : uint32_t {
38  Connected,
39  };
40 
44  void (*onDisconnect)(int errorCode, const char* message){nullptr};
45  char appId[64]{};
46  int lastErrorCode{0};
47  char lastErrorMessage[256]{};
49 
50  static RpcConnection* Create(const char* applicationId);
51  static void Destroy(RpcConnection*&);
52 
53  inline bool IsOpen() const { return state == State::Connected; }
54 
55  void Open();
56  void Close();
57  bool Write(const void* data, size_t length);
58  bool Read(JsonDocument& message);
59 };
State
Definition: rpc_connection.h:34
RpcConnection::MessageFrame sendFrame
Definition: rpc_connection.h:48
void Close()
Definition: rpc_connection.cpp:64
Definition: connection.h:11
uint32_t length
Definition: rpc_connection.h:27
bool Write(const void *data, size_t length)
Definition: rpc_connection.cpp:73
Definition: rpc_connection.h:25
void(* onDisconnect)(int errorCode, const char *message)
Definition: rpc_connection.h:44
constexpr size_t MaxRpcFrameSize
Definition: rpc_connection.h:8
ErrorCode
Definition: rpc_connection.h:11
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: rpc_connection.h:10
Definition: ibxm.h:9
bool IsOpen() const
Definition: rpc_connection.h:53
Opcode
Definition: rpc_connection.h:17
char appId[64]
Definition: rpc_connection.h:45
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:6233
Opcode opcode
Definition: rpc_connection.h:26
void Open()
Definition: rpc_connection.cpp:23
Definition: serialization.h:160
int lastErrorCode
Definition: rpc_connection.h:46
bool Read(JsonDocument &message)
Definition: rpc_connection.cpp:85
static void Destroy(RpcConnection *&)
Definition: rpc_connection.cpp:16
State state
Definition: rpc_connection.h:42
char lastErrorMessage[256]
Definition: rpc_connection.h:47
BaseConnection * connection
Definition: rpc_connection.h:41
static RpcConnection * Create(const char *applicationId)
Definition: rpc_connection.cpp:9
void(* onConnect)(JsonDocument &message)
Definition: rpc_connection.h:43
GLenum GLuint GLenum GLsizei length
Definition: glext.h:6233
Definition: rpc_connection.h:30
unsigned int uint32_t
Definition: stdint.h:126