Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rpc.h « rpc « applications - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dea8b749f1081f7938e8a87baa43a051d3c0be13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <furi.h>

#define RPC_BUFFER_SIZE (1024)
#define RPC_MAX_MESSAGE_SIZE (1536)

#define RECORD_RPC "rpc"

/** Rpc interface. Used for opening session only. */
typedef struct Rpc Rpc;
/** Rpc session interface */
typedef struct RpcSession RpcSession;

/** Callback to send to client any data (e.g. response to command) */
typedef void (*RpcSendBytesCallback)(void* context, uint8_t* bytes, size_t bytes_len);
/** Callback to notify client that buffer is empty */
typedef void (*RpcBufferIsEmptyCallback)(void* context);
/** Callback to notify transport layer that close_session command
 * is received. Any other actions lays on transport layer.
 * No destruction or session close preformed. */
typedef void (*RpcSessionClosedCallback)(void* context);
/** Callback to notify transport layer that session was closed
 * and all operations were finished */
typedef void (*RpcSessionTerminatedCallback)(void* context);

/** Open RPC session
 *
 * USAGE:
 * 1) rpc_session_open();
 * 2) rpc_session_set_context();
 * 3) rpc_session_set_send_bytes_callback();
 * 4) rpc_session_set_close_callback();
 * 5) while(1) {
 *      rpc_session_feed();
 *    }
 * 6) rpc_session_close();
 *
 *
 * @param   rpc     instance
 * @return          pointer to RpcSession descriptor, or
 *                  NULL if RPC is busy and can't open session now
 */
RpcSession* rpc_session_open(Rpc* rpc);

/** Close RPC session
 * It is guaranteed that no callbacks will be called
 * as soon as session is closed. So no need in setting
 * callbacks to NULL after session close.
 *
 * @param   session     pointer to RpcSession descriptor
 */
void rpc_session_close(RpcSession* session);

/** Set session context for callbacks to pass
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   context     context to pass to callbacks
 */
void rpc_session_set_context(RpcSession* session, void* context);

/** Set callback to send bytes to client
 *  WARN: It's forbidden to call RPC API within RpcSendBytesCallback
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   callback    callback to send bytes to client (can be NULL)
 */
void rpc_session_set_send_bytes_callback(RpcSession* session, RpcSendBytesCallback callback);

/** Set callback to notify that buffer is empty
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   callback    callback to notify client that buffer is empty (can be NULL)
 */
void rpc_session_set_buffer_is_empty_callback(
    RpcSession* session,
    RpcBufferIsEmptyCallback callback);

/** Set callback to be called when RPC command to close session is received
 *  WARN: It's forbidden to call RPC API within RpcSessionClosedCallback
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   callback    callback to inform about RPC close session command (can be NULL)
 */
void rpc_session_set_close_callback(RpcSession* session, RpcSessionClosedCallback callback);

/** Set callback to be called when RPC session is closed
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   callback    callback to inform about RPC session state
 */
void rpc_session_set_terminated_callback(
    RpcSession* session,
    RpcSessionTerminatedCallback callback);

/** Give bytes to RPC service to decode them and perform command
 *
 * @param   session     pointer to RpcSession descriptor
 * @param   buffer      buffer to provide to RPC service
 * @param   size        size of buffer
 * @param   timeout     max timeout to wait till all buffer will be consumed
 *
 * @return              actually consumed bytes
 */
size_t rpc_session_feed(RpcSession* session, uint8_t* buffer, size_t size, TickType_t timeout);

/** Get available size of RPC buffer
 *
 * @param   session     pointer to RpcSession descriptor
 *
 * @return              bytes available in buffer
 */
size_t rpc_session_get_available_size(RpcSession* session);