Skip to content

Commit

Permalink
Merge pull request #80 from Wolkabout/feature/details-gateway-synchro…
Browse files Browse the repository at this point in the history
…nization

Addition of `device_synchronization` and `children_synchronization`.
  • Loading branch information
nanavuletic authored Feb 25, 2022
2 parents 1a6b319 + fef76f6 commit 1127515
Show file tree
Hide file tree
Showing 29 changed files with 1,633 additions and 235 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
- name: Run Tests
working-directory: ${{runner.workspace}}/out
shell: bash
run: make test -j$(nproc) && ctest .
run: ctest .
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ find_package(Threads REQUIRED)
# Bring in WolkSDK-Cpp
if (NOT TARGET WolkAboutCore)
set(BUILD_CONNECTIVITY ON CACHE BOOL "Build the library with Paho MQTT and allow MQTT connection to the platform.")
set(BUILD_EXAMPLES OFF CACHE BOOL "Build the examples/runtimes for testing")
set(BUILD_POCO OFF CACHE BOOL "Build the library with Poco.")
set(BUILD_GTEST ${BUILD_TESTS} CACHE BOOL "Build the library with GTest.")
set(BUILD_AWS_LOG_UPLOADER OFF CACHE BOOL "Build the library with AwsLogUploader.")
Expand All @@ -99,6 +100,7 @@ endif ()

# WolkGateway library
set(LIB_SOURCE_FILES gateway/connectivity/GatewayMessageRouter.cpp
gateway/repository/DeviceOwnership.cpp
gateway/repository/existing_device/JsonFileExistingDevicesRepository.cpp
gateway/repository/device/InMemoryDeviceRepository.cpp
gateway/repository/device/SQLiteDeviceRepository.cpp
Expand All @@ -111,6 +113,8 @@ set(LIB_SOURCE_FILES gateway/connectivity/GatewayMessageRouter.cpp
set(LIB_HEADER_FILES gateway/api/DataHandler.h
gateway/api/DataProvider.h
gateway/connectivity/GatewayMessageRouter.h
gateway/repository/DeviceFilter.h
gateway/repository/DeviceOwnership.h
gateway/repository/device/DeviceRepository.h
gateway/repository/existing_device/ExistingDevicesRepository.h
gateway/repository/existing_device/JsonFileExistingDevicesRepository.h
Expand All @@ -134,7 +138,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${WOLKGATEWAY_VERSION_STRING} SOVERSION ${WOLKGATEWAY_VERSION_MAJOR}.${WOLKGATEWAY_VERSION_MINOR}.${WOLKGATEWAY_VERSION_PATCH})

# Create the install rule
install(DIRECTORY ${CMAKE_LIBRARY_INCLUDE_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/include PATTERN *.h)
install(DIRECTORY ${CMAKE_LIBRARY_INCLUDE_DIRECTORY} DESTINATION ${CMAKE_INSTALL_PREFIX} PATTERN *.h)
install(DIRECTORY ${CMAKE_PREFIX_PATH}/include DESTINATION ${CMAKE_INSTALL_PREFIX} PATTERN *.h)
install(DIRECTORY ${CMAKE_PREFIX_PATH}/lib/ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
Expand Down
2 changes: 1 addition & 1 deletion WolkConnect-Cpp
Submodule WolkConnect-Cpp updated 38 files
+2 −2 .github/workflows/cmake-build-and-test.yml
+1 −1 WolkSDK-Cpp
+1 −1 configure.sh
+5 −1 debian/rules
+32 −4 examples/full_feature/Application.cpp
+0 −0 examples/full_feature/wolkconnect_full_feature_set.json
+0 −0 examples/pull/wolkconnect_full_feature_set.json
+1 −1 examples/register_feed_and_attribute/Application.cpp
+1 −1 examples/simple/Application.cpp
+0 −0 examples/simple/wolkconnect_simple.json
+4 −9 examples/subdevices/Application.cpp
+1 −1 out/coverage.sh
+127 −6 tests/DataServiceTests.cpp
+5 −0 tests/ErrorServiceTests.cpp
+17 −3 tests/FileManagementServiceTests.cpp
+8 −1 tests/FirmwareUpdateServiceTests.cpp
+170 −107 tests/RegistrationServiceTests.cpp
+1 −5 tests/WolkBuilderTests.cpp
+44 −36 tests/WolkMultiTests.cpp
+72 −4 tests/WolkSingleTests.cpp
+7 −2 tests/mocks/DataServiceMock.h
+9 −7 tests/mocks/RegistrationServiceMock.h
+1 −5 tools/make_deb.sh
+27 −13 wolk/WolkBuilder.cpp
+3 −3 wolk/WolkBuilder.h
+4 −0 wolk/WolkInterface.cpp
+4 −0 wolk/WolkInterface.h
+40 −58 wolk/WolkMulti.cpp
+14 −25 wolk/WolkMulti.h
+34 −16 wolk/WolkSingle.cpp
+7 −34 wolk/WolkSingle.h
+95 −21 wolk/service/data/DataService.cpp
+16 −2 wolk/service/data/DataService.h
+22 −26 wolk/service/firmware_update/FirmwareUpdateService.cpp
+1 −1 wolk/service/platform_status/PlatformStatusService.cpp
+2 −2 wolk/service/platform_status/PlatformStatusService.h
+267 −66 wolk/service/registration_service/RegistrationService.cpp
+89 −20 wolk/service/registration_service/RegistrationService.h
4 changes: 3 additions & 1 deletion application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ int main(int argc, char** argv)
.withFileTransfer("./files")
.setMqttKeepAlive(gatewayConfiguration.getKeepAliveSec())
.platformHost(gatewayConfiguration.getPlatformMqttUri())
.withInternalDataService(gatewayConfiguration.getLocalMqttUri()));
.withInternalDataService(gatewayConfiguration.getLocalMqttUri())
.withPlatformRegistration()
.withLocalRegistration());
if (!gatewayConfiguration.getPlatformTrustStore().empty())
{
builder.platformTrustStore(gatewayConfiguration.getPlatformTrustStore());
Expand Down
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ cp tools/git/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

pushd out
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DBUILD_GTEST=OFF -DBUILD_TESTS=OFF -DBUILD_POCO_HTTP_DOWNLOADER=OFF -DBUILD_EXAMPLES=OFF ..
popd
7 changes: 4 additions & 3 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
wolkgateway (4.4.0) stable; urgency=medium
wolkgateway (5.0.0-prerelease) stable; urgency=medium

* Completely removed `libpoco` as a dependency, and now rely on `sqlite` for SQLiteDeviceRepository.
* Updated the WolkGateway to be ready for Wolkabout IoT Platform 22.GA - The Digital Twin Update
* Fixed the CMakeLists.txt file for private header file finding to use project files in private

-- Wolkabout ELab <elab@wolkabout.com> Wed, 22 Dec 2021 00:00:00 +0100
-- Wolkabout ELab <elab@wolkabout.com> Tue, 22 Feb 2022 14:22:00 +0100
2 changes: 2 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ DH_VERBOSE = 1

%:
dh $@ --builddirectory=out
override_dh_auto_configure:
dh_auto_configure -- -DBUILD_GTEST=OFF -DBUILD_TESTS=OFF -DBUILD_POCO_HTTP_DOWNLOADER=OFF -DBUILD_EXAMPLES=OFF
override_dh_auto_clean:
override_dh_auto_test:
override_dh_shlibdeps:
Expand Down
3 changes: 3 additions & 0 deletions gateway/WolkGateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "core/utilities/Logger.h"
#include "gateway/connectivity/GatewayMessageRouter.h"
#include "gateway/repository/device/DeviceRepository.h"
#include "gateway/repository/device/InMemoryDeviceRepository.h"
#include "gateway/repository/existing_device/ExistingDevicesRepository.h"
#include "gateway/service/devices/DevicesService.h"
#include "gateway/service/external_data/ExternalDataService.h"
Expand Down Expand Up @@ -134,6 +135,8 @@ void WolkGateway::notifyPlatformConnected()
LOG(INFO) << "Connection to platform established";

WolkSingle::notifyConnected();
if (m_cacheDeviceRepository != nullptr)
m_cacheDeviceRepository->loadInformationFromPersistentRepository();
if (m_subdeviceManagementService != nullptr)
m_subdeviceManagementService->updateDeviceCache();
if (m_gatewayPlatformStatusService != nullptr)
Expand Down
7 changes: 4 additions & 3 deletions gateway/WolkGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ class RegistrationService;
namespace gateway
{
class DeviceRepository;
class ExternalDataService;
class ExistingDevicesRepository;
class GatewayMessageRouter;
class ExternalDataService;
class InMemoryDeviceRepository;
class InternalDataService;
class GatewayPlatformStatusService;
class DevicesService;
Expand Down Expand Up @@ -147,9 +148,9 @@ class WolkGateway : public connect::WolkSingle

std::atomic<bool> m_localConnected;

std::shared_ptr<DeviceRepository> m_cacheDeviceRepository;
std::shared_ptr<InMemoryDeviceRepository> m_cacheDeviceRepository;
std::shared_ptr<DeviceRepository> m_persistentDeviceRepository;
std::unique_ptr<ExistingDevicesRepository> m_existingDevicesRepository;
std::shared_ptr<ExistingDevicesRepository> m_existingDevicesRepository;

// Local connectivity stack
std::shared_ptr<ConnectivityService> m_localConnectivityService;
Expand Down
23 changes: 19 additions & 4 deletions gateway/WolkGatewayBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ WolkGatewayBuilder::WolkGatewayBuilder(Device device)
, m_existingDeviceRepository{new JsonFileExistingDevicesRepository}
, m_dataProtocol{new WolkaboutDataProtocol}
, m_errorProtocol{new WolkaboutErrorProtocol}
, m_errorRetainTime{std::chrono::seconds{1}}
, m_errorRetainTime{1}
, m_platformSubdeviceProtocol{new WolkaboutGatewaySubdeviceProtocol}
, m_localSubdeviceProtocol{new WolkaboutGatewaySubdeviceProtocol(false)}
, m_platformRegistrationProtocol{new WolkaboutRegistrationProtocol}
Expand Down Expand Up @@ -271,9 +271,14 @@ std::unique_ptr<WolkGateway> WolkGatewayBuilder::build()

// Move the repository objects
if (m_deviceStoragePolicy == DeviceStoragePolicy::PERSISTENT || m_deviceStoragePolicy == DeviceStoragePolicy::FULL)
{
wolk->m_persistentDeviceRepository = std::make_shared<SQLiteDeviceRepository>();
wolk->m_existingDevicesRepository = std::make_shared<JsonFileExistingDevicesRepository>();
}
if (m_deviceStoragePolicy == DeviceStoragePolicy::CACHED || m_deviceStoragePolicy == DeviceStoragePolicy::FULL)
{
wolk->m_cacheDeviceRepository = std::make_shared<InMemoryDeviceRepository>(wolk->m_persistentDeviceRepository);
}
wolk->m_existingDevicesRepository = std::move(m_existingDeviceRepository);

// Create the platform connection
Expand Down Expand Up @@ -309,12 +314,22 @@ std::unique_ptr<WolkGateway> WolkGatewayBuilder::build()
wolk->m_parameterLambda = m_parameterHandlerLambda;
wolk->m_parameterHandler = m_parameterHandler;
wolk->m_dataService = std::make_shared<connect::DataService>(
*wolk->m_dataProtocol, *wolk->m_persistence, *wolk->m_connectivityService,
*wolk->m_dataProtocol, *wolk->m_persistence, *wolk->m_connectivityService, *wolk->m_outboundRetryMessageHandler,
[wolkRaw](const std::string& deviceKey, const std::map<std::uint64_t, std::vector<Reading>>& readings) {
wolkRaw->handleFeedUpdateCommand(deviceKey, readings);
},
[wolkRaw](const std::string& deviceKey, const std::vector<Parameter>& parameters) {
wolkRaw->handleParameterCommand(deviceKey, parameters);
},
[](const std::string& deviceKey, const std::vector<std::string>& feeds,
const std::vector<std::string>& attributes) {
LOG(DEBUG) << "Received details for device '" << deviceKey << "':";
LOG(DEBUG) << "Feeds: ";
for (const auto& feed : feeds)
LOG(DEBUG) << "\t" << feed;
LOG(DEBUG) << "Attributes: ";
for (const auto& attribute : attributes)
LOG(DEBUG) << "\t" << attribute;
});
wolk->m_errorService = std::make_shared<connect::ErrorService>(*wolk->m_errorProtocol, m_errorRetainTime);
wolk->m_inboundMessageHandler->addListener(wolk->m_dataService);
Expand Down Expand Up @@ -418,8 +433,8 @@ std::unique_ptr<WolkGateway> WolkGatewayBuilder::build()
wolk->m_subdeviceManagementService = std::make_shared<DevicesService>(
m_device.getKey(), *wolk->m_platformRegistrationProtocol, *wolk->m_outboundMessageHandler,
*wolk->m_outboundRetryMessageHandler, wolk->m_localRegistrationProtocol, wolk->m_localOutboundMessageHandler,
wolk->m_cacheDeviceRepository != nullptr ? wolk->m_cacheDeviceRepository :
wolk->m_persistentDeviceRepository);
wolk->m_cacheDeviceRepository != nullptr ? wolk->m_cacheDeviceRepository : wolk->m_persistentDeviceRepository,
wolk->m_existingDevicesRepository);
wolk->m_gatewayMessageRouter->addListener("SubdeviceManagement", wolk->m_subdeviceManagementService);
if (wolk->m_localConnectivityService != nullptr && wolk->m_localRegistrationProtocol != nullptr)
wolk->m_localInboundMessageHandler->addListener(wolk->m_subdeviceManagementService);
Expand Down
49 changes: 49 additions & 0 deletions gateway/repository/DeviceFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2022 Wolkabout Technology s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef WOLKGATEWAY_DEVICEFILTER_H
#define WOLKGATEWAY_DEVICEFILTER_H

#include <string>

namespace wolkabout
{
namespace gateway
{
/**
* This interface defines an object that is capable of filtering through devices that actually exist and can have data
* sent about them, and the ones that can not.
*/
class DeviceFilter
{
public:
/**
* Default virtual destructor.
*/
virtual ~DeviceFilter() = default;

/**
* This is the filtration method that determines whether information about device exists, or not.
*
* @param deviceKey The key of the device.
* @return Whether the device exists or not.
*/
virtual bool deviceExists(const std::string& deviceKey) = 0;
};
} // namespace gateway
} // namespace wolkabout

#endif // WOLKGATEWAY_DEVICEFILTER_H
45 changes: 45 additions & 0 deletions gateway/repository/DeviceOwnership.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2022 Wolkabout Technology s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "gateway/repository/DeviceOwnership.h"

namespace wolkabout
{
namespace gateway
{
std::string toString(DeviceOwnership deviceOwnership)
{
switch (deviceOwnership)
{
case DeviceOwnership::Platform:
return "Platform";
case DeviceOwnership::Gateway:
return "Gateway";
default:
return {};
}
}

DeviceOwnership deviceOwnershipFromString(const std::string& value)
{
if (value == "Platform")
return DeviceOwnership::Platform;
else if (value == "Gateway")
return DeviceOwnership::Gateway;
return DeviceOwnership::None;
}
} // namespace gateway
} // namespace wolkabout
52 changes: 52 additions & 0 deletions gateway/repository/DeviceOwnership.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2022 Wolkabout Technology s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef WOLKGATEWAY_DEVICEOWNERSHIP_H
#define WOLKGATEWAY_DEVICEOWNERSHIP_H

#include <string>

namespace wolkabout
{
namespace gateway
{
// This enum value describes who the device belongs to.
enum class DeviceOwnership
{
None = -1,
Platform,
Gateway
};

/**
* This is a utility method that is used to convert the enumeration value into a string.
*
* @param deviceOwnership The DeviceOwnership value.
* @return The string representation of the value.
*/
std::string toString(DeviceOwnership deviceOwnership);

/**
* This is a utility method that is used to convert a string into the enumeration value.
*
* @param value A string value.
* @return A DeviceOwnership value. If the value could not be parsed, will always be `DeviceOwnership::None`.
*/
DeviceOwnership deviceOwnershipFromString(const std::string& value);
} // namespace gateway
} // namespace wolkabout

#endif // WOLKGATEWAY_DEVICEOWNERSHIP_H
Loading

0 comments on commit 1127515

Please sign in to comment.