libcamera  v0.0.0
Supporting cameras in Linux since 2019
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_unixsocket.h - IPC mechanism based on Unix sockets
6  */
7 
8 #ifndef __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__
9 #define __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__
10 
11 #include <stdint.h>
12 #include <sys/types.h>
13 #include <vector>
14 
16 
17 namespace libcamera {
18 
20 {
21 public:
22  struct Payload {
23  std::vector<uint8_t> data;
24  std::vector<int32_t> fds;
25  };
26 
27  IPCUnixSocket();
28  ~IPCUnixSocket();
29 
30  int create();
31  int bind(int fd);
32  void close();
33  bool isBound() const;
34 
35  int send(const Payload &payload);
36  int receive(Payload *payload);
37 
39 
40 private:
41  struct Header {
42  uint32_t data;
43  uint8_t fds;
44  };
45 
46  int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
47  int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
48 
49  void dataNotifier(EventNotifier *notifier);
50 
51  int fd_;
52  bool headerReceived_;
53  struct Header header_;
54  EventNotifier *notifier_;
55 };
56 
57 } /* namespace libcamera */
58 
59 #endif /* __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__ */
Notify of activity on a file descriptor.
Definition: event_notifier.h:18
IPC mechanism based on Unix sockets.
Definition: ipc_unixsocket.h:20
int receive(Payload *payload)
Receive a message payload.
Definition: ipc_unixsocket.cpp:212
int send(const Payload &payload)
Send a message payload.
Definition: ipc_unixsocket.cpp:170
bool isBound() const
Check if the IPC channel is bound.
Definition: ipc_unixsocket.cpp:155
int bind(int fd)
Bind to an existing IPC channel.
Definition: ipc_unixsocket.cpp:120
void close()
Close the IPC channel.
Definition: ipc_unixsocket.cpp:137
int create()
Create an new IPC channel.
Definition: ipc_unixsocket.cpp:90
Signal< IPCUnixSocket * > readyRead
A Signal emitted when a message is ready to be read.
Definition: ipc_unixsocket.h:38
Generic signal and slot communication mechanism.
Definition: signal.h:39
File descriptor event notifier.
Container for an IPC payload.
Definition: ipc_unixsocket.h:22
std::vector< int32_t > fds
Array of file descriptors to cross IPC boundary.
Definition: ipc_unixsocket.h:24
std::vector< uint8_t > data
Array of bytes to cross IPC boundary.
Definition: ipc_unixsocket.h:23