summaryrefslogtreecommitdiff
path: root/src/libcamera/include
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-06-20 21:50:13 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-07-02 02:25:49 +0300
commit13dd7a01ecbe7198bbefc3b61168333b6a2bb2d8 (patch)
treef57c6f21bb371667711769f1438fbc9a6aed410e /src/libcamera/include
parent3952d49d8db15eb0788817f97b4de9eadd036324 (diff)
libcamera: ipc: unix: Add a IPC mechanism based on Unix sockets
To be able to isolate an IPA component in a separate process an IPC mechanism is needed to communicate with it. Add an IPC mechanism based on Unix sockets which allows users to pass both data and file descriptors to and from the IPA process. The implementation allows users to send both data and file descriptors in the same message. This allows users to more easily implement serialization and deserialization of objects as all elements belonging to an object can be sent in one message. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/include')
-rw-r--r--src/libcamera/include/ipc_unixsocket.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/libcamera/include/ipc_unixsocket.h b/src/libcamera/include/ipc_unixsocket.h
new file mode 100644
index 00000000..ef166d74
--- /dev/null
+++ b/src/libcamera/include/ipc_unixsocket.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * ipc_unixsocket.h - IPC mechanism based on Unix sockets
+ */
+
+#ifndef __LIBCAMERA_IPC_UNIXSOCKET_H__
+#define __LIBCAMERA_IPC_UNIXSOCKET_H__
+
+#include <cstdint>
+#include <sys/types.h>
+#include <vector>
+
+#include <libcamera/event_notifier.h>
+
+namespace libcamera {
+
+class IPCUnixSocket
+{
+public:
+ struct Payload {
+ std::vector<uint8_t> data;
+ std::vector<int32_t> fds;
+ };
+
+ IPCUnixSocket();
+ ~IPCUnixSocket();
+
+ int create();
+ int bind(int fd);
+ void close();
+ bool isBound() const;
+
+ int send(const Payload &payload);
+ int receive(Payload *payload);
+
+ Signal<IPCUnixSocket *> readyRead;
+
+private:
+ struct Header {
+ uint32_t data;
+ uint8_t fds;
+ };
+
+ int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
+ int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
+
+ void dataNotifier(EventNotifier *notifier);
+
+ int fd_;
+ EventNotifier *notifier_;
+};
+
+} /* namespace libcamera */
+
+#endif /* __LIBCAMERA_IPC_UNIXSOCKET_H__ */