Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/protocol/osc/forge.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 29 мая 2019 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib 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 Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_PROTOCOL_OSC_FORGE_H_
23 #define LSP_PLUG_IN_PROTOCOL_OSC_FORGE_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/protocol/osc/types.h>
27
28 namespace lsp
29 {
30 namespace osc
31 {
32 typedef struct forge_t forge_t;
33
34 typedef struct forge_frame_t
35 {
36 forge_t *forge;
37 forge_frame_t *parent; // Parent forge
38 forge_frame_t *child; // Child forge
39 size_t type;
40
41 size_t offset; // Offset of the frame in the buffer
42 } forge_frame_t;
43
44 struct forge_t
45 {
46 uint8_t *data;
47 size_t offset;
48 size_t capacity;
49 bool dynamic;
50
51 size_t refs;
52 size_t toff; // Head of types field
53 size_t tsize; // Size of types field
54 };
55
56 /**
57 * Initialize OSC packet serializer in fixed buffer size (RT-compatible) mode
58 *
59 * @param ref pointer to output root frame descriptor
60 * @param forge serializer structure to initialize
61 * @param data pointer to the buffer
62 * @param size size of the buffer
63 * @return status of operation
64 */
65 status_t forge_begin_fixed(forge_frame_t *ref, forge_t *forge, void *data, size_t size);
66
67 /**
68 * Initialize OSC packet serializer in dynamic buffer size (non-RT-compatible) mode
69 * @param ref pointer to output root frame descriptor
70 * @param forge serializer structure to initialize
71 * @return status of operation
72 */
73 status_t forge_begin_dynamic(forge_frame_t *ref, forge_t *forge, size_t reserve = 0);
74
75 /**
76 * Begin serialization of OSC bundle
77 * @param child pointer to output bundle frame descriptor
78 * @param ref current frame descriptor
79 * @param tag OSC time tag
80 * @return status of operation
81 */
82 status_t forge_begin_bundle(forge_frame_t *child, forge_frame_t *ref, uint64_t tag);
83
84 /**
85 * Begin serialization of OSC message
86 * @param child pointer to output message frame descriptor
87 * @param ref current frame descriptor
88 * @param address the OSC address string
89 * @return status of operation
90 */
91 status_t forge_begin_message(forge_frame_t *child, forge_frame_t *ref, const char *address);
92
93 /**
94 * Begin serialization of OSC message
95 * @param child pointer to output message frame descriptor
96 * @param ref current frame descriptor
97 * @param prefix prefix to add to address string
98 * @param address the OSC address string
99 * @return status of operation
100 */
101 status_t forge_begin_message(forge_frame_t *child, forge_frame_t *ref, const char *prefix, const char *address);
102
103 /**
104 * Forge message
105 * @param ref forge reference
106 * @param address message address
107 * @param params message parameters followed by arguments
108 * @return status of operation
109 */
110 status_t forge_message(forge_frame_t *ref, const char *address, const char *params...);
111
112 /**
113 * Forge message
114 * @param ref forge reference
115 * @param address message address
116 * @param params message parameters
117 * @param args list of arguments
118 * @return status of operation
119 */
120 status_t forge_messagev(forge_frame_t *ref, const char *address, const char *params, va_list args);
121
122 /**
123 * Begin serialization of array within OSC message
124 * @param child pointer to output array frame descriptor
125 * @param ref current frame descriptor
126 * @return status of operation
127 */
128 status_t forge_begin_array(forge_frame_t *child, forge_frame_t *ref);
129
130 status_t forge_int32(forge_frame_t *ref, int32_t value);
131 status_t forge_float32(forge_frame_t *ref, float value);
132 status_t forge_string(forge_frame_t *ref, const char *s);
133 status_t forge_blob(forge_frame_t *ref, const void *data, size_t bytes);
134 status_t forge_int64(forge_frame_t *ref, int64_t value);
135 status_t forge_double64(forge_frame_t *ref, double value);
136 status_t forge_time_tag(forge_frame_t *ref, uint64_t value);
137 status_t forge_type(forge_frame_t *ref, const char *s);
138 status_t forge_symbol(forge_frame_t *ref, const char *s);
139 status_t forge_ascii(forge_frame_t *ref, char c);
140 status_t forge_rgba(forge_frame_t *ref, const uint32_t rgba);
141 status_t forge_midi(forge_frame_t *ref, const midi::event_t *event);
142 status_t forge_midi_raw(forge_frame_t *ref, const void *event, size_t bytes);
143 status_t forge_bool(forge_frame_t *ref, bool value);
144 status_t forge_null(forge_frame_t *ref);
145 status_t forge_inf(forge_frame_t *ref);
146
147 /**
148 * Complete serialization of current frame
149 * @param ref current frame descriptor
150 * @return status of operation
151 */
152 status_t forge_end(forge_frame_t *ref);
153
154 /**
155 * Complete serialization of OSC packet
156 * @param packet packet to store size and pointer to the data, for dynamic mode data should be freed
157 * by forge_free();
158 * @param forge the forge object to close
159 * @return status of operation
160 */
161 status_t forge_close(packet_t *packet, forge_t *forge);
162
163 /**
164 * Destroy OSC serializer
165 * @param forge serializer descriptor
166 * @return status of operation
167 */
168 status_t forge_destroy(forge_t *forge);
169
170 /**
171 * Free mamory allocated by the OSC serializator
172 * @param ptr ponter to memory
173 */
174 void forge_free(void *ptr);
175
176 } /* namespace osc */
177 } /* namespace lsp */
178
179
180
181 #endif /* LSP_PLUG_IN_PROTOCOL_OSC_FORGE_H_ */