Skip to content

Commit

Permalink
CPPSDK: aggregate files based on suffix type handling added, module a…
Browse files Browse the repository at this point in the history
…nd override module generation also handled
  • Loading branch information
HaseenaSainul committed Oct 13, 2023
1 parent b7a27f0 commit 4b9f825
Show file tree
Hide file tree
Showing 34 changed files with 508 additions and 199 deletions.
7 changes: 6 additions & 1 deletion 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/moduleImpl.h",
"/src/moduleImpl.cpp"
],
"templatesPerSchema": [
"/include/common/module.h",
Expand Down
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
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}
22 changes: 11 additions & 11 deletions languages/cpp/templates/codeblocks/setter.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

/* ${method.rpc.name} - ${method.description} */
void ${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr )
{
const string method = _T("${info.title.lowercase}.${method.rpc.name}");
/* ${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;
JsonObject jsonParameters;
${if.params}${method.params.serialization}${end.if.params}

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

return;
}
return;
}
File renamed without changes.
Empty file.
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;
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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;
Empty file.
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;
52 changes: 27 additions & 25 deletions languages/cpp/templates/methods/event.c
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
/* ${method.rpc.name} - ${method.description} */
static void ${info.Title}${method.Name}InnerCallback( void* notification, const void* userData, void* jsonResponse )
{
/* ${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);
ASSERT(proxyResponse->IsValid() == true);

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

I${method.Name}Notification& notifier = *(reinterpret_cast<I${method.Name}Notification*>(notification));
notifier.${method.Name}(${event.callback.response.instantiation});
}
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 Subscribe( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${method.Name}Notification& notification, Firebolt::Error *err = nullptr )
{
const string eventName = _T("${info.title.lowercase}.${method.rpc.name}");
Firebolt::Error status = Firebolt::Error::None;
}
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;
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;
}
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;
}
void Unsubscribe( I${method.Name}Notification& notification, Firebolt::Error *err = nullptr )
{
Firebolt::Error status = FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title.lowercase}.${method.rpc.name}"), reinterpret_cast<void*>(&notification));
if (err != nullptr) {
*err = status;
}
}
}
31 changes: 16 additions & 15 deletions languages/cpp/templates/methods/property.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* ${method.rpc.name} - ${method.description} */
${method.signature.result} ${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr ) const
{
const string method = _T("${info.title.lowercase}.${method.rpc.name}");
${if.params}${method.params.serialization}${end.if.params}
${method.result.json} jsonResult;
/* ${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) {
${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}
}
if (err != nullptr) {
*err = status;
}

return ${method.result.name};
}${method.setter}
7 changes: 2 additions & 5 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} */

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

} //namespace ${info.Title}
}${end.if.declarations}
89 changes: 0 additions & 89 deletions languages/cpp/templates/modules/src/module.cpp

This file was deleted.

Loading

0 comments on commit 4b9f825

Please sign in to comment.