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

Gateway layer for bidirectional communication #350

Open
wants to merge 1 commit into
base: next-bidirectional
Choose a base branch
from
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
29 changes: 14 additions & 15 deletions src/sdks/core/src/cpp/templates/Device/src/module_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "${info.title.lowercase}_impl.h"
#include "Gateway/Gateway.h"

${if.implementations}
namespace Firebolt {
Expand All @@ -30,23 +31,21 @@ namespace ${info.Title} {
std::string version;

Firebolt::Error status = Firebolt::Error::NotConnected;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

status = transport->Invoke("${info.title.lowercase}.version", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
!jsonResult.IsSet() ? jsonResult.Clear() : (void)0;
!jsonResult.Sdk.IsSet() ? jsonResult.Sdk.Clear() : (void)0;
jsonResult.Sdk.Major = static_cast<int32_t>(${major});
jsonResult.Sdk.Minor = static_cast<int32_t>(${minor});
jsonResult.Sdk.Patch = static_cast<int32_t>(${patch});
jsonResult.Sdk.Readable = "${readable}";
jsonResult.ToString(version);
}
status = FireboltSDK::Gateway::Instance().Request("${info.title.lowercase}.version", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
!jsonResult.IsSet() ? jsonResult.Clear() : (void)0;
!jsonResult.Sdk.IsSet() ? jsonResult.Sdk.Clear() : (void)0;
jsonResult.Sdk.Major = static_cast<int32_t>(${major});
jsonResult.Sdk.Minor = static_cast<int32_t>(${minor});
jsonResult.Sdk.Patch = static_cast<int32_t>(${patch});
jsonResult.Sdk.Readable = "${readable}";
jsonResult.ToString(version);
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);
if (err != nullptr) {
*err = status;
}

return version;
}
// Methods
Expand Down
74 changes: 29 additions & 45 deletions src/sdks/core/src/cpp/templates/Lifecycle/src/module_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


#include "${info.title.lowercase}_impl.h"
#include "Gateway/Gateway.h"

${if.implementations}
namespace Firebolt {
Expand All @@ -40,7 +41,7 @@ static void readyDispatcher(const void* result) {
}

// localCallback to update the state
static void onReadyInnerCallback(void* notification, const void* userData, void* jsonResponse )
static void onReadyInnerCallback(void* notification, const void* userData, void* jsonResponse)
{
const LifecycleImpl* selfConst = static_cast<const LifecycleImpl*>(userData);
LifecycleImpl* self = const_cast<LifecycleImpl*>(selfConst);
Expand All @@ -61,11 +62,9 @@ static void onReadyInnerCallback(void* notification, const void* userData, void*

}
}



/* ready - Notify the platform that the app is ready */
void ${info.Title}Impl::ready(Firebolt::Error *err) {
void ${info.Title}Impl::ready(Firebolt::Error *err) {
Firebolt::Error status = Firebolt::Error::NotConnected;

JsonObject jsonParameters;
Expand All @@ -76,63 +75,48 @@ void ${info.Title}Impl::ready(Firebolt::Error *err) {
status = FireboltSDK::Event::Instance().Prioritize<JsonData_LifecycleEvent>("lifecycle.onInactive", jsonParameters, onReadyInnerCallback, (void*)nullptr, this);
status = FireboltSDK::Event::Instance().Prioritize<JsonData_LifecycleEvent>("lifecycle.onSuspended", jsonParameters, onReadyInnerCallback, (void*)nullptr, this);
status = FireboltSDK::Event::Instance().Prioritize<JsonData_LifecycleEvent>("lifecycle.onUnloading", jsonParameters, onReadyInnerCallback, (void*)nullptr, this);

FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {
WPEFramework::Core::JSON::VariantContainer jsonResult;
status = transport->Invoke("lifecycle.ready", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Lifecycle.ready is successfully invoked");

WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch> job = WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch>(WPEFramework::Core::ProxyType<FireboltSDK::Worker>::Create(readyDispatcher, nullptr));
WPEFramework::Core::IWorkerPool::Instance().Submit(job);
} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in invoking lifecycle.ready: %d", status);
if (err != nullptr) {
*err = status;
}
}

WPEFramework::Core::JSON::VariantContainer jsonResult;
status = FireboltSDK::Gateway::Instance().Request("lifecycle.ready", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Lifecycle.ready is successfully invoked");

WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch> job = WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch>(WPEFramework::Core::ProxyType<FireboltSDK::Worker>::Create(readyDispatcher, nullptr));
WPEFramework::Core::IWorkerPool::Instance().Submit(job);
} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);
if (err != nullptr) {
*err = status;
}
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in invoking lifecycle.ready: %d", status);
}
}

if (err != nullptr) {
*err = status;
}
}

/* state - return the state of the app */
std::string ${info.Title}Impl::state(Firebolt::Error *err) {
std::cout << "**CURRENT STATE OF THE APP::::**" << currentState << std::endl;
return currentState;
}



/* finished - Notify the platform that the app is done unloading */
void ${info.Title}Impl::finished(Firebolt::Error *err)
void ${info.Title}Impl::finished(Firebolt::Error *err)
{
Firebolt::Error status = Firebolt::Error::NotConnected;
if(currentState == "unloading")
{
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonParameters;

WPEFramework::Core::JSON::VariantContainer jsonResult;
status = transport->Invoke("lifecycle.finished", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Lifecycle.finished is successfully invoked");

}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);
}
if(currentState == "unloading")
{
JsonObject jsonParameters;

WPEFramework::Core::JSON::VariantContainer jsonResult;
status = FireboltSDK::Gateway::Instance().Request("lifecycle.finished", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Lifecycle.finished is successfully invoked");
}

if (err != nullptr) {
*err = status;
}
}

return;
}

Expand Down
82 changes: 32 additions & 50 deletions src/sdks/core/src/cpp/templates/Metrics/src/module_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,88 +17,70 @@
*/

#include "${info.title.lowercase}_impl.h"

#include "Gateway/Gateway.h"

${if.implementations}
namespace Firebolt {
namespace ${info.Title} {
${if.providers}
/* ${PROVIDERS} */${end.if.providers}

/* ready - Inform the platform that your app is minimally usable. This method is called automatically by `Lifecycle.ready()` */
bool ${info.Title}Impl::ready( Firebolt::Error *err )
/* ready - Inform the platform that your app is minimally usable. This method is called automatically by `Lifecycle.ready()` */
bool ${info.Title}Impl::ready( Firebolt::Error *err )
{
Firebolt::Error status = Firebolt::Error::NotConnected;
bool success = false;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonParameters;

WPEFramework::Core::JSON::Boolean jsonResult;
status = transport->Invoke("${info.title.lowercase}.ready", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.ready is successfully invoked");
success = jsonResult.Value();
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);

JsonObject jsonParameters;
WPEFramework::Core::JSON::Boolean jsonResult;
status = FireboltSDK::Gateway::Instance().Request("${info.title.lowercase}.ready", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.ready is successfully invoked");
success = jsonResult.Value();
}

if (err != nullptr) {
*err = status;
}

return success;
}


/* signIn - Log a sign In event, called by Discovery.signIn(). */
bool ${info.Title}Impl::signIn( Firebolt::Error *err )
/* signIn - Log a sign In event, called by Discovery.signIn(). */
bool ${info.Title}Impl::signIn( Firebolt::Error *err )
{
Firebolt::Error status = Firebolt::Error::NotConnected;
bool success = false;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonParameters;

WPEFramework::Core::JSON::Boolean jsonResult;
status = transport->Invoke("${info.title.lowercase}.signIn", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.signOut is successfully invoked");
success = jsonResult.Value();
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);

JsonObject jsonParameters;
WPEFramework::Core::JSON::Boolean jsonResult;
status = FireboltSDK::Gateway::Instance().Request("${info.title.lowercase}.signIn", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.signOut is successfully invoked");
success = jsonResult.Value();
}

if (err != nullptr) {
*err = status;
}
return success;

}
}

/* signOut - Log a sign out event, called by Discovery.signOut(). */
bool ${info.Title}Impl::signOut( Firebolt::Error *err )
bool ${info.Title}Impl::signOut( Firebolt::Error *err )
{
Firebolt::Error status = Firebolt::Error::NotConnected;
bool success = false;
FireboltSDK::Transport<WPEFramework::Core::JSON::IElement>* transport = FireboltSDK::Accessor::Instance().GetTransport();
if (transport != nullptr) {

JsonObject jsonParameters;

WPEFramework::Core::JSON::Boolean jsonResult;
status = transport->Invoke("${info.title.lowercase}.signOut", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.signOut is successfully invoked");
success = jsonResult.Value();
}

} else {
FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Error in getting Transport err = %d", status);

JsonObject jsonParameters;
WPEFramework::Core::JSON::Boolean jsonResult;
status = FireboltSDK::Gateway::Instance().Request("${info.title.lowercase}.signOut", jsonParameters, jsonResult);
if (status == Firebolt::Error::None) {
FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module<FireboltSDK::Accessor>(), "Metrics.signOut is successfully invoked");
success = jsonResult.Value();
}

if (err != nullptr) {
*err = status;
}
Expand Down
Loading