diff --git a/LocationSync/CMakeLists.txt b/LocationSync/CMakeLists.txt index 134da4dd6e..2c42097e08 100644 --- a/LocationSync/CMakeLists.txt +++ b/LocationSync/CMakeLists.txt @@ -43,7 +43,6 @@ add_library(${MODULE_NAME} SHARED set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) - target_compile_options (${MODULE_NAME} PRIVATE -Wno-psabi) target_link_libraries(${MODULE_NAME} diff --git a/LocationSync/LocationSync.cpp b/LocationSync/LocationSync.cpp index ed16939308..39d7377d03 100644 --- a/LocationSync/LocationSync.cpp +++ b/LocationSync/LocationSync.cpp @@ -31,6 +31,11 @@ namespace Plugin { static Core::ProxyPoolType responseFactory(4); static Core::ProxyPoolType> jsonResponseFactory(4); +#ifdef USE_THUNDER_R4 + namespace { + constexpr TCHAR FactorySetTimeZone[] = _T("Factory"); + } +#endif #ifdef __WINDOWS__ #pragma warning(disable : 4355) #endif @@ -57,16 +62,18 @@ namespace Plugin { config.FromString(service->ConfigLine()); if (LocationService::IsSupported(config.Source.Value()) == Core::ERROR_NONE) { - if( ( config.TimeZone.IsSet() == true ) && ( config.TimeZone.Value().empty() == false ) ) { + if ((config.TimeZone.IsSet() == true) && (config.TimeZone.Value().empty() == false)) { _locationinfo.TimeZone(config.TimeZone.Value()); _timezoneoverriden = true; UpdateSystemTimeZone(config.TimeZone.Value()); } - if( ( config.Latitude.IsSet() == true ) && ( config.Longitude.IsSet() == true ) ) { +#ifdef USE_THUNDER_R4 + if ((config.Latitude.IsSet() == true) && (config.Longitude.IsSet() == true)) { _locationinfo.Latitude(config.Latitude.Value()); _locationinfo.Longitude(config.Longitude.Value()); } +#endif _skipURL = static_cast(service->WebPrefix().length()); _source = config.Source.Value(); @@ -77,7 +84,9 @@ namespace Plugin { _sink.Initialize(config.Source.Value(), config.Interval.Value(), config.Retries.Value()); RegisterAll(); +#ifdef USE_THUNDER_R4 Exchange::JTimeZone::Register(*this, this); +#endif } else { result = _T("URL for retrieving location is incorrect !!!"); @@ -99,17 +108,21 @@ namespace Plugin { ASSERT(_service == service); UnregisterAll(); +#ifdef USE_THUNDER_R4 Exchange::JTimeZone::Unregister(*this); +#endif _sink.Deinitialize(); Config config; config.FromString(_service->ConfigLine()); +#ifdef USE_THUNDER_R4 Exchange::Controller::IConfiguration* controller = nullptr; + string callsign = _T(""); if ( (_timezoneoverriden == true) && ( _locationinfo.TimeZone() != config.TimeZone.Value() ) && - ( ( controller = _service->QueryInterfaceByCallsign(_T("")) ) != nullptr ) + ( ( controller = _service->QueryInterfaceByCallsign(callsign) ) != nullptr ) ) { config.TimeZone = _locationinfo.TimeZone(); string newconfig; @@ -118,7 +131,7 @@ namespace Plugin { controller->Persist(); controller->Release(); } - +#endif _service->Release(); _service = nullptr; } @@ -218,13 +231,22 @@ namespace Plugin { return Core::ERROR_NONE; } - uint32_t LocationSync::TimeZone(string& timeZone /* @out */) const { +#ifdef USE_THUNDER_R4 + uint32_t LocationSync::TimeZone(string& timeZone) const +#else + uint32_t LocationSync::GetTimeZone(string& timeZone) const +#endif + { timeZone = CurrentTimeZone(); return Core::ERROR_NONE; } - uint32_t LocationSync::TimeZone(const string& timeZone) { - +#ifdef USE_THUNDER_R4 + uint32_t LocationSync::TimeZone(const string& timeZone) +#else + uint32_t LocationSync::SetTimeZone(const string& timeZone) +#endif + { _adminLock.Lock(); _timezoneoverriden = true; @@ -266,7 +288,9 @@ namespace Plugin { } _adminLock.Unlock(); +#ifdef USE_THUNDER_R4 Exchange::JTimeZone::Event::TimeZoneChanged(const_cast(static_cast(*this)), timezone); +#endif SYSLOG(Logging::Startup, (_T("TimeZone change to \"%s\", local date time is now %s."), timezone.c_str(), Core::Time::Now().ToRFC1123(true).c_str())); } @@ -289,14 +313,17 @@ namespace Plugin { if ((_sink.Location() != nullptr) && (_sink.Valid() == true)) { // _sink.Location() != nullptr basically is always true string newtimezone; _adminLock.Lock(); - if( (_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min()) ) { + +#ifdef USE_THUNDER_R4 + if ((_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min())) { _locationinfo.Latitude(_sink.Location()->Latitude()); _locationinfo.Longitude(_sink.Location()->Longitude()); } +#endif _locationinfo.Country(_sink.Location()->Country()); _locationinfo.Region(_sink.Location()->Region()); _locationinfo.City(_sink.Location()->City()); - if( (_sink.Location()->TimeZone().empty() == false) && (_timezoneoverriden == false) ) { + if ((_sink.Location()->TimeZone().empty() == false) && (_timezoneoverriden == false)) { newtimezone = _sink.Location()->TimeZone(); _locationinfo.TimeZone(newtimezone); } @@ -306,21 +333,23 @@ namespace Plugin { UpdateSystemTimeZone(newtimezone); NotifyTimeZoneChanged(newtimezone); } +#ifdef USE_THUNDER_R4 } else { _adminLock.Lock(); // if they are not overriden in the config and we cannot get them from the lookup, set them to default - if( (_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min()) ) { + if ((_locationinfo.Latitude() == std::numeric_limits::min()) || (_locationinfo.Longitude() == std::numeric_limits::min())) { _locationinfo.Latitude(51977956); _locationinfo.Longitude(5726384); } _adminLock.Unlock(); +#endif } PluginHost::ISubSystem* subSystem = _service->SubSystems(); ASSERT(subSystem != nullptr); if (subSystem != nullptr) { - if( (_activateOnFailure == true) || (_sink.Location() == nullptr) || ( _sink.Valid() == true ) ) { // again _sink.Location() == nullptr should not happen but added to make it backards compatibe + if ((_activateOnFailure == true) || (_sink.Location() == nullptr) || ( _sink.Valid() == true )) { // again _sink.Location() == nullptr should not happen but added to make it backards compatibe subSystem->Set(PluginHost::ISubSystem::INTERNET, _sink.Network()); SetLocationSubsystem(*subSystem, false); event_locationchange(); @@ -334,9 +363,11 @@ namespace Plugin { void LocationSync::UpdateSystemTimeZone(const string& newtimezone) { - if( newtimezone != FactorySetTimeZone ) { +#ifdef USE_THUNDER_R4 + if (newtimezone != FactorySetTimeZone) { Core::SystemInfo::Instance().SetTimeZone(newtimezone, false); } +#endif } } // namespace Plugin diff --git a/LocationSync/LocationSync.h b/LocationSync/LocationSync.h index ad5728f1f9..b580c7bef9 100644 --- a/LocationSync/LocationSync.h +++ b/LocationSync/LocationSync.h @@ -161,16 +161,20 @@ namespace Plugin { , ActivateOnFailure(true) // as in some cases startup of the system depends on the Internet and Locatioin subsystems to be flagged this enables the activation of these subsystems even though probing was unsuccesfull (and for backward compatibility it is even the default) , Source() , TimeZone() +#ifdef USE_THUNDER_R4 , Latitude(51977956) // Divider 1.000.000 , Longitude(5726384) // Divider 1.000.000 +#endif { Add(_T("interval"), &Interval); Add(_T("retries"), &Retries); Add(_T("activateonfailure"), &ActivateOnFailure); Add(_T("source"), &Source); Add(_T("timezone"), &TimeZone); +#ifdef USE_THUNDER_R4 Add(_T("latitude"), &Latitude); Add(_T("longitude"), &Longitude); +#endif } ~Config() { @@ -182,8 +186,10 @@ namespace Plugin { Core::JSON::Boolean ActivateOnFailure; // as in some cases startup of the system depends on the Internet and Locatioin subsystems to be flagged this enables the activation of these subsystems even though probing was unsuccesfull (and for backward compatibility it is even the default) Core::JSON::String Source; Core::JSON::String TimeZone; +#ifdef USE_THUNDER_R4 Core::JSON::DecSInt32 Latitude; Core::JSON::DecSInt32 Longitude; +#endif }; class LocationInfo : public PluginHost::ISubSystem::ILocation { @@ -198,8 +204,10 @@ namespace Plugin { , _country() , _region() , _city() +#ifdef USE_THUNDER_R4 , _latitude(std::numeric_limits::min()) , _longitude(std::numeric_limits::min()) +#endif { } LocationInfo(int32_t latitude, int32_t longitude) @@ -207,8 +215,10 @@ namespace Plugin { , _country() , _region() , _city() +#ifdef USE_THUNDER_R4 , _latitude(latitude) , _longitude(longitude) +#endif { } ~LocationInfo() override = default; @@ -227,18 +237,22 @@ namespace Plugin { void Region(const string& region) { _region = region; } string City() const override { return _city; } void City(const string& city) { _city = city; } - int32_t Latitude() const override { return _latitude; } +#ifdef USE_THUNDER_R4 void Latitude(const int32_t latitude) { _latitude = latitude; } + int32_t Latitude() const override { return _latitude; } int32_t Longitude() const override { return _longitude; } void Longitude(const int32_t longitude) { _longitude = longitude; } +#endif private: string _timeZone; string _country; string _region; string _city; +#ifdef USE_THUNDER_R4 int32_t _latitude; int32_t _longitude; +#endif }; public: @@ -272,8 +286,13 @@ namespace Plugin { // ------------------------------------------------------------------------------------------------------- uint32_t Register(ITimeZone::INotification* sink) override ; uint32_t Unregister(ITimeZone::INotification* sink) override; +#ifdef USE_THUNDER_R4 uint32_t TimeZone(string& timeZone ) const override; uint32_t TimeZone(const string& timeZone) override; +#else + uint32_t GetTimeZone(string& timeZone) const override; + uint32_t SetTimeZone(const string& timeZone) override; +#endif private: string CurrentTimeZone() const; diff --git a/Monitor/Monitor.h b/Monitor/Monitor.h index 1d2ba53b86..c9ca2515fc 100644 --- a/Monitor/Monitor.h +++ b/Monitor/Monitor.h @@ -584,7 +584,11 @@ namespace Plugin { Core::ProxyType source; _adminLock.Lock(); if(_source != nullptr) { +#ifdef USE_THUNDER_R4 source = Core::ProxyType(*_source, *_source); +#else + source = Core::ProxyType(*_source); +#endif } _adminLock.Unlock(); return source; @@ -742,58 +746,9 @@ namespace Plugin { _service->Release(); _service = nullptr; } - void Activated (const string& callsign, PluginHost::IShell* service) override - { - MonitorObjectContainer::iterator index(_monitor.find(callsign)); - - if (index != _monitor.end()) { - - index->second.Active(true); - - // Get the MetaData interface - Exchange::IMemory* memory = service->QueryInterface(); - - if (memory != nullptr) { - index->second.Set(memory); - memory->Release(); - } - - if (_job.Submit() == true) { - TRACE(Trace::Information, (_T("Starting to probe as active observee appeared."))); - } - } - } - void Deactivated (const string& callsign, PluginHost::IShell* service) override - { - - MonitorObjectContainer::iterator index(_monitor.find(callsign)); - - if (index != _monitor.end()) { - - index->second.Set(nullptr); - index->second.Active(false); - - PluginHost::IShell::reason reason = service->Reason(); - if ((index->second.HasRestartAllowed() == true) && ((reason == PluginHost::IShell::MEMORY_EXCEEDED) || (reason == PluginHost::IShell::FAILURE))) { - if (index->second.RegisterRestart(reason) == false) { - uint8_t restartlimit = index->second.RestartLimit(); - uint16_t restartwindow = index->second.RestartWindow(); - TRACE(Trace::Fatal, (_T("Giving up restarting of %s: Failed more than %d times within %d seconds."), callsign.c_str(), restartlimit, restartwindow)); - const string message("{\"callsign\": \"" + callsign + "\", \"action\": \"Restart\", \"reason\":\"" + (std::to_string(restartlimit)).c_str() + " Attempts Failed within the restart window\"}"); - _service->Notify(message); - _parent.event_action(callsign, "StoppedRestaring", std::to_string(index->second.RestartLimit()) + " attempts failed within the restart window"); - } else { - const string message("{\"callsign\": \"" + callsign + "\", \"action\": \"Activate\", \"reason\": \"Automatic\" }"); - _service->Notify(message); - _parent.event_action(callsign, "Activate", "Automatic"); - TRACE(Trace::Error, (_T("Restarting %s again because we detected it misbehaved."), callsign.c_str())); - Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(service, PluginHost::IShell::ACTIVATED, PluginHost::IShell::AUTOMATIC)); - } - } - } - } - virtual void StateChange(PluginHost::IShell* service) +#ifndef USE_THUNDER_R4 + void StateChange(PluginHost::IShell* service) override { MonitorObjectContainer::iterator index(_monitor.find(service->Callsign())); @@ -806,7 +761,7 @@ namespace Plugin { if (currentState == PluginHost::IShell::ACTIVATED) { bool is_active = index->second.IsActive(); index->second.Active(true); - if (is_active == false && std::count_if(_monitor.begin(), _monitor.end(), [](const std::pair& v) { + if (is_active == false && std::count_if(_monitor.begin(), _monitor.end(), [](const std::pair& v) { return v.second.IsActive(); }) == 1) { @@ -814,11 +769,7 @@ namespace Plugin { // Moreover it's the only only which now becomes active. This means probing // has to be activated as well since it was stopped at point the last observee // turned inactive -#ifdef USE_THUNDER_R4 - _job.Reschedule(Core::Time::Now()); -#else _job.Schedule(Core::Time::Now()); -#endif /* USE_THUNDER_R4 */ TRACE(Trace::Information, (_T("Starting to probe as active observee appeared."))); } @@ -856,28 +807,58 @@ namespace Plugin { } } } - } -#if (THUNDER_VERSION_MAJOR >= 4) -#if (THUNDER_VERSION_MINOR == 2) - void Activation(const string& name, PluginHost::IShell* service) override - { - StateChange(service); - } - - void Deactivation(const string& name, PluginHost::IShell* service) override - { - StateChange(service); - } -#endif +#else void Activated (const string& callsign, PluginHost::IShell* service) override { - StateChange(service); + MonitorObjectContainer::iterator index(_monitor.find(callsign)); + + if (index != _monitor.end()) { + + index->second.Active(true); + + // Get the MetaData interface + Exchange::IMemory* memory = service->QueryInterface(); + + if (memory != nullptr) { + index->second.Set(memory); + memory->Release(); + } + + if (_job.Submit() == true) { + TRACE(Trace::Information, (_T("Starting to probe as active observee appeared."))); + } + } } void Deactivated (const string& callsign, PluginHost::IShell* service) override { - StateChange(service); + MonitorObjectContainer::iterator index(_monitor.find(callsign)); + + if (index != _monitor.end()) { + + index->second.Set(nullptr); + index->second.Active(false); + + PluginHost::IShell::reason reason = service->Reason(); + + if ((index->second.HasRestartAllowed() == true) && ((reason == PluginHost::IShell::MEMORY_EXCEEDED) || (reason == PluginHost::IShell::FAILURE))) { + if (index->second.RegisterRestart(reason) == false) { + uint8_t restartlimit = index->second.RestartLimit(); + uint16_t restartwindow = index->second.RestartWindow(); + TRACE(Trace::Fatal, (_T("Giving up restarting of %s: Failed more than %d times within %d seconds."), callsign.c_str(), restartlimit, restartwindow)); + const string message("{\"callsign\": \"" + callsign + "\", \"action\": \"Restart\", \"reason\":\"" + (std::to_string(restartlimit)).c_str() + " Attempts Failed within the restart window\"}"); + _service->Notify(message); + _parent.event_action(callsign, "StoppedRestaring", std::to_string(index->second.RestartLimit()) + " attempts failed within the restart window"); + } else { + const string message("{\"callsign\": \"" + callsign + "\", \"action\": \"Activate\", \"reason\": \"Automatic\" }"); + _service->Notify(message); + _parent.event_action(callsign, "Activate", "Automatic"); + TRACE(Trace::Error, (_T("Restarting %s again because we detected it misbehaved."), callsign.c_str())); + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(service, PluginHost::IShell::ACTIVATED, PluginHost::IShell::AUTOMATIC)); + } + } + } } void Unavailable(const string&, PluginHost::IShell*) override { diff --git a/PlayerInfo/PlayerInfo.h b/PlayerInfo/PlayerInfo.h index d5197509ca..c57ca1e167 100644 --- a/PlayerInfo/PlayerInfo.h +++ b/PlayerInfo/PlayerInfo.h @@ -50,9 +50,11 @@ namespace Plugin { { _parent.Deactivated(connection); } +#ifdef USE_THUNDER_R4 void Terminated(RPC::IRemoteConnection* /* connection */) override { } +#endif BEGIN_INTERFACE_MAP(Notification) INTERFACE_ENTRY(RPC::IRemoteConnection::INotification)