Skip to content

Commit

Permalink
CPPSDK: static code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Oct 4, 2023
1 parent 5dd184a commit 59d238f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 270 deletions.
20 changes: 5 additions & 15 deletions languages/cpp/src/shared/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef FIREBOLT_TYPES_H
#define FIREBOLT_TYPES_H
#pragma once

#include <stdint.h>
#include <stdbool.h>
#include <string>
#include <unordered_map>
#include <vector>
#include <optional>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Firebolt_String_s* Firebolt_String_t;
const char* Firebolt_String(Firebolt_String_t handle);
void Firebolt_String_Release(Firebolt_String_t handle);

#ifdef __cplusplus
}
#endif

#endif // FIREBOLT_TYPES_H
9 changes: 6 additions & 3 deletions languages/cpp/src/shared/src/Accessor/Accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ namespace FireboltSDK {
}
}

void Connect(const Transport<WPEFramework::Core::JSON::IElement>::Listener& listener)
Firebolt::Error Connect(const Transport<WPEFramework::Core::JSON::IElement>::Listener& listener)
{
CreateTransport(_config.WsUrl.Value().c_str(), listener, _config.WaitTime.Value());
CreateEventHandler();
Firebolt::Error status = CreateTransport(_config.WsUrl.Value().c_str(), listener, _config.WaitTime.Value());
if (status == Firebolt::Error::None) {
status = CreateEventHandler();
}
return status;
}

Firebolt::Error Disconnect()
Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ target_include_directories(${TARGET}
)

set_target_properties(${TARGET} PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
FRAMEWORK FALSE
LINK_WHAT_YOU_USE TRUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OPENRPC_C_TESTS_H
#define OPENRPC_C_TESTS_H
#pragma once

#include "TestUtils.h"

#ifdef __cplusplus
extern "C" {
#endif

void test_firebolt_create_instance();
void test_firebolt_dispose_instance();

int32_t test_firebolt_main();
int32_t test_properties_get_device_id();
int32_t test_properties_set();
int32_t test_eventregister();
int32_t test_eventregister_with_same_callback();
int32_t test_eventregister_by_providing_callback();
int32_t test_string_set_get_value();

#ifdef __cplusplus
namespace Firebolt {
struct IModule {
virtual ~IModule() = default;
};
}
#endif

#endif // OPENRPC_C_TESTS_H
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/src/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::Category)

{ FireboltSDK::Logger::Category::OpenRPC, _TXT("FireboltSDK::OpenRPC") },
{ FireboltSDK::Logger::Category::Core, _TXT("FireboltSDK::Core") },
{ FireboltSDK::Logger::Category::Management, _TXT("FireboltSDK::Management") },
{ FireboltSDK::Logger::Category::Manage, _TXT("FireboltSDK::Manage") },
{ FireboltSDK::Logger::Category::Discovery, _TXT("FireboltSDK::Discovery") },

ENUM_CONVERSION_END(FireboltSDK::Logger::Category)
Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/src/shared/src/Logger/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace FireboltSDK {
enum class Category : uint8_t {
OpenRPC,
Core,
Management,
Manage,
Discovery
};

Expand Down
6 changes: 6 additions & 0 deletions languages/cpp/src/shared/src/TypesPriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class String : public WPEFramework::Core::JSON::String {
_value = RHS;
return (*this);
}
String& operator=(const string RHS)
{
Base::operator = (RHS);
_value = RHS;
return (*this);
}

public:
const string& Value() const
Expand Down
27 changes: 13 additions & 14 deletions languages/cpp/src/shared/test/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "OpenRPCCTests.h"
#include "OpenRPCTests.h"

int __cnt = 0;
int __pass = 0;
Expand All @@ -26,20 +26,19 @@ int TotalTestsPassed = 0;

int main()
{
test_firebolt_create_instance();
test_firebolt_main();
const std::string config = _T("{\
\"waitTime\": 1000,\
\"logLevel\": \"Info\",\
\"workerPool\":{\
\"queueSize\": 8,\
\"threadCount\": 3\
},\
\"wsUrl\": \"ws://127.0.0.1:9998\"\
}");
FireboltSDK::Accessor::Instance(config);
FireboltSDK::Tests::Main<FireboltSDK::Tests>();

// Calling C function sequences
printf("%s:%s:%d Calling C function tests\n", __FILE__, __func__, __LINE__);
EXECUTE("test_properties_get_device_id", test_properties_get_device_id);
EXECUTE("test_properties_set", test_properties_set);
EXECUTE("test_eventregister_by_providing_callback", test_eventregister_by_providing_callback);
EXECUTE("test_eventregister", test_eventregister);
EXECUTE("test_eventregister_with_same_callback", test_eventregister_with_same_callback);
EXECUTE("test_string_set_get_value", test_string_set_get_value);

test_firebolt_dispose_instance();

printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed));
FireboltSDK::Accessor::Dispose();
}

Loading

0 comments on commit 59d238f

Please sign in to comment.