libcamera  v0.0.0+100-debian/0_git20200629+e7aa92a-8-9-g77f5237c-dirty (2021-05-05T16:20:29+01:00)
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 
15 #include <libcamera/signal.h>
16 
17 namespace libcamera {
18 
19 class EventNotifier;
20 
22 {
23 public:
24  struct Payload {
25  std::vector<uint8_t> data;
26  std::vector<int32_t> fds;
27  };
28 
29  IPCUnixSocket();
30  ~IPCUnixSocket();
31 
32  int create();
33  int bind(int fd);
34  void close();
35  bool isBound() const;
36 
37  int send(const Payload &payload);
38  int receive(Payload *payload);
39 
41 
42 private:
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(EventNotifier *notifier);
52 
53  int fd_;
54  bool headerReceived_;
55  struct Header header_;
56  EventNotifier *notifier_;
57 };
58 
59 } /* namespace libcamera */
60 
61 #endif /* __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__ */
std::vector< uint8_t > data
Array of bytes to cross IPC boundary.
Definition: ipc_unixsocket.h:25
int create()
Create an new IPC channel.
Definition: ipc_unixsocket.cpp:91
Top-level libcamera namespace.
Definition: bound_method.h:15
std::vector< int32_t > fds
Array of file descriptors to cross IPC boundary.
Definition: ipc_unixsocket.h:26
bool isBound() const
Check if the IPC channel is bound.
Definition: ipc_unixsocket.cpp:156
void close()
Close the IPC channel.
Definition: ipc_unixsocket.cpp:138
Signal & slot implementation.
IPC mechanism based on Unix sockets.
Definition: ipc_unixsocket.h:21
int bind(int fd)
Bind to an existing IPC channel.
Definition: ipc_unixsocket.cpp:121
int send(const Payload &payload)
Send a message payload.
Definition: ipc_unixsocket.cpp:171
Generic signal and slot communication mechanism.
Definition: object.h:20
Notify of activity on a file descriptor.
Definition: event_notifier.h:17
Container for an IPC payload.
Definition: ipc_unixsocket.h:24
int receive(Payload *payload)
Receive a message payload.
Definition: ipc_unixsocket.cpp:213
Signal< IPCUnixSocket * > readyRead
A Signal emitted when a message is ready to be read.
Definition: ipc_unixsocket.h:40