@@ -370,33 +370,33 @@ class Launcher : public PluginHost::IPlugin {
370370
371371 public:
372372 bool IsValid () const { return (HasSeconds () || HasMinutes () || HasHours ()); }
373- bool HasHours () const { return (_hour != static_cast < uint8_t >(~ 0 ) ); }
374- bool HasMinutes () const { return (_hour != static_cast < uint8_t >(~ 0 ) ); }
375- bool HasSeconds () const { return (_hour != static_cast < uint8_t >(~ 0 ) ); }
373+ bool HasHours () const { return (_hour < 24 ); }
374+ bool HasMinutes () const { return (_minute < 60 ); }
375+ bool HasSeconds () const { return (_second < 60 ); }
376376 uint8_t Hour () const { return _hour; }
377377 uint8_t Minute () const { return _minute; }
378378 uint8_t Second () const { return _second; }
379379
380380 private:
381381 bool Parse (const string& time) {
382382 bool status = true ;
383- printf ( " %s:%s:%d: time = %s \n " , __FILE__, __func__, __LINE__, time. c_str ()) ;
383+ string t = time;
384384
385385 // Get hours
386386 uint8_t hour;
387- string hValue = Split (time , " :" );
387+ string hValue = Split (t , " :" );
388388 status = IsValidTime (hValue, hour, 24 );
389389 if (status == true ) {
390390
391391 // Get minutes
392392 uint8_t minute;
393- string mValue = Split (time , " ." );
393+ string mValue = Split (t , " ." );
394394 status = IsValidTime (mValue , minute, 60 );
395395 if (status == true ) {
396396
397397 // Store seconds
398398 uint8_t second;
399- string sValue = time ;
399+ string sValue = t ;
400400 status = IsValidTime (sValue , second, 60 );
401401 if (status == true ) {
402402
@@ -411,7 +411,6 @@ class Launcher : public PluginHost::IPlugin {
411411 _second = second;
412412 }
413413 }
414- printf (" %s:%s:%d: HH = %s MM = %s SS = %s\n " , __FILE__, __func__, __LINE__, hValue.c_str (), mValue .c_str (), sValue .c_str ());
415414 }
416415 }
417416 return status;
@@ -426,7 +425,7 @@ class Launcher : public PluginHost::IPlugin {
426425 bool status = true ;
427426 if (IsDigit (str)) {
428427 int t = atoi (str.c_str ());
429- if (t > limit || t < 0 ) {
428+ if (t >= limit || t < 0 ) {
430429 status = false ;
431430 TRACE (Trace::Information, (_T (" Invalid time %s" ), str.c_str ()));
432431 }
@@ -448,7 +447,6 @@ class Launcher : public PluginHost::IPlugin {
448447 word = str.substr (0 , position);
449448 str = str.substr (word.size () + 1 , str.size ());
450449 }
451- printf (" %s:%s:%d: %s: %s\n " , __FILE__, __func__, __LINE__, word.c_str (), str.c_str ());
452450 return word;
453451 }
454452
@@ -458,17 +456,20 @@ class Launcher : public PluginHost::IPlugin {
458456 uint8_t _second;
459457 };
460458
461- private :
459+ public :
462460 class Job : public Core ::IDispatchType<void > {
463461 private:
464462 Job () = delete ;
465463 Job (const Job&) = delete ;
466464 Job& operator =(const Job&) = delete ;
467465
468466 public:
469- Job (Config* config const Time& interval)
467+ Job (Config* config, const Time& interval)
470468 : _hasRun(false )
469+ , _pid(0 )
471470 , _options(config->Command.Value().c_str())
471+ , _process(false )
472+ , _interval(interval)
472473 {
473474 auto iter = config->Parameters .Elements ();
474475
@@ -477,10 +478,10 @@ class Launcher : public PluginHost::IPlugin {
477478
478479 if ((element.Option .IsSet () == true ) && (element.Option .Value ().empty () == false )) {
479480 if ((element.Value .IsSet () == true ) && (element.Value .Value ().empty () == false )) {
480- options .Set (element.Option .Value (), element.Value .Value ());
481+ _options .Set (element.Option .Value (), element.Value .Value ());
481482 }
482483 else {
483- options .Set (element.Option .Value ());
484+ _options .Set (element.Option .Value ());
484485 }
485486 }
486487 }
@@ -491,29 +492,39 @@ class Launcher : public PluginHost::IPlugin {
491492
492493 public:
493494 bool IsOperational () const {
494- return ((_hasRun == false ) && (_interval.IsValid () == false ));
495+
496+ return ((_hasRun == true ) && (_interval.IsValid () == true ));
495497 }
496498 Core::Process& Process () {
497- _return (_process);
499+ return (_process);
500+ }
501+ uint32_t Pid () {
502+ return _pid;
498503 }
499504 virtual void Dispatch () override
500505 {
501506 _hasRun = true ;
502- Time time;
503- // Check if the process is not active, no need to reschedule the same job againb.
507+ // Check if the process is not active, no need to reschedule the same job again.
504508 if (_process.IsActive () == false ) {
505- printf (" %s:%s:%d: \n " , __FILE__, __func__, __LINE__);
506- _process.Launch (_options);
509+ _process.Launch (_options, &_pid);
507510 }
508- if (_interval.IsValid () == true ) {
511+
512+ if (_interval.IsValid () == true && ((_interval.Hour () != 0 ) || (_interval.Minute () != 0 ) || (_interval.Second () != 0 ))) {
509513 // Reschedule our next launch point...
510- Workerpool::Instance ().Schedule (this , CurrentTime + Interval);
514+ Core::Time scheduledTime (Core::Time::Now ());
515+ uint64_t intervalTime = ((_interval.Hour () * 60 + _interval.Minute ()) * 60 + _interval.Second ()) * 1000 ;
516+ scheduledTime.Add (intervalTime);
517+ PluginHost::WorkerPool::Instance ().Schedule (scheduledTime,Core::ProxyType<Core::IDispatch>(*this ));
518+ }
519+ else {
520+ _hasRun = false ;
511521 }
512522 }
513523
514524 private:
515525 bool _hasRun;
516- Core::Process::Options _options (config.Command.Value().c_str());
526+ uint32_t _pid;
527+ Core::Process::Options _options;
517528 Core::Process _process;
518529 Time _interval;
519530 };
@@ -524,15 +535,9 @@ class Launcher : public PluginHost::IPlugin {
524535#endif
525536 Launcher ()
526537 : _service(nullptr )
527- , _process(false )
528- , _pid(0 )
529538 , _closeTime(0 )
530539 , _notification(this )
531540 , _memory(nullptr )
532- , _time()
533- , _interval()
534- , _options(nullptr )
535- , _client(this )
536541 , _activity()
537542 {
538543 }
@@ -576,12 +581,12 @@ class Launcher : public PluginHost::IPlugin {
576581
577582private:
578583 PluginHost::IShell* _service;
579- uint32_t _pid;
580584 uint8_t _closeTime;
581585 Core::Sink<Notification> _notification;
582586 Exchange::IMemory* _memory;
583587
584588 static ProcessObserver _observer;
589+ Core::ProxyType<Job> _activity;
585590};
586591
587592} // namespace Plugin
0 commit comments