Skip to content

Commit c083469

Browse files
committed
Compiled and make it working [testing in progress]
1 parent 6de1ebe commit c083469

3 files changed

Lines changed: 57 additions & 44 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CMakeCache.txt
2+
Launcher.json
3+
Makefile
4+
cmake_install.cmake
5+
install_manifest.txt
6+
libWPEFrameworkLauncher.so

Launcher.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,30 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
8585

8686
time = Time(config.ScheduleTime.Time.Value());
8787
if (time.IsValid() != true) {
88-
SYSLOG(Trace::Warning, "Interval format is wrong");
88+
SYSLOG(Trace::Warning, (_T("Time format is wrong")));
8989
}
9090

9191
interval = Time(config.ScheduleTime.Interval.Value());
9292
if (interval.IsValid() != true) {
93-
SYSLOG(Trace::Warning, "Interval format is wrong");
93+
SYSLOG(Trace::Warning, (_T("Interval format is wrong")));
9494
}
95-
printf("%s:%s:%d %s %s\n", __FILE__, __func__, __LINE__, time.c_str(), interval.c_str());
9695
}
9796

98-
_activity = Core::ProxyType<Job>::Create(&config, interval)
99-
97+
_activity = Core::ProxyType<Job>::Create(&config, interval);
10098
if (_activity.IsValid() == true) {
101-
if (_activity->IsOperational() == true) {
99+
if (_activity->IsOperational() == false) {
102100
// Well if we where able to parse the parameters (if needed) we are ready to start it..
103101
_observer.Register(&_notification);
104102

105-
if (_time.Valid() == true) {
106-
Workerpool::Instance().Schedule(scheduledTime, _activity);
103+
if (time.IsValid() == true) {
104+
Core::Time scheduledTime(Core::Time::Now());
105+
uint64_t timeValueToTrigger = ((time.Hour() * 60 + time.Minute()) * 60 + time.Second()) * 1000;
106+
scheduledTime.Add(timeValueToTrigger);
107+
108+
PluginHost::WorkerPool::Instance().Schedule(scheduledTime, _activity);
107109
}
108110
else {
109-
Workerpool::Instance().Submit(_activity);
111+
PluginHost::WorkerPool::Instance().Submit(_activity);
110112
}
111113
}
112114
else {
@@ -132,13 +134,13 @@ SERVICE_REGISTRATION(Launcher, 1, 0);
132134
_memory = nullptr;
133135
}
134136

135-
if (_process.IsActive() == true) {
137+
if (_activity->Process().IsActive() == true) {
136138
// First try a gentle touch....
137-
_process.Kill(false);
139+
_activity->Process().Kill(false);
138140

139141
// Wait for a maximum of 3 Seconds before we shoot the process!!
140-
if (_process.WaitProcessCompleted(_closeTime * 1000) != Core::ERROR_NONE) {
141-
_process.Kill(true);
142+
if (_activity->Process().WaitProcessCompleted(_closeTime * 1000) != Core::ERROR_NONE) {
143+
_activity->Process().Kill(true);
142144
}
143145
}
144146

@@ -155,7 +157,7 @@ void Launcher::Update(const ProcessObserver::Info& info)
155157
{
156158
// This can potentially be called on a socket thread, so the deactivation (wich in turn kills this object) must be done
157159
// on a seperate thread. Also make sure this call-stack can be unwound before we are totally destructed.
158-
if ((_activity.IsValid() == true) && (_activity->Process.Pid() == info.Id()) {
160+
if ((_activity.IsValid() == true) && (_activity->Pid() == info.Id())) {
159161

160162
ASSERT(_service != nullptr);
161163

Launcher.h

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

577582
private:
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

Comments
 (0)