Files
external_libcamera/include/libcamera/internal/ipc_unixsocket.h
Hirokazu Honda 9143668887 libcamera: ipc_unixsocket: Use UniqueFD for a file descriptor
IPCUnixSocket::create() creates two file descriptors. One of
them is stored in IPCUnixSocket and the other is returned to a
caller. This clarifies the ownership using UniqueFD.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-12-04 23:05:03 +02:00

60 lines
1.0 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* ipc_unixsocket.h - IPC mechanism based on Unix sockets
*/
#pragma once
#include <stdint.h>
#include <sys/types.h>
#include <vector>
#include <libcamera/base/signal.h>
#include <libcamera/base/unique_fd.h>
namespace libcamera {
class EventNotifier;
class IPCUnixSocket
{
public:
struct Payload {
std::vector<uint8_t> data;
std::vector<int32_t> fds;
};
IPCUnixSocket();
~IPCUnixSocket();
UniqueFD create();
int bind(UniqueFD fd);
void close();
bool isBound() const;
int send(const Payload &payload);
int receive(Payload *payload);
Signal<> 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();
UniqueFD fd_;
bool headerReceived_;
struct Header header_;
EventNotifier *notifier_;
};
} /* namespace libcamera */