Skip to content

Commit 1c677c3

Browse files
committed
Memory Observer implementation corrected
1 parent 48a52a0 commit 1c677c3

2 files changed

Lines changed: 27 additions & 18 deletions

File tree

Launcher.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
2626
Config config;
2727

2828
ASSERT(_service == nullptr);
29+
ASSERT(_memory == nullptr);
2930

3031
// Setup skip URL for right offset.
3132
_service = service;
@@ -47,7 +48,10 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
4748
}
4849
}
4950

50-
_activity = Core::ProxyType<Job>::Create(&config, interval);
51+
_memory = Core::Service<MemoryObserverImpl>::Create<Exchange::IMemory>(0);
52+
ASSERT(_memory != nullptr);
53+
54+
_activity = Core::ProxyType<Job>::Create(&config, interval, _memory);
5155
if (_activity.IsValid() == true) {
5256
if (_activity->IsOperational() == false) {
5357
// Well if we where able to parse the parameters (if needed) we are ready to start it..
@@ -77,28 +81,39 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
7781
else {
7882
PluginHost::WorkerPool::Instance().Submit(_activity);
7983
}
84+
8085
}
8186
else {
87+
_activity.Release();
8288
message = _T("Could not parse the configuration for the job.");
8389
}
8490
}
8591
else {
8692
message = _T("Could not create the job.");
8793
}
8894

95+
if (_activity.IsValid() == false) {
96+
if (_memory != nullptr) {
97+
_memory->Release();
98+
_memory = nullptr;
99+
}
100+
}
101+
89102
return (message);
90103
}
91104

92105
/* virtual */ void Launcher::Deinitialize(PluginHost::IShell* service)
93106
{
94107
ASSERT(_service == service);
108+
ASSERT(_memory != nullptr);
95109

96110
PluginHost::WorkerPool::Instance().Revoke(_activity);
97111

98112
_observer.Unregister(&_notification);
99113

100-
if (_activity->Memory() != nullptr) {
101-
_activity->Memory()->Release();
114+
if (_memory != nullptr) {
115+
_memory->Release();
116+
_memory = nullptr;
102117
}
103118

104119
if (_activity->Process().IsActive() == true) {
@@ -129,7 +144,8 @@ void Launcher::Update(const ProcessObserver::Info& info)
129144
ASSERT(_service != nullptr);
130145

131146
if (info.Event() == ProcessObserver::Info::EVENT_EXIT) {
132-
147+
148+
_memory->Observe(0);
133149
if ((info.ExitCode() & 0xFFFF) == 0) {
134150
// Only do this if we do not need a retrigger on an intervall.
135151
if (_activity->IsOperational() == false) {

Launcher.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -535,19 +535,19 @@ class Launcher : public PluginHost::IPlugin {
535535
};
536536

537537
public:
538-
class Job: public Core::IDispatchType<void>, public Core::IUnknown {
538+
class Job: public Core::IDispatchType<void> {
539539
private:
540540
Job() = delete;
541541
Job(const Job&) = delete;
542542
Job& operator=(const Job&) = delete;
543543

544544
public:
545-
Job(Config* config, const Time& interval)
545+
Job(Config* config, const Time& interval, Exchange::IMemory* memory)
546546
: _hasRun(false)
547547
, _pid(0)
548548
, _options(config->Command.Value().c_str())
549549
, _process(false)
550-
, _memory(nullptr)
550+
, _memory(memory)
551551
, _interval(interval)
552552
{
553553
auto iter = config->Parameters.Elements();
@@ -580,9 +580,6 @@ class Launcher : public PluginHost::IPlugin {
580580
uint32_t Pid() {
581581
return _pid;
582582
}
583-
Exchange::IMemory* Memory() {
584-
return _memory;
585-
}
586583
virtual void Dispatch() override
587584
{
588585
_hasRun = true;
@@ -591,9 +588,8 @@ class Launcher : public PluginHost::IPlugin {
591588

592589
_process.Launch(_options, &_pid);
593590
if (_memory != nullptr) {
594-
_memory->Release();
591+
_memory->Observe(_pid);
595592
}
596-
_memory = Core::Service<MemoryObserverImpl>::Create<Exchange::IMemory>(_pid);
597593
}
598594

599595
if (_interval.IsValid() == true) {
@@ -609,12 +605,6 @@ class Launcher : public PluginHost::IPlugin {
609605
}
610606
}
611607

612-
public:
613-
BEGIN_INTERFACE_MAP(Job)
614-
INTERFACE_AGGREGATE(Exchange::IMemory, _memory)
615-
END_INTERFACE_MAP
616-
617-
618608
private:
619609
bool _hasRun;
620610
uint32_t _pid;
@@ -632,6 +622,7 @@ class Launcher : public PluginHost::IPlugin {
632622
: _service(nullptr)
633623
, _closeTime(0)
634624
, _notification(this)
625+
, _memory(nullptr)
635626
, _activity()
636627
{
637628
}
@@ -645,6 +636,7 @@ class Launcher : public PluginHost::IPlugin {
645636
public:
646637
BEGIN_INTERFACE_MAP(Launcher)
647638
INTERFACE_ENTRY(PluginHost::IPlugin)
639+
INTERFACE_AGGREGATE(Exchange::IMemory, _memory)
648640
END_INTERFACE_MAP
649641

650642
public:
@@ -677,6 +669,7 @@ class Launcher : public PluginHost::IPlugin {
677669
PluginHost::IShell* _service;
678670
uint8_t _closeTime;
679671
Core::Sink<Notification> _notification;
672+
Exchange::IMemory* _memory;
680673

681674
static ProcessObserver _observer;
682675
Core::ProxyType<Job> _activity;

0 commit comments

Comments
 (0)