aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/command.h
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 08:59:43 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 11:37:46 +0200
commitf471fbdf27462b82febe4e8db8358ab3380d2a28 (patch)
tree6c41abf4e32214cd8bdb0f8a377f93b3c7c0d830 /src/command.h
parentci_queue: fix a broken getter (diff)
downloadcimple-f471fbdf27462b82febe4e8db8358ab3380d2a28.tar.gz
cimple-f471fbdf27462b82febe4e8db8358ab3380d2a28.zip
add command module to handle request-response communications
Diffstat (limited to 'src/command.h')
-rw-r--r--src/command.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/command.h b/src/command.h
new file mode 100644
index 0000000..b4c3b40
--- /dev/null
+++ b/src/command.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+ * This file is part of the "cimple" project.
+ * For details, see https://github.com/egor-tensin/cimple.
+ * Distributed under the MIT License.
+ */
+
+#ifndef __COMMAND_H__
+#define __COMMAND_H__
+
+#include "msg.h"
+
+#include <stdlib.h>
+
+typedef int (*command_processor)(int conn_fd, const struct msg *request, void *ctx,
+ struct msg **response);
+
+struct command_def {
+ char *name;
+ command_processor processor;
+};
+
+struct command_dispatcher;
+
+int command_dispatcher_create(struct command_dispatcher **, struct command_def *, size_t numof_defs,
+ void *ctx);
+void command_dispatcher_destroy(struct command_dispatcher *);
+
+int command_dispatcher_msg_handler(const struct command_dispatcher *, int conn_fd,
+ const struct msg *);
+
+/* This is supposed to be used as an argument to tcp_server_accept. */
+int command_dispatcher_conn_handler(int conn_fd, void *dispatcher);
+
+#endif