Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions languages/cpp/src/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(FIREBOLT_ENABLE_STATIC_LIB "Create Firebolt library as Static library" OF
option(ENABLE_BIDIRECTIONAL "Enable bidirectional communication over WS" OFF)
option(ENABLE_TESTS "Build openrpc native test" ON)
option(ENABLE_UNIT_TESTS "Enable unit test" ON)
option(ENABLE_MOCK_TESTS "Enable mock test" OFF)
option(ENABLE_COVERAGE "Enable code coverage build." ON)
option(ENABLE_INTERACTIVE_APP "Enable interactive application" ON)
option(FIREBOLT_PLAIN_LOG "Disable log coloring" OFF)
Expand Down
6 changes: 6 additions & 0 deletions languages/cpp/src/shared/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ list(APPEND SOURCES
Transport/Transport.cpp
Accessor/Accessor.cpp
Async/Async.cpp
Properties/Properties.cpp
Copy link
Contributor

@tomasz-blasz tomasz-blasz Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, all methods in Propierties class are static and should remain static. Tests should verify code as it is

)

if (ENABLE_BIDIRECTIONAL)
Expand All @@ -38,6 +39,10 @@ endif ()

add_library(${TARGET} ${FIREBOLT_LIBRARY_TYPE} ${SOURCES})

if(ENABLE_MOCK_TESTS)
add_compile_definitions(MOCK_TEST)
endif()

if(ENABLE_UNIT_TESTS)
target_compile_definitions(FireboltSDK PRIVATE UNIT_TEST)
endif()
Expand All @@ -60,6 +65,7 @@ target_link_libraries(${TARGET}
target_include_directories(${TARGET}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../test/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
)

Expand Down
5 changes: 5 additions & 0 deletions languages/cpp/src/shared/src/Gateway/Gateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ namespace FireboltSDK

void TransportUpdated(Transport<WPEFramework::Core::JSON::IElement>* transport);

void UpdateGateway(std::unique_ptr<GatewayImpl> mockGateway)
Copy link
Contributor

@tomasz-blasz tomasz-blasz Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is only for tests, should be at least under #ifdef ... #endif block, not exposed for any other application using the API.

{
implementation = std::move(mockGateway);
}

template <typename RESPONSE>
Firebolt::Error Request(const std::string &method, const JsonObject &parameters, RESPONSE &response)
{
Expand Down
32 changes: 23 additions & 9 deletions languages/cpp/src/shared/src/Gateway/unidi/gateway_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

#include "../common.h"

#ifndef MOCK_TEST
#include "Transport/Transport.h"
#else
#include "IGatewayMock.h"
#endif

#include <string>
#include <stdio.h>
Expand All @@ -35,60 +39,70 @@ namespace FireboltSDK

using EventCallback = std::function<void(const std::string & /* eventName */, const JsonObject & /* parameters */, Firebolt::Error /* error */)>;

#ifndef MOCK_TEST
class GatewayImpl
{

Transport<WPEFramework::Core::JSON::IElement>* transport;
Transport<WPEFramework::Core::JSON::IElement> *transport;
#else
class GatewayImpl : public IGatewayMock
{
#endif

public:
GatewayImpl()
{
}

public:
void TransportUpdated(Transport<WPEFramework::Core::JSON::IElement>* transport)
void TransportUpdated(Transport<WPEFramework::Core::JSON::IElement> *transport)
{
this->transport = transport;
}

#ifndef MOCK_TEST
template <typename RESPONSE>
Firebolt::Error Request(const std::string &method, const JsonObject &parameters, RESPONSE &response)
{
if (transport == nullptr) {
if (transport == nullptr)
{
return Firebolt::Error::NotConnected;
}
return transport->Invoke(method, parameters, response);
}
#endif

Firebolt::Error Response(unsigned id, const std::string &method, const JsonObject &response)
{
return Firebolt::Error::General;
}

template <typename RESPONSE>
Firebolt::Error Subscribe(const string& event, const string& parameters, RESPONSE& response)
Firebolt::Error Subscribe(const string &event, const string &parameters, RESPONSE &response)
{
if (transport == nullptr) {
if (transport == nullptr)
{
return Firebolt::Error::NotConnected;
}
return transport->Subscribe(event, parameters, response);
}

Firebolt::Error Unsubscribe(const string& event, const string& parameters)
Firebolt::Error Unsubscribe(const string &event, const string &parameters)
{
if (transport == nullptr) {
if (transport == nullptr)
{
return Firebolt::Error::NotConnected;
}
return transport->Unsubscribe(event, parameters);
}

template <typename RESPONSE, typename PARAMETERS, typename CALLBACK>
Firebolt::Error RegisterProviderInterface(const std::string &method, const PARAMETERS &parameters, const CALLBACK& callback, void* usercb)
Firebolt::Error RegisterProviderInterface(const std::string &method, const PARAMETERS &parameters, const CALLBACK &callback, void *usercb)
{
return Firebolt::Error::General;
}

Firebolt::Error UnregisterProviderInterface(const std::string &interface, const std::string &method, void* usercb)
Firebolt::Error UnregisterProviderInterface(const std::string &interface, const std::string &method, void *usercb)
{
return Firebolt::Error::General;
}
Expand Down
43 changes: 43 additions & 0 deletions languages/cpp/src/shared/src/Properties/Properties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Comcast Cable Communications Management, LLC
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "Properties.h"

namespace FireboltSDK
{

std::unique_ptr<Properties> Properties::instance = nullptr;

Properties &Properties::Instance()
{
if (instance == nullptr)
{
instance = std::make_unique<Properties>();
}
return *instance;
}

void Properties::Dispose()
{
ASSERT(instance != nullptr);
if (instance != nullptr)
{
instance = nullptr;
}
}
}
27 changes: 27 additions & 0 deletions languages/cpp/src/shared/src/Properties/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,56 @@
#include "Event/Event.h"
#include "Gateway/Gateway.h"

#ifdef MOCK_TEST
#include "IPropertiesMock.h"
#endif

namespace FireboltSDK {

#ifndef MOCK_TEST
class Properties {
#else
class Properties : public IPropertiesMock{
#endif
public:
Properties(const Properties&) = delete;
Properties& operator= (const Properties&) = delete;

Properties() = default;
~Properties() = default;

static Properties &Instance();
static void Dispose();

void UpdateProperties(std::unique_ptr<Properties> mockProperties)
{
instance = std::move(mockProperties);
}

private:
static std::unique_ptr<Properties> instance;
Properties(std::unique_ptr<Properties> instance);

public:

#ifndef MOCK_TEST

template <typename RESPONSETYPE>
static Firebolt::Error Get(const string& propertyName, RESPONSETYPE& response)
{
std::cout << "Properties::Get()\n";
JsonObject parameters;
return Gateway::Instance().Request<RESPONSETYPE>(propertyName, parameters, response);
}

template <typename PARAMETERS, typename RESPONSETYPE>
static Firebolt::Error Get(const string& propertyName, const PARAMETERS& parameters, RESPONSETYPE& response)
{
std::cout << "Properties::Get()\n";
return Gateway::Instance().Request(propertyName, parameters, response);
}

#endif

template <typename PARAMETERS>
static Firebolt::Error Set(const string& propertyName, const PARAMETERS& parameters)
Expand Down
1 change: 1 addition & 0 deletions languages/cpp/src/shared/src/TypesPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <string>
#include <core/JSON.h>

namespace FireboltSDK {
namespace JSON {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
using ${title} = WPEFramework::Core::JSON::VariantContainer;
class ${title} : public WPEFramework::Core::JSON::VariantContainer {};
2 changes: 1 addition & 1 deletion languages/cpp/templates/json-types/object-empty-property.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
using ${title} = WPEFramework::Core::JSON::VariantContainer;
class ${title} : public WPEFramework::Core::JSON::VariantContainer {};
2 changes: 1 addition & 1 deletion languages/cpp/templates/json-types/tuple.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
using ${title} = WPEFramework::Core::JSON::ArrayType<${json.type}>;
class ${title} : public WPEFramework::Core::JSON::ArrayType<${json.type}> {};
4 changes: 2 additions & 2 deletions languages/cpp/templates/methods/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
${if.params}${method.params.serialization}${end.if.params}
${method.result.json} jsonResult;
${method.result.initialization}
${if.params}Firebolt::Error status = FireboltSDK::Properties::Get(method, jsonParameters, jsonResult);${end.if.params}
${if.params.empty}Firebolt::Error status = FireboltSDK::Properties::Get(method, jsonResult);${end.if.params.empty}
${if.params}Firebolt::Error status = FireboltSDK::Properties::Instance().Get(method, jsonParameters, jsonResult);${end.if.params}
${if.params.empty}Firebolt::Error status = FireboltSDK::Properties::Instance().Get(method, jsonResult);${end.if.params.empty}
if (status == Firebolt::Error::None) {
${method.result.instantiation}
}
Expand Down