Skip to content

Commit ac6b868

Browse files
committed
[OBSERVER] Add a memory observing interface so the object can be monitored (by the MonitorPlugin)
1 parent 94e4d81 commit ac6b868

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Launcher.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
#include "Launcher.h"
22

33
namespace WPEFramework {
4+
45
namespace Plugin {
56

67
SERVICE_REGISTRATION(Launcher, 1, 0);
78

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

1069
/* virtual */ const string Launcher::Initialize(PluginHost::IShell* service)
@@ -13,6 +72,7 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
1372
Config config;
1473

1574
ASSERT(_service == nullptr);
75+
ASSERT(_memory == nullptr);
1676

1777
// Setup skip URL for right offset.
1878
_service = service;
@@ -45,16 +105,25 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
45105
_observer.Unregister(&_notification);
46106
message = _T("Could not spawn the requested app/script [") + config.Command.Value() + ']';
47107
}
108+
else {
109+
_memory = Core::Service<MemoryObserverImpl>::Create<Exchange::IMemory>(_pid);
110+
}
48111

49112
return (message);
50113
}
51114

52115
/* virtual */ void Launcher::Deinitialize(PluginHost::IShell* service)
53116
{
54117
ASSERT(_service == service);
118+
ASSERT(_memory != nullptr);
55119

56120
_observer.Unregister(&_notification);
57121

122+
if (_memory != nullptr) {
123+
_memory->Release();
124+
_memory = nullptr;
125+
}
126+
58127
if (_process.IsActive() == true) {
59128
// First try a gentle touch....
60129
_process.Kill(false);
@@ -94,5 +163,7 @@ void Launcher::Update(const ProcessObserver::Info& info)
94163
}
95164
}
96165

166+
97167
} //namespace Plugin
168+
98169
} // namespace WPEFramework

Launcher.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "Module.h"
4+
#include <interfaces/IMemory.h>
45
#include <linux/cn_proc.h>
56

67
namespace WPEFramework {
@@ -322,6 +323,7 @@ class Launcher : public PluginHost::IPlugin {
322323
, _pid(0)
323324
, _closeTime(0)
324325
, _notification(this)
326+
, _memory(nullptr)
325327
{
326328
}
327329
#ifdef __WIN32__
@@ -334,6 +336,7 @@ class Launcher : public PluginHost::IPlugin {
334336
public:
335337
BEGIN_INTERFACE_MAP(Launcher)
336338
INTERFACE_ENTRY(PluginHost::IPlugin)
339+
INTERFACE_AGGREGATE(Exchange::IMemory, _memory)
337340
END_INTERFACE_MAP
338341

339342
public:
@@ -366,6 +369,7 @@ class Launcher : public PluginHost::IPlugin {
366369
uint32_t _pid;
367370
uint8_t _closeTime;
368371
Core::Sink<Notification> _notification;
372+
Exchange::IMemory* _memory;
369373

370374
static ProcessObserver _observer;
371375
};

0 commit comments

Comments
 (0)