libcamera  v0.0.0+3-3b6e2d50-dirty (2022-01-27T16:18:04+08:00)
Supporting cameras in Linux since 2019
ipc_pipe.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2020, Google Inc.
4  *
5  * ipc_pipe.h - Image Processing Algorithm IPC module for IPA proxies
6  */
7 #ifndef __LIBCAMERA_INTERNAL_IPA_IPC_H__
8 #define __LIBCAMERA_INTERNAL_IPA_IPC_H__
9 
10 #include <vector>
11 
12 #include <libcamera/base/signal.h>
13 
15 
17 
18 namespace libcamera {
19 
21 {
22 public:
23  struct Header {
24  uint32_t cmd;
25  uint32_t cookie;
26  };
27 
28  IPCMessage();
29  IPCMessage(uint32_t cmd);
30  IPCMessage(const Header &header);
32 
34 
35  Header &header() { return header_; }
36  std::vector<uint8_t> &data() { return data_; }
37  std::vector<FileDescriptor> &fds() { return fds_; }
38 
39  const Header &header() const { return header_; }
40  const std::vector<uint8_t> &data() const { return data_; }
41  const std::vector<FileDescriptor> &fds() const { return fds_; }
42 
43 private:
44  Header header_;
45 
46  std::vector<uint8_t> data_;
47  std::vector<FileDescriptor> fds_;
48 };
49 
50 class IPCPipe
51 {
52 public:
53  IPCPipe();
54  virtual ~IPCPipe();
55 
56  bool isConnected() const { return connected_; }
57 
58  virtual int sendSync(const IPCMessage &in,
59  IPCMessage *out) = 0;
60 
61  virtual int sendAsync(const IPCMessage &data) = 0;
62 
64 
65 protected:
66  bool connected_;
67 };
68 
69 } /* namespace libcamera */
70 
71 #endif /* __LIBCAMERA_INTERNAL_IPA_IPC_H__ */
IPC message to be passed through IPC message pipe.
Definition: ipc_pipe.h:21
const std::vector< uint8_t > & data() const
Returns a const reference to the byte vector containing data.
Definition: ipc_pipe.h:40
std::vector< FileDescriptor > & fds()
Returns a reference to the vector containing file descriptors.
Definition: ipc_pipe.h:37
const Header & header() const
Returns a const reference to the header.
Definition: ipc_pipe.h:39
IPCMessage()
Construct an empty IPCMessage instance.
Definition: ipc_pipe.cpp:51
IPCUnixSocket::Payload payload() const
Create an IPCUnixSocket payload from the IPCMessage.
Definition: ipc_pipe.cpp:100
const std::vector< FileDescriptor > & fds() const
Returns a const reference to the vector containing file descriptors.
Definition: ipc_pipe.h:41
Header & header()
Returns a reference to the header.
Definition: ipc_pipe.h:35
std::vector< uint8_t > & data()
Returns a reference to the byte vector containing data.
Definition: ipc_pipe.h:36
IPC message pipe for IPA isolation.
Definition: ipc_pipe.h:51
IPCPipe()
Construct an IPCPipe instance.
Definition: ipc_pipe.cpp:163
virtual int sendAsync(const IPCMessage &data)=0
Send a message over IPC asynchronously.
virtual int sendSync(const IPCMessage &in, IPCMessage *out)=0
Send a message over IPC synchronously.
Signal< const IPCMessage & > recv
Signal to be emitted when a message is received over IPC.
Definition: ipc_pipe.h:63
bool isConnected() const
Check if the IPCPipe instance is connected.
Definition: ipc_pipe.h:56
bool connected_
Flag to indicate if the IPCPipe instance is connected.
Definition: ipc_pipe.h:66
Generic signal and slot communication mechanism.
Definition: signal.h:39
File descriptor wrapper.
IPC mechanism based on Unix sockets.
Top-level libcamera namespace.
Definition: bound_method.h:15
Signal & slot implementation.
Container for an IPCMessage header.
Definition: ipc_pipe.h:23
uint32_t cmd
Type of IPCMessage.
Definition: ipc_pipe.h:24
uint32_t cookie
Cookie to identify the message and a corresponding reply.
Definition: ipc_pipe.h:25
Container for an IPC payload.
Definition: ipc_unixsocket.h:24