From ebe1439d70a6b233348895c2135bb2d08ee04cbe Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:56:55 +0530 Subject: [PATCH] CPPSDK: template added for capabilties-method (#142) --- languages/cpp/src/shared/include/firebolt.h | 68 ------------------- .../templates/declarations-override/default.h | 5 ++ .../cpp/templates/declarations/default.h | 6 ++ .../cpp/templates/declarations/rpc-only.h | 0 languages/cpp/templates/methods/default.cpp | 23 +++++++ languages/cpp/templates/methods/rpc-only.cpp | 0 .../parameter-serialization/array.cpp | 2 +- .../parameter-serialization/generic.cpp | 2 +- .../templates/result-initialization/array.cpp | 2 +- .../result-initialization/string.cpp | 2 +- 10 files changed, 38 insertions(+), 72 deletions(-) delete mode 100644 languages/cpp/src/shared/include/firebolt.h create mode 100644 languages/cpp/templates/declarations/rpc-only.h create mode 100644 languages/cpp/templates/methods/rpc-only.cpp diff --git a/languages/cpp/src/shared/include/firebolt.h b/languages/cpp/src/shared/include/firebolt.h deleted file mode 100644 index 565b363c..00000000 --- a/languages/cpp/src/shared/include/firebolt.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef FIREBOLT_H -#define FIREBOLT_H - -#include "error.h" -#include "types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define IN -#define OUT - -/** - * @brief Intitialize the Firebolt SDK - * - * @param configLine JSON String with configuration options - * - * CONFIG Format: - * { - * "waitTime": 1000, - * "logLevel": "Info", - * "workerPool":{ - * "queueSize": 8, - * "threadCount": 3 - * }, - * "wsUrl": "ws://127.0.0.1:9998" - * } - * - * - * @return FireboltSDKErrorNone if success, appropriate error otherwise. - * - */ -uint32_t FireboltSDK_Initialize(char* configLine); - - -/** - * @brief Deintitialize the Firebolt SDK - * - * @return FireboltSDKErrorNone if success, appropriate error otherwise. - * - */ -uint32_t FireboltSDK_Deinitialize(void); - -#ifdef __cplusplus -} -#endif - - -#endif // FIREBOLT_H diff --git a/languages/cpp/templates/declarations-override/default.h b/languages/cpp/templates/declarations-override/default.h index e69de29b..cc0c3a2a 100644 --- a/languages/cpp/templates/declarations-override/default.h +++ b/languages/cpp/templates/declarations-override/default.h @@ -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; diff --git a/languages/cpp/templates/declarations/default.h b/languages/cpp/templates/declarations/default.h index e69de29b..5e7f8e3f 100644 --- a/languages/cpp/templates/declarations/default.h +++ b/languages/cpp/templates/declarations/default.h @@ -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; \ No newline at end of file diff --git a/languages/cpp/templates/declarations/rpc-only.h b/languages/cpp/templates/declarations/rpc-only.h new file mode 100644 index 00000000..e69de29b diff --git a/languages/cpp/templates/methods/default.cpp b/languages/cpp/templates/methods/default.cpp index e69de29b..dde99ffc 100644 --- a/languages/cpp/templates/methods/default.cpp +++ b/languages/cpp/templates/methods/default.cpp @@ -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* transport = FireboltSDK::Accessor::Instance().GetTransport(); + if (transport != nullptr) { + + 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(), "${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(), "Error in getting Transport err = %d", status); + } + + return${if.result.nonvoid} ${method.result.name}${end.if.result.nonvoid}; + } diff --git a/languages/cpp/templates/methods/rpc-only.cpp b/languages/cpp/templates/methods/rpc-only.cpp new file mode 100644 index 00000000..e69de29b diff --git a/languages/cpp/templates/parameter-serialization/array.cpp b/languages/cpp/templates/parameter-serialization/array.cpp index d45916ab..5768dfc5 100644 --- a/languages/cpp/templates/parameter-serialization/array.cpp +++ b/languages/cpp/templates/parameter-serialization/array.cpp @@ -4,4 +4,4 @@ } WPEFramework::Core::JSON::Variant ${Property}Variant; ${Property}Variant.Array(${Property}); - jsonParameters.Set(_T("${property}"), ${Property}Variant); + jsonParameters.Set(_T("${property}"), ${Property}Variant); \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/generic.cpp b/languages/cpp/templates/parameter-serialization/generic.cpp index 566c7354..d38bcfca 100644 --- a/languages/cpp/templates/parameter-serialization/generic.cpp +++ b/languages/cpp/templates/parameter-serialization/generic.cpp @@ -1,2 +1,2 @@ WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional}); - jsonParameters.Set(_T("${property}"), ${Property}); + jsonParameters.Set(_T("${property}"), ${Property}); \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/array.cpp b/languages/cpp/templates/result-initialization/array.cpp index 2f0629ac..1bcce663 100644 --- a/languages/cpp/templates/result-initialization/array.cpp +++ b/languages/cpp/templates/result-initialization/array.cpp @@ -1 +1 @@ - ${type} ${property}; + ${type} ${property}; \ No newline at end of file diff --git a/languages/cpp/templates/result-initialization/string.cpp b/languages/cpp/templates/result-initialization/string.cpp index 2f0629ac..1bcce663 100644 --- a/languages/cpp/templates/result-initialization/string.cpp +++ b/languages/cpp/templates/result-initialization/string.cpp @@ -1 +1 @@ - ${type} ${property}; + ${type} ${property}; \ No newline at end of file