libcamera v0.7.1
Supporting cameras in Linux since 2019
Loading...
Searching...
No Matches
ipc_unixsocket.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2019, Google Inc.
4 *
5 * IPC mechanism based on Unix sockets
6 */
7
8#pragma once
9
10#include <memory>
11#include <stdint.h>
12#include <sys/types.h>
13#include <vector>
14
17
18namespace libcamera {
19
20class EventNotifier;
21
22class IPCUnixSocket
23{
24public:
25 struct Payload {
26 std::vector<uint8_t> data;
27 std::vector<int32_t> fds;
28 };
29
30 IPCUnixSocket();
31 ~IPCUnixSocket();
32
34 int bind(UniqueFD fd);
35 void close();
36 bool isBound() const;
37
38 int send(const Payload &payload);
39 int receive(Payload *payload);
40
42
43private:
44 struct Header {
45 uint32_t data;
46 uint8_t fds;
47 };
48
49 int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
50 int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
51
52 void dataNotifier();
53
54 UniqueFD fd_;
55 bool headerReceived_;
56 struct Header header_;
57 std::unique_ptr<EventNotifier> notifier_;
58};
59
60} /* namespace libcamera */
Notify of activity on a file descriptor.
Definition event_notifier.h:20
int receive(Payload *payload)
Receive a message payload.
Definition ipc_unixsocket.cpp:216
Signal readyRead
A Signal emitted when a message is ready to be read.
Definition ipc_unixsocket.h:41
int send(const Payload &payload)
Send a message payload.
Definition ipc_unixsocket.cpp:174
bool isBound() const
Check if the IPC channel is bound.
Definition ipc_unixsocket.cpp:159
void close()
Close the IPC channel.
Definition ipc_unixsocket.cpp:144
int bind(UniqueFD fd)
Bind to an existing IPC channel.
Definition ipc_unixsocket.cpp:127
UniqueFD create()
Create an new IPC channel.
Definition ipc_unixsocket.cpp:93
Generic signal and slot communication mechanism.
Definition signal.h:39
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:17
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
Container for an IPC payload.
Definition ipc_unixsocket.h:25
std::vector< int32_t > fds
Array of file descriptors to cross IPC boundary.
Definition ipc_unixsocket.h:27
std::vector< uint8_t > data
Array of bytes to cross IPC boundary.
Definition ipc_unixsocket.h:26
File descriptor wrapper that owns a file descriptor.