Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPPSDK: aggregate files based on suffix type handling added, module and override module generation also handled #139

Merged
merged 6 commits into from
Oct 24, 2023
Merged
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
10 changes: 8 additions & 2 deletions languages/cpp/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"unwrapResultObjects": false,
"createPolymorphicMethods": true,
"excludeDeclarations":true,
"aggregateFiles": [
"/include/firebolt.h",
"/src/firebolt.cpp"
],
"templatesPerModule": [
"/include/module.h",
"/src/module.cpp"
"/src/module_impl.h",
"/src/module_impl.cpp"
],
"templatesPerSchema": [
"/include/common/module.h",
Expand All @@ -23,5 +28,6 @@
"string": "std::string"
},
"langVersion" : "c++17",
"additionalSchemaTemplates": [ "json-types" ]
"additionalSchemaTemplates": [ "json-types" ],
"additionalMethodTemplates": [ "declarations", "declarations-override" ]
}
12 changes: 10 additions & 2 deletions languages/cpp/src/shared/src/Transport/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ namespace FireboltSDK {
, _scheduledTime(0)
, _waitTime(waitTime)
, _listener(listener)
, _connected(false)
, _status(Firebolt::Error::NotConnected)
{
_channel->Register(*this);
Expand Down Expand Up @@ -680,7 +681,10 @@ namespace FireboltSDK {
virtual void Opened()
{
_status = Firebolt::Error::None;
_listener(true, _status);
if (_connected != true) {
_connected = true;
_listener(_connected, _status);
}
}

void Closed()
Expand All @@ -696,7 +700,10 @@ namespace FireboltSDK {
}

_adminLock.Unlock();
_listener(false, _status);
if (_connected != false) {
_connected = false;
_listener(_connected, _status);
}
}

int32_t Submit(const WPEFramework::Core::ProxyType<WPEFramework::Core::JSONRPC::Message>& inbound)
Expand Down Expand Up @@ -953,6 +960,7 @@ namespace FireboltSDK {
uint64_t _scheduledTime;
uint32_t _waitTime;
Listener _listener;
bool _connected;
Firebolt::Error _status;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,29 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "Module.h"
#include "types.h"
#include "TypesPriv.h"
#include "OpenRPCTests.h"

#ifdef __cplusplus
extern "C" {
#endif
int __cnt = 0;
int __pass = 0;

// String Type Handler Interfaces
const char* Firebolt_String(Firebolt_String_t handle)
{
return ((reinterpret_cast<FireboltSDK::JSON::String*>(handle))->Value().c_str());
}
int TotalTests = 0;
int TotalTestsPassed = 0;

void Firebolt_String_Release(Firebolt_String_t handle)
int main()
{
delete reinterpret_cast<FireboltSDK::JSON::String*>(handle);
}
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>();


#ifdef __cplusplus
printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed));
FireboltSDK::Accessor::Dispose();
}
#endif
1 change: 0 additions & 1 deletion languages/cpp/templates/codeblocks/mock-import.c

This file was deleted.

1 change: 0 additions & 1 deletion languages/cpp/templates/codeblocks/mock-parameter.c

This file was deleted.

2 changes: 2 additions & 0 deletions languages/cpp/templates/codeblocks/module-include-private.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${if.modules}#include "${info.title.lowercase}_impl.h"
${end.if.modules}${module.includes.private}
2 changes: 2 additions & 0 deletions languages/cpp/templates/codeblocks/module-include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${if.modules}#include "${info.title.lowercase}.h"
${end.if.modules}${module.includes}
15 changes: 15 additions & 0 deletions languages/cpp/templates/codeblocks/module-init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
${if.modules} ${info.Title}::I${info.Title}& ${info.Title}Interface() const override
{
auto module = _moduleMap.find("${info.Title}");
${info.Title}::I${info.Title}* ${info.title.lowercase} = nullptr;

if (module != _moduleMap.end()) {
${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(module->second);
} else {
${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(new ${info.Title}::${info.Title}Impl());
_moduleMap.emplace("${info.Title}", reinterpret_cast<IModule*>(${info.title.lowercase}));
}
return *${info.title.lowercase};
}

${end.if.modules}${module.init}
3 changes: 3 additions & 0 deletions languages/cpp/templates/codeblocks/module-init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
${if.modules} virtual ${info.Title}::I${info.Title}& ${info.Title}Interface() const = 0;

${end.if.modules}${module.init}
16 changes: 0 additions & 16 deletions languages/cpp/templates/codeblocks/setter.c

This file was deleted.

16 changes: 16 additions & 0 deletions languages/cpp/templates/codeblocks/setter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/* ${method.rpc.name} - ${method.description} */
void ${info.Title}Impl::${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err )
{
const string method = _T("${info.title.lowercase}.${method.rpc.name}");

JsonObject jsonParameters;
${if.params}${method.params.serialization}${end.if.params}

Firebolt::Error status = FireboltSDK::Properties::Set(method, jsonParameters);
if (err != nullptr) {
*err = status;
}

return;
}
4 changes: 4 additions & 0 deletions languages/cpp/templates/declarations-override/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// signature callback params: ${event.signature.callback.params}
// method result properties : ${method.result.properties}
void Subscribe( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${info.Title}::I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) override;
void Unsubscribe( I${info.Title}::I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) override;
5 changes: 5 additions & 0 deletions languages/cpp/templates/declarations-override/property.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* ${method.description}
* ${method.params}
*/
${method.signature.result} ${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr ) const override;
5 changes: 5 additions & 0 deletions languages/cpp/templates/declarations-override/setter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* ${method.rpc.name}
* ${method.description}
*/
void ${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr ) override;
1 change: 1 addition & 0 deletions languages/cpp/templates/imports/default.impl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "jsondata_${info.title.lowercase}.h"
33 changes: 0 additions & 33 deletions languages/cpp/templates/methods/event.c

This file was deleted.

35 changes: 35 additions & 0 deletions languages/cpp/templates/methods/event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* ${method.rpc.name} - ${method.description} */
static void ${info.Title}${method.Name}InnerCallback( void* notification, const void* userData, void* jsonResponse )
{
${event.callback.params.serialization}
ASSERT(proxyResponse->IsValid() == true);

if (proxyResponse->IsValid() == true) {
${event.callback.result.instantiation}
proxyResponse->Release();

I${info.Title}::I${method.Name}Notification& notifier = *(reinterpret_cast<I${info.Title}::I${method.Name}Notification*>(notification));
notifier.${method.Name}(${event.callback.response.instantiation});
}
}
void ${info.Title}Impl::Subscribe( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${info.Title}::I${method.Name}Notification& notification, Firebolt::Error *err )
{
const string eventName = _T("${info.title.lowercase}.${method.rpc.name}");
Firebolt::Error status = Firebolt::Error::None;

JsonObject jsonParameters;
${event.params.serialization}
status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${info.Title}${method.Name}InnerCallback, reinterpret_cast<void*>(&notification), nullptr);

if (err != nullptr) {
*err = status;
}
}
void ${info.Title}Impl::Unsubscribe( I${info.Title}::I${method.Name}Notification& notification, Firebolt::Error *err )
{
Firebolt::Error status = FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title.lowercase}.${method.rpc.name}"), reinterpret_cast<void*>(&notification));

if (err != nullptr) {
*err = status;
}
}
Empty file.
Empty file.
Empty file.
17 changes: 0 additions & 17 deletions languages/cpp/templates/methods/property.c

This file was deleted.

18 changes: 18 additions & 0 deletions languages/cpp/templates/methods/property.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ${method.rpc.name} - ${method.description} */
${method.signature.result} ${info.Title}Impl::${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) const
{
const string method = _T("${info.title.lowercase}.${method.rpc.name}");
${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 (status == Firebolt::Error::None) {
${method.result.instantiation}
}
if (err != nullptr) {
*err = status;
}

return ${method.result.name};
}${method.setter}
Empty file.
Empty file.
9 changes: 3 additions & 6 deletions languages/cpp/templates/modules/include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ namespace ${info.Title} {
// Types
/* ${TYPES} */
${end.if.types}
struct I${info.Title} {

static I${info.Title}& Instance();
static void Dispose();
${if.methods}struct I${info.Title} {

virtual ~I${info.Title}() = default;

// Methods & Events
/* ${DECLARATIONS} */
/* ${METHODS:declarations} */

};
};${end.if.methods}

} //namespace ${info.Title}
}${end.if.declarations}
Loading
Loading