11#include " Launcher.h"
22
33namespace WPEFramework {
4+
45namespace Plugin {
56
67SERVICE_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
0 commit comments