Skip to content

Commit

Permalink
Syncup of Metrological plugins from Metrological version: changes aft…
Browse files Browse the repository at this point in the history
…er R2 build
  • Loading branch information
HaseenaSainul committed Feb 27, 2024
1 parent 4088040 commit 186881f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 85 deletions.
1 change: 0 additions & 1 deletion LocationSync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
55 changes: 43 additions & 12 deletions LocationSync/LocationSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace Plugin {
static Core::ProxyPoolType<Web::Response> responseFactory(4);
static Core::ProxyPoolType<Web::JSONBodyType<LocationSync::Data>> jsonResponseFactory(4);

#ifdef USE_THUNDER_R4
namespace {
constexpr TCHAR FactorySetTimeZone[] = _T("Factory");
}
#endif
#ifdef __WINDOWS__
#pragma warning(disable : 4355)
#endif
Expand All @@ -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<uint16_t>(service->WebPrefix().length());
_source = config.Source.Value();
Expand All @@ -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 !!!");
Expand All @@ -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<Exchange::Controller::IConfiguration>(_T("")) ) != nullptr )
( ( controller = _service->QueryInterfaceByCallsign<Exchange::Controller::IConfiguration>(callsign) ) != nullptr )
) {
config.TimeZone = _locationinfo.TimeZone();
string newconfig;
Expand All @@ -118,7 +131,7 @@ namespace Plugin {
controller->Persist();
controller->Release();
}

#endif
_service->Release();
_service = nullptr;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -266,7 +288,9 @@ namespace Plugin {
}
_adminLock.Unlock();

#ifdef USE_THUNDER_R4
Exchange::JTimeZone::Event::TimeZoneChanged(const_cast<PluginHost::JSONRPC&>(static_cast<const PluginHost::JSONRPC&>(*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()));
}

Expand All @@ -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<int32_t>::min()) || (_locationinfo.Longitude() == std::numeric_limits<int32_t>::min()) ) {

#ifdef USE_THUNDER_R4
if ((_locationinfo.Latitude() == std::numeric_limits<int32_t>::min()) || (_locationinfo.Longitude() == std::numeric_limits<int32_t>::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);
}
Expand All @@ -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<int32_t>::min()) || (_locationinfo.Longitude() == std::numeric_limits<int32_t>::min()) ) {
if ((_locationinfo.Latitude() == std::numeric_limits<int32_t>::min()) || (_locationinfo.Longitude() == std::numeric_limits<int32_t>::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();
Expand All @@ -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
Expand Down
21 changes: 20 additions & 1 deletion LocationSync/LocationSync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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 {
Expand All @@ -198,17 +204,21 @@ namespace Plugin {
, _country()
, _region()
, _city()
#ifdef USE_THUNDER_R4
, _latitude(std::numeric_limits<int32_t>::min())
, _longitude(std::numeric_limits<int32_t>::min())
#endif
{
}
LocationInfo(int32_t latitude, int32_t longitude)
: _timeZone()
, _country()
, _region()
, _city()
#ifdef USE_THUNDER_R4
, _latitude(latitude)
, _longitude(longitude)
#endif
{
}
~LocationInfo() override = default;
Expand All @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 186881f

Please sign in to comment.