174 std::size_t max_message_size = 256 * 1024 * 1024;
176 char buf[16 * 4096]{};
177 std::vector<char> queue;
179 std::size_t scanned{};
182 std::unique_ptr<QProcess> process;
183 QSocketNotifier* socket{};
184 QSocketNotifier* write_socket{};
190 QString node_path, QString module_path, QString entrypoint,
191 QString connection_id);
194 void on_read(QSocketDescriptor, QSocketNotifier::Type);
195 void do_write(std::string_view res);
197 bool restart_process();
199 virtual void processMessage(std::string_view) = 0;
200 virtual void on_process_exited() { }
203 int release_grace_ms{};
206 void start_process();
207 void release_process(
int grace_ms);
208 void process_queue();
210 void on_disconnected();
212 QString m_nodePath, m_modulePath, m_entrypoint, m_connectionId;
222 QString path, QString entrypoint, QString nodeVersion, QString apiversion,
223 module_configuration config, QString label = {},
bool firstInit =
false,
224 std::optional<int> upgradeIndex = {},
225 std::optional<std::set<QString>> secretKeys = {});
228 using module_handler_base::do_write;
229 void do_write(QString res);
230 QString jsonToString(QJsonObject obj);
232 void afterRegistration(std::function<
void()>);
234 void processMessage(std::string_view v)
override;
235 void on_process_exited()
override;
237 int writeRequest(QString name, QString p);
238 void writeNotification(QString name, QString p);
239 void writeReply(QJsonValue
id, QString p);
240 void writeReply(QJsonValue
id, QJsonObject p);
241 void writeReply(QJsonValue
id, QString p,
bool success);
242 void writeReply(QJsonValue
id, QJsonObject p,
bool success);
245 void on_register(QJsonValue
id);
246 void on_setActionDefinitions(QJsonArray obj);
247 void on_setVariableDefinitions(QJsonArray obj, QJsonArray values);
248 void on_setFeedbackDefinitions(QJsonArray obj);
249 void on_setPresetDefinitions(QJsonArray obj);
250 void on_setVariableValues(QJsonArray obj);
251 void on_set_status(QJsonObject obj);
252 void on_log_message(QJsonObject obj);
253 void on_saveConfig(QJsonObject obj);
254 void on_parseVariablesInString(QJsonValue
id, QJsonObject obj);
255 void on_updateFeedbackValues(QJsonObject obj);
256 void on_recordAction(QJsonObject obj);
257 void on_setCustomVariable(QJsonObject obj);
258 void on_sharedUdpSocketJoin(QJsonValue
id, QJsonObject obj);
259 void on_sharedUdpSocketLeave(QJsonObject obj);
260 void on_sharedUdpSocketSend(QJsonObject obj);
261 void on_send_osc(QJsonObject obj);
266 void on_response_configFields(QJsonArray fields);
270 int init(QString label);
271 void send_success(QJsonValue
id);
272 void updateConfigAndLabel(QString label, module_configuration conf);
273 int requestConfigFields();
274 void updateFeedbacks(
const std::map<QString, module_data::feedback_instance>& feedbacks);
275 void feedbackLearnValues();
276 void feedbackDelete();
277 void variablesChanged();
280 void actionLearnValues();
281 void actionRun(std::string_view act, QVariantMap options);
283 void executeHttpRequest(
284 const QString& method,
const QString& path,
const QString& body,
288 void startStopRecordingActions();
289 void sharedUdpSocketMessage(
290 const QString& handleId,
int port,
const QByteArray& data,
const QString& address,
291 int sourcePort,
bool ipv6);
292 void sharedUdpSocketError(
const QString& handleId,
int port,
const QString& message);
295 std::optional<std::set<QString>> secretKeys()
const;
297 enum DefinitionCategory
307 void configurationParsed() W_SIGNAL(configurationParsed);
309 void reregistered() W_SIGNAL(reregistered);
311 void definitionsChanged() W_SIGNAL(definitionsChanged);
313 void configurationSaved() W_SIGNAL(configurationSaved);
314 void variableChanged(QString var, QVariant val) W_SIGNAL(variableChanged, var, val);
315 void feedbackValueChanged(QString
id, QString controlId, QVariant value)
316 W_SIGNAL(feedbackValueChanged,
id, controlId, value);
319 QJsonObject configObject(
bool secrets) const;
320 void notifyDefinitionsChanged(DefinitionCategory c);
321 void completeRegistration();
322 void on_init_response(const QJsonObject& payload);
326 boost::asio::io_context m_send_service;
327 boost::asio::ip::udp::socket m_socket{m_send_service};
329 std::map<QString, std::shared_ptr<shared_udp_port>> m_shared_udp_handles;
331 std::map<int, QString> m_pendingActions;
333 std::vector<std::function<void()>> m_afterRegistrationQueue;
334 std::set<QString> m_secretFields;
335 bool m_secretsKnown{};
340 int m_init_msg_id{-1};
341 int m_req_cfg_id{-1};
343 bool m_expects_label_updates{
true};
344 bool m_hasHttpHandler{
false};
345 bool m_registered{
false};
346 bool m_firstInit{
false};
347 bool m_destroyed{
false};
348 bool m_definitionsPending{
false};
349 int m_changedDefinitions{};
350 QJsonArray m_lastActions, m_lastFeedbacks, m_lastVariables;
351 bool m_initDone{
false};
352 bool m_everRegistered{
false};
354 QElapsedTimer m_uptime;
355 bool m_fieldsDone{
false};