| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/helper/pmon/processmonitor.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "processmonitor.h"cxx . . $ `<file>/src/helper/pmon/processmonitor.h`/ |
| 5 | |
| 6 | #include "iappregistry.h"cxx . . $ `<file>/src/helper/pmon/iappregistry.h`/ |
| 7 | #include "ipidsolver.h"cxx . . $ `<file>/src/helper/pmon/ipidsolver.h`/ |
| 8 | #include "ipmonmsgdispatcher.h"cxx . . $ `<file>/src/helper/pmon/ipmonmsgdispatcher.h`/ |
| 9 | #include "processevent.h"cxx . . $ `<file>/src/helper/pmon/processevent.h`/ |
| 10 | #include "processregistry.h"cxx . . $ `<file>/src/helper/pmon/processregistry.h`/ |
| 11 | #include <utility> |
| 12 | |
| 13 | ProcessMonitorcxx . . $ ProcessMonitor#::ProcessMonitorcxx . . $ ProcessMonitor#ProcessMonitor(37ff3fbc937abec4).( |
| 14 | stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<IAppRegistrycxx . . $ IAppRegistry#> appRegistry, |
| 15 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IPIDSolvercxx . . $ IPIDSolver#> &&pidSolver, |
| 16 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IPMonMsgDispatchercxx . . $ IPMonMsgDispatcher#> &&msgDispatcher) noexcept |
| 17 | : appRegistry_cxx . . $ ProcessMonitor#appRegistry_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(appRegistry)) |
| 18 | , pidSolver_cxx . . $ ProcessMonitor#pidSolver_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(pidSolver)) |
| 19 | , msgDispatcher_cxx . . $ ProcessMonitor#msgDispatcher_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(msgDispatcher)) |
| 20 | { |
| 21 | procRegistry_cxx . . $ ProcessMonitor#procRegistry_. =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<ProcessRegistrycxx . . $ ProcessRegistry#>(this->appRegistry_cxx . . $ ProcessMonitor#appRegistry_.); |
| 22 | } |
| 23 | |
| 24 | ProcessMonitorcxx . . $ ProcessMonitor#::~cxx . . $ ProcessMonitor#`~ProcessMonitor`(ced63f7c635d850d).ProcessMonitorcxx . . $ ProcessMonitor#() = default; |
| 25 | |
| 26 | void ProcessMonitorcxx . . $ ProcessMonitor#::startcxx . . $ ProcessMonitor#start(49f6e7a06ebc5aa8).() |
| 27 | { |
| 28 | while (!stopSignal_cxx . . $ ProcessMonitor#stopSignal_..loadcxx . . $ std/atomic#load(84dca352c0e0dfc2).(stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.)) { |
| 29 | ProcessEventcxx . . $ ProcessEvent# const e = waitProcessEventcxx . . $ IProcessMonitor#waitProcessEvent(16a510d0ea03e539).(); |
| 30 | |
| 31 | switch (e.eventcxx . . $ ProcessEvent#event.) { |
| 32 | case ProcessEventcxx . . $ ProcessEvent#::Typecxx . . $ ProcessEvent#Type#::IGNOREcxx . . $ ProcessEvent#Type#IGNORE.: |
| 33 | continue; |
| 34 | |
| 35 | case ProcessEventcxx . . $ ProcessEvent#::Typecxx . . $ ProcessEvent#Type#::EXECcxx . . $ ProcessEvent#Type#EXEC.: |
| 36 | processExeccxx . . $ ProcessMonitor#processExec(d4f767463ce0a6b3).(e.pidcxx . . $ ProcessEvent#pid.); |
| 37 | break; |
| 38 | |
| 39 | case ProcessEventcxx . . $ ProcessEvent#::Typecxx . . $ ProcessEvent#Type#::EXITcxx . . $ ProcessEvent#Type#EXIT.: |
| 40 | processExitcxx . . $ ProcessMonitor#processExit(d4f767463ce0a6b3).(e.pidcxx . . $ ProcessEvent#pid.); |
| 41 | break; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void ProcessMonitorcxx . . $ ProcessMonitor#::stopcxx . . $ ProcessMonitor#stop(49f6e7a06ebc5aa8).() |
| 47 | { |
| 48 | stopSignal_cxx . . $ ProcessMonitor#stopSignal_..storecxx . . $ std/atomic#store(8f3cbf3da563ad44).(true, stdcxx . . $ std/::memory_order_relaxedcxx . . $ std/memory_order_relaxed.); |
| 49 | } |
| 50 | |
| 51 | void ProcessMonitorcxx . . $ ProcessMonitor#::processExeccxx . . $ ProcessMonitor#processExec(d4f767463ce0a6b3).(int pid) |
| 52 | { |
| 53 | auto const app = pidSolver_cxx . . $ ProcessMonitor#pidSolver_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).appcxx . . $ IPIDSolver#app(7eb93f795f0defb3).(pid); |
| 54 | |
| 55 | if (!appRegistry_cxx . . $ ProcessMonitor#appRegistry_.->cxx . . $ std/__shared_ptr_access#`operator->`(34d6acfd341ba7ab).registeredcxx . . $ IAppRegistry#registered(7c222eea44a24d43).(app)) |
| 56 | return; |
| 57 | |
| 58 | if (!procRegistry_cxx . . $ ProcessMonitor#procRegistry_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).runningcxx . . $ ProcessRegistry#running(7c222eea44a24d43).(app)) |
| 59 | msgDispatcher_cxx . . $ ProcessMonitor#msgDispatcher_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).sendExeccxx . . $ IPMonMsgDispatcher#sendExec(9c546c94e5fcce4e).(app); |
| 60 | |
| 61 | procRegistry_cxx . . $ ProcessMonitor#procRegistry_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).addcxx . . $ ProcessRegistry#add(448e1223d74ef93).(pid, app); |
| 62 | } |
| 63 | |
| 64 | void ProcessMonitorcxx . . $ ProcessMonitor#::processExitcxx . . $ ProcessMonitor#processExit(d4f767463ce0a6b3).(int pid) |
| 65 | { |
| 66 | auto app = procRegistry_cxx . . $ ProcessMonitor#procRegistry_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).findAppcxx . . $ ProcessRegistry#findApp(aeccc7d5c30f8eff).(pid); |
| 67 | if (!app) // no app registered to that PID |
| 68 | return; |
| 69 | |
| 70 | procRegistry_cxx . . $ ProcessMonitor#procRegistry_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).removecxx . . $ ProcessRegistry#remove(d4f767463ce0a6b3).(pid); |
| 71 | |
| 72 | if (!procRegistry_cxx . . $ ProcessMonitor#procRegistry_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).runningcxx . . $ ProcessRegistry#running(7c222eea44a24d43).(app.valuecxx . . $ std/optional#value(db8caaf2f996d67e).())) |
| 73 | msgDispatcher_cxx . . $ ProcessMonitor#msgDispatcher_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).sendExitcxx . . $ IPMonMsgDispatcher#sendExit(9c546c94e5fcce4e).(app.valuecxx . . $ std/optional#value(db8caaf2f996d67e).()); |
| 74 | } |