Many signals used in internal and public APIs carry the emitter pointer as a signal argument. This was done to allow slots connected to multiple signal instances to differentiate between emitters. While starting from a good intention of facilitating the implementation of slots, it turned out to be a bad API design as the signal isn't meant to know what it will be connected to, and thus shouldn't carry parameters that are solely meant to support a use case specific to the connected slot. These pointers turn out to be unused in all slots but one. In the only case where it is needed, it can be obtained by wrapping the slot in a lambda function when connecting the signal. Do so, and drop the emitter pointer from all signals. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
85 lines
1.4 KiB
C++
85 lines
1.4 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* process.h - Process object
|
|
*/
|
|
#ifndef __LIBCAMERA_INTERNAL_PROCESS_H__
|
|
#define __LIBCAMERA_INTERNAL_PROCESS_H__
|
|
|
|
#include <signal.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <libcamera/base/signal.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class EventNotifier;
|
|
|
|
class Process final
|
|
{
|
|
public:
|
|
enum ExitStatus {
|
|
NotExited,
|
|
NormalExit,
|
|
SignalExit,
|
|
};
|
|
|
|
Process();
|
|
~Process();
|
|
|
|
int start(const std::string &path,
|
|
const std::vector<std::string> &args = std::vector<std::string>(),
|
|
const std::vector<int> &fds = std::vector<int>());
|
|
|
|
ExitStatus exitStatus() const { return exitStatus_; }
|
|
int exitCode() const { return exitCode_; }
|
|
|
|
void kill();
|
|
|
|
Signal<enum ExitStatus, int> finished;
|
|
|
|
private:
|
|
void closeAllFdsExcept(const std::vector<int> &fds);
|
|
int isolate();
|
|
void died(int wstatus);
|
|
|
|
pid_t pid_;
|
|
bool running_;
|
|
enum ExitStatus exitStatus_;
|
|
int exitCode_;
|
|
|
|
friend class ProcessManager;
|
|
};
|
|
|
|
class ProcessManager
|
|
{
|
|
public:
|
|
ProcessManager();
|
|
~ProcessManager();
|
|
|
|
void registerProcess(Process *proc);
|
|
|
|
static ProcessManager *instance();
|
|
|
|
int writePipe() const;
|
|
|
|
const struct sigaction &oldsa() const;
|
|
|
|
private:
|
|
static ProcessManager *self_;
|
|
|
|
void sighandler();
|
|
|
|
std::list<Process *> processes_;
|
|
|
|
struct sigaction oldsa_;
|
|
EventNotifier *sigEvent_;
|
|
int pipe_[2];
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_INTERNAL_PROCESS_H__ */
|