libcamera: include/libcamera/internal/process.h Source File

libcamera v0.5.1 Supporting cameras in Linux since 2019 |

Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2019, Google Inc.
4 *
5 * Process object
6 */
7
8#pragma once
9
10#include <signal.h>
11#include <string>
12#include <vector>
13
14#include <libcamera/base/signal.h>
15#include <libcamera/base/unique_fd.h>
16
17namespace libcamera {
18
19class EventNotifier;
20
21 class Process final
22{
23public:
24 enum ExitStatus {
25 NotExited,
26 NormalExit,
27 SignalExit,
28 };
29
30 Process();
31 ~Process();
32
33 int start(const std::string &path,
34 const std::vector<std::string> &args = std::vector<std::string>(),
35 const std::vector<int> &fds = std::vector<int>());
36
37 ExitStatus exitStatus() const { return exitStatus_; }
38 int exitCode() const { return exitCode_; }
39
40 void kill();
41
42 Signal<enum ExitStatus, int> finished;
43
44private:
45 void closeAllFdsExcept(const std::vector<int> &fds);
46 int isolate();
47 void died(int wstatus);
48
49 pid_t pid_;
50 bool running_;
51 enum ExitStatus exitStatus_;
52 int exitCode_;
53
54 friend class ProcessManager;
55};
56
57 class ProcessManager
58{
59public:
60 ProcessManager();
61 ~ProcessManager();
62
63 void registerProcess(Process *proc);
64
65 static ProcessManager *instance();
66
67 int writePipe() const;
68
69 const struct sigaction &oldsa() const;
70
71private:
72 static ProcessManager *self_;
73
74 void sighandler();
75
76 std::list<Process *> processes_;
77
78 struct sigaction oldsa_;
79
80 EventNotifier *sigEvent_;
81 UniqueFD pipe_[2];
82};
83
84} /* namespace libcamera */
libcamera::EventNotifier
Notify of activity on a file descriptor.
Definition event_notifier.h:20
libcamera::ProcessManager::instance
static ProcessManager * instance()
Retrieve the Process manager instance.
Definition process.cpp:162
libcamera::ProcessManager::writePipe
int writePipe() const
Retrieve the Process manager's write pipe.
Definition process.cpp:174
libcamera::ProcessManager::registerProcess
void registerProcess(Process *proc)
Register process with process manager.
Definition process.cpp:101
libcamera::ProcessManager::ProcessManager
ProcessManager()
Construct a ProcessManager instance.
Definition process.cpp:114
libcamera::ProcessManager::oldsa
const struct sigaction & oldsa() const
Retrive the old signal action data.
Definition process.cpp:186
libcamera::Process
Process object.
Definition process.h:22
libcamera::Process::kill
void kill()
Kill the process.
Definition process.cpp:383
libcamera::Process::start
int start(const std::string &path, const std::vector< std::string > &args=std::vector< std::string >(), const std::vector< int > &fds=std::vector< int >())
Fork and exec a process, and close fds.
Definition process.cpp:237
libcamera::Process::ExitStatus
ExitStatus
Exit status of process.
Definition process.h:24
libcamera::Process::SignalExit
@ SignalExit
Definition process.h:27
libcamera::Process::NotExited
@ NotExited
Definition process.h:25
libcamera::Process::NormalExit
@ NormalExit
Definition process.h:26
libcamera::Process::finished
Signal< enum ExitStatus, int > finished
Definition process.h:42
libcamera::Process::exitCode
int exitCode() const
Retrieve the exit code of the process.
Definition process.h:38
libcamera::Process::exitStatus
ExitStatus exitStatus() const
Retrieve the exit status of the process.
Definition process.h:37
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::UniqueFD
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:17
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
signal.h
Signal & slot implementation.
unique_fd.h
File descriptor wrapper that owns a file descriptor.