libcamera: Add Process and ProcessManager classes

Add a Process class to abstract a process, and a ProcessManager singleton
to monitor and manage the processes.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Paul Elder
2019-07-12 16:32:29 +09:00
parent 099815b853
commit 3d20beca66
6 changed files with 527 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* process.h - Process object
*/
#ifndef __LIBCAMERA_PROCESS_H__
#define __LIBCAMERA_PROCESS_H__
#include <string>
#include <vector>
#include <libcamera/event_notifier.h>
namespace libcamera {
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<Process *, 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;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_PROCESS_H__ */