Skip to content

Commit 48a52a0

Browse files
committed
Memory observer moved to class job and revoke added for shceduled job
1 parent 9d3b7d4 commit 48a52a0

2 files changed

Lines changed: 77 additions & 68 deletions

File tree

Launcher.cpp

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,6 @@ namespace Plugin {
1515

1616
SERVICE_REGISTRATION(Launcher, 1, 0);
1717

18-
class MemoryObserverImpl : public Exchange::IMemory {
19-
private:
20-
MemoryObserverImpl();
21-
MemoryObserverImpl(const MemoryObserverImpl&);
22-
MemoryObserverImpl& operator=(const MemoryObserverImpl&);
23-
24-
public:
25-
MemoryObserverImpl(const uint32_t id)
26-
: _main(id == 0 ? Core::ProcessInfo().Id() : id)
27-
, _observable(false)
28-
{
29-
}
30-
~MemoryObserverImpl()
31-
{
32-
}
33-
34-
public:
35-
virtual void Observe(const uint32_t pid)
36-
{
37-
if (pid == 0) {
38-
_observable = false;
39-
}
40-
else {
41-
_main = Core::ProcessInfo(pid);
42-
_observable = true;
43-
}
44-
}
45-
virtual uint64_t Resident() const
46-
{
47-
return (_observable == false ? 0 : _main.Resident());
48-
}
49-
virtual uint64_t Allocated() const
50-
{
51-
return (_observable == false ? 0 : _main.Allocated());
52-
}
53-
virtual uint64_t Shared() const
54-
{
55-
return (_observable == false ? 0 : _main.Shared());
56-
}
57-
virtual uint8_t Processes() const
58-
{
59-
return (IsOperational() ? 1 : 0);
60-
}
61-
virtual const bool IsOperational() const
62-
{
63-
return (_observable == false) || (_main.IsActive());
64-
}
65-
66-
BEGIN_INTERFACE_MAP(MemoryObserverImpl)
67-
INTERFACE_ENTRY(Exchange::IMemory)
68-
END_INTERFACE_MAP
69-
70-
private:
71-
Core::ProcessInfo _main;
72-
bool _observable;
73-
};
74-
75-
7618
/* static */ Launcher::ProcessObserver Launcher::_observer;
7719

7820
/* virtual */ const string Launcher::Initialize(PluginHost::IShell* service)
@@ -84,7 +26,6 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
8426
Config config;
8527

8628
ASSERT(_service == nullptr);
87-
ASSERT(_memory == nullptr);
8829

8930
// Setup skip URL for right offset.
9031
_service = service;
@@ -151,13 +92,13 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
15192
/* virtual */ void Launcher::Deinitialize(PluginHost::IShell* service)
15293
{
15394
ASSERT(_service == service);
154-
ASSERT(_memory != nullptr);
95+
96+
PluginHost::WorkerPool::Instance().Revoke(_activity);
15597

15698
_observer.Unregister(&_notification);
15799

158-
if (_memory != nullptr) {
159-
_memory->Release();
160-
_memory = nullptr;
100+
if (_activity->Memory() != nullptr) {
101+
_activity->Memory()->Release();
161102
}
162103

163104
if (_activity->Process().IsActive() == true) {

Launcher.h

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,63 @@ class Launcher : public PluginHost::IPlugin {
265265
Launcher& _parent;
266266
};
267267

268+
class MemoryObserverImpl : public Exchange::IMemory {
269+
private:
270+
MemoryObserverImpl();
271+
MemoryObserverImpl(const MemoryObserverImpl&);
272+
MemoryObserverImpl& operator=(const MemoryObserverImpl&);
273+
274+
public:
275+
MemoryObserverImpl(const uint32_t id)
276+
: _main(id == 0 ? Core::ProcessInfo().Id() : id)
277+
, _observable(false)
278+
{
279+
}
280+
~MemoryObserverImpl()
281+
{
282+
}
283+
284+
public:
285+
virtual void Observe(const uint32_t pid)
286+
{
287+
if (pid == 0) {
288+
_observable = false;
289+
}
290+
else {
291+
_main = Core::ProcessInfo(pid);
292+
_observable = true;
293+
}
294+
}
295+
virtual uint64_t Resident() const
296+
{
297+
return (_observable == false ? 0 : _main.Resident());
298+
}
299+
virtual uint64_t Allocated() const
300+
{
301+
return (_observable == false ? 0 : _main.Allocated());
302+
}
303+
virtual uint64_t Shared() const
304+
{
305+
return (_observable == false ? 0 : _main.Shared());
306+
}
307+
virtual uint8_t Processes() const
308+
{
309+
return (IsOperational() ? 1 : 0);
310+
}
311+
virtual const bool IsOperational() const
312+
{
313+
return (_observable == false) || (_main.IsActive());
314+
}
315+
316+
BEGIN_INTERFACE_MAP(MemoryObserverImpl)
317+
INTERFACE_ENTRY(Exchange::IMemory)
318+
END_INTERFACE_MAP
319+
320+
private:
321+
Core::ProcessInfo _main;
322+
bool _observable;
323+
};
324+
268325
public:
269326
class Config : public Core::JSON::Container {
270327
private:
@@ -478,7 +535,7 @@ class Launcher : public PluginHost::IPlugin {
478535
};
479536

480537
public:
481-
class Job: public Core::IDispatchType<void> {
538+
class Job: public Core::IDispatchType<void>, public Core::IUnknown {
482539
private:
483540
Job() = delete;
484541
Job(const Job&) = delete;
@@ -490,6 +547,7 @@ class Launcher : public PluginHost::IPlugin {
490547
, _pid(0)
491548
, _options(config->Command.Value().c_str())
492549
, _process(false)
550+
, _memory(nullptr)
493551
, _interval(interval)
494552
{
495553
auto iter = config->Parameters.Elements();
@@ -522,14 +580,20 @@ class Launcher : public PluginHost::IPlugin {
522580
uint32_t Pid() {
523581
return _pid;
524582
}
583+
Exchange::IMemory* Memory() {
584+
return _memory;
585+
}
525586
virtual void Dispatch() override
526587
{
527588
_hasRun = true;
528589
// Check if the process is not active, no need to reschedule the same job again.
529590
if (_process.IsActive() == false) {
530591

531-
Core::Time currentTime(Core::Time::Now());
532592
_process.Launch(_options, &_pid);
593+
if (_memory != nullptr) {
594+
_memory->Release();
595+
}
596+
_memory = Core::Service<MemoryObserverImpl>::Create<Exchange::IMemory>(_pid);
533597
}
534598

535599
if (_interval.IsValid() == true) {
@@ -545,11 +609,18 @@ class Launcher : public PluginHost::IPlugin {
545609
}
546610
}
547611

612+
public:
613+
BEGIN_INTERFACE_MAP(Job)
614+
INTERFACE_AGGREGATE(Exchange::IMemory, _memory)
615+
END_INTERFACE_MAP
616+
617+
548618
private:
549619
bool _hasRun;
550620
uint32_t _pid;
551621
Core::Process::Options _options;
552622
Core::Process _process;
623+
Exchange::IMemory* _memory;
553624
Time _interval;
554625
};
555626

@@ -561,7 +632,6 @@ class Launcher : public PluginHost::IPlugin {
561632
: _service(nullptr)
562633
, _closeTime(0)
563634
, _notification(this)
564-
, _memory(nullptr)
565635
, _activity()
566636
{
567637
}
@@ -575,7 +645,6 @@ class Launcher : public PluginHost::IPlugin {
575645
public:
576646
BEGIN_INTERFACE_MAP(Launcher)
577647
INTERFACE_ENTRY(PluginHost::IPlugin)
578-
INTERFACE_AGGREGATE(Exchange::IMemory, _memory)
579648
END_INTERFACE_MAP
580649

581650
public:
@@ -608,7 +677,6 @@ class Launcher : public PluginHost::IPlugin {
608677
PluginHost::IShell* _service;
609678
uint8_t _closeTime;
610679
Core::Sink<Notification> _notification;
611-
Exchange::IMemory* _memory;
612680

613681
static ProcessObserver _observer;
614682
Core::ProxyType<Job> _activity;

0 commit comments

Comments
 (0)