ipc_unixsocket.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ipc_unixsocket.h - IPC mechanism based on Unix sockets
*/
#ifndef __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__
#define __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__
#include <stdint.h>
#include <sys/types.h>
#include <vector>
#include <libcamera/event_notifier.h>
namespace libcamera {
class IPCUnixSocket
{
public:
struct Payload {
std::vector<uint8_t> data;
std::vector<int32_t> fds;
};
IPCUnixSocket();
~IPCUnixSocket();
int create();
int bind(int fd);
void close();
bool isBound() const;
int send(const Payload &payload);
int receive(Payload *payload);
Signal<IPCUnixSocket *> readyRead;
private:
struct Header {
uint32_t data;
uint8_t fds;
};
int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
void dataNotifier(EventNotifier *notifier);
int fd_;
bool headerReceived_;
struct Header header_;
EventNotifier *notifier_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_INTERNAL_IPC_UNIXSOCKET_H__ */
libcamera::EventNotifier
Notify of activity on a file descriptor.
Definition: event_notifier.h:18
libcamera::IPCUnixSocket
IPC mechanism based on Unix sockets.
Definition: ipc_unixsocket.h:20
libcamera::IPCUnixSocket::receive
int receive(Payload *payload)
Receive a message payload.
Definition: ipc_unixsocket.cpp:212
libcamera::IPCUnixSocket::send
int send(const Payload &payload)
Send a message payload.
Definition: ipc_unixsocket.cpp:170
libcamera::IPCUnixSocket::isBound
bool isBound() const
Check if the IPC channel is bound.
Definition: ipc_unixsocket.cpp:155
libcamera::IPCUnixSocket::bind
int bind(int fd)
Bind to an existing IPC channel.
Definition: ipc_unixsocket.cpp:120
libcamera::IPCUnixSocket::close
void close()
Close the IPC channel.
Definition: ipc_unixsocket.cpp:137
libcamera::IPCUnixSocket::create
int create()
Create an new IPC channel.
Definition: ipc_unixsocket.cpp:90
libcamera::IPCUnixSocket::readyRead
Signal< IPCUnixSocket * > readyRead
A Signal emitted when a message is ready to be read.
Definition: ipc_unixsocket.h:38
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
event_notifier.h
File descriptor event notifier.
libcamera::IPCUnixSocket::Payload
Container for an IPC payload.
Definition: ipc_unixsocket.h:22
libcamera::IPCUnixSocket::Payload::fds
std::vector< int32_t > fds
Array of file descriptors to cross IPC boundary.
Definition: ipc_unixsocket.h:24
libcamera::IPCUnixSocket::Payload::data
std::vector< uint8_t > data
Array of bytes to cross IPC boundary.
Definition: ipc_unixsocket.h:23