-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPPSDK: polymorphic-pull method/event generation support added
- Loading branch information
1 parent
77f2cfc
commit d26e2c5
Showing
9 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
void subscribe( 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
${method.name} | ||
${method.description} | ||
*/ | ||
${method.signature.result} ${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr )${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} override; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* ${method.name} - ${method.description} */ | ||
struct I${method.Name}Notification { | ||
virtual ${method.pulls.type} ${method.name}( ${method.pulls.param.type} ) = 0; | ||
}; | ||
virtual void subscribe( I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) = 0; | ||
virtual void unsubscribe( I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
${method.name} | ||
${method.description} | ||
${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}${end.if.deprecated} | ||
*/ | ||
virtual ${method.signature.result} ${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr )${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* ${method.rpc.name} - ${method.description} */ | ||
static void ${method.name}InnerCallback( void* notification, const void* userData, void* jsonResponse ) | ||
{ | ||
${event.callback.serialization} | ||
ASSERT(proxyResponse.IsValid() == true); | ||
|
||
if (proxyResponse.IsValid() == true) { | ||
${method.pulls.param.json.type} jsonResult = proxyResponse->Parameters; | ||
${method.pulls.response.initialization} | ||
${method.pulls.response.instantiation} | ||
|
||
I${info.Title}::I${method.Name}Notification& notifier = *(reinterpret_cast<I${info.Title}::I${method.Name}Notification*>(notification)); | ||
${method.pulls.type} element = notifier.${method.name}(${method.pulls.param.title}); | ||
Firebolt::Error status = Firebolt::Error::NotConnected; | ||
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport(); | ||
if (transport != nullptr) { | ||
JsonObject jsonParameters; | ||
WPEFramework::Core::JSON::Variant CorrelationId = proxyResponse->CorrelationId.Value(); | ||
jsonParameters.Set(_T("correlationId"), CorrelationId); | ||
${method.pulls.json.type} ${method.pulls.result.title}Container; | ||
|
||
${method.pulls.result.serialization.with.indent} | ||
string resultStr; | ||
${method.pulls.result.title}Container.ToString(resultStr); | ||
WPEFramework::Core::JSON::VariantContainer resultContainer(resultStr); | ||
WPEFramework::Core::JSON::Variant Result = resultContainer; | ||
jsonParameters.Set(_T("result"), Result); | ||
WPEFramework::Core::JSON::Boolean jsonResult; | ||
|
||
status = transport->Invoke("${info.title.lowercase}.${method.pulls.for}", jsonParameters, jsonResult); | ||
if (status == Firebolt::Error::None) { | ||
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "${info.Title}.${method.rpc.name} is successfully pushed with status as %d", jsonResult.Value()); | ||
} | ||
|
||
} else { | ||
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status); | ||
} | ||
proxyResponse.Release(); | ||
} | ||
} | ||
void ${info.Title}Impl::subscribe( 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; | ||
status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${method.name}InnerCallback, reinterpret_cast<void*>(¬ification), 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*>(¬ification)); | ||
|
||
if (err != nullptr) { | ||
*err = status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* ${method.rpc.name} - ${method.description} */ | ||
${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) ${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} | ||
{ | ||
Firebolt::Error status = Firebolt::Error::NotConnected; | ||
${if.result.nonvoid}${method.result.initialization}${end.if.result.nonvoid} | ||
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport(); | ||
if (transport != nullptr) { | ||
string correlationId = ""; | ||
JsonObject jsonParameters; | ||
${method.params.serialization.with.indent} | ||
${method.result.json.type} jsonResult; | ||
status = transport->Invoke("${info.title.lowercase}.${method.rpc.name}", jsonParameters, jsonResult); | ||
if (status == Firebolt::Error::None) { | ||
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "${info.Title}.${method.rpc.name} is successfully invoked"); | ||
${if.result.nonvoid}${method.result.instantiation.with.indent}${end.if.result.nonvoid} | ||
} | ||
|
||
} else { | ||
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status); | ||
} | ||
|
||
return${if.result.nonvoid} ${method.result.name}${end.if.result.nonvoid}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters