@@ -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+
268325public:
269326 class Config : public Core ::JSON::Container {
270327 private:
@@ -478,7 +535,7 @@ class Launcher : public PluginHost::IPlugin {
478535 };
479536
480537public:
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 {
575645public:
576646 BEGIN_INTERFACE_MAP (Launcher)
577647 INTERFACE_ENTRY (PluginHost::IPlugin)
578- INTERFACE_AGGREGATE (Exchange::IMemory, _memory)
579648 END_INTERFACE_MAP
580649
581650public:
@@ -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