libcamera v0.4.0
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 <stdint.h>
11#include <sys/types.h>
12#include <vector>
13
16
17namespace libcamera {
18
19class EventNotifier;
20
21class IPCUnixSocket
22{
23public:
24 struct Payload {
25 std::vector<uint8_t> data;
26 std::vector<int32_t> fds;
27 };
28
29 IPCUnixSocket();
30 ~IPCUnixSocket();
31
33 int bind(UniqueFD fd);
34 void close();
35 bool isBound() const;
36
37 int send(const Payload &payload);
38 int receive(Payload *payload);
39
41
42private:
43 struct Header {
44 uint32_t data;
45 uint8_t fds;
46 };
47
48 int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
49 int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
50
51 void dataNotifier();
52
53 UniqueFD fd_;
54 bool headerReceived_;
55 struct Header header_;
56 EventNotifier *notifier_;
57};
58
59} /* 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:217
Signal readyRead
A Signal emitted when a message is ready to be read.
Definition ipc_unixsocket.h:40
int send(const Payload &payload)
Send a message payload.
Definition ipc_unixsocket.cpp:175
bool isBound() const
Check if the IPC channel is bound.
Definition ipc_unixsocket.cpp:160
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:18
Top-level libcamera namespace.
Definition backtrace.h:17
Signal & slot implementation.
Container for an IPC payload.
Definition ipc_unixsocket.h:24
std::vector< int32_t > fds
Array of file descriptors to cross IPC boundary.
Definition ipc_unixsocket.h:26
std::vector< uint8_t > data
Array of bytes to cross IPC boundary.
Definition ipc_unixsocket.h:25
File descriptor wrapper that owns a file descriptor.