Files
external_libcamera/include/libcamera/internal/ipc_unixsocket.h
Laurent Pinchart 1e4e158d98 libcamera: Replace plain pointers with std::unique<>
libcamera uses std::unique_ptr<> to simplify life time management of
objects and avoid leaks. For historical reasons there are a fair number
of plain pointers with manual memory management. Replace them with
std::unique_ptr<> when the conversion is simple.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
2026-04-24 01:17:37 +03:00

61 lines
1.0 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* IPC mechanism based on Unix sockets
*/
#pragma once
#include <memory>
#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_;
std::unique_ptr<EventNotifier> notifier_;
};
} /* namespace libcamera */