diff --git a/languages/c-structs/language.config.json b/languages/c-structs/language.config.json deleted file mode 100644 index 1179d74e..00000000 --- a/languages/c-structs/language.config.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "C", - "langcode": "c", - "createModuleDirectories": false, - "extractSubSchemas": true, - "unwrapResultObjects": true, - "convertTuplesToArraysOrObjects": true, - "templatesPerModule": [ - "/include/module.h", - "/src/module.cpp" - ], - "templatesPerSchema": [ - "/include/common/module.h", - "/src/module_common.cpp", - "/src/jsondata_module.h" - ], - "persistPermission": true, - "primitives": { - "boolean": "bool", - "integer": "int", - "number": "float", - "string": "char*" - }, - "additionalSchemaTemplates": [ - "json-types" - ] -} diff --git a/languages/c-structs/src/index.mjs b/languages/c-structs/src/index.mjs deleted file mode 100644 index 51c547a1..00000000 --- a/languages/c-structs/src/index.mjs +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2021 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 - */ - -export { default as Transport } from './shared/Transport/index.mjs' \ No newline at end of file diff --git a/languages/c-structs/templates/codeblocks/export.c b/languages/c-structs/templates/codeblocks/export.c deleted file mode 100644 index c98498e4..00000000 --- a/languages/c-structs/templates/codeblocks/export.c +++ /dev/null @@ -1 +0,0 @@ -export { default as ${info.title} } from './${info.title}/index.mjs' \ No newline at end of file diff --git a/languages/c-structs/templates/codeblocks/mock-import.c b/languages/c-structs/templates/codeblocks/mock-import.c deleted file mode 100644 index 5d22512a..00000000 --- a/languages/c-structs/templates/codeblocks/mock-import.c +++ /dev/null @@ -1 +0,0 @@ -import { default as _${info.title} } from './${info.title}/defaults.mjs' \ No newline at end of file diff --git a/languages/c-structs/templates/codeblocks/mock-parameter.c b/languages/c-structs/templates/codeblocks/mock-parameter.c deleted file mode 100644 index 63e63902..00000000 --- a/languages/c-structs/templates/codeblocks/mock-parameter.c +++ /dev/null @@ -1 +0,0 @@ - ${info.title}: _${info.title}, \ No newline at end of file diff --git a/languages/c-structs/templates/codeblocks/module.c b/languages/c-structs/templates/codeblocks/module.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/codeblocks/setter.c b/languages/c-structs/templates/codeblocks/setter.c deleted file mode 100644 index 9f496543..00000000 --- a/languages/c-structs/templates/codeblocks/setter.c +++ /dev/null @@ -1,9 +0,0 @@ -/* ${method.name} - ${method.description} */ -uint32_t ${info.title}_${method.Name}( ${method.signature.params} ) -{ - const string method = _T("${info.title}.${method.name}"); - ${if.params} -${method.params.serialization} - ${end.if.params} - return FireboltSDK::Properties::Set(method, jsonParameters); -} diff --git a/languages/c-structs/templates/declarations/clear.c b/languages/c-structs/templates/declarations/clear.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/declarations/default.c b/languages/c-structs/templates/declarations/default.c deleted file mode 100644 index 5d972e4a..00000000 --- a/languages/c-structs/templates/declarations/default.c +++ /dev/null @@ -1,5 +0,0 @@ -/* - * ${method.summary} - * ${method.params} - */ -int F${info.title}_${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}); diff --git a/languages/c-structs/templates/declarations/event.c b/languages/c-structs/templates/declarations/event.c deleted file mode 100644 index c2f0e3d2..00000000 --- a/languages/c-structs/templates/declarations/event.c +++ /dev/null @@ -1,4 +0,0 @@ -/* ${method.name} - ${method.description} */ -typedef void (*F${info.Title}${method.Name}Callback)( const void* userData, ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${method.result.properties} ); -int F${info.title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}F${info.Title}${method.Name}Callback userCB, const void* userData ); -int F${info.title}_Unregister_${method.Name}( F${info.Title}${method.Name}Callback userCB); diff --git a/languages/c-structs/templates/declarations/listen.c b/languages/c-structs/templates/declarations/listen.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/declarations/once.c b/languages/c-structs/templates/declarations/once.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/declarations/polymorphic-reducer.c b/languages/c-structs/templates/declarations/polymorphic-reducer.c deleted file mode 100644 index 5d972e4a..00000000 --- a/languages/c-structs/templates/declarations/polymorphic-reducer.c +++ /dev/null @@ -1,5 +0,0 @@ -/* - * ${method.summary} - * ${method.params} - */ -int F${info.title}_${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}); diff --git a/languages/c-structs/templates/declarations/property.c b/languages/c-structs/templates/declarations/property.c deleted file mode 100644 index 77aac221..00000000 --- a/languages/c-structs/templates/declarations/property.c +++ /dev/null @@ -1,5 +0,0 @@ -/* - * ${method.summary} - * ${method.params} - */ -int F${info.title}_Get${method.Name}(${method.signature.params}${if.params}, ${end.if.params}${method.result.properties}); diff --git a/languages/c-structs/templates/declarations/provide.c b/languages/c-structs/templates/declarations/provide.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/declarations/rpc-only.c b/languages/c-structs/templates/declarations/rpc-only.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/defaults/default.c b/languages/c-structs/templates/defaults/default.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/defaults/property.c b/languages/c-structs/templates/defaults/property.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/imports/default.cpp b/languages/c-structs/templates/imports/default.cpp deleted file mode 100644 index caf84bc9..00000000 --- a/languages/c-structs/templates/imports/default.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "jsondata_${info.title.lowercase}.h" diff --git a/languages/c-structs/templates/imports/default.h b/languages/c-structs/templates/imports/default.h deleted file mode 100644 index 56a97a40..00000000 --- a/languages/c-structs/templates/imports/default.h +++ /dev/null @@ -1 +0,0 @@ -#include "common/${info.title.lowercase}.h" diff --git a/languages/c-structs/templates/imports/default.jsondata b/languages/c-structs/templates/imports/default.jsondata deleted file mode 100644 index caf84bc9..00000000 --- a/languages/c-structs/templates/imports/default.jsondata +++ /dev/null @@ -1 +0,0 @@ -#include "jsondata_${info.title.lowercase}.h" diff --git a/languages/c-structs/templates/json-types/additionalProperties.c b/languages/c-structs/templates/json-types/additionalProperties.c deleted file mode 100644 index b814e5fb..00000000 --- a/languages/c-structs/templates/json-types/additionalProperties.c +++ /dev/null @@ -1 +0,0 @@ -// need cpp code to init, get, set, clear additional properties... \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/anyOf.c b/languages/c-structs/templates/json-types/anyOf.c deleted file mode 100644 index a2682179..00000000 --- a/languages/c-structs/templates/json-types/anyOf.c +++ /dev/null @@ -1 +0,0 @@ -/* AnyOf is not supported in C: ${title} */ \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/array.c b/languages/c-structs/templates/json-types/array.c deleted file mode 100644 index 508a9eac..00000000 --- a/languages/c-structs/templates/json-types/array.c +++ /dev/null @@ -1,4 +0,0 @@ -uint32_t ${info.Title}_${Title}Array_Size(${type} handle); -${type} ${title}Array_Get(${type} handle, uint32_t index); -void ${info.Title}_${Title}Array_Add(${propertyType} handle, ${valueType} value); -void ${info.Title}_${Title}Array_Clear(${propertyType} handle); diff --git a/languages/c-structs/templates/json-types/boolean.c b/languages/c-structs/templates/json-types/boolean.c deleted file mode 100644 index 18bbeec2..00000000 --- a/languages/c-structs/templates/json-types/boolean.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::Boolean \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/const.c b/languages/c-structs/templates/json-types/const.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/json-types/default.cpp b/languages/c-structs/templates/json-types/default.cpp deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c-structs/templates/json-types/default.cpp +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/enum.cpp b/languages/c-structs/templates/json-types/enum.cpp deleted file mode 100644 index 6776b41a..00000000 --- a/languages/c-structs/templates/json-types/enum.cpp +++ /dev/null @@ -1,4 +0,0 @@ - /* ${title} ${description} */ - ENUM_CONVERSION_BEGIN(${name}) - { ${NAME}_${key}, _T("${value}") }, - ENUM_CONVERSION_END(${name}) diff --git a/languages/c-structs/templates/json-types/enum.h b/languages/c-structs/templates/json-types/enum.h deleted file mode 100644 index 92108c75..00000000 --- a/languages/c-structs/templates/json-types/enum.h +++ /dev/null @@ -1,4 +0,0 @@ -/* ${title} ${description} */ -typedef enum { - ${NAME}_${key}, -} ${name}; diff --git a/languages/c-structs/templates/json-types/float.c b/languages/c-structs/templates/json-types/float.c deleted file mode 100644 index c38bca91..00000000 --- a/languages/c-structs/templates/json-types/float.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::Float \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/integer.c b/languages/c-structs/templates/json-types/integer.c deleted file mode 100644 index b57fe26e..00000000 --- a/languages/c-structs/templates/json-types/integer.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::DecSInt32 \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/namespace.c b/languages/c-structs/templates/json-types/namespace.c deleted file mode 100644 index 8ea9d7de..00000000 --- a/languages/c-structs/templates/json-types/namespace.c +++ /dev/null @@ -1 +0,0 @@ -FireboltSDK::${info.Title}:: \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/object.cpp b/languages/c-structs/templates/json-types/object.cpp deleted file mode 100644 index db24d12c..00000000 --- a/languages/c-structs/templates/json-types/object.cpp +++ /dev/null @@ -1,25 +0,0 @@ - class ${title}: public WPEFramework::Core::JSON::Container { - public: - ~${title}() override = default; - - public: - ${title}() - : WPEFramework::Core::JSON::Container() - { - ${properties.register} - } - - ${title}(const ${title}& other) - { - ${properties.assign} - } - - ${title}& operator=(const ${title}& other) - { - ${properties.assign} - return (*this); - } - - public: - ${properties} - }; diff --git a/languages/c-structs/templates/json-types/primitive.c b/languages/c-structs/templates/json-types/primitive.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/json-types/property-assign.cpp b/languages/c-structs/templates/json-types/property-assign.cpp deleted file mode 100644 index cc1b2860..00000000 --- a/languages/c-structs/templates/json-types/property-assign.cpp +++ /dev/null @@ -1,2 +0,0 @@ -Add(_T("${property}"), &${Property}); -${Property} = other.${Property} \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/property-register.cpp b/languages/c-structs/templates/json-types/property-register.cpp deleted file mode 100644 index f9b86372..00000000 --- a/languages/c-structs/templates/json-types/property-register.cpp +++ /dev/null @@ -1 +0,0 @@ -Add(_T("${property}"), &${Property}); \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/property.cpp b/languages/c-structs/templates/json-types/property.cpp deleted file mode 100644 index 46e3ef8e..00000000 --- a/languages/c-structs/templates/json-types/property.cpp +++ /dev/null @@ -1 +0,0 @@ -${title} ${Property}; \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/ref.c b/languages/c-structs/templates/json-types/ref.c deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c-structs/templates/json-types/ref.c +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/string.c b/languages/c-structs/templates/json-types/string.c deleted file mode 100644 index 2d60a3c8..00000000 --- a/languages/c-structs/templates/json-types/string.c +++ /dev/null @@ -1 +0,0 @@ -FireboltSDK::JSON::String \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/title.c b/languages/c-structs/templates/json-types/title.c deleted file mode 100644 index ae1512e5..00000000 --- a/languages/c-structs/templates/json-types/title.c +++ /dev/null @@ -1 +0,0 @@ -JsonData_${Title} \ No newline at end of file diff --git a/languages/c-structs/templates/json-types/tuple.c b/languages/c-structs/templates/json-types/tuple.c deleted file mode 100644 index db24d12c..00000000 --- a/languages/c-structs/templates/json-types/tuple.c +++ /dev/null @@ -1,25 +0,0 @@ - class ${title}: public WPEFramework::Core::JSON::Container { - public: - ~${title}() override = default; - - public: - ${title}() - : WPEFramework::Core::JSON::Container() - { - ${properties.register} - } - - ${title}(const ${title}& other) - { - ${properties.assign} - } - - ${title}& operator=(const ${title}& other) - { - ${properties.assign} - return (*this); - } - - public: - ${properties} - }; diff --git a/languages/c-structs/templates/json-types/types/object.c b/languages/c-structs/templates/json-types/types/object.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/json-types/x-method.c b/languages/c-structs/templates/json-types/x-method.c deleted file mode 100644 index 573c9f8e..00000000 --- a/languages/c-structs/templates/json-types/x-method.c +++ /dev/null @@ -1 +0,0 @@ -void* \ No newline at end of file diff --git a/languages/c-structs/templates/language/enum-item.c b/languages/c-structs/templates/language/enum-item.c deleted file mode 100644 index 79aabbeb..00000000 --- a/languages/c-structs/templates/language/enum-item.c +++ /dev/null @@ -1 +0,0 @@ - ${key} diff --git a/languages/c-structs/templates/language/enum.c b/languages/c-structs/templates/language/enum.c deleted file mode 100644 index 0551b99c..00000000 --- a/languages/c-structs/templates/language/enum.c +++ /dev/null @@ -1,3 +0,0 @@ -typedef enum { - ${items} -} F${info.title}_${title}; diff --git a/languages/c-structs/templates/language/parameter.c b/languages/c-structs/templates/language/parameter.c deleted file mode 100644 index 2ff7a678..00000000 --- a/languages/c-structs/templates/language/parameter.c +++ /dev/null @@ -1 +0,0 @@ -${type} ${name} \ No newline at end of file diff --git a/languages/c-structs/templates/language/schema-item.c b/languages/c-structs/templates/language/schema-item.c deleted file mode 100644 index ecded7d5..00000000 --- a/languages/c-structs/templates/language/schema-item.c +++ /dev/null @@ -1 +0,0 @@ - ${type} ${property}; diff --git a/languages/c-structs/templates/language/schema.c b/languages/c-structs/templates/language/schema.c deleted file mode 100644 index 22760540..00000000 --- a/languages/c-structs/templates/language/schema.c +++ /dev/null @@ -1,3 +0,0 @@ -typedef struct { - ${properties} -} F${info.title}_${title}; diff --git a/languages/c-structs/templates/methods/clear.c b/languages/c-structs/templates/methods/clear.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/default.c b/languages/c-structs/templates/methods/default.c deleted file mode 100644 index 3707e68b..00000000 --- a/languages/c-structs/templates/methods/default.c +++ /dev/null @@ -1,24 +0,0 @@ -/* ${method.name} - ${method.description} */ -int F${info.title}_${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}) { - int status = FireboltSDKErrorUnavailable; - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - - JsonObject jsonParameters; - - ${if.params} -${method.params.json} - ${end.if.params} - - WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke("${info.title}.${method.name}", jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - *success = jsonResult.Value(); - } - - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; -} diff --git a/languages/c-structs/templates/methods/event.c b/languages/c-structs/templates/methods/event.c deleted file mode 100644 index 6e0e966a..00000000 --- a/languages/c-structs/templates/methods/event.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ${method.name} - ${method.description} */ -static void F${info.Title}${method.Name}InnerCallback( void* userCB, const void* userData, void* response ) -{ -${event.callback.params.serialization} - ASSERT(jsonResponse->IsValid() == true); - if (jsonResponse->IsValid() == true) { -${event.callback.result.instantiation} - ${info.Title}${method.Name}Callback callback = reinterpret_cast<${info.Title}${method.Name}Callback>(userCB); - callback(userData, ${event.callback.response.instantiation}); - } -} -int F${info.title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}${info.Title}${method.Name}Callback userCB, const void* userData ) -{ - const string eventName = _T("${info.title}.${method.name}"); - int status = FireboltSDKErrorNone; - - if (userCB != nullptr) { - ${event.params.serialization} - status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${info.Title}${method.Name}InnerCallback, reinterpret_cast(userCB), userData); - } - return status; -} -int F${info.title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB) -{ - return FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title}.${method.name}"), reinterpret_cast(userCB)); -} diff --git a/languages/c-structs/templates/methods/listen.c b/languages/c-structs/templates/methods/listen.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/once.c b/languages/c-structs/templates/methods/once.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/polymorphic-pull-event.c b/languages/c-structs/templates/methods/polymorphic-pull-event.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/polymorphic-pull.c b/languages/c-structs/templates/methods/polymorphic-pull.c deleted file mode 100644 index 553b2946..00000000 --- a/languages/c-structs/templates/methods/polymorphic-pull.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ${method.name} - ${method.description} */ -uint32_t ${info.title}_Push${method.Name}(${method.signature.params}) -{ - uint32_t status = FireboltSDKErrorUnavailable; - ${if.params} -${method.params.serialization} - ${end.if.params} - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke(_T("${info.title}.${method.name}"), jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.title}.${method.name} is successfully pushed with status as %d", jsonResult.Value()); - status = (jsonResult.Value() == true) ? FireboltSDKErrorNone : FireboltSDKErrorNotSupported; - } - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; -} diff --git a/languages/c-structs/templates/methods/polymorphic-reducer.c b/languages/c-structs/templates/methods/polymorphic-reducer.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/property.c b/languages/c-structs/templates/methods/property.c deleted file mode 100644 index 7c46f7c1..00000000 --- a/languages/c-structs/templates/methods/property.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ${method.name} - ${method.description} */ -int F${info.title}_Get${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}) { - const string method = _T("${info.title}.${method.name}"); -${if.params}${method.params.serialization}${end.if.params} - ${method.result.json} jsonResult; - ${if.params}int status = FireboltSDK::Properties::Get(method, jsonParameters, jsonResult);${end.if.params} - ${if.params.empty}int status = FireboltSDK::Properties::Get(method, jsonResult);${end.if.params.empty} - if (status == FireboltSDKErrorNone) { - if (${method.result.name} != nullptr) { -${method.result.instantiation} - } - } - return status; -} -${method.setter} diff --git a/languages/c-structs/templates/methods/provide.c b/languages/c-structs/templates/methods/provide.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/rpc-only.c b/languages/c-structs/templates/methods/rpc-only.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/methods/setter.c b/languages/c-structs/templates/methods/setter.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/modules/include/Module.h b/languages/c-structs/templates/modules/include/Module.h deleted file mode 100644 index 7a192768..00000000 --- a/languages/c-structs/templates/modules/include/Module.h +++ /dev/null @@ -1,41 +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 _${info.TITLE}_H -#define _${info.TITLE}_H - -#include "Firebolt.h" -/* ${IMPORTS} */ - -#ifdef __cplusplus -extern "C" { -#endif - -// Enums - -/* ${ENUMS} */ - -/* ${TYPES} */ - -/* ${DECLARATIONS} */ - -#ifdef __cplusplus -} -#endif - -#endif // Header Include Guard diff --git a/languages/c-structs/templates/modules/src/Module.cpp b/languages/c-structs/templates/modules/src/Module.cpp deleted file mode 100644 index 7d59c172..00000000 --- a/languages/c-structs/templates/modules/src/Module.cpp +++ /dev/null @@ -1,41 +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 - */ - -#include "FireboltSDK.h" -/* ${IMPORTS} */ -#include "${info.title}.h" - -namespace FireboltSDK { - namespace ${info.title} { - // Types - /* ${TYPES:json-types} */ - } -} - -/* ${ENUMS:json-types} */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* ${METHODS} */ -/* ${EVENTS} */ - -#ifdef __cplusplus -} -#endif diff --git a/languages/c-structs/templates/parameter-serialization/boolean.cpp b/languages/c-structs/templates/parameter-serialization/boolean.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c-structs/templates/parameter-serialization/boolean.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c-structs/templates/parameter-serialization/default.cpp b/languages/c-structs/templates/parameter-serialization/default.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c-structs/templates/parameter-serialization/default.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c-structs/templates/parameter-serialization/object.cpp b/languages/c-structs/templates/parameter-serialization/object.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c-structs/templates/parameter-serialization/object.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c-structs/templates/parameter-serialization/primitive.cpp b/languages/c-structs/templates/parameter-serialization/primitive.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c-structs/templates/parameter-serialization/primitive.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c-structs/templates/parameter-serialization/string.cpp b/languages/c-structs/templates/parameter-serialization/string.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c-structs/templates/parameter-serialization/string.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c-structs/templates/parameters/default.c b/languages/c-structs/templates/parameters/default.c deleted file mode 100644 index e6e3b8ba..00000000 --- a/languages/c-structs/templates/parameters/default.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} ${method.param.name} \ No newline at end of file diff --git a/languages/c-structs/templates/parameters/json.c b/languages/c-structs/templates/parameters/json.c deleted file mode 100644 index 5ee36bec..00000000 --- a/languages/c-structs/templates/parameters/json.c +++ /dev/null @@ -1,3 +0,0 @@ - ${json.param.type} ${method.param.Name} = ${method.param.name}; - jsonParameters.Add("_T(${method.param.name})", &${method.param.Name}); - diff --git a/languages/c-structs/templates/parameters/optional.c b/languages/c-structs/templates/parameters/optional.c deleted file mode 100644 index e6e3b8ba..00000000 --- a/languages/c-structs/templates/parameters/optional.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} ${method.param.name} \ No newline at end of file diff --git a/languages/c-structs/templates/parameters/result.c b/languages/c-structs/templates/parameters/result.c deleted file mode 100644 index 699c8b5b..00000000 --- a/languages/c-structs/templates/parameters/result.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} *${method.param.name} \ No newline at end of file diff --git a/languages/c-structs/templates/result-instantiation/boolean.cpp b/languages/c-structs/templates/result-instantiation/boolean.cpp deleted file mode 100644 index 036b4a7d..00000000 --- a/languages/c-structs/templates/result-instantiation/boolean.cpp +++ /dev/null @@ -1,2 +0,0 @@ - *${property} = jsonResult.Value(); - \ No newline at end of file diff --git a/languages/c-structs/templates/result-instantiation/default.cpp b/languages/c-structs/templates/result-instantiation/default.cpp deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c-structs/templates/result-instantiation/default.cpp +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c-structs/templates/result-instantiation/object.cpp b/languages/c-structs/templates/result-instantiation/object.cpp deleted file mode 100644 index dcf0b333..00000000 --- a/languages/c-structs/templates/result-instantiation/object.cpp +++ /dev/null @@ -1,4 +0,0 @@ - WPEFramework::Core::ProxyType* resultPtr = new WPEFramework::Core::ProxyType(); - *resultPtr = WPEFramework::Core::ProxyType::Create(); - *(*resultPtr) = jsonResult; - *${property} = static_cast<${info.Title}_${title}>(resultPtr); diff --git a/languages/c-structs/templates/result-instantiation/primitive.cpp b/languages/c-structs/templates/result-instantiation/primitive.cpp deleted file mode 100644 index 23bbace7..00000000 --- a/languages/c-structs/templates/result-instantiation/primitive.cpp +++ /dev/null @@ -1 +0,0 @@ -${type} \ No newline at end of file diff --git a/languages/c-structs/templates/result-instantiation/string.cpp b/languages/c-structs/templates/result-instantiation/string.cpp deleted file mode 100644 index b6c9dcb5..00000000 --- a/languages/c-structs/templates/result-instantiation/string.cpp +++ /dev/null @@ -1,2 +0,0 @@ - FireboltSDK::JSON::String* strResult = new FireboltSDK::JSON::String(jsonResult); - *value = static_cast(strResult); diff --git a/languages/c-structs/templates/schemas/default.c b/languages/c-structs/templates/schemas/default.c deleted file mode 100644 index 9a52cff7..00000000 --- a/languages/c-structs/templates/schemas/default.c +++ /dev/null @@ -1 +0,0 @@ -${schema.shape} diff --git a/languages/c-structs/templates/schemas/include/Common/Module.h b/languages/c-structs/templates/schemas/include/Common/Module.h deleted file mode 100644 index ff037fba..00000000 --- a/languages/c-structs/templates/schemas/include/Common/Module.h +++ /dev/null @@ -1,39 +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 _COMMON_${info.TITLE}_H -#define _COMMON_${info.TITLE}_H - -#include "Firebolt.h" -/* ${IMPORTS} */ - -#ifdef __cplusplus -extern "C" { -#endif - -// Enums - -/* ${ENUMS} */ - -/* ${TYPES} */ - -#ifdef __cplusplus -} -#endif - -#endif // Header Include Guard diff --git a/languages/c-structs/templates/schemas/src/JsonData_Module.h b/languages/c-structs/templates/schemas/src/JsonData_Module.h deleted file mode 100644 index 7c41a2ab..00000000 --- a/languages/c-structs/templates/schemas/src/JsonData_Module.h +++ /dev/null @@ -1,30 +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 - */ - -#pragma once - -/* ${IMPORTS} */ -#include "Common/${info.title}.h" - -namespace FireboltSDK { - namespace ${info.title} { - // Types - - /* ${SCHEMAS:json-types} */ - } -} diff --git a/languages/c-structs/templates/schemas/src/Module_Common.cpp b/languages/c-structs/templates/schemas/src/Module_Common.cpp deleted file mode 100644 index 0ccdfc28..00000000 --- a/languages/c-structs/templates/schemas/src/Module_Common.cpp +++ /dev/null @@ -1,35 +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 - */ - -#include "FireboltSDK.h" -/* ${IMPORTS} */ -#include "JsonData_${info.title}.h" - -/* ${ENUMS} */ - -#ifdef __cplusplus -extern "C" { -#endif - - /* ${ACCESSORS} */ - /* ${METHODS} */ - /* ${EVENTS} */ - -#ifdef __cplusplus -} -#endif diff --git a/languages/c-structs/templates/sdk/CMakeLists.txt b/languages/c-structs/templates/sdk/CMakeLists.txt deleted file mode 100644 index 5efcad1a..00000000 --- a/languages/c-structs/templates/sdk/CMakeLists.txt +++ /dev/null @@ -1,61 +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 - -cmake_minimum_required(VERSION 3.3) - -project(Firebolt) - -set(FIREBOLT_TRANSPORT_WAITTIME 1000 CACHE STRING "Maximum time to wait for Transport layer to get response") -set(FIREBOLT_LOGLEVEL "Info" CACHE STRING "Log level to be enabled") -option(FIREBOLT_ENABLE_STATIC_LIB "Create Firebolt library as Static library" OFF) -option(ENABLE_TESTS "Build openrpc native test" OFF) - -if (NOT SYSROOT_PATH) - # Set sysroot to support PC builds, sysroot_path not configured case - set(SYSROOT_PATH "${CMAKE_SOURCE_DIR}/../../firebolt") -endif() - -if (FIREBOLT_ENABLE_STATIC_LIB) - set(FIREBOLT_LIBRARY_TYPE STATIC) -else () - set(FIREBOLT_LIBRARY_TYPE SHARED) -endif () - -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${SYSROOT_PATH}/usr" CACHE INTERNAL "" FORCE) - set(CMAKE_PREFIX_PATH ${SYSROOT_PATH}/usr/lib/cmake CACHE INTERNAL "" FORCE) -endif() - -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_SOURCE_DIR}/cmake" - "${SYSROOT_PATH}/usr/lib/cmake" - "${SYSROOT_PATH}/tools/cmake") -include(HelperFunctions) - -set(FIREBOLT_NAMESPACE ${PROJECT_NAME} CACHE STRING "Namespace of the project") - -find_package(WPEFramework CONFIG REQUIRED) - -add_subdirectory(src) - -if (ENABLE_TESTS) - add_subdirectory(test) -endif() - -# make sure others can make use cmake settings of Firebolt OpenRPC -configure_file( "${CMAKE_SOURCE_DIR}/cmake/project.cmake.in" - "${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}Config.cmake" - @ONLY) diff --git a/languages/c-structs/templates/sdk/cmake/HelperFunctions.cmake b/languages/c-structs/templates/sdk/cmake/HelperFunctions.cmake deleted file mode 100644 index b3647c16..00000000 --- a/languages/c-structs/templates/sdk/cmake/HelperFunctions.cmake +++ /dev/null @@ -1,144 +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 - -macro(GetSubDirs subdirs currentdir) - file(GLOB subdirectories RELATIVE ${currentdir} ${currentdir}/*) - set(subdirs "") - foreach(subdir ${subdirectories}) - if (IS_DIRECTORY ${currentdir}/${subdir}) - list(APPEND subdirs ${subdir}) - endif() - endforeach() -endmacro() - -function(InstallHeaders) - set(optionsArgs EXCLUDE_ROOT_DIR) - set(oneValueArgs TARGET NAMESPACE SOURCE DESTINATION) - set(multiValueArgs HEADERS) - - cmake_parse_arguments(Argument "${optionsArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (Argument_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to InstallHeaders(): \"${Argument_UNPARSED_ARGUMENTS}\"") - endif() - if (Argument_HEADERS) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMENT "=================== Installing Headers ======================" - ) - foreach(directory ${Argument_HEADERS}) - if (Argument_EXCLUDE_ROOT_DIR) - set(destination ${Argument_DESTINATION}) - else() - set(destination ${Argument_DESTINATION}/${directory}) - endif() - - if (Argument_SOURCE) - set(source ${Argument_SOURCE}) - else() - set(source ${CMAKE_CURRENT_LIST_DIR}) - endif() - - GetSubDirs(subdirs ${source}/${directory}) - list(APPEND subdirs ${directory}) - - foreach(subdir ${subdirs}) - set(dest ${destination}/${subdir}) - file(GLOB headers "${source}/${directory}/${subdir}/*.h") - if (headers) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${Argument_NAMESPACE}/usr/include/${dest} - COMMAND ${CMAKE_COMMAND} -E copy ${source}/${directory}/${subdir}/*.h ${CMAKE_BINARY_DIR}/${Argument_NAMESPACE}/usr/include/${dest} - ) - endif() - endforeach(subdir) - endforeach(directory) - endif() -endfunction(InstallHeaders) - -function(InstallLibraries) - set(optionsArgs SHARED STATIC) - set(oneValueArgs TARGET DESTINATION LIBDIR) - set(multiValueArgs LIBRARIES) - - cmake_parse_arguments(Argument "${optionsArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (Argument_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to InstallLibraries(): \"${Argument_UNPARSED_ARGUMENTS}\"") - endif() - if (Argument_LIBRARIES) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMENT "=================== Installing Libraries ======================" - ) - foreach(LIBRARY ${Argument_LIBRARIES}) - if (Argument_SHARED) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${Argument_LIBDIR}/lib${LIBRARY}.so.${PROJECT_VERSION} ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib - COMMAND ${CMAKE_COMMAND} -E create_symlink lib${LIBRARY}.so.${PROJECT_VERSION} ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/lib${LIBRARY}.so.${PROJECT_VERSION_MAJOR} - COMMAND ${CMAKE_COMMAND} -E create_symlink lib${LIBRARY}.so.${PROJECT_VERSION_MAJOR} ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/lib${LIBRARY}.so - ) - elseif (Argument_STATIC) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBRARY}.a ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib - ) - - endif() - endforeach(LIBRARY) - endif() -endfunction(InstallLibraries) - -function(InstallCMakeConfigs) - set(optionsArgs) - set(oneValueArgs TARGET DESTINATION) - set(multiValueArgs) - - cmake_parse_arguments(Argument "${optionsArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (Argument_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to InstallCMakeConfigs(): \"${Argument_UNPARSED_ARGUMENTS}\"") - endif() - if (Argument_TARGET) - if (${CMAKE_VERSION} VERSION_LESS "3.25.0") - set(EXPORT_CONFIG_PATH "lib/cmake/${Argument_TARGET}") - else () - set(EXPORT_CONFIG_PATH "*") - endif () - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMENT "=================== Installing CMakeConfigs ======================" - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/cmake/${Argument_TARGET} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${Argument_TARGET}Config*.cmake ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/cmake/${Argument_TARGET} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Export/${EXPORT_CONFIG_PATH}/${Argument_TARGET}Targets*.cmake ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/cmake/${Argument_TARGET} - ) - if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${Argument_TARGET}.pc) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/pkgconfig - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${Argument_TARGET}.pc ${CMAKE_BINARY_DIR}/${Argument_DESTINATION}/usr/lib/pkgconfig - ) - endif() - endif() -endfunction(InstallCMakeConfigs) diff --git a/languages/c-structs/templates/sdk/cmake/project.cmake.in b/languages/c-structs/templates/sdk/cmake/project.cmake.in deleted file mode 100644 index eca32f8c..00000000 --- a/languages/c-structs/templates/sdk/cmake/project.cmake.in +++ /dev/null @@ -1,35 +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 - -set(FIREBOLT_NAMESPACE "@FIREBOLT_NAMESPACE@" CACHE INTERNAL "" FORCE) -set("${FIREBOLT_NAMESPACE}_FOUND" TRUE CACHE INTERNAL "" FORCE) - -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_SOURCE_DIR}/cmake" - "${SYSROOT_PATH}/usr/lib/cmake" - "${SYSROOT_PATH}/usr/lib/cmake/Firebolt" - "${SYSROOT_PATH}/tools/cmake") - -if (NOT DEFINED CMAKE_PREFIX_PATH) - set(CMAKE_PREFIX_PATH ${SYSROOT_PATH}/usr/lib/cmake CACHE INTERNAL "" FORCE) -endif() - -if (FIREBOLT_ENABLE_STATIC_LIB) - set(FIREBOLT_LIBRARY_TYPE STATIC) -else () - set(FIREBOLT_LIBRARY_TYPE SHARED) -endif () - diff --git a/languages/c-structs/templates/sdk/include/Error.h b/languages/c-structs/templates/sdk/include/Error.h deleted file mode 100644 index 87cda9dd..00000000 --- a/languages/c-structs/templates/sdk/include/Error.h +++ /dev/null @@ -1,41 +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_ERROR_H -#define _FIREBOLT_ERROR_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum FireboltSDKError { - FireboltSDKErrorNone = 0, - FireboltSDKErrorGeneral = 1, - FireboltSDKErrorUnavailable = 2, - FireboltSDKErrorTimedout = 3, - FireboltSDKErrorNotSubscribed = 4, - FireboltSDKErrorUnknown = 5, - FireboltSDKErrorInUse = 6, - FireboltSDKErrorNotSupported = 7 -} FireboltSDKError_t; - -#ifdef __cplusplus -} -#endif - -#endif // _FIREBOLT_ERROR_H diff --git a/languages/c-structs/templates/sdk/include/Firebolt.h b/languages/c-structs/templates/sdk/include/Firebolt.h deleted file mode 100644 index 2223bad3..00000000 --- a/languages/c-structs/templates/sdk/include/Firebolt.h +++ /dev/null @@ -1,65 +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 - -/** - * @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/c-structs/templates/sdk/include/Types.h b/languages/c-structs/templates/sdk/include/Types.h deleted file mode 100644 index 4fd16256..00000000 --- a/languages/c-structs/templates/sdk/include/Types.h +++ /dev/null @@ -1,37 +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_TYPES_H -#define _FIREBOLT_TYPES_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* FireboltTypes_StringHandle; -const char* FireboltTypes_String(FireboltTypes_StringHandle handle); -void FireboltTypes_StringHandle_Release(FireboltTypes_StringHandle handle); - -#ifdef __cplusplus -} -#endif - -#endif // _FIREBOLT_TYPES_H diff --git a/languages/c-structs/templates/sdk/scripts/build.sh b/languages/c-structs/templates/sdk/scripts/build.sh deleted file mode 100755 index e9b01f20..00000000 --- a/languages/c-structs/templates/sdk/scripts/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -SDK_PATH="." -if [ "$1" != "" ] -then - SDK_PATH=$1 - echo "inside ${1}" -fi -echo ${SDK_PATH} -rm -rf ${SDK_PATH}/build -cmake -B${SDK_PATH}/build -S${SDK_PATH} -DSYSROOT_PATH=${SYSROOT_PATH} -cmake --build ${SDK_PATH}/build diff --git a/languages/c-structs/templates/sdk/scripts/install.js b/languages/c-structs/templates/sdk/scripts/install.js deleted file mode 100644 index 5c332ceb..00000000 --- a/languages/c-structs/templates/sdk/scripts/install.js +++ /dev/null @@ -1,32 +0,0 @@ -import { createRequire } from 'module'; -const require = createRequire(import.meta.url); -const fs = require('fs'); -const path = require('path'); - -var dest = process.env.NODE_INSTALL_PATH; -var src = 'src/native/build/' + process.env.TARGET_NAME; - -installFiles(src, dest); -function installFiles(src, dest) { - if (!fs.existsSync(dest)) { - fs.mkdirSync(dest); - } - - var entries = fs.readdirSync(src); - entries.forEach((entry) => { - const srcPath = path.join(src, entry); - const destPath = path.join(dest, entry); - const stat = fs.lstatSync(srcPath); - - if (stat.isFile()) { - fs.copyFileSync(srcPath, destPath); - } else if (stat.isDirectory()) { - installFiles(srcPath, destPath); - } else if (stat.isSymbolicLink()) { - if (fs.existsSync(destPath)) { - fs.unlinkSync(destPath); - } - fs.symlinkSync(fs.readlinkSync(srcPath), destPath); - } - }); -} diff --git a/languages/c-structs/templates/sdk/src/Accessor/Accessor.cpp b/languages/c-structs/templates/sdk/src/Accessor/Accessor.cpp deleted file mode 100644 index e4a5df32..00000000 --- a/languages/c-structs/templates/sdk/src/Accessor/Accessor.cpp +++ /dev/null @@ -1,117 +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 - */ - -#include "Accessor.h" - -namespace FireboltSDK { - - Accessor* Accessor::_singleton = nullptr; - - Accessor::Accessor(const string& configLine) - : _workerPool() - , _transport(nullptr) - , _config() - { - _singleton = this; - _config.FromString(configLine); - - Logger::SetLogLevel(WPEFramework::Core::EnumerateType(_config.LogLevel.Value().c_str()).Value()); - - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Url = %s", _config.WsUrl.Value().c_str()); - CreateTransport(_config.WsUrl.Value().c_str(), _config.WaitTime.Value()); - CreateEventHandler(); - - _workerPool = WPEFramework::Core::ProxyType::Create(_config.WorkerPool.ThreadCount.Value(), _config.WorkerPool.StackSize.Value(), _config.WorkerPool.QueueSize.Value()); - WPEFramework::Core::WorkerPool::Assign(&(*_workerPool)); - _workerPool->Run(); - } - - Accessor::~Accessor() - { - DestroyTransport(); - DestroyEventHandler(); - WPEFramework::Core::IWorkerPool::Assign(nullptr); - _workerPool->Stop(); - _singleton = nullptr; - } - - uint32_t Accessor::CreateEventHandler() - { - Event::Instance().Configure(_transport); - return FireboltSDKErrorNone; - } - - uint32_t Accessor::DestroyEventHandler() - { - Event::Dispose(); - return FireboltSDKErrorNone; - } - - Event& Accessor::GetEventManager() - { - return Event::Instance(); - } - - uint32_t Accessor::CreateTransport(const string& url, const uint32_t waitTime = DefaultWaitTime) - { - if (_transport != nullptr) { - delete _transport; - } - - _transport = new Transport(static_cast(url), waitTime); - if (WaitForLinkReady(_transport, waitTime) != FireboltSDKErrorNone) { - delete _transport; - _transport = nullptr; - } - - ASSERT(_transport != nullptr); - return ((_transport != nullptr) ? FireboltSDKErrorNone : FireboltSDKErrorUnavailable); - } - - uint32_t Accessor::DestroyTransport() - { - if (_transport != nullptr) { - delete _transport; - _transport = nullptr; - } - return FireboltSDKErrorNone; - } - - Transport* Accessor::GetTransport() - { - ASSERT(_transport != nullptr); - return _transport; - } - - uint32_t Accessor::WaitForLinkReady(Transport* transport, const uint32_t waitTime = DefaultWaitTime) { - uint32_t waiting = (waitTime == WPEFramework::Core::infinite ? WPEFramework::Core::infinite : waitTime); - static constexpr uint32_t SLEEPSLOT_TIME = 100; - - // Right, a wait till connection is closed is requested.. - while ((waiting > 0) && (transport->IsOpen() == false)) { - - uint32_t sleepSlot = (waiting > SLEEPSLOT_TIME ? SLEEPSLOT_TIME : waiting); - - // Right, lets sleep in slices of 100 ms - SleepMs(sleepSlot); - - waiting -= (waiting == WPEFramework::Core::infinite ? 0 : sleepSlot); - } - return (((waiting == 0) || (transport->IsOpen() == true)) ? FireboltSDKErrorNone : FireboltSDKErrorTimedout); - } -} diff --git a/languages/c-structs/templates/sdk/src/Accessor/Accessor.h b/languages/c-structs/templates/sdk/src/Accessor/Accessor.h deleted file mode 100644 index f12dc51c..00000000 --- a/languages/c-structs/templates/sdk/src/Accessor/Accessor.h +++ /dev/null @@ -1,122 +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 - */ - -#pragma once - -#include "Module.h" -#include "WorkerPool.h" -#include "Transport/Transport.h" -#include "Event/Event.h" -#include "Logger/Logger.h" - -namespace FireboltSDK { - class Accessor { - private: - static constexpr uint8_t JSONVersion = 2; - - private: - //Singleton - Accessor(const string& configLine); - - public: - class EXTERNAL Config : public WPEFramework::Core::JSON::Container { - public: - Config(const Config&) = delete; - Config& operator=(const Config&) = delete; - - class WorkerPoolConfig : public WPEFramework::Core::JSON::Container { - public: - WorkerPoolConfig& operator=(const WorkerPoolConfig&); - - WorkerPoolConfig() - : WPEFramework::Core::JSON::Container() - , QueueSize(8) - , ThreadCount(3) - , StackSize(WPEFramework::Core::Thread::DefaultStackSize()) - { - Add("queueSize", &QueueSize); - Add("threadCount", &ThreadCount); - Add("stackSize", &StackSize); - } - - virtual ~WorkerPoolConfig() = default; - - public: - WPEFramework::Core::JSON::DecUInt32 QueueSize; - WPEFramework::Core::JSON::DecUInt32 ThreadCount; - WPEFramework::Core::JSON::DecUInt32 StackSize; - }; - - - Config() - : WPEFramework::Core::JSON::Container() - , WaitTime(1000) - , LogLevel(_T("Info")) - , WorkerPool() - , WsUrl(_T("ws://127.0.0.1:9998")) - { - Add(_T("waitTime"), &WaitTime); - Add(_T("logLevel"), &LogLevel); - Add(_T("workerPool"), &WorkerPool); - Add(_T("wsUrl"), &WsUrl); - } - - public: - WPEFramework::Core::JSON::DecUInt32 WaitTime; - WPEFramework::Core::JSON::String LogLevel; - WorkerPoolConfig WorkerPool; - WPEFramework::Core::JSON::String WsUrl; - }; - - Accessor(const Accessor&) = delete; - Accessor& operator= (const Accessor&) = delete; - Accessor() = delete; - ~Accessor(); - - static Accessor& Instance(const string& configLine = "") - { - static Accessor *instance = new Accessor(configLine); - ASSERT(instance != nullptr); - return *instance; - } - - static void Dispose() - { - ASSERT(_singleton != nullptr); - - if (_singleton != nullptr) { - delete _singleton; - } - } - Event& GetEventManager(); - Transport* GetTransport(); - - private: - uint32_t CreateEventHandler(); - uint32_t DestroyEventHandler(); - uint32_t CreateTransport(const string& url, const uint32_t waitTime); - uint32_t DestroyTransport(); - uint32_t WaitForLinkReady(Transport* transport, const uint32_t waitTime); - - private: - WPEFramework::Core::ProxyType _workerPool; - Transport* _transport; - static Accessor* _singleton; - Config _config; - }; -} diff --git a/languages/c-structs/templates/sdk/src/Accessor/WorkerPool.h b/languages/c-structs/templates/sdk/src/Accessor/WorkerPool.h deleted file mode 100644 index 69005a5e..00000000 --- a/languages/c-structs/templates/sdk/src/Accessor/WorkerPool.h +++ /dev/null @@ -1,102 +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 - */ - -#pragma once - -#include "Module.h" - -namespace FireboltSDK { - - class WorkerPoolImplementation : public WPEFramework::Core::WorkerPool { - public: - WorkerPoolImplementation() = delete; - WorkerPoolImplementation(const WorkerPoolImplementation&) = delete; - WorkerPoolImplementation& operator=(const WorkerPoolImplementation&) = delete; - - WorkerPoolImplementation(const uint8_t threads, const uint32_t stackSize, const uint32_t queueSize) - : WorkerPool(threads, stackSize, queueSize, &_dispatcher) - { - } - - ~WorkerPoolImplementation() - { - // Diable the queue so the minions can stop, even if they are processing and waiting for work.. - Stop(); - } - - public: - void Stop() - { - WPEFramework::Core::WorkerPool::Stop(); - } - - void Run() - { - WPEFramework::Core::WorkerPool::Run(); - } - - private: - class Dispatcher : public WPEFramework::Core::ThreadPool::IDispatcher { - public: - Dispatcher(const Dispatcher&) = delete; - Dispatcher& operator=(const Dispatcher&) = delete; - - Dispatcher() = default; - ~Dispatcher() override = default; - - private: - void Initialize() override { } - void Deinitialize() override { } - void Dispatch(WPEFramework::Core::IDispatch* job) override - { job->Dispatch(); } - }; - - Dispatcher _dispatcher; - }; - - class Worker : public WPEFramework::Core::IDispatch { - public: - typedef std::function Dispatcher; - - protected: - Worker(const Dispatcher& dispatcher, const void* userData) - : _dispatcher(dispatcher) - , _userData(userData) - { - } - - public: - Worker() = delete; - Worker(const Worker&) = delete; - Worker& operator=(const Worker&) = delete; - - ~Worker() = default; - - public: - static WPEFramework::Core::ProxyType Create(const Dispatcher& dispatcher, const void* userData); - - void Dispatch() override - { - _dispatcher(_userData); - } - - private: - Dispatcher _dispatcher; - const void* _userData; - }; -} diff --git a/languages/c-structs/templates/sdk/src/CMakeLists.txt b/languages/c-structs/templates/sdk/src/CMakeLists.txt deleted file mode 100644 index 2f00bdf1..00000000 --- a/languages/c-structs/templates/sdk/src/CMakeLists.txt +++ /dev/null @@ -1,84 +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 - -cmake_minimum_required(VERSION 3.3) - -project(FireboltSDK) -project_version(1.0.0) -set(TARGET ${PROJECT_NAME}) -message("Setup ${TARGET} v${PROJECT_VERSION}") -file(GLOB GENERATED_SOURCES "${GENERATED_CODE_PATH}/src/*.cpp") - -file(GLOB SOURCES *.cpp) -add_library(${TARGET} ${FIREBOLT_LIBRARY_TYPE} - ${SOURCES} - Logger/Logger.cpp - Transport/Transport.cpp - Accessor/Accessor.cpp - Event/Event.cpp -) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_package(${NAMESPACE}WebSocket CONFIG REQUIRED) - -target_link_libraries(${TARGET} - PUBLIC - ${NAMESPACE}WebSocket::${NAMESPACE}WebSocket -) - -target_include_directories(${TARGET} - PRIVATE - $ - $ - $ - $ -) - -set_target_properties(${TARGET} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - FRAMEWORK FALSE - LINK_WHAT_YOU_USE TRUE - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} -) - -install( - TARGETS ${TARGET} EXPORT ${TARGET}Targets - LIBRARY DESTINATION lib COMPONENT libs - PUBLIC_HEADER DESTINATION include/${TARGET} COMPONENT devel # headers for mac (note the different component -> different package) - INCLUDES DESTINATION include/${TARGET} # headers -) - -InstallHeaders(TARGET ${TARGET} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION ${FIREBOLT_NAMESPACE}SDK) -InstallHeaders(TARGET ${TARGET} EXCLUDE_ROOT_DIR HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} - SOURCE ${GENERATED_CODE_PATH}/include DESTINATION ${FIREBOLT_NAMESPACE}/generated) -InstallHeaders(TARGET ${TARGET} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} - SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/../include DESTINATION ${FIREBOLT_NAMESPACE}) - -InstallLibraries(TARGET ${TARGET} ${FIREBOLT_LIBRARY_TYPE} LIBDIR ${LIBDIR} LIBRARIES ${TARGET} DESTINATION ${FIREBOLT_NAMESPACE}) -InstallCMakeConfig(TARGETS ${TARGET}) -InstallPackageConfig(TARGETS ${TARGET} DESCRIPTION "Firebolt SDK Library") -InstallCMakeConfigs(TARGET ${TARGET} DESTINATION ${FIREBOLT_NAMESPACE}) - -add_custom_command( - TARGET ${TARGET} - POST_BUILD - COMMENT "=================== Installing FireboltConfig & Helper CMakes ======================" - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/lib/cmake/${FIREBOLT_NAMESPACE} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}Config.cmake ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/lib/cmake/${FIREBOLT_NAMESPACE} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/*.cmake ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/lib/cmake/${FIREBOLT_NAMESPACE} -) diff --git a/languages/c-structs/templates/sdk/src/Event/Event.cpp b/languages/c-structs/templates/sdk/src/Event/Event.cpp deleted file mode 100644 index 5e98a36f..00000000 --- a/languages/c-structs/templates/sdk/src/Event/Event.cpp +++ /dev/null @@ -1,147 +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 - */ - -#include "Transport/Transport.h" -#include "Event.h" - -namespace FireboltSDK { - Event* Event::_singleton = nullptr; - Event::Event() - : _eventMap() - , _adminLock() - , _transport(nullptr) - { - ASSERT(_singleton == nullptr); - _singleton = this; - } - - Event::~Event() /* override */ - { - _transport->SetEventHandler(nullptr); - _transport = nullptr; - - _singleton = nullptr; - } - - /* static */ Event& Event::Instance() - { - static Event *instance = new Event(); - ASSERT(instance != nullptr); - return *instance; - } - - /* static */ void Event::Dispose() - { - ASSERT(_singleton != nullptr); - - if (_singleton != nullptr) { - delete _singleton; - } - } - - void Event::Configure(Transport* transport) - { - _transport = transport; - _transport->SetEventHandler(this); - } - - uint32_t Event::Unsubscribe(const string& eventName, void* usercb) - { - uint32_t status = Revoke(eventName, usercb); - - if (status == FireboltSDKErrorNone) { - if (_transport != nullptr) { - - const string parameters("{\"listen\":false}"); - status = _transport->Unsubscribe(eventName, parameters); - } - } - return ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone: status); - } - - uint32_t Event::ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) /* override */ - { - uint32_t result = FireboltSDKErrorGeneral; - Response response; - _transport->FromMessage((WPEFramework::Core::JSON::IElement*)&response, *jsonResponse); - if (response.Listening.IsSet() == true) { - result = FireboltSDKErrorNone; - enabled = response.Listening.Value(); - } - return result; - } - - uint32_t Event::Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) /* override */ - { - string response = jsonResponse->Result.Value(); - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.begin(); - while(callbackIndex != eventIndex->second.end()) { - State state; - if (callbackIndex->second.state != State::REVOKED) { - callbackIndex->second.state = State::EXECUTING; - } - state = callbackIndex->second.state; - _adminLock.Unlock(); - if (state == State::EXECUTING) { - callbackIndex->second.lambda(callbackIndex->first, callbackIndex->second.userdata, (jsonResponse->Result.Value())); - } - _adminLock.Lock(); - if (callbackIndex->second.state == State::REVOKED) { - callbackIndex = eventIndex->second.erase(callbackIndex); - if (eventIndex->second.size() == 0) { - _eventMap.erase(eventIndex); - } - } else { - callbackIndex->second.state = State::IDLE; - callbackIndex++; - } - } - } - _adminLock.Unlock(); - - return FireboltSDKErrorNone;; - } - - uint32_t Event::Revoke(const string& eventName, void* usercb) - { - uint32_t status = FireboltSDKErrorNone; - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.find(usercb); - if (callbackIndex->second.state != State::EXECUTING) { - if (callbackIndex != eventIndex->second.end()) { - eventIndex->second.erase(callbackIndex); - } - } else { - callbackIndex->second.state = State::REVOKED; - } - if (eventIndex->second.size() == 0) { - _eventMap.erase(eventIndex); - } else { - status = FireboltSDKErrorInUse; - } - } - _adminLock.Unlock(); - - return status; - } -} diff --git a/languages/c-structs/templates/sdk/src/Event/Event.h b/languages/c-structs/templates/sdk/src/Event/Event.h deleted file mode 100644 index efa8457a..00000000 --- a/languages/c-structs/templates/sdk/src/Event/Event.h +++ /dev/null @@ -1,165 +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 - */ - -#pragma once - -#include "Module.h" - -namespace FireboltSDK { - - static constexpr uint32_t DefaultWaitTime = 1000; - - class Event : public IEventHandler { - public: - typedef std::function DispatchFunction; - private: - enum State : uint8_t { - IDLE, - EXECUTING, - REVOKED - }; - - struct CallbackData { - const DispatchFunction lambda; - const void* userdata; - State state; - }; - using CallbackMap = std::map; - using EventMap = std::map; - - class Response : public WPEFramework::Core::JSON::Container { - public: - Response& operator=(const Response&) = delete; - Response() - : WPEFramework::Core::JSON::Container() - , Listening(false) - { - Add(_T("listening"), &Listening); - } - Response(const Response& copy) - : WPEFramework::Core::JSON::Container() - , Listening(copy.Listening) - { - Add(_T("listening"), &Listening); - } - ~Response() override = default; - - public: - WPEFramework::Core::JSON::Boolean Listening; - }; - - private: - Event(); - public: - ~Event() override; - static Event& Instance(); - static void Dispose(); - void Configure(Transport* transport); - - public: - template - uint32_t Subscribe(const string& eventName, const CALLBACK& callback, void* usercb, const void* userdata) - { - JsonObject jsonParameters; - return Subscribe(eventName, jsonParameters, callback, usercb, userdata); - } - - template - uint32_t Subscribe(const string& eventName, JsonObject& jsonParameters, const CALLBACK& callback, void* usercb, const void* userdata) - { - uint32_t status = FireboltSDKErrorUnavailable; - if (_transport != nullptr) { - - status = Assign(eventName, callback, usercb, userdata); - if (status == FireboltSDKErrorNone) { - Response response; - - WPEFramework::Core::JSON::Variant Listen = true; - jsonParameters.Set(_T("listen"), Listen); - string parameters; - jsonParameters.ToString(parameters); - - status = _transport->Subscribe(eventName, parameters, response); - - if (status != FireboltSDKErrorNone) { - Revoke(eventName, usercb); - } else if ((response.Listening.IsSet() == true) && - (response.Listening.Value() == true)) { - status = FireboltSDKErrorNone; - } else { - status = FireboltSDKErrorNotSubscribed; - } - } - } - - return status; - } - - uint32_t Unsubscribe(const string& eventName, void* usercb); - - private: - template - uint32_t Assign(const string& eventName, const CALLBACK& callback, void* usercb, const void* userdata) - { - uint32_t status = FireboltSDKErrorNone; - std::function actualCallback = callback; - DispatchFunction implementation = [actualCallback](void* usercb, const void* userdata, const string& parameters) -> uint32_t { - - WPEFramework::Core::ProxyType* inbound = new WPEFramework::Core::ProxyType(); - *inbound = WPEFramework::Core::ProxyType::Create(); - (*inbound)->FromString(parameters); - actualCallback(usercb, userdata, static_cast(inbound)); - return (FireboltSDKErrorNone); - }; - CallbackData callbackData = {implementation, userdata, State::IDLE}; - - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.find(usercb); - if (callbackIndex == eventIndex->second.end()) { - eventIndex->second.emplace(std::piecewise_construct, std::forward_as_tuple(usercb), std::forward_as_tuple(callbackData)); - } else { - // Already registered, no need to register again; - status = FireboltSDKErrorInUse; - } - } else { - - CallbackMap callbackMap; - callbackMap.emplace(std::piecewise_construct, std::forward_as_tuple(usercb), std::forward_as_tuple(callbackData)); - _eventMap.emplace(std::piecewise_construct, std::forward_as_tuple(eventName), std::forward_as_tuple(callbackMap)); - - } - - _adminLock.Unlock(); - return status; - } - uint32_t Revoke(const string& eventName, void* usercb); - - private: - uint32_t ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) override; - uint32_t Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) override; - - private: - EventMap _eventMap; - WPEFramework::Core::CriticalSection _adminLock; - Transport* _transport; - - static Event* _singleton; - }; -} diff --git a/languages/c-structs/templates/sdk/src/Firebolt.cpp b/languages/c-structs/templates/sdk/src/Firebolt.cpp deleted file mode 100644 index ffc1369a..00000000 --- a/languages/c-structs/templates/sdk/src/Firebolt.cpp +++ /dev/null @@ -1,40 +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 - */ - -#include "FireboltSDK.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - - -uint32_t FireboltSDK_Initialize(char* configLine) { - FireboltSDK::Accessor::Instance(configLine); - return FireboltSDKErrorNone; -} - -uint32_t FireboltSDK_Deinitialize(void) { - FireboltSDK::Accessor::Dispose(); - return FireboltSDKErrorNone; -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c-structs/templates/sdk/src/FireboltSDK.conf.in b/languages/c-structs/templates/sdk/src/FireboltSDK.conf.in deleted file mode 100644 index 6964a7bc..00000000 --- a/languages/c-structs/templates/sdk/src/FireboltSDK.conf.in +++ /dev/null @@ -1,3 +0,0 @@ -url = "@FIREBOLT_SERVER_URL@" -waittime = "@FIREBOLT_TRANSPORT_WAITTIME@" -loglevel = "@FIREBOLT_LOGLEVEL@" diff --git a/languages/c-structs/templates/sdk/src/FireboltSDK.h b/languages/c-structs/templates/sdk/src/FireboltSDK.h deleted file mode 100644 index 19946126..00000000 --- a/languages/c-structs/templates/sdk/src/FireboltSDK.h +++ /dev/null @@ -1,26 +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 - */ - -#pragma once - -#include "Transport/Transport.h" -#include "Properties/Properties.h" -#include "Accessor/Accessor.h" -#include "Logger/Logger.h" -#include "TypesPriv.h" -#include "Types.h" diff --git a/languages/c-structs/templates/sdk/src/Logger/Logger.cpp b/languages/c-structs/templates/sdk/src/Logger/Logger.cpp deleted file mode 100644 index 0e49dfce..00000000 --- a/languages/c-structs/templates/sdk/src/Logger/Logger.cpp +++ /dev/null @@ -1,83 +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 - */ - -#include "Module.h" -#include "Error.h" -#include "Logger.h" - -namespace WPEFramework { - -ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::LogLevel) - - { FireboltSDK::Logger::LogLevel::Error, _TXT("Error") }, - { FireboltSDK::Logger::LogLevel::Warning, _TXT("Warning") }, - { FireboltSDK::Logger::LogLevel::Info, _TXT("Info") }, - { FireboltSDK::Logger::LogLevel::Debug, _TXT("Debug") }, - -ENUM_CONVERSION_END(FireboltSDK::Logger::LogLevel) - -ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::Category) - - { FireboltSDK::Logger::Category::OpenRPC, _TXT("FireboltSDK::OpenRPC") }, - { FireboltSDK::Logger::Category::Core, _TXT("FireboltSDK::Core") }, - { FireboltSDK::Logger::Category::Management, _TXT("FireboltSDK::Management") }, - { FireboltSDK::Logger::Category::Discovery, _TXT("FireboltSDK::Discovery") }, - -ENUM_CONVERSION_END(FireboltSDK::Logger::Category) - -} - -namespace FireboltSDK { - /* static */ Logger::LogLevel Logger::_logLevel = Logger::LogLevel::Error; - - uint32_t Logger::SetLogLevel(Logger::LogLevel logLevel) - { - ASSERT(logLevel < Logger::LogLevel::MaxLevel); - uint32_t status = FireboltSDKErrorNotSupported; - if (logLevel < Logger::LogLevel::MaxLevel) { - _logLevel = logLevel; - status = FireboltSDKErrorNone; - } - return status; - } - - void Logger::Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...) - { - if (logLevel <= _logLevel) { - va_list arg; - char msg[Logger::MaxBufSize]; - va_start(arg, format); - int length = vsnprintf(msg, Logger::MaxBufSize, format.c_str(), arg); - va_end(arg); - - uint32_t position = (length >= Logger::MaxBufSize) ? (Logger::MaxBufSize - 1) : length; - msg[position] = '\0'; - - char formattedMsg[Logger::MaxBufSize]; - const string time = WPEFramework::Core::Time::Now().ToTimeOnly(true); - const string categoryName = WPEFramework::Core::EnumerateType(category).Data(); - if (categoryName.empty() != true) { - sprintf(formattedMsg, "--->\033[1;32m[%s]:[%s]:[%s][%s:%d](%s) : %s\n", time.c_str(), categoryName.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg); - } else { - sprintf(formattedMsg, "--->\033[1;32m[%s]:[%s][%s:%d](%s) : %s\n", time.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg); - } - LOG_MESSAGE(formattedMsg); - } - } -} - diff --git a/languages/c-structs/templates/sdk/src/Logger/Logger.h b/languages/c-structs/templates/sdk/src/Logger/Logger.h deleted file mode 100644 index cffeff54..00000000 --- a/languages/c-structs/templates/sdk/src/Logger/Logger.h +++ /dev/null @@ -1,85 +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 - */ - -#pragma once - -#include "Types.h" - -namespace FireboltSDK { - - class Logger { - private: - static constexpr uint16_t MaxBufSize = 512; - - public: - enum class LogLevel : uint8_t { - Error, - Warning, - Info, - Debug, - MaxLevel - }; - - enum class Category : uint8_t { - OpenRPC, - Core, - Management, - Discovery - }; - - public: - Logger() = default; - Logger(const Logger&) = delete; - Logger& operator=(const Logger&) = delete; - ~Logger() = default; - - public: - static uint32_t SetLogLevel(LogLevel logLevel); - static void Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...); - - public: - template - static const string Module() - { - return WPEFramework::Core::ClassNameOnly(typeid(CLASS).name()).Text(); - } - - private: - static LogLevel _logLevel; - }; -} - -#define FIREBOLT_LOG(level, category, module, ...) \ - FireboltSDK::Logger::Log(level, category, module, __FILE__, __func__, __LINE__, __VA_ARGS__) - -#define FIREBOLT_LOG_ERROR(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Error, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_WARNING(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Warning, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_INFO(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Info, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_DEBUG(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Debug, category, module, __VA_ARGS__) - -#ifdef ENABLE_SYSLOG -#define LOG_MESSAGE(message) \ - syslog(sLOG_NOTIC, "%s", message); -#else -#define LOG_MESSAGE(message) \ - fprintf(stderr, "%s", message); fflush(stdout); -#endif diff --git a/languages/c-structs/templates/sdk/src/Module.cpp b/languages/c-structs/templates/sdk/src/Module.cpp deleted file mode 100644 index d63badc4..00000000 --- a/languages/c-structs/templates/sdk/src/Module.cpp +++ /dev/null @@ -1,21 +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 - */ - -#include "Module.h" - -MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/languages/c-structs/templates/sdk/src/Module.h b/languages/c-structs/templates/sdk/src/Module.h deleted file mode 100644 index 00ea64bb..00000000 --- a/languages/c-structs/templates/sdk/src/Module.h +++ /dev/null @@ -1,29 +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 - */ - -#pragma once - -#ifndef MODULE_NAME -#define MODULE_NAME OpenRPCNativeSDK -#endif - -#include -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/languages/c-structs/templates/sdk/src/Properties/Properties.h b/languages/c-structs/templates/sdk/src/Properties/Properties.h deleted file mode 100644 index d75c3ba5..00000000 --- a/languages/c-structs/templates/sdk/src/Properties/Properties.h +++ /dev/null @@ -1,148 +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 - */ - -#pragma once - -#include "Accessor/Accessor.h" -#include "Event/Event.h" - -namespace FireboltSDK { - - class Properties { - public: - Properties(const Properties&) = delete; - Properties& operator= (const Properties&) = delete; - - Properties() = default; - ~Properties() = default; - - public: - template - static uint32_t Get(const string& propertyName, WPEFramework::Core::ProxyType& response) - { - uint32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject parameters; - RESPONSETYPE responseType; - status = transport->Invoke(propertyName, parameters, responseType); - if (status == FireboltSDKErrorNone) { - ASSERT(response.IsValid() == false); - if (response.IsValid() == true) { - response.Release(); - } - response = WPEFramework::Core::ProxyType::Create(); - (*response) = responseType; - } - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static uint32_t Get(const string& propertyName, const PARAMETERS& parameters, WPEFramework::Core::ProxyType& response) - { - uint32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - RESPONSETYPE responseType; - status = transport->Invoke(propertyName, parameters, responseType); - if (status == FireboltSDKErrorNone) { - ASSERT(response.IsValid() == false); - if (response.IsValid() == true) { - response.Release(); - } - response = WPEFramework::Core::ProxyType::Create(); - (*response) = responseType; - } - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - - template - static uint32_t Get(const string& propertyName, RESPONSETYPE& response) - { - uint32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject parameters; - status = transport->Invoke(propertyName, parameters, response); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static uint32_t Get(const string& propertyName, const PARAMETERS& parameters, RESPONSETYPE& response) - { - uint32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - status = transport->Invoke(propertyName, parameters, response); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static uint32_t Set(const string& propertyName, const PARAMETERS& parameters) - { - uint32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject responseType; - status = transport->Invoke(propertyName, parameters, responseType); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static uint32_t Subscribe(const string& propertyName, JsonObject& paramsters, const CALLBACK& callback, void* usercb, const void* userdata) - { - return Event::Instance().Subscribe(EventName(propertyName), paramsters, callback, usercb, userdata); - } - - static uint32_t Unsubscribe(const string& propertyName, void* usercb) - { - return Event::Instance().Unsubscribe(EventName(propertyName), usercb); - } - private: - static inline string EventName(const string& propertyName) { - size_t pos = propertyName.find_first_of('.'); - string eventName = propertyName; - if (pos != std::string::npos) { - eventName[pos + 1] = std::toupper(eventName[pos + 1]); - eventName = string(eventName.substr(0, pos + 1) + "on" + eventName.substr(pos + 1) + "Changed"); - } - return eventName; - } - }; -} diff --git a/languages/c-structs/templates/sdk/src/Transport/Transport.cpp b/languages/c-structs/templates/sdk/src/Transport/Transport.cpp deleted file mode 100644 index 280944c6..00000000 --- a/languages/c-structs/templates/sdk/src/Transport/Transport.cpp +++ /dev/null @@ -1,24 +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 - */ - -#include "Transport.h" - -namespace FireboltSDK { - -} - diff --git a/languages/c-structs/templates/sdk/src/Transport/Transport.h b/languages/c-structs/templates/sdk/src/Transport/Transport.h deleted file mode 100644 index 2aff350d..00000000 --- a/languages/c-structs/templates/sdk/src/Transport/Transport.h +++ /dev/null @@ -1,897 +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 - */ - -#pragma once - -#include "Module.h" -#include "Error.h" - -namespace FireboltSDK { - - using namespace WPEFramework::Core::TypeTraits; - - template - class CommunicationChannel { - public: - typedef std::function Callback; - class Entry { - private: - Entry(const Entry&) = delete; - Entry& operator=(const Entry& rhs) = delete; - struct Synchronous { - Synchronous() - : _signal(false, true) - , _response() - { - } - WPEFramework::Core::Event _signal; - std::list> _response; - }; - struct ASynchronous { - ASynchronous(const uint32_t waitTime, const Callback& completed) - : _waitTime(WPEFramework::Core::Time::Now().Add(waitTime).Ticks()) - , _completed(completed) - { - } - uint64_t _waitTime; - Callback _completed; - }; - - public: - Entry() - : _synchronous(true) - , _info() - { - } - Entry(const uint32_t waitTime, const Callback& completed) - : _synchronous(false) - , _info(waitTime, completed) - { - } - ~Entry() - { - if (_synchronous == true) { - _info.sync.~Synchronous(); - } - else { - _info.async.~ASynchronous(); - } - } - - public: - const WPEFramework::Core::ProxyType& Response() const - { - return (*(_info.sync._response.begin())); - } - bool Signal(const WPEFramework::Core::ProxyType& response) - { - if (_synchronous == true) { - _info.sync._response.push_back(response); - _info.sync._signal.SetEvent(); - } - else { - _info.async._completed(*response); - } - - return (_synchronous == false); - } - const uint64_t& Expiry() const - { - return (_info.async._waitTime); - } - void Abort(const uint32_t id) - { - if (_synchronous == true) { - _info.sync._signal.SetEvent(); - } - else { - MESSAGETYPE message; - ToMessage(id, message, WPEFramework::Core::ERROR_ASYNC_ABORTED); - _info.async._completed(message); - } - } - bool Expired(const uint32_t id, const uint64_t& currentTime, uint64_t& nextTime) - { - bool expired = false; - - if (_synchronous == false) { - if (_info.async._waitTime > currentTime) { - if (_info.async._waitTime < nextTime) { - nextTime = _info.async._waitTime; - } - } - else { - MESSAGETYPE message; - ToMessage(id, message, WPEFramework::Core::ERROR_TIMEDOUT); - _info.async._completed(message); - expired = true; - } - } - return (expired); - } - bool WaitForResponse(const uint32_t waitTime) - { - return (_info.sync._signal.Lock(waitTime) == WPEFramework::Core::ERROR_NONE); - } - - private: - void ToMessage(const uint32_t id, WPEFramework::Core::JSONRPC::Message& message, uint32_t error) - { - message.Id = id; - message.Error.Code = error; - switch (error) { - case WPEFramework::Core::ERROR_ASYNC_ABORTED: { - message.Error.Text = _T("Pending a-sync call has been aborted"); - break; - } - case WPEFramework::Core::ERROR_TIMEDOUT: { - message.Error.Text = _T("Pending a-sync call has timed out"); - break; - } - } - } - - bool _synchronous; - union Info { - public: - Info() - : sync() - { - } - Info(const uint32_t waitTime, const Callback& completed) - : async(waitTime, completed) - { - } - ~Info() - { - } - Synchronous sync; - ASynchronous async; - } _info; - }; - - - - private: - class FactoryImpl { - private: - FactoryImpl(const FactoryImpl&) = delete; - FactoryImpl& operator=(const FactoryImpl&) = delete; - - class WatchDog { - private: - WatchDog() = delete; - WatchDog& operator=(const WatchDog&) = delete; - - public: - WatchDog(CLIENT* client) - : _client(client) - { - } - WatchDog(const WatchDog& copy) - : _client(copy._client) - { - } - ~WatchDog() - { - } - - bool operator==(const WatchDog& rhs) const - { - return (rhs._client == _client); - } - bool operator!=(const WatchDog& rhs) const - { - return (!operator==(rhs)); - } - - public: - uint64_t Timed(const uint64_t scheduledTime) { - return (_client->Timed()); - } - - private: - CLIENT* _client; - }; - - friend WPEFramework::Core::SingletonType; - - FactoryImpl() - : _messageFactory(2) - , _watchDog(WPEFramework::Core::Thread::DefaultStackSize(), _T("TransportCleaner")) - { - } - - public: - static FactoryImpl& Instance() - { - return (WPEFramework::Core::SingletonType::Instance()); - } - - ~FactoryImpl() - { - } - - public: - WPEFramework::Core::ProxyType Element(const string&) - { - return (_messageFactory.Element()); - } - void Trigger(const uint64_t& time, CLIENT* client) - { - _watchDog.Trigger(time, client); - } - void Revoke(CLIENT* client) - { - _watchDog.Revoke(client); - } - private: - WPEFramework::Core::ProxyPoolType _messageFactory; - WPEFramework::Core::TimerType _watchDog; - }; - - class ChannelImpl : public WPEFramework::Core::StreamJSONType, FactoryImpl&, INTERFACE> { - private: - ChannelImpl(const ChannelImpl&) = delete; - ChannelImpl& operator=(const ChannelImpl&) = delete; - - typedef WPEFramework::Core::StreamJSONType, FactoryImpl&, INTERFACE> BaseClass; - - public: - ChannelImpl(CommunicationChannel* parent, const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask) - : BaseClass(5, FactoryImpl::Instance(), path, _T("JSON"), query, "", false, mask, false, remoteNode.AnyInterface(), remoteNode, 1024 * 2, 1024 * 2) //TODO Relook this size issue - , _parent(*parent) - { - } - ~ChannelImpl() override = default; - - public: - void Received(WPEFramework::Core::ProxyType& response) override - { - WPEFramework::Core::ProxyType inbound(response); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - _parent.Inbound(inbound); - } - } - void Send(WPEFramework::Core::ProxyType& msg) override - { -#ifdef __DEBUG__ - string message; - ToMessage(msg, message); - TRACE_L1("Message: %s send", message.c_str()); -#endif - } - void StateChange() override - { - _parent.StateChange(); - } - bool IsIdle() const override - { - return (true); - } - - private: - void ToMessage(const WPEFramework::Core::ProxyType& jsonObject, string& message) const - { - WPEFramework::Core::ProxyType inbound(jsonObject); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - inbound->ToString(message); - } - } - void ToMessage(const WPEFramework::Core::ProxyType& jsonObject, string& message) const - { - WPEFramework::Core::ProxyType inbound(jsonObject); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - std::vector values; - inbound->ToBuffer(values); - if (values.empty() != true) { - WPEFramework::Core::ToString(values.data(), static_cast(values.size()), false, message); - } - } - } - - private: - CommunicationChannel& _parent; - }; - - protected: - CommunicationChannel(const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask) - : _channel(this, remoteNode, path, query, mask) - , _sequence(0) - { - } - - public: - ~CommunicationChannel() = default; - static WPEFramework::Core::ProxyType Instance(const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask = true) - { - static WPEFramework::Core::ProxyMapType channelMap; - - string searchLine = remoteNode.HostAddress() + '@' + path; - - return (channelMap.template Instance(searchLine, remoteNode, path, query, mask)); - } - - public: - static void Trigger(const uint64_t& time, CLIENT* client) - { - FactoryImpl::Instance().Trigger(time, client); - } - static WPEFramework::Core::ProxyType Message() - { - return (FactoryImpl::Instance().Element(string())); - } - uint32_t Sequence() const - { - return (++_sequence); - } - void Register(CLIENT& client) - { - _adminLock.Lock(); - ASSERT(std::find(_observers.begin(), _observers.end(), &client) == _observers.end()); - _observers.push_back(&client); - if (_channel.IsOpen() == true) { - client.Opened(); - } - _adminLock.Unlock(); - } - void Unregister(CLIENT& client) - { - _adminLock.Lock(); - typename std::list::iterator index(std::find(_observers.begin(), _observers.end(), &client)); - if (index != _observers.end()) { - _observers.erase(index); - } - FactoryImpl::Instance().Revoke(&client); - _adminLock.Unlock(); - } - - void Submit(const WPEFramework::Core::ProxyType& message) - { - _channel.Submit(message); - } - bool IsSuspended() const - { - return (_channel.IsSuspended()); - } - uint32_t Initialize() - { - return (Open(0)); - } - void Deinitialize() - { - Close(); - } - bool IsOpen() - { - return (_channel.IsOpen() == true); - } - - protected: - void StateChange() - { - _adminLock.Lock(); - typename std::list::iterator index(_observers.begin()); - while (index != _observers.end()) { - if (_channel.IsOpen() == true) { - (*index)->Opened(); - } - else { - (*index)->Closed(); - } - index++; - } - _adminLock.Unlock(); - } - bool Open(const uint32_t waitTime) - { - bool result = true; - if (_channel.IsClosed() == true) { - result = (_channel.Open(waitTime) == WPEFramework::Core::ERROR_NONE); - } - return (result); - } - void Close() - { - _channel.Close(WPEFramework::Core::infinite); - } - - private: - uint32_t Inbound(const WPEFramework::Core::ProxyType& inbound) - { - uint32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - _adminLock.Lock(); - typename std::list::iterator index(_observers.begin()); - while ((result != WPEFramework::Core::ERROR_NONE) && (index != _observers.end())) { - result = (*index)->Submit(inbound); - index++; - } - _adminLock.Unlock(); - - return (result); - } - - private: - WPEFramework::Core::CriticalSection _adminLock; - ChannelImpl _channel; - mutable std::atomic _sequence; - std::list _observers; - }; - - class IEventHandler { - public: - virtual uint32_t ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) = 0; - virtual uint32_t Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) = 0; - virtual ~IEventHandler() = default; - }; - - template - class Transport { - private: - using Channel = CommunicationChannel; - using Entry = typename CommunicationChannel::Entry; - using PendingMap = std::unordered_map; - using EventMap = std::map; - typedef std::function& jsonResponse, bool& enabled)> EventResponseValidatioionFunction; - - class Job : public WPEFramework::Core::IDispatch { - protected: - Job(const WPEFramework::Core::ProxyType& inbound, class Transport* parent) - : _inbound(inbound) - , _parent(parent) - { - } - - public: - Job() = delete; - Job(const Job&) = delete; - Job& operator=(const Job&) = delete; - - ~Job() = default; - - public: - static WPEFramework::Core::ProxyType Create(const WPEFramework::Core::ProxyType& inbound, class Transport* parent); - - void Dispatch() override - { - _parent->Inbound(_inbound); - } - - private: - const WPEFramework::Core::ProxyType _inbound; - class Transport* _parent; - }; - - protected: - static constexpr uint32_t DefaultWaitTime = 10000; - - inline void Announce() { - _channel->Register(*this); - } - - private: - static constexpr const TCHAR* PathPrefix = _T("/"); - public: - Transport() = delete; - Transport(const Transport&) = delete; - Transport& operator=(Transport&) = delete; - Transport(const WPEFramework::Core::URL& url, const uint32_t waitTime) - : _adminLock() - , _connectId(WPEFramework::Core::NodeId(url.Host().Value().c_str(), url.Port().Value())) - , _channel(Channel::Instance(_connectId, ((url.Path().Value().rfind(PathPrefix, 0) == 0) ? url.Path().Value() : string(PathPrefix + url.Path().Value())), url.Query().Value(), true)) - , _eventHandler(nullptr) - , _pendingQueue() - , _scheduledTime(0) - , _waitTime(waitTime) - { - _channel->Register(*this); - } - - virtual ~Transport() - { - _channel->Unregister(*this); - - for (auto& element : _pendingQueue) { - element.second.Abort(element.first); - } - } - - public: - inline bool IsOpen() - { - return _channel->IsOpen(); - } - - void Revoke(const string& eventName) - { - _adminLock.Lock(); - _eventMap.erase(eventName); - _adminLock.Unlock(); - } - - void SetEventHandler(IEventHandler* eventHandler) - { - _eventHandler = eventHandler; - } - - template - uint32_t Invoke(const string& method, const PARAMETERS& parameters, RESPONSE& response) - { - Entry slot; - uint32_t id = _channel->Sequence(); - uint32_t result = Send(method, parameters, id); - if (result == WPEFramework::Core::ERROR_NONE) { - result = WaitForResponse(id, response, _waitTime); - } - - return (FireboltErrorValue(result)); - } - - template - uint32_t Subscribe(const string& eventName, const string& parameters, RESPONSE& response) - { - Entry slot; - uint32_t id = _channel->Sequence(); - uint32_t result = Send(eventName, parameters, id); - if (result == WPEFramework::Core::ERROR_NONE) { - _adminLock.Lock(); - _eventMap.emplace(std::piecewise_construct, - std::forward_as_tuple(eventName), - std::forward_as_tuple(~0)); - _adminLock.Unlock(); - - result = WaitForEventResponse(id, eventName, response, _waitTime); - } - - return (FireboltErrorValue(result)); - } - - uint32_t Unsubscribe(const string& eventName, const string& parameters) - { - Revoke(eventName); - Entry slot; - uint32_t id = _channel->Sequence(); - uint32_t result = Send(eventName, parameters, id); - - return (FireboltErrorValue(result)); - } - - private: - friend Channel; - inline bool IsEvent(const uint32_t id, string& eventName) - { - _adminLock.Lock(); - for (auto& event : _eventMap) { - if (event.second == id) { - eventName = event.first; - break; - } - } - _adminLock.Unlock(); - return (eventName.empty() != true); - } - uint64_t Timed() - { - uint64_t result = ~0; - uint64_t currentTime = WPEFramework::Core::Time::Now().Ticks(); - - // Lets see if some callback are expire. If so trigger and remove... - _adminLock.Lock(); - - typename PendingMap::iterator index = _pendingQueue.begin(); - - while (index != _pendingQueue.end()) { - - if (index->second.Expired(index->first, currentTime, result) == true) { - index = _pendingQueue.erase(index); - } - else { - index++; - } - } - _scheduledTime = (result != static_cast(~0) ? result : 0); - - _adminLock.Unlock(); - - return (_scheduledTime); - } - - virtual void Opened() - { - // Nice to know :-) - } - - void Closed() - { - // Abort any in progress RPC command: - _adminLock.Lock(); - - // See if we issued anything, if so abort it.. - while (_pendingQueue.size() != 0) { - - _pendingQueue.begin()->second.Abort(_pendingQueue.begin()->first); - _pendingQueue.erase(_pendingQueue.begin()); - } - - _adminLock.Unlock(); - } - - uint32_t Submit(const WPEFramework::Core::ProxyType& inbound) - { - uint32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(inbound, this)); - WPEFramework::Core::IWorkerPool::Instance().Submit(job); - return result; - } - - uint32_t Inbound(const WPEFramework::Core::ProxyType& inbound) - { - uint32_t result = WPEFramework::Core::ERROR_INVALID_SIGNATURE; - - ASSERT(inbound.IsValid() == true); - - if ((inbound->Id.IsSet() == true) && (inbound->Result.IsSet() || inbound->Error.IsSet())) { - // Looks like this is a response.. - ASSERT(inbound->Parameters.IsSet() == false); - ASSERT(inbound->Designator.IsSet() == false); - - _adminLock.Lock(); - - // See if we issued this.. - typename PendingMap::iterator index = _pendingQueue.find(inbound->Id.Value()); - - if (index != _pendingQueue.end()) { - - if (index->second.Signal(inbound) == true) { - _pendingQueue.erase(index); - } - - result = WPEFramework::Core::ERROR_NONE; - } else { - - string eventName; - if (IsEvent(inbound->Id.Value(), eventName)) { - _eventHandler->Dispatch(eventName, inbound); - } - - } - _adminLock.Unlock(); - } - - return (result); - } - - - template - uint32_t Send(const string& method, const PARAMETERS& parameters, const uint32_t& id) - { - uint32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - - if ((_channel.IsValid() == true) && (_channel->IsSuspended() == true)) { - result = WPEFramework::Core::ERROR_ASYNC_FAILED; - } - else if (_channel.IsValid() == true) { - - result = WPEFramework::Core::ERROR_ASYNC_FAILED; - - WPEFramework::Core::ProxyType message(Channel::Message()); - message->Id = id; - message->Designator = method; - ToMessage(parameters, message); - - _adminLock.Lock(); - - typename std::pair< typename PendingMap::iterator, bool> newElement = - _pendingQueue.emplace(std::piecewise_construct, - std::forward_as_tuple(id), - std::forward_as_tuple()); - ASSERT(newElement.second == true); - - if (newElement.second == true) { - - _adminLock.Unlock(); - - _channel->Submit(WPEFramework::Core::ProxyType(message)); - - message.Release(); - result = WPEFramework::Core::ERROR_NONE; - } - } - return result; - } - - template - uint32_t WaitForResponse(const uint32_t& id, RESPONSE& response, const uint32_t waitTime) - { - uint32_t result = WPEFramework::Core::ERROR_TIMEDOUT; - _adminLock.Lock(); - typename PendingMap::iterator index = _pendingQueue.find(id); - Entry& slot(index->second); - _adminLock.Unlock(); - - if (slot.WaitForResponse(waitTime) == true) { - WPEFramework::Core::ProxyType jsonResponse = slot.Response(); - - // See if we have a jsonResponse, maybe it was just the connection - // that closed? - if (jsonResponse.IsValid() == true) { - if (jsonResponse->Error.IsSet() == true) { - result = jsonResponse->Error.Code.Value(); - } - else { - result = WPEFramework::Core::ERROR_NONE; - if ((jsonResponse->Result.IsSet() == true) - && (jsonResponse->Result.Value().empty() == false)) { - FromMessage((INTERFACE*)&response, *jsonResponse); - } - } - } - } else { - result = WPEFramework::Core::ERROR_TIMEDOUT; - } - _adminLock.Lock(); - _pendingQueue.erase(id); - _adminLock.Unlock(); - return result; - } - - static constexpr uint32_t WAITSLOT_TIME = 100; - template - uint32_t WaitForEventResponse(const uint32_t& id, const string& eventName, RESPONSE& response, const uint32_t waitTime) - { - uint32_t result = WPEFramework::Core::ERROR_TIMEDOUT; - _adminLock.Lock(); - typename PendingMap::iterator index = _pendingQueue.find(id); - Entry& slot(index->second); - _adminLock.Unlock(); - - uint8_t waiting = waitTime; - do { - uint32_t waitSlot = (waiting > WAITSLOT_TIME ? WAITSLOT_TIME : waiting); - if (slot.WaitForResponse(waitSlot) == true) { - WPEFramework::Core::ProxyType jsonResponse = slot.Response(); - - // See if we have a jsonResponse, maybe it was just the connection - // that closed? - if (jsonResponse.IsValid() == true) { - if (jsonResponse->Error.IsSet() == true) { - result = jsonResponse->Error.Code.Value(); - } else { - if ((jsonResponse->Result.IsSet() == true) - && (jsonResponse->Result.Value().empty() == false)) { - result = WPEFramework::Core::ERROR_NONE; - bool enabled; - result = _eventHandler->ValidateResponse(jsonResponse, enabled); - if (result == WPEFramework::Core::ERROR_NONE) { - FromMessage((INTERFACE*)&response, *jsonResponse); - if (enabled) { - _adminLock.Lock(); - typename EventMap::iterator index = _eventMap.find(eventName); - if (index != _eventMap.end()) { - index->second = id; - } - _adminLock.Unlock(); - } - } - } - } - } - } else { - result = WPEFramework::Core::ERROR_TIMEDOUT; - } - waiting -= (waiting == WPEFramework::Core::infinite ? 0 : waitSlot); - } while ((result != WPEFramework::Core::ERROR_NONE) && (waiting > 0 )); - _adminLock.Lock(); - _pendingQueue.erase(id); - _adminLock.Unlock(); - - return result; - } - - public: - void FromMessage(WPEFramework::Core::JSON::IElement* response, const WPEFramework::Core::JSONRPC::Message& message) const - { - response->FromString(message.Result.Value()); - } - - void FromMessage(WPEFramework::Core::JSON::IMessagePack* response, const WPEFramework::Core::JSONRPC::Message& message) const - { - string value = message.Result.Value(); - std::vector result(value.begin(), value.end()); - response->FromBuffer(result); - } - - - private: - - void ToMessage(const string& parameters, WPEFramework::Core::ProxyType& message) const - { - if (parameters.empty() != true) { - message->Parameters = parameters; - } - } - - template - void ToMessage(PARAMETERS& parameters, WPEFramework::Core::ProxyType& message) const - { - ToMessage((INTERFACE*)(¶meters), message); - return; - } - - void ToMessage(WPEFramework::Core::JSON::IMessagePack* parameters, WPEFramework::Core::ProxyType& message) const - { - std::vector values; - parameters->ToBuffer(values); - if (values.empty() != true) { - string strValues(values.begin(), values.end()); - message->Parameters = strValues; - } - return; - } - - void ToMessage(WPEFramework::Core::JSON::IElement* parameters, WPEFramework::Core::ProxyType& message) const - { - string values; - parameters->ToString(values); - if (values.empty() != true) { - message->Parameters = values; - } - return; - } - - uint32_t FireboltErrorValue(const uint32_t error) - { - - uint32_t fireboltError = FireboltSDKErrorUnknown; - switch (error) { - case WPEFramework::Core::ERROR_NONE: - fireboltError = FireboltSDKErrorNone; - break; - case WPEFramework::Core::ERROR_GENERAL: - fireboltError = FireboltSDKErrorGeneral; - break; - case WPEFramework::Core::ERROR_UNAVAILABLE: - fireboltError = FireboltSDKErrorUnavailable; - break; - case WPEFramework::Core::ERROR_TIMEDOUT: - fireboltError = FireboltSDKErrorTimedout; - break; - default: - break; - } - - return fireboltError; - } - - private: - WPEFramework::Core::CriticalSection _adminLock; - WPEFramework::Core::NodeId _connectId; - WPEFramework::Core::ProxyType _channel; - IEventHandler* _eventHandler; - PendingMap _pendingQueue; - EventMap _eventMap; - uint64_t _scheduledTime; - uint32_t _waitTime; - }; -} diff --git a/languages/c-structs/templates/sdk/src/Types.cpp b/languages/c-structs/templates/sdk/src/Types.cpp deleted file mode 100644 index f19cfe63..00000000 --- a/languages/c-structs/templates/sdk/src/Types.cpp +++ /dev/null @@ -1,40 +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 - */ - -#include "Module.h" -#include "Types.h" -#include "TypesPriv.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// String Type Handler Interfaces -const char* FireboltTypes_String(FireboltTypes_StringHandle handle) -{ - return ((static_cast(handle))->Value().c_str()); -} - -void FireboltTypes_StringHandle_Release(FireboltTypes_StringHandle handle) -{ - delete static_cast(handle); -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c-structs/templates/sdk/src/TypesPriv.h b/languages/c-structs/templates/sdk/src/TypesPriv.h deleted file mode 100644 index 6e365ec7..00000000 --- a/languages/c-structs/templates/sdk/src/TypesPriv.h +++ /dev/null @@ -1,56 +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 - */ - -#pragma once - -#include - -namespace FireboltSDK { -namespace JSON { -class String : public WPEFramework::Core::JSON::String { - using Base = WPEFramework::Core::JSON::String; - public: - String() - : Base() - , _value() - { - } - String(const char value[]) - : Base(value) - , _value(value) - { - } - String& operator=(const char RHS[]) - { - Base::operator = (RHS); - _value = RHS; - return (*this); - } - - public: - const string& Value() const - { - _value = Base::Value(); - return _value; - } - - private: - mutable std::string _value; - }; -} -} diff --git a/languages/c-structs/templates/sdk/test/CMakeLists.txt b/languages/c-structs/templates/sdk/test/CMakeLists.txt deleted file mode 100644 index a56ca20a..00000000 --- a/languages/c-structs/templates/sdk/test/CMakeLists.txt +++ /dev/null @@ -1,86 +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 - -cmake_minimum_required(VERSION 3.3) - -project(FireboltSDKTests) -project_version(1.0.0) - -set(TESTLIB ${PROJECT_NAME}) - -message("Setup ${TESTLIB} v${PROJECT_VERSION}") - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_package(${NAMESPACE}Core CONFIG REQUIRED) - -add_library(${TESTLIB} STATIC OpenRPCTests.cpp) - -target_link_libraries(${TESTLIB} - PUBLIC - ${NAMESPACE}Core::${NAMESPACE}Core - ${FIREBOLT_NAMESPACE}SDK -) - -target_include_directories(${TESTLIB} - PRIVATE - $ - $ -) - -set_target_properties(${TESTLIB} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - LINK_WHAT_YOU_USE TRUE - FRAMEWORK FALSE -) - -install( - TARGETS ${TESTLIB} EXPORT ${TESTLIB}Targets - LIBRARY DESTINATION lib COMPONENT libs - PUBLIC_HEADER DESTINATION include/${FIREBOLT_NAMESPACE}Test COMPONENT devel # headers for mac (note the different component -> different package) - INCLUDES DESTINATION include/${FIREBOLT_NAMESPACE}Test # headers -) - -InstallCMakeConfig(TARGETS ${TESTLIB}) -InstallCMakeConfigs(TARGET ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) -InstallHeaders(TARGET ${TESTLIB} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION FireboltTest) -InstallLibraries(TARGET ${TESTLIB} LIBRARIES ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) - -set(TESTAPP "FireboltSDKTestApp") - -message("Setup ${TESTAPP}") - -add_executable(${TESTAPP} Main.c) - -target_link_libraries(${TESTAPP} - PRIVATE - ${TESTLIB} -) - -target_include_directories(${TESTAPP} - PRIVATE - $ - $ -) - -add_custom_command( - TARGET ${TESTAPP} - POST_BUILD - COMMENT "=================== Installing TestApp ======================" - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${TESTAPP} ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin -) - diff --git a/languages/c-structs/templates/sdk/test/Main.c b/languages/c-structs/templates/sdk/test/Main.c deleted file mode 100644 index 7c4c94a5..00000000 --- a/languages/c-structs/templates/sdk/test/Main.c +++ /dev/null @@ -1,44 +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 - */ - -#include "OpenRPCCTests.h" - -int __cnt = 0; -int __pass = 0; - -int TotalTests = 0; -int TotalTestsPassed = 0; - -int main() -{ - test_firebolt_create_instance(); - test_firebolt_main(); - - // Calling C function sequences - printf("%s:%s:%d Calling C function tests\n", __FILE__, __func__, __LINE__); - EXECUTE("test_properties_get_device_id", test_properties_get_device_id); - EXECUTE("test_properties_set", test_properties_set); - EXECUTE("test_eventregister_by_providing_callback", test_eventregister_by_providing_callback); - EXECUTE("test_eventregister", test_eventregister); - EXECUTE("test_string_set_get_value", test_string_set_get_value); - - test_firebolt_dispose_instance(); - - printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); -} - diff --git a/languages/c-structs/templates/sdk/test/Module.cpp b/languages/c-structs/templates/sdk/test/Module.cpp deleted file mode 100644 index d63badc4..00000000 --- a/languages/c-structs/templates/sdk/test/Module.cpp +++ /dev/null @@ -1,21 +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 - */ - -#include "Module.h" - -MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/languages/c-structs/templates/sdk/test/Module.h b/languages/c-structs/templates/sdk/test/Module.h deleted file mode 100644 index d5340b68..00000000 --- a/languages/c-structs/templates/sdk/test/Module.h +++ /dev/null @@ -1,29 +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 - */ - -#pragma once - -#ifndef MODULE_NAME -#define MODULE_NAME OpenRPCTestApp -#endif - -#include -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/languages/c-structs/templates/sdk/test/OpenRPCCTests.h b/languages/c-structs/templates/sdk/test/OpenRPCCTests.h deleted file mode 100644 index 7f2fb59e..00000000 --- a/languages/c-structs/templates/sdk/test/OpenRPCCTests.h +++ /dev/null @@ -1,42 +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 _OPENRPC_C_TESTS_H -#define _OPENRPC_C_TESTS_H - -#include "TestUtils.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t test_firebolt_create_instance(); -uint32_t test_firebolt_dispose_instance(); - -uint32_t test_firebolt_main(); -uint32_t test_properties_get_device_id(); -uint32_t test_properties_set(); -uint32_t test_eventregister(); -uint32_t test_eventregister_by_providing_callback(); -uint32_t test_string_set_get_value(); - -#ifdef __cplusplus -} -#endif - -#endif // _OPENRPC_C_TESTS_H diff --git a/languages/c-structs/templates/sdk/test/OpenRPCTests.cpp b/languages/c-structs/templates/sdk/test/OpenRPCTests.cpp deleted file mode 100644 index cf9ea5a0..00000000 --- a/languages/c-structs/templates/sdk/test/OpenRPCTests.cpp +++ /dev/null @@ -1,385 +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 - */ - -#include "Module.h" -#include "OpenRPCTests.h" -#include "OpenRPCCTests.h" - -namespace WPEFramework { - -ENUM_CONVERSION_BEGIN(::JsonValue::type) - - { JsonValue::type::EMPTY, _TXT("empty") }, - { JsonValue::type::BOOLEAN, _TXT("boolean") }, - { JsonValue::type::NUMBER, _TXT("number") }, - { JsonValue::type::STRING, _TXT("string") }, - -ENUM_CONVERSION_END(::JsonValue::type) - -ENUM_CONVERSION_BEGIN(TestEnum) - { TestEnum::Test1, _TXT("Test1ValueCheck") }, - { TestEnum::Test2, _TXT("Test2ValueCheck") }, - { TestEnum::Test3, _TXT("Test3ValueCheck") }, - { TestEnum::Test4, _TXT("Test4ValueCheck") }, -ENUM_CONVERSION_END(TestEnum) -} -namespace FireboltSDK { - Tests::Tests() - { - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEventWithMultipleCallback"), - std::forward_as_tuple(&SubscribeEventWithMultipleCallback)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEvent"), - std::forward_as_tuple(&SubscribeEvent)); - - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Set UnKnown Method"), - std::forward_as_tuple(&SetUnKnownMethod)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Set LifeCycle Close"), - std::forward_as_tuple(&SetLifeCycleClose)); - - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get UnKnown Method"), - std::forward_as_tuple(&GetUnKnownMethod)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Device Version"), - std::forward_as_tuple(&GetDeviceVersion)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Device Id"), - std::forward_as_tuple(&GetDeviceId)); - } - - /* static */ void Tests::PrintJsonObject(const JsonObject::Iterator& iterator) - { - JsonObject::Iterator index = iterator; - while (index.Next() == true) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "Element [%s]: <%s> = \"%s\"\n", - index.Label(), - WPEFramework::Core::EnumerateType(index.Current().Content()).Data(), - index.Current().Value().c_str()); - } - } - - /* static */ uint32_t Tests::GetDeviceId() - { - const string method = _T("device.id"); - WPEFramework::Core::ProxyType response; - uint32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "DeviceId : %s", response->Value().c_str()); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /*static */ uint32_t Tests::GetDeviceVersion() - { - const string method = _T("device.version"); - WPEFramework::Core::ProxyType response; - uint32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "DeviceVersion"); - PrintJsonObject(response->Variants()); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d", method.c_str(), status); - } - - return status; - } - - /* static */ uint32_t Tests::GetUnKnownMethod() - { - const string method = _T("get.unknownMethod"); - WPEFramework::Core::ProxyType response; - uint32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_NE(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /* static */ uint32_t Tests::SetLifeCycleClose() - { - const string method = _T("lifecycle.close"); - JsonObject parameters; - parameters["reason"] = "remoteButton"; - uint32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /* static */ uint32_t Tests::SetUnKnownMethod() - { - const string method = _T("set.unknownMethod"); - JsonObject parameters; - uint32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_NE(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d", method.c_str(), status); - } - - return status; - } - - static void deviceNameChangeCallback(const void* userData, void* response) - { - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Received a new event: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - eventControl->NotifyEvent(); - } - - /* static */ uint32_t Tests::SubscribeEvent() - { - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - uint32_t id = 0; - - eventControl->ResetEvent(); - uint32_t status = Properties::Subscribe(eventName, deviceNameChangeCallback, userdata, id); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), - "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - EXPECT_EQ(Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); - delete eventControl; - - return status; - } - - template - /* static */ uint32_t Tests::SubscribeEventForC(const string& eventName, CALLBACK& callbackFunc, const void* userdata, uint32_t& id) - { - return Properties::Subscribe(eventName, callbackFunc, userdata, id);; - } - - static void deviceNameChangeMultipleCallback(const void* userData, void* response) - { - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "Received a new event from deviceNameChangeMultipleCallback: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - eventControl->NotifyEvent(); - } - - /* static */ uint32_t Tests::SubscribeEventWithMultipleCallback() - { - FireboltSDK::Tests::EventControl* eventControl1 = new FireboltSDK::Tests::EventControl(); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl1); - uint32_t id1 = 0, id2 = 0; - - eventControl1->ResetEvent(); - uint32_t status = Properties::Subscribe(eventName, deviceNameChangeCallback, userdata, id1); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), - "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully", __func__); - } - - if (status == FireboltSDKErrorNone) { - FireboltSDK::Tests::EventControl* eventControl2 = new FireboltSDK::Tests::EventControl(); - userdata = static_cast(eventControl2); - - status = Properties::Subscribe(eventName, deviceNameChangeMultipleCallback, userdata, id2); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered second callback also successfully", __func__); - eventControl1->WaitForEvent(WPEFramework::Core::infinite); - eventControl2->WaitForEvent(WPEFramework::Core::infinite); - } - EXPECT_EQ(Properties::Unsubscribe(eventName, id1), FireboltSDKErrorNone); - delete eventControl2; - } - EXPECT_EQ(Properties::Unsubscribe(eventName, id2), FireboltSDKErrorNone); - - delete eventControl1; - return status; - } - -} - -#ifdef __cplusplus -extern "C" { -#endif - -uint32_t test_firebolt_create_instance() -{ - FireboltSDK::Accessor::Instance(); -} - -uint32_t test_firebolt_dispose_instance() -{ - FireboltSDK::Accessor::Dispose(); -} - -uint32_t test_firebolt_main() -{ - return FireboltSDK::Tests::Main(); -} - -uint32_t test_properties_get_device_id() -{ - const string method = _T("device.id"); - WPEFramework::Core::ProxyType response; - uint32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "DeviceId : %s", response->Value().c_str()); - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Get %s status = %d", method.c_str(), status); - } - - return status; -} - -uint32_t test_properties_set() -{ - const string method = _T("lifecycle.close"); - JsonObject parameters; - parameters["reason"] = "remoteButton"; - uint32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Set %s status = %d", method.c_str(), status); - } - - return status; -} - -static void deviceNameChangeCallbackForC(const void* userData, void* response) -{ - WPEFramework::Core::ProxyType& jsonResponse = *(static_cast*>(response)); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Received a new event--->: %s", jsonResponse->Value().c_str()); - jsonResponse.Release(); - - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - eventControl->NotifyEvent(); -} - -uint32_t test_eventregister() -{ - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - JsonObject parameters; - - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - uint32_t id = 0; - - eventControl->ResetEvent(); - uint32_t status = FireboltSDK::Properties::Subscribe(eventName, deviceNameChangeCallbackForC, userdata, id); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Set %s status = %d", __func__, eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); - - return status; -} - -uint32_t test_eventregister_by_providing_callback() -{ - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - uint32_t id = 0; - - eventControl->ResetEvent(); - uint32_t status = FireboltSDK::Tests::SubscribeEventForC(eventName, deviceNameChangeCallbackForC, userdata, id); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Set %s status = %d", __func__, eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, id), FireboltSDKErrorNone); -} - -#include "TypesPriv.h" -uint32_t test_string_set_get_value() -{ - uint32_t status = FireboltSDKErrorNone; - FireboltSDK::String* str = new FireboltSDK::String("testString"); - void* handle = static_cast(str); - - const char* value = FireboltTypes_String(handle); - EXPECT_EQ(strncmp(value, str->Value().c_str(), str->Value().length()), 0); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - " ---> type name = %s %s", str->Value().c_str(), value); - - WPEFramework::Core::JSON::EnumType<::TestEnum> testEnum = Test4; - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - " EnumTest = %d %s", testEnum.Value(), testEnum.Data()); - FireboltTypes_StringHandle_Release(handle); - return status; -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c-structs/templates/sdk/test/OpenRPCTests.h b/languages/c-structs/templates/sdk/test/OpenRPCTests.h deleted file mode 100644 index 00abd364..00000000 --- a/languages/c-structs/templates/sdk/test/OpenRPCTests.h +++ /dev/null @@ -1,99 +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 - */ - -#pragma once - -#include "TestUtils.h" -#include "Firebolt.h" - -namespace FireboltSDK { - typedef uint32_t (*Func)(); - - class Tests { - public: - class EventControl { - public: - EventControl() - : _event(false, true) - { - } - ~EventControl() = default; - - public: - void NotifyEvent() - { - _event.SetEvent(); - } - uint32_t WaitForEvent(uint32_t waitTime) - { - return _event.Lock(waitTime); - } - void ResetEvent() - { - _event.ResetEvent(); - } - private: - WPEFramework::Core::Event _event; - }; - - private: - typedef std::unordered_map TestFunctionMap; - - public: - Tests(); - virtual ~Tests() = default; - - inline TestFunctionMap& TestList() - { - return _functionMap; - } - - template - static uint32_t Main() - { - TESTS fireboltTest; - for (auto i = fireboltTest.TestList().begin(); i != fireboltTest.TestList().end(); i++) { - EXECUTE(i->first.c_str(), i->second); - } - - printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); - - return 0; - } - - static uint32_t GetDeviceId(); - static uint32_t GetDeviceVersion(); - static uint32_t GetUnKnownMethod(); - - static uint32_t SetLifeCycleClose(); - static uint32_t SetUnKnownMethod(); - - static uint32_t SubscribeEvent(); - static uint32_t SubscribeEventWithMultipleCallback(); - - template - static uint32_t SubscribeEventForC(const string& eventName, CALLBACK& callbackFunc, const void* userdata, uint32_t& id); - - protected: - static void PrintJsonObject(const JsonObject::Iterator& iterator); - - protected: - std::list menu; - TestFunctionMap _functionMap; - }; -} diff --git a/languages/c-structs/templates/sdk/test/TestUtils.h b/languages/c-structs/templates/sdk/test/TestUtils.h deleted file mode 100644 index 8c3cb732..00000000 --- a/languages/c-structs/templates/sdk/test/TestUtils.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _TEST_UTILS_H -#define _TEST_UTILS_H - -#include -#include -#include - -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) - -#define _RESULT(expr, exprorig, result) if (expr) { printf(" SUCCESS: %s\n", #exprorig); __pass++; } else printf(" FAILED: %s, actual: %u\n", #exprorig, result) -#define _EVAL(result, expected, op) do { __cnt++; uint32_t resval = ((uint32_t)(result)); uint32_t expval = ((uint32_t)(expected)); _RESULT(resval op expval, result op expected, resval); } while(0) -#define _HEAD(name) printf("\n======== %s\n", name); __cnt = 0; __pass = 0 -#define _FOOT(name) printf("\n======== %s - %i PASSED, %i FAILED\n", name, __pass, (__cnt - __pass)); TotalTests += __cnt; TotalTestsPassed += __pass; - -#define EXECUTE(name, test) do { _HEAD(name); test(); _FOOT(name); printf("\n"); } while(0) -#define EXPECT_EQ(result, expected) _EVAL(result, expected, ==) -#define EXPECT_NE(result, expected) _EVAL(result, expected, !=) -#define EXPECT_LT(result, expected) _EVAL(result, expected, <) -#define EXPECT_LE(result, expected) _EVAL(result, expected, <=) -#define EXPECT_GT(result, expected) _EVAL(result, expected, >) -#define EXPECT_GE(result, expected) _EVAL(result, expected, >=) - -#ifdef __cplusplus -extern "C" { -#endif - -extern int __cnt; -extern int __pass; - -extern int TotalTests ; -extern int TotalTestsPassed; - -#ifdef __cplusplus -} -#endif - -#endif // _TEST_UTILS_H diff --git a/languages/c-structs/templates/sections/accessors.c b/languages/c-structs/templates/sections/accessors.c deleted file mode 100644 index 1c790810..00000000 --- a/languages/c-structs/templates/sections/accessors.c +++ /dev/null @@ -1,2 +0,0 @@ -// Accessors -${schema.list} diff --git a/languages/c-structs/templates/sections/declarations.c b/languages/c-structs/templates/sections/declarations.c deleted file mode 100644 index b3ef974d..00000000 --- a/languages/c-structs/templates/sections/declarations.c +++ /dev/null @@ -1 +0,0 @@ -${declaration.list} diff --git a/languages/c-structs/templates/sections/enums.c b/languages/c-structs/templates/sections/enums.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c-structs/templates/sections/enums.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c-structs/templates/sections/events.c b/languages/c-structs/templates/sections/events.c deleted file mode 100644 index 5be10409..00000000 --- a/languages/c-structs/templates/sections/events.c +++ /dev/null @@ -1 +0,0 @@ -${event.list} diff --git a/languages/c-structs/templates/sections/methods.c b/languages/c-structs/templates/sections/methods.c deleted file mode 100644 index 3ab606c0..00000000 --- a/languages/c-structs/templates/sections/methods.c +++ /dev/null @@ -1,4 +0,0 @@ - -// Methods - -${method.list} diff --git a/languages/c-structs/templates/sections/methods_accessors.c b/languages/c-structs/templates/sections/methods_accessors.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c-structs/templates/sections/methods_accessors.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c-structs/templates/sections/methods_types.c b/languages/c-structs/templates/sections/methods_types.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c-structs/templates/sections/methods_types.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c-structs/templates/sections/provider-interfaces.c b/languages/c-structs/templates/sections/provider-interfaces.c deleted file mode 100644 index 418d7abf..00000000 --- a/languages/c-structs/templates/sections/provider-interfaces.c +++ /dev/null @@ -1,11 +0,0 @@ - // Provider Interfaces - - interface ProviderSession { - correlationId(): string // Returns the correlation id of the current provider session - } - - interface FocusableProviderSession extends ProviderSession { - focus(): Promise // Requests that the provider app be moved into focus to prevent a user experience - } - - ${providers.list} \ No newline at end of file diff --git a/languages/c-structs/templates/sections/schemas.c b/languages/c-structs/templates/sections/schemas.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c-structs/templates/sections/schemas.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c-structs/templates/sections/types.c b/languages/c-structs/templates/sections/types.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c-structs/templates/sections/types.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c-structs/templates/types/anyOf.c b/languages/c-structs/templates/types/anyOf.c deleted file mode 100644 index 9cc8aaef..00000000 --- a/languages/c-structs/templates/types/anyOf.c +++ /dev/null @@ -1 +0,0 @@ -/* AnyOf is not supported in C */ \ No newline at end of file diff --git a/languages/c-structs/templates/types/array.c b/languages/c-structs/templates/types/array.c deleted file mode 100644 index 6f532328..00000000 --- a/languages/c-structs/templates/types/array.c +++ /dev/null @@ -1 +0,0 @@ -${title} * \ No newline at end of file diff --git a/languages/c-structs/templates/types/const.c b/languages/c-structs/templates/types/const.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c-structs/templates/types/default.c b/languages/c-structs/templates/types/default.c deleted file mode 100644 index 38b05042..00000000 --- a/languages/c-structs/templates/types/default.c +++ /dev/null @@ -1,4 +0,0 @@ -/* - * ${title} - ${description} - */ -typedef ${shape} ${title}; diff --git a/languages/c-structs/templates/types/enum.cpp b/languages/c-structs/templates/types/enum.cpp deleted file mode 100644 index 6776b41a..00000000 --- a/languages/c-structs/templates/types/enum.cpp +++ /dev/null @@ -1,4 +0,0 @@ - /* ${title} ${description} */ - ENUM_CONVERSION_BEGIN(${name}) - { ${NAME}_${key}, _T("${value}") }, - ENUM_CONVERSION_END(${name}) diff --git a/languages/c-structs/templates/types/enum.h b/languages/c-structs/templates/types/enum.h deleted file mode 100644 index 92108c75..00000000 --- a/languages/c-structs/templates/types/enum.h +++ /dev/null @@ -1,4 +0,0 @@ -/* ${title} ${description} */ -typedef enum { - ${NAME}_${key}, -} ${name}; diff --git a/languages/c-structs/templates/types/object.c b/languages/c-structs/templates/types/object.c deleted file mode 100644 index e6d948cd..00000000 --- a/languages/c-structs/templates/types/object.c +++ /dev/null @@ -1,3 +0,0 @@ -struct { - ${properties} -} \ No newline at end of file diff --git a/languages/c-structs/templates/types/primitive.c b/languages/c-structs/templates/types/primitive.c deleted file mode 100644 index 21ae259c..00000000 --- a/languages/c-structs/templates/types/primitive.c +++ /dev/null @@ -1 +0,0 @@ -${type} \ No newline at end of file diff --git a/languages/c-structs/templates/types/property.c b/languages/c-structs/templates/types/property.c deleted file mode 100644 index 7bd100e4..00000000 --- a/languages/c-structs/templates/types/property.c +++ /dev/null @@ -1 +0,0 @@ -${title} ${property}; \ No newline at end of file diff --git a/languages/c-structs/templates/types/ref.c b/languages/c-structs/templates/types/ref.c deleted file mode 100644 index 41d15c96..00000000 --- a/languages/c-structs/templates/types/ref.c +++ /dev/null @@ -1 +0,0 @@ -${title} \ No newline at end of file diff --git a/languages/c-structs/templates/types/title.c b/languages/c-structs/templates/types/title.c deleted file mode 100644 index ca6b6897..00000000 --- a/languages/c-structs/templates/types/title.c +++ /dev/null @@ -1 +0,0 @@ -F${info.Title}_${Title} \ No newline at end of file diff --git a/languages/c-structs/templates/types/tuple.c b/languages/c-structs/templates/types/tuple.c deleted file mode 100644 index e6d948cd..00000000 --- a/languages/c-structs/templates/types/tuple.c +++ /dev/null @@ -1,3 +0,0 @@ -struct { - ${properties} -} \ No newline at end of file diff --git a/languages/c/Types.mjs b/languages/c/Types.mjs deleted file mode 100644 index 35c46ba2..00000000 --- a/languages/c/Types.mjs +++ /dev/null @@ -1,767 +0,0 @@ -/* - * Copyright 2021 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 - */ - -import deepmerge from 'deepmerge' -import { getPath, getSafeEnumKeyName } from '../../src/shared/json-schema.mjs' -import { getTypeName, getModuleName, description, getObjectManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, getPropertyGetterSignature, getFireboltStringType } from './src/types/NativeHelpers.mjs' -import { getArrayAccessorsImpl, getMapAccessorsImpl, getObjectManagementImpl, getParameterInstantiation, getPropertyAccessorsImpl, getResultInstantiation, getCallbackParametersInstantiation, getCallbackResultInstantiation, getCallbackResponseInstantiation } from './src/types/ImplHelpers.mjs' -import { getJsonContainerDefinition, getJsonDataStructName, getJsonDataPrefix } from './src/types/JSONHelpers.mjs' - -const getSdkNameSpace = () => 'FireboltSDK' -const getJsonNativeTypeForOpaqueString = () => getSdkNameSpace() + '::JSON::String' -const getEnumName = (name, prefix) => ((prefix.length > 0) ? (prefix + '_' + name) : name) - -const getRefModule = (title) => { - let module = { - info: { - title: `${title}` - } - } - return module -} - -const hasProperties = (prop) => { - let hasProperty = false - if (prop.properties) { - hasProperty = true - } else if (prop.additionalProperties && ( prop.additionalProperties.type && (((prop.additionalProperties.type === 'object') && prop.additionalProperties.properties) || (prop.additionalProperties.type !== 'object')))) { - hasProperty = true - } - return hasProperty -} - -function validJsonObjectProperties(json = {}) { - - let valid = true - if (json.type === 'object' || (json.additonalProperties && typeof json.additonalProperties.type === 'object')) { - if (json.properties || json.additonalProperties) { - Object.entries(json.properties || json.additonalProperties).every(([pname, prop]) => { - if (!prop['$ref'] && (pname !== 'additionalProperties') && - ((!prop.type && !prop.const && (prop.schema && !prop.schema.type)) || (Array.isArray(prop.type) && (prop.type.find(t => t === 'null'))))) { - valid = false - } - return valid - }) - } - } - return valid -} - -function union(schemas, module, commonSchemas) { - - const result = {}; - for (const schema of schemas) { - for (const [key, value] of Object.entries(schema)) { - if (!result.hasOwnProperty(key)) { - // If the key does not already exist in the result schema, add it - if (value && value.anyOf) { - result[key] = union(value.anyOf, module, commonSchemas) - } else if (key === 'title' || key === 'description' || key === 'required') { - //console.warn(`Ignoring "${key}"`) - } else { - result[key] = value; - } - } else if (key === 'type') { - // If the key is 'type', merge the types of the two schemas - if(result[key] === value) { - //console.warn(`Ignoring "${key}" that is already present and same`) - } else { - console.warn(`ERROR "${key}" is not same -${JSON.stringify(result, null, 4)} ${key} ${result[key]} - ${value}`); - return {} - } - } else { - //If the Key is a const then merge them into an enum - if(value && value.const) { - if(result[key].enum) { - result[key].enum = Array.from(new Set([...result[key].enum, value.const])) - } - else { - result[key].enum = Array.from(new Set([result[key].const, value.const])) - delete result[key].const - } - } - // If the key exists in both schemas and is not 'type', merge the values - else if (Array.isArray(result[key])) { - // If the value is an array, concatenate the arrays and remove duplicates - result[key] = Array.from(new Set([...result[key], ...value])) - } else if (result[key] && result[key].enum && value && value.enum) { - //If the value is an enum, merge the enums together and remove duplicates - result[key].enum = Array.from(new Set([...result[key].enum, ...value.enum])) - } else if (typeof result[key] === 'object' && typeof value === 'object') { - // If the value is an object, recursively merge the objects - result[key] = union([result[key], value], module, commonSchemas); - } else if (result[key] !== value) { - // If the value is a primitive and is not the same in both schemas, ignore it - //console.warn(`Ignoring conflicting value for key "${key}"`) - } - } - } - } - return result; -} - -function getMergedSchema(module, json, name, schemas) { - let refsResolved = [...json.anyOf.map(x => x['$ref'] ? getPath(x['$ref'], module, schemas) || x : x)] - let allOfsResolved = refsResolved.map(sch => sch.allOf ? deepmerge.all([...sch.allOf.map(x => x['$ref'] ? getPath(x['$ref'], module, schemas) || x : x)]) : sch) - - let mergedSchema = union(allOfsResolved, module, schemas) - if (json.title) { - mergedSchema['title'] = json.title - } - else { - mergedSchema['title'] = name - } - - delete mergedSchema['$ref'] - return mergedSchema -} - -const deepMergeAll = (module, name, schema, schemas, options) => { - let nonRefsProperty = [...schema.allOf.map(x => x['$ref'] ? '' : x)].filter(elm => elm) - let refsProperty = [...schema.allOf.map(x => x['$ref'] ? getPath(x['$ref'], module, schemas) : '')].filter(elm => elm) - let mergedProperty = [] - let mergedParamSchema = { - type: "object", - properties: {} - } - - nonRefsProperty.forEach(p => { - if (p.properties) { - Object.entries(p.properties).every(([pname, prop]) => { - let present = false - refsProperty.forEach(refP => { - if (refP.properties) { - Object.entries(refP.properties).every(([refname, refprop]) => { - if (refname == pname) { - present = true - } - return !present - }) - } - }) - let prefixedName = (present == false) ? (name + capitalize(pname)) : pname - mergedParamSchema.properties[prefixedName] = prop - return true - }) - mergedProperty.push(mergedParamSchema) - } - }) - refsProperty.forEach(ref => mergedProperty.push(ref)) - let union = deepmerge.all(mergedProperty) - - return union -} -const hasTag = (method, tag) => { - return method.tags && method.tags.filter(t => t.name === tag).length > 0 -} - -const IsResultConstNullSuccess = (schema, name) => (name === 'success' && !schema.const && !schema.type) -const IsResultBooleanSuccess = (schema, name) => (name === 'success' && schema.type === 'boolean') - -function getParamList(schema, module) { - let paramList = [] - if (schema.params.length > 0) { - schema.params.map(p => { - /* - param = {name='', nativeType='', jsonType='', required=boolean} - */ - let param = {} - param['nativeType'] = getSchemaType(p.schema, module, { title: true, name: p.name }) - param['jsonType'] = getJsonType(p.schema, module, {name: p.name}) - param['name'] = p.name - param['required'] = p.required - paramList.push(param) - }) - - } - return paramList -} - -function getMethodSignature(method, module, { destination, isInterface = false }) { - - let signature = '' - if (hasTag(method, 'property') || hasTag(method, 'property:readonly') || hasTag(method, 'property:immutable')) { - let paramList = getParamList(method, module) - let resultType = method.result && getSchemaType(method.result.schema, module, { title: true, name: method.result.name, resultSchema: true}) || '' - - signature = getPropertyGetterSignature(method, module, resultType, paramList) + ';\n' - } - return signature -} - -function getMethodSignatureParams(method, module, { destination, callback = false } = {}) { - let signatureParams = '' - let polymorphicPull = method.tags.find(t => t.name === 'polymorphic-pull') - method.params.map(param => { - if (polymorphicPull && (param.name === 'correlationId')) { - return - } - signatureParams += (signatureParams.length > 0) ? ', ' : '' - let type = getSchemaType(param.schema, module, { name: param.name, title: true, destination }) - if ((callback === true) && (type === 'char*')) { - type = getFireboltStringType() - } - - signatureParams += type + ((!param.required && !type.includes('_t') && (type !== 'char*')) ? '* ' : ' ') + param.name - }) - return signatureParams -} - -const safeName = prop => prop.match(/[.+]/) ? '"' + prop + '"' : prop - -function getSchemaType(schema, module, { name, prefix = '', destination, resultSchema = false, link = false, title = false, code = false, asPath = false, event = false, expandEnums = true, baseUrl = '' } = {}) { - let info = getSchemaTypeInfo(module, schema, name, module['x-schemas'], prefix, { title: title, resultSchema: resultSchema, event: event }) - return info.type -} - -function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, prefix = '', options = { level: 0, descriptions: true, title: false, resultSchema: false, event: false}) { - - if (json.schema) { - json = json.schema - } - - let fireboltString = options.resultSchema || options.event - - let structure = {} - structure["type"] = '' - structure["json"] = [] - structure["name"] = {} - structure["namespace"] = {} - - if (json['$ref']) { - if (json['$ref'][0] === '#') { - //Ref points to local schema - //Get Path to ref in this module and getSchemaType - let definition = getPath(json['$ref'], module, schemas) - let tName = definition.title || json['$ref'].split('/').pop() - let schema = module - if (json['$ref'].includes('x-schemas')) { - schema = (getRefModule(json['$ref'].split('/')[2])) - } - - const res = getSchemaTypeInfo(schema, definition, tName, schemas, '', options) - structure.type = res.type - structure.json = res.json - structure.name = res.name - structure.namespace = res.namespace - } - } - else if (json.const) { - structure.type = getNativeType(json, fireboltString) - structure.json = json - } - else if (json['x-method']) { - console.log(`WARNING UNHANDLED: x-method in ${name}`) - //throw "x-methods not supported yet" - } - else if (json.type === 'string' && json.enum) { - //Enum - structure.name = name || json.title - let typeName = getTypeName(getModuleName(module), name || json.title, prefix, false, false) - let res = description(capitalize(name || json.title), json.description) + '\n' + generateEnum(json, typeName) - structure.json = json - structure.type = typeName - structure.namespace = getModuleName(module) - } - else if (Array.isArray(json.type)) { - let type = json.type.find(t => t !== 'null') - let sch = JSON.parse(JSON.stringify(json)) - sch.type = type - structure = getSchemaTypeInfo(module, sch, name, schemas, prefix, options) - } - else if (json.type === 'array' && json.items && (validJsonObjectProperties(json) === true)) { - let res = '' - if (Array.isArray(json.items)) { - //TODO - const IsHomogenous = arr => new Set(arr.map( item => item.type ? item.type : typeof item)).size === 1 - if (!IsHomogenous(json.items)) { - throw 'Heterogenous Arrays not supported yet' - } - res = getSchemaTypeInfo(module, json.items[0], json.items[0].name || name, schemas, prefix) - } - else { - // grab the type for the non-array schema - res = getSchemaTypeInfo(module, json.items, json.items.name || name, schemas, prefix) - } - res.name = capitalize(res.name) - let n = getTypeName(getModuleName(module), res.name, '') - structure.name = res.name - structure.type = n + 'Array_t' - structure.json = json - structure.namespace = getModuleName(module) - } - else if (json.allOf) { - let title = json.title ? json.title : name - let union = deepMergeAll(module, title, json, schemas, options) - union['title'] = title - - delete union['$ref'] - structure = getSchemaTypeInfo(module, union, '', schemas, '', options) - } - else if (json.oneOf) { - structure.type = fireboltString ? getFireboltStringType() : 'char*' - structure.json.type = 'string' - } - else if (json.anyOf) { - let mergedSchema = getMergedSchema(module, json, name, schemas) - if (mergedSchema.type) { - let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name) - structure = getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options) - } - else { - structure.type = fireboltString ? getFireboltStringType() : 'char*' - structure.json.type = 'string' - } - } - else if (json.type === 'object') { - structure.json = json - if (hasProperties(json)) { - structure.type = getTypeName(getModuleName(module), json.title || name, prefix) + '_t' - structure.name = (json.name ? json.name : (json.title ? json.title : name)) - structure.namespace = (json.namespace ? json.namespace : getModuleName(module)) - } - else { - structure.type = fireboltString ? getFireboltStringType() : 'char*' - } - if (name) { - structure.name = capitalize(name) - } - } - else if (json.type) { - if (!IsResultBooleanSuccess(json, name) && !IsResultConstNullSuccess(json, name)) { - structure.type = getNativeType(json, fireboltString) - structure.json = json - if (name || json.title) { - structure.name = capitalize(name || json.title) - } - structure.namespace = getModuleName(module) - } - } - - return structure -} - -function getSchemaShape(json, module, { name = '', prefix = '', level = 0, title, summary, descriptions = true, destination = '', section = '', enums = true } = {}) { - - let shape = getSchemaShapeInfo(json, module, module['x-schemas'], { name, prefix, merged: false, level, title, summary, descriptions, destination, section, enums }) - return shape -} -function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = '', merged = false, level = 0, title, summary, descriptions = true, destination = '', section = '', enums = true } = {}) { - let shape = '' - - if (destination && section) { - const isHeader = (destination.includes(getJsonDataPrefix().toLowerCase()) !== true) && destination.endsWith(".h") - const isCPP = ((destination.endsWith(".cpp") || destination.includes(getJsonDataPrefix().toLowerCase())) && (section.includes('accessors') !== true)) - - json = JSON.parse(JSON.stringify(json)) - - name = json.title || name - - if (json['$ref']) { - if (json['$ref'][0] === '#') { - //Ref points to local schema - //Get Path to ref in this module and getSchemaType - let schema = getPath(json['$ref'], module, schemas) - const tName = schema.title || json['$ref'].split('/').pop() - if (json['$ref'].includes('x-schemas')) { - schema = (getRefModule(json['$ref'].split('/')[2])) - } - shape = getSchemaShapeInfo(schema, module, schemas, { name: tName, prefix, merged, level, title, summary, descriptions, destination, section, enums }) - } - } - //If the schema is a const, - else if (json.hasOwnProperty('const') && !isCPP) { - if (level > 0) { - - let t = description(capitalize(name), json.description) - typeName = getTypeName(getModuleName(module), name, prefix) - t += (isHeader ? getPropertyAccessors(typeName, capitalize(name), typeof schema.const, { level: level, readonly: true, optional: false }) : getPropertyAccessorsImpl(typeName, getJsonType(schema, module, { level, name }), typeof schema.const, { level: level, readonly: true, optional: false })) - shape += '\n' + t - } - } - else if (json.type === 'object') { - if (!name) { - console.log(`WARNING: unnamed schema in ${module.info.title}.`) - console.dir(json) - shape = '' - } - else if (json.properties && (validJsonObjectProperties(json) === true)) { - let c_shape = '\n' + description(capitalize(name), json.description) - let cpp_shape = '' - let tName = getTypeName(getModuleName(module), name, prefix) - c_shape += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, getJsonType(json, module, { name }))) - let props = [] - let containerName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? (prefix + '_' + capitalize(name)) : capitalize(name) - Object.entries(json.properties).forEach(([pname, prop]) => { - let items - var desc = '\n' + description(capitalize(pname), prop.description) - if (prop.type === 'array') { - if (Array.isArray(prop.items)) { - //TODO - const IsHomogenous = arr => new Set(arr.map( item => item.type ? item.type : typeof item)).size === 1 - if (!IsHomogenous(prop.items)) { - throw 'Heterogenous Arrays not supported yet' - } - items = prop.items[0] - } - else { - // grab the type for the non-array schema - items = prop.items - } - - let info = getSchemaTypeInfo(module, items, items.name || pname, schemas, prefix, {level : level, descriptions: descriptions, title: true}) - if (info.type && info.type.length > 0) { - let objName = tName + '_' + capitalize(prop.title || pname) - info.json.namespace = info.namespace - let moduleProperty = getJsonTypeInfo(module, json, json.title || name, schemas, prefix) - let prefixName = ((prefix.length > 0) && items['$ref']) ? '' : prefix - let subModuleProperty = getJsonTypeInfo(module, info.json, info.name, schemas, prefix) - - let t = description(capitalize(info.name), json.description) + '\n' - t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(tName, moduleProperty.type, (tName + '_t'), subModuleProperty.type, capitalize(pname || prop.title), info.type, info.json)) - c_shape += '\n' + t - props.push({name: `${pname}`, type: `WPEFramework::Core::JSON::ArrayType<${subModuleProperty.type}>`}) - } - else { - console.log(`a. WARNING: Type undetermined for ${name}:${pname}`) - } - } else { - if (((merged === false) || ((merged === true) && (pname.includes(name)))) && (prop.type === 'object' || prop.anyOf || prop.allOf)) { - shape += getSchemaShapeInfo(prop, module, schemas, { name : pname, prefix, merged: false, level: 1, title, summary, descriptions, destination, section, enums }) - } - let info = getSchemaTypeInfo(module, prop, pname, module['x-schemas'], prefix, {descriptions: descriptions, level: level + 1, title: true}) - if (info.type && info.type.length > 0) { - let subPropertyName = ((pname.length !== 0) ? capitalize(pname) : info.name) - let moduleProperty = getJsonTypeInfo(module, json, name, schemas, prefix) - let subProperty = getJsonTypeInfo(module, prop, pname, schemas, prefix) - c_shape += '\n' + description(capitalize(pname), info.json.description) - c_shape += '\n' + (isHeader ? getPropertyAccessors(tName, capitalize(pname), info.type, { level: 0, readonly: false, optional: isOptional(pname, json) }) : getPropertyAccessorsImpl(tName, moduleProperty.type, subProperty.type, subPropertyName, info.type, info.json, {readonly:false, optional:isOptional(pname, json)})) - let property = getJsonType(prop, module, { name : pname, prefix }) - props.push({name: `${pname}`, type: `${property}`}) - } - } - }) - - cpp_shape += getJsonContainerDefinition(json, containerName, props) - - if (isCPP) { - shape += '\n' + cpp_shape - } - else { - shape += '\n' + c_shape - } - } - else if (json.propertyNames && json.propertyNames.enum) { - //propertyNames in object not handled yet - } - else if (json.additionalProperties && (typeof json.additionalProperties === 'object') && (validJsonObjectProperties(json) === true) && !isCPP) { - let info = getSchemaTypeInfo(module, json.additionalProperties, name, module['x-schemas'], prefix) - if (!info.type || (info.type.length === 0)) { - info.type = 'char*' - info.json = json.additionalProperties - info.json.type = 'string' - } - - let tName = getTypeName(getModuleName(module), name, prefix) - let t = '\n' + description(capitalize(name), json.description) - let containerType = 'WPEFramework::Core::JSON::VariantContainer' - - let subModuleProperty = getJsonTypeInfo(module, info.json, info.name, module['x-schemas']) - if (isCPP && ((info.json.type === 'object' && info.json.properties) || info.json.type === 'array')) { - // Handle Container generation here - } - - t += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, containerType)) - t += (isHeader ? getMapAccessors(tName, info.type, { descriptions: descriptions, level: level }) : getMapAccessorsImpl(tName, containerType, subModuleProperty.type, info.type, info.json, { readonly: true, optional: false })) - shape += '\n' + t - } - } - else if (json.anyOf) { - if (level > 0) { - let mergedSchema = getMergedSchema(module, json, name, schemas) - if (mergedSchema.type) { - let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name) - shape += getSchemaShapeInfo(mergedSchema, module, schemas, { name, prefix: prefixName, merged, level, title, summary, descriptions, destination, section, enums }) - } - } - } - else if (json.oneOf) { - //Just ignore schema shape, since this has to be treated as string - } - else if (json.allOf) { - let title = (json.title ? json.title : name) - let union = deepMergeAll(module, title, json, schemas) - union.title = title - - delete union['$ref'] - - return getSchemaShapeInfo(union, module, schemas, { name, prefix, merged: true, level, title, summary, descriptions, destination, section, enums }) - } - else if (json.type === 'array') { - let j - if (Array.isArray(json.items)) { - //TODO - const IsHomogenous = arr => new Set(arr.map( item => item.type ? item.type : typeof item)).size === 1 - if (!IsHomogenous(json.items)) { - throw 'Heterogenous Arrays not supported yet' - } - j = json.items[0] - } - else { - j = json.items - } - - if (!isCPP) { - name = name.endsWith("_ArrayType") ? name.split('_ArrayType')[0] : name - let subPrefix = prefix ? prefix + name : name - let info = getSchemaTypeInfo(module, j, j.title || name, schemas, subPrefix, {level : level, descriptions: descriptions, title: true}) - - if (info.type && info.type.length > 0) { - let arrayName = capitalize(info.name); - let objName = getTypeName(getModuleName(module), arrayName, subPrefix) - let tName = objName + 'Array' - - info.json.namespace = info.namespace - let moduleProperty = getJsonTypeInfo(module, json, json.title || name, schemas, prefix) - let subModuleProperty = getJsonTypeInfo(module, j, j.title || name, schemas, prefix) - let t = '' - if (level === 0) { - t += '\n' + description(capitalize(info.name), json.description) - t += '\n' + (isHeader ? getObjectManagement(tName) : getObjectManagementImpl(tName, moduleProperty.type)) - } - t += '\n' + (isHeader ? getArrayAccessors(objName, tName, info.type) : getArrayAccessorsImpl(objName, moduleProperty.type, (tName + '_t'), subModuleProperty.type, '', info.type, info.json)) - shape += '\n' + t - } - } - } - else { - shape += '\n' + getSchemaType(module, json, name, schemas, prefix, {level: level, descriptions: descriptions}) - } - } - - return shape -} - -const getJsonNativeType = json => { - let type - let jsonType = json.const ? typeof json.const : json.type - - if (jsonType === 'string') { - type = getSdkNameSpace() + '::JSON::String' - } - else if (jsonType === 'number') { - type = 'WPEFramework::Core::JSON::Float' - } - else if (json.type === 'integer') { - type = 'WPEFramework::Core::JSON::DecSInt32' - } - else if (jsonType === 'boolean') { - type = 'WPEFramework::Core::JSON::Boolean' - } - else if (jsonType === 'null') { - type = 'void' - } - else { - throw 'Unknown JSON Native Type !!!' - } - return type -} - -function getJsonType(schema = {}, module = {}, { name = '', prefix = '', descriptions = false, level = 0 } = {}) { - let info = getJsonTypeInfo(module, schema, name, module['x-schemas'], prefix, { descriptions: descriptions, level: level }) - return info.type -} - -function getJsonTypeInfo(module = {}, json = {}, name = '', schemas, prefix = '', {descriptions = false, level = 0} = {}) { - - if (json.schema) { - json = json.schema - } - - let structure = {} - structure["deps"] = new Set() //To avoid duplication of local ref definitions - structure["type"] = [] - - if (json['$ref']) { - if (json['$ref'][0] === '#') { - //Ref points to local schema - //Get Path to ref in this module and getSchemaType - let definition = getPath(json['$ref'], module, schemas) - let tName = definition.title || json['$ref'].split('/').pop() - - let schema = module - if (json['$ref'].includes('x-schemas')) { - schema = (getRefModule(json['$ref'].split('/')[2])) - } - - const res = getJsonTypeInfo(schema, definition, tName, schemas, '', {descriptions, level}) - structure.deps = res.deps - structure.type = res.type - return structure - } - } - else if (json.const) { - structure.type = getJsonNativeType(json) - return structure - } - else if (json['x-method']) { - return structure - //throw "x-methods not supported yet" - } - else if (json.additionalProperties && (typeof json.additionalProperties === 'object')) { - //This is a map of string to type in schema - //Get the Type - let type = getJsonTypeInfo(module, json.additionalProperties, name, schemas, prefix) - if (type.type && type.type.length > 0) { - structure.type = 'WPEFramework::Core::JSON::VariantContainer'; - return structure - } - else { - console.log(`WARNING: Type undetermined for ${name}`) - } - } - else if (json.type === 'string' && json.enum) { - //Enum - let t = 'WPEFramework::Core::JSON::EnumType<' + (json.namespace ? json.namespace : getModuleName(module)) + '_' + (getEnumName(name, prefix)) + '>' - structure.type.push(t) - return structure - } - else if (Array.isArray(json.type)) { - let type = json.type.find(t => t !== 'null') - let sch = JSON.parse(JSON.stringify(json)) - sch.type = type - return getJsonTypeInfo(module, sch, name, schemas, prefix ) - } - else if (json.type === 'array' && json.items) { - let res - let items - if (Array.isArray(json.items)) { - //TODO - const IsHomogenous = arr => new Set(arr.map( item => item.type ? item.type : typeof item)).size === 1 - if (!IsHomogenous(json.items)) { - throw 'Heterogenous Arrays not supported yet' - } - items = json.items[0] - } - else { - items = json.items - // grab the type for the non-array schema - } - - res = getJsonTypeInfo(module, items, items.name || name, schemas, prefix) - structure.deps = res.deps - structure.type.push(`WPEFramework::Core::JSON::ArrayType<${res.type}>`) - - return structure - } - else if (json.allOf) { - let title = json.title ? json.title : name - let union = deepMergeAll(module, title, json, schemas) - union['title'] = title - - delete union['$ref'] - return getJsonTypeInfo(module, union, '', schemas, '', {descriptions, level}) - } - else if (json.oneOf) { - structure.type = getJsonNativeTypeForOpaqueString() - return structure - } - else if (json.patternProperties) { - structure.type = getJsonNativeTypeForOpaqueString() - return structure - } - else if (json.anyOf) { - let mergedSchema = getMergedSchema(module, json, name, schemas) - if (mergedSchema.type) { - let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name) - structure = getJsonTypeInfo(module, mergedSchema, name, schemas, prefixName, {descriptions, level}) - } - else { - structure.type = getJsonNativeTypeForOpaqueString() - } - } - else if (json.type === 'object') { - if (hasProperties(json) !== true) { - structure.type = getJsonNativeTypeForOpaqueString() - } - else { - let schema = getSchemaTypeInfo(module, json, name, module['x-schemas'], prefix) - if (schema.namespace && schema.namespace.length > 0) { - structure.type.push(getJsonDataStructName(schema.namespace, json.title || name, prefix)) - } - } - return structure - } - else if (json.type) { - structure.type = getJsonNativeType(json) - return structure - } - else { - structure.type = 'JsonObject' - } - return structure -} - -function getSchemaInstantiation(schema, module, name, { instantiationType = '', prefix = '' } = {}) { - - if (instantiationType === 'params') { - return getParameterInstantiation(getParamList(schema, module)) - } - else if (instantiationType === 'result') { - let result = '' - - if (!IsResultConstNullSuccess(schema, name)) { - let resultJsonType = getJsonType(schema, module, {name: name}) || '' - let resultType = '' - if (!IsResultBooleanSuccess(schema, name)) { - resultType = getSchemaType(schema, module, { title: true, name: name, resultSchema: true}) || '' - } - result = getResultInstantiation(name, resultType, resultJsonType) - } - return result - } - else if (instantiationType === 'callback.params') { - let resultJsonType = getJsonType(schema.result.schema, module, { name: schema.result.name, prefix }) || '' - return getCallbackParametersInstantiation(getParamList(schema, module), resultJsonType) - } - else if (instantiationType === 'callback.result') { - let resultType = getSchemaType(schema.result.schema, module, { title: true, name: schema.result.name, prefix, resultSchema: true}) || '' - let resultJsonType = getJsonType(schema.result.schema, module, { name: schema.result.name }) || '' - return getCallbackResultInstantiation(resultType, resultJsonType) - } - else if (instantiationType === 'callback.response') { - let resultType = getSchemaType(schema.result.schema, module, { title: true, name: schema.result.name, prefix, resultSchema: true}) || '' - let resultJsonType = getJsonType(schema.result.schema, module, { name: schema.result.name, prefix }) || '' - return getCallbackResponseInstantiation(getParamList(schema, module), resultType, resultJsonType) - } - else if (instantiationType === 'pull.param.name') { - let resultJsonType = getJsonType(schema, module, { name: name }) || '' - return resultJsonType.length && resultJsonType[0].split('_')[1] || '' - } - - return '' -} - -export default { - getMethodSignature, - getMethodSignatureParams, - getSchemaShape, - getSchemaType, - getJsonType, - getSchemaInstantiation -} diff --git a/languages/c/language.config.json b/languages/c/language.config.json deleted file mode 100644 index b19eddb8..00000000 --- a/languages/c/language.config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "C", - "langcode": "c", - "createModuleDirectories": false, - "extractSubSchemas": true, - "templatesPerModule": [ - "/include/module.h", - "/src/module.cpp" - ], - "templatesPerSchema": [ - "/include/common/module.h", - "/src/module_common.cpp", - "/src/jsondata_module.h" - ], - "persistPermission": true, - "createPolymorphicMethods": true, - "excludeDeclarations":true -} diff --git a/languages/c/src/index.mjs b/languages/c/src/index.mjs deleted file mode 100644 index 51c547a1..00000000 --- a/languages/c/src/index.mjs +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2021 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 - */ - -export { default as Transport } from './shared/Transport/index.mjs' \ No newline at end of file diff --git a/languages/c/src/shared/CMakeLists.txt b/languages/c/src/shared/CMakeLists.txt deleted file mode 100644 index fe7a0085..00000000 --- a/languages/c/src/shared/CMakeLists.txt +++ /dev/null @@ -1,56 +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 - -cmake_minimum_required(VERSION 3.3) - -project(Firebolt) - -set(FIREBOLT_TRANSPORT_WAITTIME 1000 CACHE STRING "Maximum time to wait for Transport layer to get response") -set(FIREBOLT_LOGLEVEL "Info" CACHE STRING "Log level to be enabled") -option(FIREBOLT_ENABLE_STATIC_LIB "Create Firebolt library as Static library" OFF) -option(ENABLE_TESTS "Build openrpc native test" OFF) - -if (FIREBOLT_ENABLE_STATIC_LIB) - set(FIREBOLT_LIBRARY_TYPE STATIC) -else () - set(FIREBOLT_LIBRARY_TYPE SHARED) -endif () - -if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${SYSROOT_PATH}/usr" CACHE INTERNAL "" FORCE) - set(CMAKE_PREFIX_PATH ${SYSROOT_PATH}/usr/lib/cmake CACHE INTERNAL "" FORCE) -endif() - -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_SOURCE_DIR}/cmake" - "${SYSROOT_PATH}/usr/lib/cmake" - "${SYSROOT_PATH}/tools/cmake") -include(HelperFunctions) - -set(FIREBOLT_NAMESPACE ${PROJECT_NAME} CACHE STRING "Namespace of the project") - -find_package(WPEFramework CONFIG REQUIRED) - -add_subdirectory(src) - -if (ENABLE_TESTS) - add_subdirectory(test) -endif() - -# make sure others can make use cmake settings of Firebolt OpenRPC -configure_file( "${CMAKE_SOURCE_DIR}/cmake/project.cmake.in" - "${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}Config.cmake" - @ONLY) diff --git a/languages/c/src/shared/cmake/HelperFunctions.cmake b/languages/c/src/shared/cmake/HelperFunctions.cmake deleted file mode 100644 index eb2ae296..00000000 --- a/languages/c/src/shared/cmake/HelperFunctions.cmake +++ /dev/null @@ -1,72 +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 - -macro(GetSubDirs subdirs currentdir) - file(GLOB subdirectories RELATIVE ${currentdir} ${currentdir}/*) - set(subdirs "") - foreach(subdir ${subdirectories}) - if (IS_DIRECTORY ${currentdir}/${subdir}) - list(APPEND subdirs ${subdir}) - endif() - endforeach() -endmacro() - -function(InstallHeaders) - set(optionsArgs EXCLUDE_ROOT_DIR) - set(oneValueArgs TARGET NAMESPACE SOURCE DESTINATION) - set(multiValueArgs HEADERS) - - cmake_parse_arguments(Argument "${optionsArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (Argument_UNPARSED_ARGUMENTS) - message(FATAL_ERROR "Unknown keywords given to InstallHeaders(): \"${Argument_UNPARSED_ARGUMENTS}\"") - endif() - if (Argument_HEADERS) - add_custom_command( - TARGET ${Argument_TARGET} - POST_BUILD - COMMENT "=================== Installing Headers ======================" - ) - foreach(directory ${Argument_HEADERS}) - if (Argument_EXCLUDE_ROOT_DIR) - set(destination ${Argument_DESTINATION}) - else() - set(destination ${Argument_DESTINATION}/${directory}) - endif() - - if (Argument_SOURCE) - set(source ${Argument_SOURCE}) - else() - set(source ${CMAKE_CURRENT_LIST_DIR}) - endif() - - GetSubDirs(subdirs ${source}/${directory}) - list(APPEND subdirs ${directory}) - - foreach(subdir ${subdirs}) - if (NOT subdir STREQUAL ".") - set(dest ${destination}/${subdir}) - file(GLOB headers "${source}/${directory}/${subdir}/*.h") - if (headers) - install( - DIRECTORY "${source}/${directory}/${subdir}" - DESTINATION include/${dest} - FILES_MATCHING PATTERN "*.h") - endif() - endif() - endforeach(subdir) - endforeach(directory) - endif() -endfunction(InstallHeaders) diff --git a/languages/c/src/shared/cmake/project.cmake.in b/languages/c/src/shared/cmake/project.cmake.in deleted file mode 100644 index eca32f8c..00000000 --- a/languages/c/src/shared/cmake/project.cmake.in +++ /dev/null @@ -1,35 +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 - -set(FIREBOLT_NAMESPACE "@FIREBOLT_NAMESPACE@" CACHE INTERNAL "" FORCE) -set("${FIREBOLT_NAMESPACE}_FOUND" TRUE CACHE INTERNAL "" FORCE) - -list(APPEND CMAKE_MODULE_PATH - "${CMAKE_SOURCE_DIR}/cmake" - "${SYSROOT_PATH}/usr/lib/cmake" - "${SYSROOT_PATH}/usr/lib/cmake/Firebolt" - "${SYSROOT_PATH}/tools/cmake") - -if (NOT DEFINED CMAKE_PREFIX_PATH) - set(CMAKE_PREFIX_PATH ${SYSROOT_PATH}/usr/lib/cmake CACHE INTERNAL "" FORCE) -endif() - -if (FIREBOLT_ENABLE_STATIC_LIB) - set(FIREBOLT_LIBRARY_TYPE STATIC) -else () - set(FIREBOLT_LIBRARY_TYPE SHARED) -endif () - diff --git a/languages/c/src/shared/include/error.h b/languages/c/src/shared/include/error.h deleted file mode 100644 index 07d6268a..00000000 --- a/languages/c/src/shared/include/error.h +++ /dev/null @@ -1,41 +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_ERROR_H -#define FIREBOLT_ERROR_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum FireboltSDKError { - FireboltSDKErrorNone = 0, - FireboltSDKErrorGeneral = 1, - FireboltSDKErrorUnavailable = 2, - FireboltSDKErrorTimedout = 3, - FireboltSDKErrorNotSubscribed = 4, - FireboltSDKErrorUnknown = 5, - FireboltSDKErrorInUse = 6, - FireboltSDKErrorNotSupported = 7 -} FireboltSDKError_t; - -#ifdef __cplusplus -} -#endif - -#endif // FIREBOLT_ERROR_H diff --git a/languages/c/src/shared/include/firebolt.h b/languages/c/src/shared/include/firebolt.h deleted file mode 100644 index 565b363c..00000000 --- a/languages/c/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/c/src/shared/include/types.h b/languages/c/src/shared/include/types.h deleted file mode 100644 index 8333f0eb..00000000 --- a/languages/c/src/shared/include/types.h +++ /dev/null @@ -1,37 +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_TYPES_H -#define FIREBOLT_TYPES_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct Firebolt_String_s* Firebolt_String_t; -const char* Firebolt_String(Firebolt_String_t handle); -void Firebolt_String_Release(Firebolt_String_t handle); - -#ifdef __cplusplus -} -#endif - -#endif // FIREBOLT_TYPES_H diff --git a/languages/c/src/shared/src/Accessor/Accessor.cpp b/languages/c/src/shared/src/Accessor/Accessor.cpp deleted file mode 100644 index 6d4aceae..00000000 --- a/languages/c/src/shared/src/Accessor/Accessor.cpp +++ /dev/null @@ -1,117 +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 - */ - -#include "Accessor.h" - -namespace FireboltSDK { - - Accessor* Accessor::_singleton = nullptr; - - Accessor::Accessor(const string& configLine) - : _workerPool() - , _transport(nullptr) - , _config() - { - _singleton = this; - _config.FromString(configLine); - - Logger::SetLogLevel(WPEFramework::Core::EnumerateType(_config.LogLevel.Value().c_str()).Value()); - - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Url = %s", _config.WsUrl.Value().c_str()); - CreateTransport(_config.WsUrl.Value().c_str(), _config.WaitTime.Value()); - CreateEventHandler(); - - _workerPool = WPEFramework::Core::ProxyType::Create(_config.WorkerPool.ThreadCount.Value(), _config.WorkerPool.StackSize.Value(), _config.WorkerPool.QueueSize.Value()); - WPEFramework::Core::WorkerPool::Assign(&(*_workerPool)); - _workerPool->Run(); - } - - Accessor::~Accessor() - { - DestroyTransport(); - DestroyEventHandler(); - WPEFramework::Core::IWorkerPool::Assign(nullptr); - _workerPool->Stop(); - _singleton = nullptr; - } - - int32_t Accessor::CreateEventHandler() - { - Event::Instance().Configure(_transport); - return FireboltSDKErrorNone; - } - - int32_t Accessor::DestroyEventHandler() - { - Event::Dispose(); - return FireboltSDKErrorNone; - } - - Event& Accessor::GetEventManager() - { - return Event::Instance(); - } - - int32_t Accessor::CreateTransport(const string& url, const uint32_t waitTime = DefaultWaitTime) - { - if (_transport != nullptr) { - delete _transport; - } - - _transport = new Transport(static_cast(url), waitTime); - if (WaitForLinkReady(_transport, waitTime) != FireboltSDKErrorNone) { - delete _transport; - _transport = nullptr; - } - - ASSERT(_transport != nullptr); - return ((_transport != nullptr) ? FireboltSDKErrorNone : FireboltSDKErrorUnavailable); - } - - int32_t Accessor::DestroyTransport() - { - if (_transport != nullptr) { - delete _transport; - _transport = nullptr; - } - return FireboltSDKErrorNone; - } - - Transport* Accessor::GetTransport() - { - ASSERT(_transport != nullptr); - return _transport; - } - - int32_t Accessor::WaitForLinkReady(Transport* transport, const uint32_t waitTime = DefaultWaitTime) { - uint32_t waiting = (waitTime == WPEFramework::Core::infinite ? WPEFramework::Core::infinite : waitTime); - static constexpr uint32_t SLEEPSLOT_TIME = 100; - - // Right, a wait till connection is closed is requested.. - while ((waiting > 0) && (transport->IsOpen() == false)) { - - uint32_t sleepSlot = (waiting > SLEEPSLOT_TIME ? SLEEPSLOT_TIME : waiting); - - // Right, lets sleep in slices of 100 ms - SleepMs(sleepSlot); - - waiting -= (waiting == WPEFramework::Core::infinite ? 0 : sleepSlot); - } - return (((waiting == 0) || (transport->IsOpen() == true)) ? FireboltSDKErrorNone : FireboltSDKErrorTimedout); - } -} diff --git a/languages/c/src/shared/src/Accessor/Accessor.h b/languages/c/src/shared/src/Accessor/Accessor.h deleted file mode 100644 index e247df98..00000000 --- a/languages/c/src/shared/src/Accessor/Accessor.h +++ /dev/null @@ -1,122 +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 - */ - -#pragma once - -#include "Module.h" -#include "WorkerPool.h" -#include "Transport/Transport.h" -#include "Event/Event.h" -#include "Logger/Logger.h" - -namespace FireboltSDK { - class Accessor { - private: - static constexpr uint8_t JSONVersion = 2; - - private: - //Singleton - Accessor(const string& configLine); - - public: - class EXTERNAL Config : public WPEFramework::Core::JSON::Container { - public: - Config(const Config&) = delete; - Config& operator=(const Config&) = delete; - - class WorkerPoolConfig : public WPEFramework::Core::JSON::Container { - public: - WorkerPoolConfig& operator=(const WorkerPoolConfig&); - - WorkerPoolConfig() - : WPEFramework::Core::JSON::Container() - , QueueSize(8) - , ThreadCount(3) - , StackSize(WPEFramework::Core::Thread::DefaultStackSize()) - { - Add("queueSize", &QueueSize); - Add("threadCount", &ThreadCount); - Add("stackSize", &StackSize); - } - - virtual ~WorkerPoolConfig() = default; - - public: - WPEFramework::Core::JSON::DecUInt32 QueueSize; - WPEFramework::Core::JSON::DecUInt32 ThreadCount; - WPEFramework::Core::JSON::DecUInt32 StackSize; - }; - - - Config() - : WPEFramework::Core::JSON::Container() - , WaitTime(1000) - , LogLevel(_T("Info")) - , WorkerPool() - , WsUrl(_T("ws://127.0.0.1:9998")) - { - Add(_T("waitTime"), &WaitTime); - Add(_T("logLevel"), &LogLevel); - Add(_T("workerPool"), &WorkerPool); - Add(_T("wsUrl"), &WsUrl); - } - - public: - WPEFramework::Core::JSON::DecUInt32 WaitTime; - WPEFramework::Core::JSON::String LogLevel; - WorkerPoolConfig WorkerPool; - WPEFramework::Core::JSON::String WsUrl; - }; - - Accessor(const Accessor&) = delete; - Accessor& operator= (const Accessor&) = delete; - Accessor() = delete; - ~Accessor(); - - static Accessor& Instance(const string& configLine = "") - { - static Accessor *instance = new Accessor(configLine); - ASSERT(instance != nullptr); - return *instance; - } - - static void Dispose() - { - ASSERT(_singleton != nullptr); - - if (_singleton != nullptr) { - delete _singleton; - } - } - Event& GetEventManager(); - Transport* GetTransport(); - - private: - int32_t CreateEventHandler(); - int32_t DestroyEventHandler(); - int32_t CreateTransport(const string& url, const uint32_t waitTime); - int32_t DestroyTransport(); - int32_t WaitForLinkReady(Transport* transport, const uint32_t waitTime); - - private: - WPEFramework::Core::ProxyType _workerPool; - Transport* _transport; - static Accessor* _singleton; - Config _config; - }; -} diff --git a/languages/c/src/shared/src/Accessor/WorkerPool.h b/languages/c/src/shared/src/Accessor/WorkerPool.h deleted file mode 100644 index 69005a5e..00000000 --- a/languages/c/src/shared/src/Accessor/WorkerPool.h +++ /dev/null @@ -1,102 +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 - */ - -#pragma once - -#include "Module.h" - -namespace FireboltSDK { - - class WorkerPoolImplementation : public WPEFramework::Core::WorkerPool { - public: - WorkerPoolImplementation() = delete; - WorkerPoolImplementation(const WorkerPoolImplementation&) = delete; - WorkerPoolImplementation& operator=(const WorkerPoolImplementation&) = delete; - - WorkerPoolImplementation(const uint8_t threads, const uint32_t stackSize, const uint32_t queueSize) - : WorkerPool(threads, stackSize, queueSize, &_dispatcher) - { - } - - ~WorkerPoolImplementation() - { - // Diable the queue so the minions can stop, even if they are processing and waiting for work.. - Stop(); - } - - public: - void Stop() - { - WPEFramework::Core::WorkerPool::Stop(); - } - - void Run() - { - WPEFramework::Core::WorkerPool::Run(); - } - - private: - class Dispatcher : public WPEFramework::Core::ThreadPool::IDispatcher { - public: - Dispatcher(const Dispatcher&) = delete; - Dispatcher& operator=(const Dispatcher&) = delete; - - Dispatcher() = default; - ~Dispatcher() override = default; - - private: - void Initialize() override { } - void Deinitialize() override { } - void Dispatch(WPEFramework::Core::IDispatch* job) override - { job->Dispatch(); } - }; - - Dispatcher _dispatcher; - }; - - class Worker : public WPEFramework::Core::IDispatch { - public: - typedef std::function Dispatcher; - - protected: - Worker(const Dispatcher& dispatcher, const void* userData) - : _dispatcher(dispatcher) - , _userData(userData) - { - } - - public: - Worker() = delete; - Worker(const Worker&) = delete; - Worker& operator=(const Worker&) = delete; - - ~Worker() = default; - - public: - static WPEFramework::Core::ProxyType Create(const Dispatcher& dispatcher, const void* userData); - - void Dispatch() override - { - _dispatcher(_userData); - } - - private: - Dispatcher _dispatcher; - const void* _userData; - }; -} diff --git a/languages/c/src/shared/src/CMakeLists.txt b/languages/c/src/shared/src/CMakeLists.txt deleted file mode 100644 index ecaf4efb..00000000 --- a/languages/c/src/shared/src/CMakeLists.txt +++ /dev/null @@ -1,73 +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 - -cmake_minimum_required(VERSION 3.3) - -project(FireboltSDK) -project_version(1.0.0) -set(TARGET ${PROJECT_NAME}) -message("Setup ${TARGET} v${PROJECT_VERSION}") - -file(GLOB SOURCES *.cpp) -add_library(${TARGET} ${FIREBOLT_LIBRARY_TYPE} - ${SOURCES} - Logger/Logger.cpp - Transport/Transport.cpp - Accessor/Accessor.cpp - Event/Event.cpp -) - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_package(${NAMESPACE}WebSocket CONFIG REQUIRED) - -target_link_libraries(${TARGET} - PUBLIC - ${NAMESPACE}WebSocket::${NAMESPACE}WebSocket -) - -target_include_directories(${TARGET} - PRIVATE - $ - $ -) - -set_target_properties(${TARGET} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - FRAMEWORK FALSE - LINK_WHAT_YOU_USE TRUE - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR} -) - -install( - TARGETS ${TARGET} EXPORT ${TARGET}Targets - ARCHIVE DESTINATION lib COMPONENT libs # static lib - LIBRARY DESTINATION lib COMPONENT libs # shared lib -) - -install( - DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION include/${FIREBOLT_NAMESPACE}SDK - FILES_MATCHING PATTERN "*.h") - -install( - FILES ${CMAKE_BINARY_DIR}/FireboltConfig.cmake - DESTINATION lib/cmake/${FIREBOLT_NAMESPACE}) - -InstallHeaders(TARGET ${TARGET} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION ${FIREBOLT_NAMESPACE}SDK) -InstallCMakeConfig(TARGETS ${TARGET}) -InstallPackageConfig(TARGETS ${TARGET} DESCRIPTION "Firebolt SDK Library") diff --git a/languages/c/src/shared/src/Event/Event.cpp b/languages/c/src/shared/src/Event/Event.cpp deleted file mode 100644 index c1fdff6f..00000000 --- a/languages/c/src/shared/src/Event/Event.cpp +++ /dev/null @@ -1,147 +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 - */ - -#include "Transport/Transport.h" -#include "Event.h" - -namespace FireboltSDK { - Event* Event::_singleton = nullptr; - Event::Event() - : _eventMap() - , _adminLock() - , _transport(nullptr) - { - ASSERT(_singleton == nullptr); - _singleton = this; - } - - Event::~Event() /* override */ - { - _transport->SetEventHandler(nullptr); - _transport = nullptr; - - _singleton = nullptr; - } - - /* static */ Event& Event::Instance() - { - static Event *instance = new Event(); - ASSERT(instance != nullptr); - return *instance; - } - - /* static */ void Event::Dispose() - { - ASSERT(_singleton != nullptr); - - if (_singleton != nullptr) { - delete _singleton; - } - } - - void Event::Configure(Transport* transport) - { - _transport = transport; - _transport->SetEventHandler(this); - } - - int32_t Event::Unsubscribe(const string& eventName, void* usercb) - { - int32_t status = Revoke(eventName, usercb); - - if (status == FireboltSDKErrorNone) { - if (_transport != nullptr) { - - const string parameters("{\"listen\":false}"); - status = _transport->Unsubscribe(eventName, parameters); - } - } - return ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone: status); - } - - int32_t Event::ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) /* override */ - { - int32_t result = FireboltSDKErrorGeneral; - Response response; - _transport->FromMessage((WPEFramework::Core::JSON::IElement*)&response, *jsonResponse); - if (response.Listening.IsSet() == true) { - result = FireboltSDKErrorNone; - enabled = response.Listening.Value(); - } - return result; - } - - int32_t Event::Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) /* override */ - { - string response = jsonResponse->Result.Value(); - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.begin(); - while(callbackIndex != eventIndex->second.end()) { - State state; - if (callbackIndex->second.state != State::REVOKED) { - callbackIndex->second.state = State::EXECUTING; - } - state = callbackIndex->second.state; - _adminLock.Unlock(); - if (state == State::EXECUTING) { - callbackIndex->second.lambda(callbackIndex->first, callbackIndex->second.userdata, (jsonResponse->Result.Value())); - } - _adminLock.Lock(); - if (callbackIndex->second.state == State::REVOKED) { - callbackIndex = eventIndex->second.erase(callbackIndex); - if (eventIndex->second.size() == 0) { - _eventMap.erase(eventIndex); - } - } else { - callbackIndex->second.state = State::IDLE; - callbackIndex++; - } - } - } - _adminLock.Unlock(); - - return FireboltSDKErrorNone;; - } - - int32_t Event::Revoke(const string& eventName, void* usercb) - { - int32_t status = FireboltSDKErrorNone; - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.find(usercb); - if (callbackIndex->second.state != State::EXECUTING) { - if (callbackIndex != eventIndex->second.end()) { - eventIndex->second.erase(callbackIndex); - } - } else { - callbackIndex->second.state = State::REVOKED; - } - if (eventIndex->second.size() == 0) { - _eventMap.erase(eventIndex); - } else { - status = FireboltSDKErrorInUse; - } - } - _adminLock.Unlock(); - - return status; - } -} diff --git a/languages/c/src/shared/src/Event/Event.h b/languages/c/src/shared/src/Event/Event.h deleted file mode 100644 index dd65cb53..00000000 --- a/languages/c/src/shared/src/Event/Event.h +++ /dev/null @@ -1,165 +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 - */ - -#pragma once - -#include "Module.h" - -namespace FireboltSDK { - - static constexpr uint32_t DefaultWaitTime = 1000; - - class Event : public IEventHandler { - public: - typedef std::function DispatchFunction; - private: - enum State : uint8_t { - IDLE, - EXECUTING, - REVOKED - }; - - struct CallbackData { - const DispatchFunction lambda; - const void* userdata; - State state; - }; - using CallbackMap = std::map; - using EventMap = std::map; - - class Response : public WPEFramework::Core::JSON::Container { - public: - Response& operator=(const Response&) = delete; - Response() - : WPEFramework::Core::JSON::Container() - , Listening(false) - { - Add(_T("listening"), &Listening); - } - Response(const Response& copy) - : WPEFramework::Core::JSON::Container() - , Listening(copy.Listening) - { - Add(_T("listening"), &Listening); - } - ~Response() override = default; - - public: - WPEFramework::Core::JSON::Boolean Listening; - }; - - private: - Event(); - public: - ~Event() override; - static Event& Instance(); - static void Dispose(); - void Configure(Transport* transport); - - public: - template - int32_t Subscribe(const string& eventName, const CALLBACK& callback, void* usercb, const void* userdata) - { - JsonObject jsonParameters; - return Subscribe(eventName, jsonParameters, callback, usercb, userdata); - } - - template - int32_t Subscribe(const string& eventName, JsonObject& jsonParameters, const CALLBACK& callback, void* usercb, const void* userdata) - { - int32_t status = FireboltSDKErrorUnavailable; - if (_transport != nullptr) { - - status = Assign(eventName, callback, usercb, userdata); - if (status == FireboltSDKErrorNone) { - Response response; - - WPEFramework::Core::JSON::Variant Listen = true; - jsonParameters.Set(_T("listen"), Listen); - string parameters; - jsonParameters.ToString(parameters); - - status = _transport->Subscribe(eventName, parameters, response); - - if (status != FireboltSDKErrorNone) { - Revoke(eventName, usercb); - } else if ((response.Listening.IsSet() == true) && - (response.Listening.Value() == true)) { - status = FireboltSDKErrorNone; - } else { - status = FireboltSDKErrorNotSubscribed; - } - } - } - - return status; - } - - int32_t Unsubscribe(const string& eventName, void* usercb); - - private: - template - int32_t Assign(const string& eventName, const CALLBACK& callback, void* usercb, const void* userdata) - { - int32_t status = FireboltSDKErrorNone; - std::function actualCallback = callback; - DispatchFunction implementation = [actualCallback](void* usercb, const void* userdata, const string& parameters) -> int32_t { - - WPEFramework::Core::ProxyType* inbound = new WPEFramework::Core::ProxyType(); - *inbound = WPEFramework::Core::ProxyType::Create(); - (*inbound)->FromString(parameters); - actualCallback(usercb, userdata, static_cast(inbound)); - return (FireboltSDKErrorNone); - }; - CallbackData callbackData = {implementation, userdata, State::IDLE}; - - _adminLock.Lock(); - EventMap::iterator eventIndex = _eventMap.find(eventName); - if (eventIndex != _eventMap.end()) { - CallbackMap::iterator callbackIndex = eventIndex->second.find(usercb); - if (callbackIndex == eventIndex->second.end()) { - eventIndex->second.emplace(std::piecewise_construct, std::forward_as_tuple(usercb), std::forward_as_tuple(callbackData)); - } else { - // Already registered, no need to register again; - status = FireboltSDKErrorInUse; - } - } else { - - CallbackMap callbackMap; - callbackMap.emplace(std::piecewise_construct, std::forward_as_tuple(usercb), std::forward_as_tuple(callbackData)); - _eventMap.emplace(std::piecewise_construct, std::forward_as_tuple(eventName), std::forward_as_tuple(callbackMap)); - - } - - _adminLock.Unlock(); - return status; - } - int32_t Revoke(const string& eventName, void* usercb); - - private: - int32_t ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) override; - int32_t Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) override; - - private: - EventMap _eventMap; - WPEFramework::Core::CriticalSection _adminLock; - Transport* _transport; - - static Event* _singleton; - }; -} diff --git a/languages/c/src/shared/src/FireboltSDK.conf.in b/languages/c/src/shared/src/FireboltSDK.conf.in deleted file mode 100644 index 6964a7bc..00000000 --- a/languages/c/src/shared/src/FireboltSDK.conf.in +++ /dev/null @@ -1,3 +0,0 @@ -url = "@FIREBOLT_SERVER_URL@" -waittime = "@FIREBOLT_TRANSPORT_WAITTIME@" -loglevel = "@FIREBOLT_LOGLEVEL@" diff --git a/languages/c/src/shared/src/FireboltSDK.h b/languages/c/src/shared/src/FireboltSDK.h deleted file mode 100644 index d78687dc..00000000 --- a/languages/c/src/shared/src/FireboltSDK.h +++ /dev/null @@ -1,26 +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 - */ - -#pragma once - -#include "Transport/Transport.h" -#include "Properties/Properties.h" -#include "Accessor/Accessor.h" -#include "Logger/Logger.h" -#include "TypesPriv.h" -#include "types.h" diff --git a/languages/c/src/shared/src/Logger/Logger.cpp b/languages/c/src/shared/src/Logger/Logger.cpp deleted file mode 100644 index 44ebaba8..00000000 --- a/languages/c/src/shared/src/Logger/Logger.cpp +++ /dev/null @@ -1,86 +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 - */ - -#include "Module.h" -#include "error.h" -#include "Logger.h" - -namespace WPEFramework { - -ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::LogLevel) - - { FireboltSDK::Logger::LogLevel::Error, _TXT("Error") }, - { FireboltSDK::Logger::LogLevel::Warning, _TXT("Warning") }, - { FireboltSDK::Logger::LogLevel::Info, _TXT("Info") }, - { FireboltSDK::Logger::LogLevel::Debug, _TXT("Debug") }, - -ENUM_CONVERSION_END(FireboltSDK::Logger::LogLevel) - -ENUM_CONVERSION_BEGIN(FireboltSDK::Logger::Category) - - { FireboltSDK::Logger::Category::OpenRPC, _TXT("FireboltSDK::OpenRPC") }, - { FireboltSDK::Logger::Category::Core, _TXT("FireboltSDK::Core") }, - { FireboltSDK::Logger::Category::Management, _TXT("FireboltSDK::Management") }, - { FireboltSDK::Logger::Category::Discovery, _TXT("FireboltSDK::Discovery") }, - -ENUM_CONVERSION_END(FireboltSDK::Logger::Category) - -} - -namespace FireboltSDK { - /* static */ Logger::LogLevel Logger::_logLevel = Logger::LogLevel::Error; - - int32_t Logger::SetLogLevel(Logger::LogLevel logLevel) - { - ASSERT(logLevel < Logger::LogLevel::MaxLevel); - int32_t status = FireboltSDKErrorNotSupported; - if (logLevel < Logger::LogLevel::MaxLevel) { - _logLevel = logLevel; - status = FireboltSDKErrorNone; - } - return status; - } - - void Logger::Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...) - { - if (logLevel <= _logLevel) { - va_list arg; - char msg[Logger::MaxBufSize]; - va_start(arg, format); - int length = vsnprintf(msg, Logger::MaxBufSize, format.c_str(), arg); - va_end(arg); - - uint32_t position = (length >= Logger::MaxBufSize) ? (Logger::MaxBufSize - 1) : length; - msg[position] = '\0'; - - char formattedMsg[Logger::MaxBufSize]; - const string time = WPEFramework::Core::Time::Now().ToTimeOnly(true); - const string categoryName = WPEFramework::Core::EnumerateType(category).Data(); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-truncation" - if (categoryName.empty() != true) { - snprintf(formattedMsg, sizeof(formattedMsg), "--->\033[1;32m[%s]:[%s]:[%s][%s:%d](%s) : %s\n", time.c_str(), categoryName.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg); - } else { - snprintf(formattedMsg, sizeof(formattedMsg), "--->\033[1;32m[%s]:[%s][%s:%d](%s) : %s\n", time.c_str(), module.c_str(), WPEFramework::Core::File::FileName(file).c_str(), line, function.c_str(), TRACE_PROCESS_ID, TRACE_THREAD_ID, msg); - } -#pragma GCC diagnostic pop - LOG_MESSAGE(formattedMsg); - } - } -} - diff --git a/languages/c/src/shared/src/Logger/Logger.h b/languages/c/src/shared/src/Logger/Logger.h deleted file mode 100644 index b8e42031..00000000 --- a/languages/c/src/shared/src/Logger/Logger.h +++ /dev/null @@ -1,85 +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 - */ - -#pragma once - -#include "types.h" - -namespace FireboltSDK { - - class Logger { - private: - static constexpr uint16_t MaxBufSize = 512; - - public: - enum class LogLevel : uint8_t { - Error, - Warning, - Info, - Debug, - MaxLevel - }; - - enum class Category : uint8_t { - OpenRPC, - Core, - Management, - Discovery - }; - - public: - Logger() = default; - Logger(const Logger&) = delete; - Logger& operator=(const Logger&) = delete; - ~Logger() = default; - - public: - static int32_t SetLogLevel(LogLevel logLevel); - static void Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...); - - public: - template - static const string Module() - { - return WPEFramework::Core::ClassNameOnly(typeid(CLASS).name()).Text(); - } - - private: - static LogLevel _logLevel; - }; -} - -#define FIREBOLT_LOG(level, category, module, ...) \ - FireboltSDK::Logger::Log(level, category, module, __FILE__, __func__, __LINE__, __VA_ARGS__) - -#define FIREBOLT_LOG_ERROR(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Error, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_WARNING(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Warning, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_INFO(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Info, category, module, __VA_ARGS__) -#define FIREBOLT_LOG_DEBUG(category, module, ...) \ - FIREBOLT_LOG(FireboltSDK::Logger::LogLevel::Debug, category, module, __VA_ARGS__) - -#ifdef ENABLE_SYSLOG -#define LOG_MESSAGE(message) \ - syslog(sLOG_NOTIC, "%s", message); -#else -#define LOG_MESSAGE(message) \ - fprintf(stderr, "%s", message); fflush(stdout); -#endif diff --git a/languages/c/src/shared/src/Module.cpp b/languages/c/src/shared/src/Module.cpp deleted file mode 100644 index d63badc4..00000000 --- a/languages/c/src/shared/src/Module.cpp +++ /dev/null @@ -1,21 +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 - */ - -#include "Module.h" - -MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/languages/c/src/shared/src/Module.h b/languages/c/src/shared/src/Module.h deleted file mode 100644 index 00ea64bb..00000000 --- a/languages/c/src/shared/src/Module.h +++ /dev/null @@ -1,29 +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 - */ - -#pragma once - -#ifndef MODULE_NAME -#define MODULE_NAME OpenRPCNativeSDK -#endif - -#include -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/languages/c/src/shared/src/Properties/Properties.h b/languages/c/src/shared/src/Properties/Properties.h deleted file mode 100644 index eaf6c1a4..00000000 --- a/languages/c/src/shared/src/Properties/Properties.h +++ /dev/null @@ -1,148 +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 - */ - -#pragma once - -#include "Accessor/Accessor.h" -#include "Event/Event.h" - -namespace FireboltSDK { - - class Properties { - public: - Properties(const Properties&) = delete; - Properties& operator= (const Properties&) = delete; - - Properties() = default; - ~Properties() = default; - - public: - template - static int32_t Get(const string& propertyName, WPEFramework::Core::ProxyType& response) - { - int32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject parameters; - RESPONSETYPE responseType; - status = transport->Invoke(propertyName, parameters, responseType); - if (status == FireboltSDKErrorNone) { - ASSERT(response.IsValid() == false); - if (response.IsValid() == true) { - response.Release(); - } - response = WPEFramework::Core::ProxyType::Create(); - (*response) = responseType; - } - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static int32_t Get(const string& propertyName, const PARAMETERS& parameters, WPEFramework::Core::ProxyType& response) - { - int32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - RESPONSETYPE responseType; - status = transport->Invoke(propertyName, parameters, responseType); - if (status == FireboltSDKErrorNone) { - ASSERT(response.IsValid() == false); - if (response.IsValid() == true) { - response.Release(); - } - response = WPEFramework::Core::ProxyType::Create(); - (*response) = responseType; - } - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - - template - static int32_t Get(const string& propertyName, RESPONSETYPE& response) - { - int32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject parameters; - status = transport->Invoke(propertyName, parameters, response); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static int32_t Get(const string& propertyName, const PARAMETERS& parameters, RESPONSETYPE& response) - { - int32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - status = transport->Invoke(propertyName, parameters, response); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static int32_t Set(const string& propertyName, const PARAMETERS& parameters) - { - int32_t status = FireboltSDKErrorUnavailable; - Transport* transport = Accessor::Instance().GetTransport(); - if (transport != nullptr) { - JsonObject responseType; - status = transport->Invoke(propertyName, parameters, responseType); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; - } - - template - static int32_t Subscribe(const string& propertyName, JsonObject& paramsters, const CALLBACK& callback, void* usercb, const void* userdata) - { - return Event::Instance().Subscribe(EventName(propertyName), paramsters, callback, usercb, userdata); - } - - static int32_t Unsubscribe(const string& propertyName, void* usercb) - { - return Event::Instance().Unsubscribe(EventName(propertyName), usercb); - } - private: - static inline string EventName(const string& propertyName) { - size_t pos = propertyName.find_first_of('.'); - string eventName = propertyName; - if (pos != std::string::npos) { - eventName[pos + 1] = std::toupper(eventName[pos + 1]); - eventName = string(eventName.substr(0, pos + 1) + "on" + eventName.substr(pos + 1) + "Changed"); - } - return eventName; - } - }; -} diff --git a/languages/c/src/shared/src/Transport/Transport.cpp b/languages/c/src/shared/src/Transport/Transport.cpp deleted file mode 100644 index 280944c6..00000000 --- a/languages/c/src/shared/src/Transport/Transport.cpp +++ /dev/null @@ -1,24 +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 - */ - -#include "Transport.h" - -namespace FireboltSDK { - -} - diff --git a/languages/c/src/shared/src/Transport/Transport.h b/languages/c/src/shared/src/Transport/Transport.h deleted file mode 100644 index 6b80cd25..00000000 --- a/languages/c/src/shared/src/Transport/Transport.h +++ /dev/null @@ -1,897 +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 - */ - -#pragma once - -#include "Module.h" -#include "error.h" - -namespace FireboltSDK { - - using namespace WPEFramework::Core::TypeTraits; - - template - class CommunicationChannel { - public: - typedef std::function Callback; - class Entry { - private: - Entry(const Entry&) = delete; - Entry& operator=(const Entry& rhs) = delete; - struct Synchronous { - Synchronous() - : _signal(false, true) - , _response() - { - } - WPEFramework::Core::Event _signal; - std::list> _response; - }; - struct ASynchronous { - ASynchronous(const uint32_t waitTime, const Callback& completed) - : _waitTime(WPEFramework::Core::Time::Now().Add(waitTime).Ticks()) - , _completed(completed) - { - } - uint64_t _waitTime; - Callback _completed; - }; - - public: - Entry() - : _synchronous(true) - , _info() - { - } - Entry(const uint32_t waitTime, const Callback& completed) - : _synchronous(false) - , _info(waitTime, completed) - { - } - ~Entry() - { - if (_synchronous == true) { - _info.sync.~Synchronous(); - } - else { - _info.async.~ASynchronous(); - } - } - - public: - const WPEFramework::Core::ProxyType& Response() const - { - return (*(_info.sync._response.begin())); - } - bool Signal(const WPEFramework::Core::ProxyType& response) - { - if (_synchronous == true) { - _info.sync._response.push_back(response); - _info.sync._signal.SetEvent(); - } - else { - _info.async._completed(*response); - } - - return (_synchronous == false); - } - const uint64_t& Expiry() const - { - return (_info.async._waitTime); - } - void Abort(const uint32_t id) - { - if (_synchronous == true) { - _info.sync._signal.SetEvent(); - } - else { - MESSAGETYPE message; - ToMessage(id, message, WPEFramework::Core::ERROR_ASYNC_ABORTED); - _info.async._completed(message); - } - } - bool Expired(const uint32_t id, const uint64_t& currentTime, uint64_t& nextTime) - { - bool expired = false; - - if (_synchronous == false) { - if (_info.async._waitTime > currentTime) { - if (_info.async._waitTime < nextTime) { - nextTime = _info.async._waitTime; - } - } - else { - MESSAGETYPE message; - ToMessage(id, message, WPEFramework::Core::ERROR_TIMEDOUT); - _info.async._completed(message); - expired = true; - } - } - return (expired); - } - bool WaitForResponse(const uint32_t waitTime) - { - return (_info.sync._signal.Lock(waitTime) == WPEFramework::Core::ERROR_NONE); - } - - private: - void ToMessage(const uint32_t id, WPEFramework::Core::JSONRPC::Message& message, uint32_t error) - { - message.Id = id; - message.Error.Code = error; - switch (error) { - case WPEFramework::Core::ERROR_ASYNC_ABORTED: { - message.Error.Text = _T("Pending a-sync call has been aborted"); - break; - } - case WPEFramework::Core::ERROR_TIMEDOUT: { - message.Error.Text = _T("Pending a-sync call has timed out"); - break; - } - } - } - - bool _synchronous; - union Info { - public: - Info() - : sync() - { - } - Info(const uint32_t waitTime, const Callback& completed) - : async(waitTime, completed) - { - } - ~Info() - { - } - Synchronous sync; - ASynchronous async; - } _info; - }; - - - - private: - class FactoryImpl { - private: - FactoryImpl(const FactoryImpl&) = delete; - FactoryImpl& operator=(const FactoryImpl&) = delete; - - class WatchDog { - private: - WatchDog() = delete; - WatchDog& operator=(const WatchDog&) = delete; - - public: - WatchDog(CLIENT* client) - : _client(client) - { - } - WatchDog(const WatchDog& copy) - : _client(copy._client) - { - } - ~WatchDog() - { - } - - bool operator==(const WatchDog& rhs) const - { - return (rhs._client == _client); - } - bool operator!=(const WatchDog& rhs) const - { - return (!operator==(rhs)); - } - - public: - uint64_t Timed(const uint64_t scheduledTime) { - return (_client->Timed()); - } - - private: - CLIENT* _client; - }; - - friend WPEFramework::Core::SingletonType; - - FactoryImpl() - : _messageFactory(2) - , _watchDog(WPEFramework::Core::Thread::DefaultStackSize(), _T("TransportCleaner")) - { - } - - public: - static FactoryImpl& Instance() - { - return (WPEFramework::Core::SingletonType::Instance()); - } - - ~FactoryImpl() - { - } - - public: - WPEFramework::Core::ProxyType Element(const string&) - { - return (_messageFactory.Element()); - } - void Trigger(const uint64_t& time, CLIENT* client) - { - _watchDog.Trigger(time, client); - } - void Revoke(CLIENT* client) - { - _watchDog.Revoke(client); - } - private: - WPEFramework::Core::ProxyPoolType _messageFactory; - WPEFramework::Core::TimerType _watchDog; - }; - - class ChannelImpl : public WPEFramework::Core::StreamJSONType, FactoryImpl&, INTERFACE> { - private: - ChannelImpl(const ChannelImpl&) = delete; - ChannelImpl& operator=(const ChannelImpl&) = delete; - - typedef WPEFramework::Core::StreamJSONType, FactoryImpl&, INTERFACE> BaseClass; - - public: - ChannelImpl(CommunicationChannel* parent, const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask) - : BaseClass(5, FactoryImpl::Instance(), path, _T("JSON"), query, "", false, mask, false, remoteNode.AnyInterface(), remoteNode, 512, 512) - , _parent(*parent) - { - } - ~ChannelImpl() override = default; - - public: - void Received(WPEFramework::Core::ProxyType& response) override - { - WPEFramework::Core::ProxyType inbound(response); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - _parent.Inbound(inbound); - } - } - void Send(WPEFramework::Core::ProxyType& msg) override - { -#ifdef __DEBUG__ - string message; - ToMessage(msg, message); - TRACE_L1("Message: %s send", message.c_str()); -#endif - } - void StateChange() override - { - _parent.StateChange(); - } - bool IsIdle() const override - { - return (true); - } - - private: - void ToMessage(const WPEFramework::Core::ProxyType& jsonObject, string& message) const - { - WPEFramework::Core::ProxyType inbound(jsonObject); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - inbound->ToString(message); - } - } - void ToMessage(const WPEFramework::Core::ProxyType& jsonObject, string& message) const - { - WPEFramework::Core::ProxyType inbound(jsonObject); - - ASSERT(inbound.IsValid() == true); - if (inbound.IsValid() == true) { - std::vector values; - inbound->ToBuffer(values); - if (values.empty() != true) { - WPEFramework::Core::ToString(values.data(), static_cast(values.size()), false, message); - } - } - } - - private: - CommunicationChannel& _parent; - }; - - protected: - CommunicationChannel(const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask) - : _channel(this, remoteNode, path, query, mask) - , _sequence(0) - { - } - - public: - ~CommunicationChannel() = default; - static WPEFramework::Core::ProxyType Instance(const WPEFramework::Core::NodeId& remoteNode, const string& path, const string& query, const bool mask = true) - { - static WPEFramework::Core::ProxyMapType channelMap; - - string searchLine = remoteNode.HostAddress() + '@' + path; - - return (channelMap.template Instance(searchLine, remoteNode, path, query, mask)); - } - - public: - static void Trigger(const uint64_t& time, CLIENT* client) - { - FactoryImpl::Instance().Trigger(time, client); - } - static WPEFramework::Core::ProxyType Message() - { - return (FactoryImpl::Instance().Element(string())); - } - uint32_t Sequence() const - { - return (++_sequence); - } - void Register(CLIENT& client) - { - _adminLock.Lock(); - ASSERT(std::find(_observers.begin(), _observers.end(), &client) == _observers.end()); - _observers.push_back(&client); - if (_channel.IsOpen() == true) { - client.Opened(); - } - _adminLock.Unlock(); - } - void Unregister(CLIENT& client) - { - _adminLock.Lock(); - typename std::list::iterator index(std::find(_observers.begin(), _observers.end(), &client)); - if (index != _observers.end()) { - _observers.erase(index); - } - FactoryImpl::Instance().Revoke(&client); - _adminLock.Unlock(); - } - - void Submit(const WPEFramework::Core::ProxyType& message) - { - _channel.Submit(message); - } - bool IsSuspended() const - { - return (_channel.IsSuspended()); - } - uint32_t Initialize() - { - return (Open(0)); - } - void Deinitialize() - { - Close(); - } - bool IsOpen() - { - return (_channel.IsOpen() == true); - } - - protected: - void StateChange() - { - _adminLock.Lock(); - typename std::list::iterator index(_observers.begin()); - while (index != _observers.end()) { - if (_channel.IsOpen() == true) { - (*index)->Opened(); - } - else { - (*index)->Closed(); - } - index++; - } - _adminLock.Unlock(); - } - bool Open(const uint32_t waitTime) - { - bool result = true; - if (_channel.IsClosed() == true) { - result = (_channel.Open(waitTime) == WPEFramework::Core::ERROR_NONE); - } - return (result); - } - void Close() - { - _channel.Close(WPEFramework::Core::infinite); - } - - private: - int32_t Inbound(const WPEFramework::Core::ProxyType& inbound) - { - int32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - _adminLock.Lock(); - typename std::list::iterator index(_observers.begin()); - while ((result != WPEFramework::Core::ERROR_NONE) && (index != _observers.end())) { - result = (*index)->Submit(inbound); - index++; - } - _adminLock.Unlock(); - - return (result); - } - - private: - WPEFramework::Core::CriticalSection _adminLock; - ChannelImpl _channel; - mutable std::atomic _sequence; - std::list _observers; - }; - - class IEventHandler { - public: - virtual int32_t ValidateResponse(const WPEFramework::Core::ProxyType& jsonResponse, bool& enabled) = 0; - virtual int32_t Dispatch(const string& eventName, const WPEFramework::Core::ProxyType& jsonResponse) = 0; - virtual ~IEventHandler() = default; - }; - - template - class Transport { - private: - using Channel = CommunicationChannel; - using Entry = typename CommunicationChannel::Entry; - using PendingMap = std::unordered_map; - using EventMap = std::map; - typedef std::function& jsonResponse, bool& enabled)> EventResponseValidatioionFunction; - - class Job : public WPEFramework::Core::IDispatch { - protected: - Job(const WPEFramework::Core::ProxyType& inbound, class Transport* parent) - : _inbound(inbound) - , _parent(parent) - { - } - - public: - Job() = delete; - Job(const Job&) = delete; - Job& operator=(const Job&) = delete; - - ~Job() = default; - - public: - static WPEFramework::Core::ProxyType Create(const WPEFramework::Core::ProxyType& inbound, class Transport* parent); - - void Dispatch() override - { - _parent->Inbound(_inbound); - } - - private: - const WPEFramework::Core::ProxyType _inbound; - class Transport* _parent; - }; - - protected: - static constexpr uint32_t DefaultWaitTime = 10000; - - inline void Announce() { - _channel->Register(*this); - } - - private: - static constexpr const TCHAR* PathPrefix = _T("/"); - public: - Transport() = delete; - Transport(const Transport&) = delete; - Transport& operator=(Transport&) = delete; - Transport(const WPEFramework::Core::URL& url, const uint32_t waitTime) - : _adminLock() - , _connectId(WPEFramework::Core::NodeId(url.Host().Value().c_str(), url.Port().Value())) - , _channel(Channel::Instance(_connectId, ((url.Path().Value().rfind(PathPrefix, 0) == 0) ? url.Path().Value() : string(PathPrefix + url.Path().Value())), url.Query().Value(), true)) - , _eventHandler(nullptr) - , _pendingQueue() - , _scheduledTime(0) - , _waitTime(waitTime) - { - _channel->Register(*this); - } - - virtual ~Transport() - { - _channel->Unregister(*this); - - for (auto& element : _pendingQueue) { - element.second.Abort(element.first); - } - } - - public: - inline bool IsOpen() - { - return _channel->IsOpen(); - } - - void Revoke(const string& eventName) - { - _adminLock.Lock(); - _eventMap.erase(eventName); - _adminLock.Unlock(); - } - - void SetEventHandler(IEventHandler* eventHandler) - { - _eventHandler = eventHandler; - } - - template - int32_t Invoke(const string& method, const PARAMETERS& parameters, RESPONSE& response) - { - Entry slot; - uint32_t id = _channel->Sequence(); - int32_t result = Send(method, parameters, id); - if (result == WPEFramework::Core::ERROR_NONE) { - result = WaitForResponse(id, response, _waitTime); - } - - return (FireboltErrorValue(result)); - } - - template - int32_t Subscribe(const string& eventName, const string& parameters, RESPONSE& response) - { - Entry slot; - uint32_t id = _channel->Sequence(); - int32_t result = Send(eventName, parameters, id); - if (result == WPEFramework::Core::ERROR_NONE) { - _adminLock.Lock(); - _eventMap.emplace(std::piecewise_construct, - std::forward_as_tuple(eventName), - std::forward_as_tuple(~0)); - _adminLock.Unlock(); - - result = WaitForEventResponse(id, eventName, response, _waitTime); - } - - return (FireboltErrorValue(result)); - } - - int32_t Unsubscribe(const string& eventName, const string& parameters) - { - Revoke(eventName); - Entry slot; - uint32_t id = _channel->Sequence(); - int32_t result = Send(eventName, parameters, id); - - return (FireboltErrorValue(result)); - } - - private: - friend Channel; - inline bool IsEvent(const uint32_t id, string& eventName) - { - _adminLock.Lock(); - for (auto& event : _eventMap) { - if (event.second == id) { - eventName = event.first; - break; - } - } - _adminLock.Unlock(); - return (eventName.empty() != true); - } - uint64_t Timed() - { - uint64_t result = ~0; - uint64_t currentTime = WPEFramework::Core::Time::Now().Ticks(); - - // Lets see if some callback are expire. If so trigger and remove... - _adminLock.Lock(); - - typename PendingMap::iterator index = _pendingQueue.begin(); - - while (index != _pendingQueue.end()) { - - if (index->second.Expired(index->first, currentTime, result) == true) { - index = _pendingQueue.erase(index); - } - else { - index++; - } - } - _scheduledTime = (result != static_cast(~0) ? result : 0); - - _adminLock.Unlock(); - - return (_scheduledTime); - } - - virtual void Opened() - { - // Nice to know :-) - } - - void Closed() - { - // Abort any in progress RPC command: - _adminLock.Lock(); - - // See if we issued anything, if so abort it.. - while (_pendingQueue.size() != 0) { - - _pendingQueue.begin()->second.Abort(_pendingQueue.begin()->first); - _pendingQueue.erase(_pendingQueue.begin()); - } - - _adminLock.Unlock(); - } - - int32_t Submit(const WPEFramework::Core::ProxyType& inbound) - { - int32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(inbound, this)); - WPEFramework::Core::IWorkerPool::Instance().Submit(job); - return result; - } - - int32_t Inbound(const WPEFramework::Core::ProxyType& inbound) - { - int32_t result = WPEFramework::Core::ERROR_INVALID_SIGNATURE; - - ASSERT(inbound.IsValid() == true); - - if ((inbound->Id.IsSet() == true) && (inbound->Result.IsSet() || inbound->Error.IsSet())) { - // Looks like this is a response.. - ASSERT(inbound->Parameters.IsSet() == false); - ASSERT(inbound->Designator.IsSet() == false); - - _adminLock.Lock(); - - // See if we issued this.. - typename PendingMap::iterator index = _pendingQueue.find(inbound->Id.Value()); - - if (index != _pendingQueue.end()) { - - if (index->second.Signal(inbound) == true) { - _pendingQueue.erase(index); - } - - result = WPEFramework::Core::ERROR_NONE; - _adminLock.Unlock(); - } else { - _adminLock.Unlock(); - string eventName; - if (IsEvent(inbound->Id.Value(), eventName)) { - _eventHandler->Dispatch(eventName, inbound); - } - - } - } - - return (result); - } - - - template - int32_t Send(const string& method, const PARAMETERS& parameters, const uint32_t& id) - { - int32_t result = WPEFramework::Core::ERROR_UNAVAILABLE; - - if ((_channel.IsValid() == true) && (_channel->IsSuspended() == true)) { - result = WPEFramework::Core::ERROR_ASYNC_FAILED; - } - else if (_channel.IsValid() == true) { - - result = WPEFramework::Core::ERROR_ASYNC_FAILED; - - WPEFramework::Core::ProxyType message(Channel::Message()); - message->Id = id; - message->Designator = method; - ToMessage(parameters, message); - - _adminLock.Lock(); - - typename std::pair< typename PendingMap::iterator, bool> newElement = - _pendingQueue.emplace(std::piecewise_construct, - std::forward_as_tuple(id), - std::forward_as_tuple()); - ASSERT(newElement.second == true); - - if (newElement.second == true) { - - _adminLock.Unlock(); - - _channel->Submit(WPEFramework::Core::ProxyType(message)); - - message.Release(); - result = WPEFramework::Core::ERROR_NONE; - } - } - return result; - } - - template - int32_t WaitForResponse(const uint32_t& id, RESPONSE& response, const uint32_t waitTime) - { - int32_t result = WPEFramework::Core::ERROR_TIMEDOUT; - _adminLock.Lock(); - typename PendingMap::iterator index = _pendingQueue.find(id); - Entry& slot(index->second); - _adminLock.Unlock(); - - if (slot.WaitForResponse(waitTime) == true) { - WPEFramework::Core::ProxyType jsonResponse = slot.Response(); - - // See if we have a jsonResponse, maybe it was just the connection - // that closed? - if (jsonResponse.IsValid() == true) { - if (jsonResponse->Error.IsSet() == true) { - result = jsonResponse->Error.Code.Value(); - } - else { - result = WPEFramework::Core::ERROR_NONE; - if ((jsonResponse->Result.IsSet() == true) - && (jsonResponse->Result.Value().empty() == false)) { - FromMessage((INTERFACE*)&response, *jsonResponse); - } - } - } - } else { - result = WPEFramework::Core::ERROR_TIMEDOUT; - } - _adminLock.Lock(); - _pendingQueue.erase(id); - _adminLock.Unlock(); - return result; - } - - static constexpr uint32_t WAITSLOT_TIME = 100; - template - int32_t WaitForEventResponse(const uint32_t& id, const string& eventName, RESPONSE& response, const uint32_t waitTime) - { - int32_t result = WPEFramework::Core::ERROR_TIMEDOUT; - _adminLock.Lock(); - typename PendingMap::iterator index = _pendingQueue.find(id); - Entry& slot(index->second); - _adminLock.Unlock(); - - uint8_t waiting = waitTime; - do { - uint32_t waitSlot = (waiting > WAITSLOT_TIME ? WAITSLOT_TIME : waiting); - if (slot.WaitForResponse(waitSlot) == true) { - WPEFramework::Core::ProxyType jsonResponse = slot.Response(); - - // See if we have a jsonResponse, maybe it was just the connection - // that closed? - if (jsonResponse.IsValid() == true) { - if (jsonResponse->Error.IsSet() == true) { - result = jsonResponse->Error.Code.Value(); - } else { - if ((jsonResponse->Result.IsSet() == true) - && (jsonResponse->Result.Value().empty() == false)) { - result = WPEFramework::Core::ERROR_NONE; - bool enabled; - result = _eventHandler->ValidateResponse(jsonResponse, enabled); - if (result == WPEFramework::Core::ERROR_NONE) { - FromMessage((INTERFACE*)&response, *jsonResponse); - if (enabled) { - _adminLock.Lock(); - typename EventMap::iterator index = _eventMap.find(eventName); - if (index != _eventMap.end()) { - index->second = id; - } - _adminLock.Unlock(); - } - } - } - } - } - } else { - result = WPEFramework::Core::ERROR_TIMEDOUT; - } - waiting -= (waiting == WPEFramework::Core::infinite ? 0 : waitSlot); - } while ((result != WPEFramework::Core::ERROR_NONE) && (waiting > 0 )); - _adminLock.Lock(); - _pendingQueue.erase(id); - _adminLock.Unlock(); - - return result; - } - - public: - void FromMessage(WPEFramework::Core::JSON::IElement* response, const WPEFramework::Core::JSONRPC::Message& message) const - { - response->FromString(message.Result.Value()); - } - - void FromMessage(WPEFramework::Core::JSON::IMessagePack* response, const WPEFramework::Core::JSONRPC::Message& message) const - { - string value = message.Result.Value(); - std::vector result(value.begin(), value.end()); - response->FromBuffer(result); - } - - - private: - - void ToMessage(const string& parameters, WPEFramework::Core::ProxyType& message) const - { - if (parameters.empty() != true) { - message->Parameters = parameters; - } - } - - template - void ToMessage(PARAMETERS& parameters, WPEFramework::Core::ProxyType& message) const - { - ToMessage((INTERFACE*)(¶meters), message); - return; - } - - void ToMessage(WPEFramework::Core::JSON::IMessagePack* parameters, WPEFramework::Core::ProxyType& message) const - { - std::vector values; - parameters->ToBuffer(values); - if (values.empty() != true) { - string strValues(values.begin(), values.end()); - message->Parameters = strValues; - } - return; - } - - void ToMessage(WPEFramework::Core::JSON::IElement* parameters, WPEFramework::Core::ProxyType& message) const - { - string values; - parameters->ToString(values); - if (values.empty() != true) { - message->Parameters = values; - } - return; - } - - int32_t FireboltErrorValue(const uint32_t error) - { - - int32_t fireboltError = error; - switch (error) { - case WPEFramework::Core::ERROR_NONE: - fireboltError = FireboltSDKErrorNone; - break; - case WPEFramework::Core::ERROR_GENERAL: - fireboltError = FireboltSDKErrorGeneral; - break; - case WPEFramework::Core::ERROR_UNAVAILABLE: - fireboltError = FireboltSDKErrorUnavailable; - break; - case WPEFramework::Core::ERROR_TIMEDOUT: - fireboltError = FireboltSDKErrorTimedout; - break; - default: - break; - } - - return fireboltError; - } - - private: - WPEFramework::Core::CriticalSection _adminLock; - WPEFramework::Core::NodeId _connectId; - WPEFramework::Core::ProxyType _channel; - IEventHandler* _eventHandler; - PendingMap _pendingQueue; - EventMap _eventMap; - uint64_t _scheduledTime; - uint32_t _waitTime; - }; -} diff --git a/languages/c/src/shared/src/Types.cpp b/languages/c/src/shared/src/Types.cpp deleted file mode 100644 index 93f6a8d8..00000000 --- a/languages/c/src/shared/src/Types.cpp +++ /dev/null @@ -1,40 +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 - */ - -#include "Module.h" -#include "types.h" -#include "TypesPriv.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// String Type Handler Interfaces -const char* Firebolt_String(Firebolt_String_t handle) -{ - return ((reinterpret_cast(handle))->Value().c_str()); -} - -void Firebolt_String_Release(Firebolt_String_t handle) -{ - delete reinterpret_cast(handle); -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c/src/shared/src/TypesPriv.h b/languages/c/src/shared/src/TypesPriv.h deleted file mode 100644 index 6e365ec7..00000000 --- a/languages/c/src/shared/src/TypesPriv.h +++ /dev/null @@ -1,56 +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 - */ - -#pragma once - -#include - -namespace FireboltSDK { -namespace JSON { -class String : public WPEFramework::Core::JSON::String { - using Base = WPEFramework::Core::JSON::String; - public: - String() - : Base() - , _value() - { - } - String(const char value[]) - : Base(value) - , _value(value) - { - } - String& operator=(const char RHS[]) - { - Base::operator = (RHS); - _value = RHS; - return (*this); - } - - public: - const string& Value() const - { - _value = Base::Value(); - return _value; - } - - private: - mutable std::string _value; - }; -} -} diff --git a/languages/c/src/shared/src/firebolt.cpp b/languages/c/src/shared/src/firebolt.cpp deleted file mode 100644 index 90c54c5c..00000000 --- a/languages/c/src/shared/src/firebolt.cpp +++ /dev/null @@ -1,39 +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 - */ - -#include "FireboltSDK.h" - - -#ifdef __cplusplus -extern "C" { -#endif - - -int32_t FireboltSDK_Initialize(char* configLine) { - FireboltSDK::Accessor::Instance(configLine); - return FireboltSDKErrorNone; -} - -int32_t FireboltSDK_Deinitialize(void) { - FireboltSDK::Accessor::Dispose(); - return FireboltSDKErrorNone; -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c/src/shared/test/CMakeLists.txt b/languages/c/src/shared/test/CMakeLists.txt deleted file mode 100644 index 21ee1f55..00000000 --- a/languages/c/src/shared/test/CMakeLists.txt +++ /dev/null @@ -1,86 +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 - -cmake_minimum_required(VERSION 3.3) - -project(FireboltSDKTests) -project_version(1.0.0) - -set(TESTLIB ${PROJECT_NAME}) - -message("Setup ${TESTLIB} v${PROJECT_VERSION}") - -set(CMAKE_POSITION_INDEPENDENT_CODE ON) -find_package(${NAMESPACE}Core CONFIG REQUIRED) - -add_library(${TESTLIB} STATIC OpenRPCTests.cpp) - -target_link_libraries(${TESTLIB} - PUBLIC - ${NAMESPACE}Core::${NAMESPACE}Core - ${FIREBOLT_NAMESPACE}SDK -) - -target_include_directories(${TESTLIB} - PRIVATE - $ - $ -) - -set_target_properties(${TESTLIB} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - LINK_WHAT_YOU_USE TRUE - FRAMEWORK FALSE -) - -install( - TARGETS ${TESTLIB} EXPORT ${TESTLIB}Targets - LIBRARY DESTINATION lib COMPONENT libs - PUBLIC_HEADER DESTINATION include/${FIREBOLT_NAMESPACE}Test COMPONENT devel # headers for mac (note the different component -> different package) - INCLUDES DESTINATION include/${FIREBOLT_NAMESPACE}Test # headers -) - -InstallCMakeConfig(TARGETS ${TESTLIB}) -InstallCMakeConfigs(TARGET ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) -InstallHeaders(TARGET ${TESTLIB} HEADERS . NAMESPACE ${FIREBOLT_NAMESPACE} DESTINATION FireboltTest) -InstallLibraries(TARGET ${TESTLIB} STATIC LIBRARIES ${TESTLIB} DESTINATION ${FIREBOLT_NAMESPACE}) - -set(TESTAPP "FireboltSDKTestApp") - -message("Setup ${TESTAPP}") - -add_executable(${TESTAPP} Main.c) - -target_link_libraries(${TESTAPP} - PRIVATE - ${TESTLIB} -) - -target_include_directories(${TESTAPP} - PRIVATE - $ - $ -) - -add_custom_command( - TARGET ${TESTAPP} - POST_BUILD - COMMENT "=================== Installing TestApp ======================" - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${TESTAPP} ${CMAKE_BINARY_DIR}/${FIREBOLT_NAMESPACE}/usr/bin -) - diff --git a/languages/c/src/shared/test/Main.c b/languages/c/src/shared/test/Main.c deleted file mode 100644 index 6161792e..00000000 --- a/languages/c/src/shared/test/Main.c +++ /dev/null @@ -1,45 +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 - */ - -#include "OpenRPCCTests.h" - -int __cnt = 0; -int __pass = 0; - -int TotalTests = 0; -int TotalTestsPassed = 0; - -int main() -{ - test_firebolt_create_instance(); - test_firebolt_main(); - - // Calling C function sequences - printf("%s:%s:%d Calling C function tests\n", __FILE__, __func__, __LINE__); - EXECUTE("test_properties_get_device_id", test_properties_get_device_id); - EXECUTE("test_properties_set", test_properties_set); - EXECUTE("test_eventregister_by_providing_callback", test_eventregister_by_providing_callback); - EXECUTE("test_eventregister", test_eventregister); - EXECUTE("test_eventregister_with_same_callback", test_eventregister_with_same_callback); - EXECUTE("test_string_set_get_value", test_string_set_get_value); - - test_firebolt_dispose_instance(); - - printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); -} - diff --git a/languages/c/src/shared/test/Module.cpp b/languages/c/src/shared/test/Module.cpp deleted file mode 100644 index d63badc4..00000000 --- a/languages/c/src/shared/test/Module.cpp +++ /dev/null @@ -1,21 +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 - */ - -#include "Module.h" - -MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/languages/c/src/shared/test/Module.h b/languages/c/src/shared/test/Module.h deleted file mode 100644 index a147ff75..00000000 --- a/languages/c/src/shared/test/Module.h +++ /dev/null @@ -1,28 +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 - */ - -#pragma once - -#ifndef MODULE_NAME -#define MODULE_NAME OpenRPCTestApp -#endif - -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/languages/c/src/shared/test/OpenRPCCTests.h b/languages/c/src/shared/test/OpenRPCCTests.h deleted file mode 100644 index 936a1ff9..00000000 --- a/languages/c/src/shared/test/OpenRPCCTests.h +++ /dev/null @@ -1,43 +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 OPENRPC_C_TESTS_H -#define OPENRPC_C_TESTS_H - -#include "TestUtils.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void test_firebolt_create_instance(); -void test_firebolt_dispose_instance(); - -int32_t test_firebolt_main(); -int32_t test_properties_get_device_id(); -int32_t test_properties_set(); -int32_t test_eventregister(); -int32_t test_eventregister_with_same_callback(); -int32_t test_eventregister_by_providing_callback(); -int32_t test_string_set_get_value(); - -#ifdef __cplusplus -} -#endif - -#endif // OPENRPC_C_TESTS_H diff --git a/languages/c/src/shared/test/OpenRPCTests.cpp b/languages/c/src/shared/test/OpenRPCTests.cpp deleted file mode 100644 index 03fd2645..00000000 --- a/languages/c/src/shared/test/OpenRPCTests.cpp +++ /dev/null @@ -1,504 +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 - */ - -#include "Module.h" -#include "OpenRPCTests.h" -#include "OpenRPCCTests.h" - -namespace WPEFramework { - -ENUM_CONVERSION_BEGIN(::JsonValue::type) - - { JsonValue::type::EMPTY, _TXT("empty") }, - { JsonValue::type::BOOLEAN, _TXT("boolean") }, - { JsonValue::type::NUMBER, _TXT("number") }, - { JsonValue::type::STRING, _TXT("string") }, - -ENUM_CONVERSION_END(::JsonValue::type) - -ENUM_CONVERSION_BEGIN(TestEnum) - { TestEnum::Test1, _TXT("Test1ValueCheck") }, - { TestEnum::Test2, _TXT("Test2ValueCheck") }, - { TestEnum::Test3, _TXT("Test3ValueCheck") }, - { TestEnum::Test4, _TXT("Test4ValueCheck") }, -ENUM_CONVERSION_END(TestEnum) -} - -typedef void (*OnNotifyDeviceNameChanged)(const void* userData, const char* data); -static void NotifyEvent(const void* userData, const char* data) -{ - printf("NotifyEvent data : %s\n", data); -} - -namespace FireboltSDK { - Tests::Tests() - { - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEventWithMultipleCallback"), - std::forward_as_tuple(&SubscribeEventWithMultipleCallback)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEventwithSameCallback"), - std::forward_as_tuple(&SubscribeEventwithSameCallback)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("SubscribeEvent"), - std::forward_as_tuple(&SubscribeEvent)); - - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Set UnKnown Method"), - std::forward_as_tuple(&SetUnKnownMethod)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Set LifeCycle Close"), - std::forward_as_tuple(&SetLifeCycleClose)); - - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get UnKnown Method"), - std::forward_as_tuple(&GetUnKnownMethod)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Device Version"), - std::forward_as_tuple(&GetDeviceVersion)); - _functionMap.emplace(std::piecewise_construct, std::forward_as_tuple("Get Device Id"), - std::forward_as_tuple(&GetDeviceId)); - } - - /* static */ void Tests::PrintJsonObject(const JsonObject::Iterator& iterator) - { - JsonObject::Iterator index = iterator; - while (index.Next() == true) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "Element [%s]: <%s> = \"%s\"\n", - index.Label(), - WPEFramework::Core::EnumerateType(index.Current().Content()).Data(), - index.Current().Value().c_str()); - } - } - - /* static */ int32_t Tests::GetDeviceId() - { - const string method = _T("device.id"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "DeviceId : %s", response->Value().c_str()); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /*static */ int32_t Tests::GetDeviceVersion() - { - const string method = _T("device.version"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "DeviceVersion"); - PrintJsonObject(response->Variants()); - } else { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d", method.c_str(), status); - } - - return status; - } - - /* static */ int32_t Tests::GetUnKnownMethod() - { - const string method = _T("get.unknownMethod"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_NE(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Get %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /* static */ int32_t Tests::SetLifeCycleClose() - { - const string method = _T("lifecycle.close"); - JsonObject parameters; - parameters["reason"] = "remoteButton"; - int32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d\n", method.c_str(), status); - } - - return status; - } - - /* static */ int32_t Tests::SetUnKnownMethod() - { - const string method = _T("set.unknownMethod"); - JsonObject parameters; - int32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_NE(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d", method.c_str(), status); - } - - return status; - } - - static void deviceNameChangeCallback(void* userCB, const void* userData, void* response) - { - WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), "Received a new event: %s", jsonResponse->Value().c_str()); - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - OnNotifyDeviceNameChanged notifyDeviceNameChanged = reinterpret_cast(userCB); - notifyDeviceNameChanged(userData, jsonResponse->Value().c_str()); - eventControl->NotifyEvent(); - jsonResponse.Release(); - } - - /* static */ int32_t Tests::SubscribeEvent() - { - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl("EventControl"); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - eventControl->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback,reinterpret_cast(NotifyEvent), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), - "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully, Waiting for event...", __func__); - - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); - delete eventControl; - - return status; - } - - /* static */ int32_t Tests::SubscribeEventwithSameCallback() - { - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl("EventControl"); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - eventControl->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback,reinterpret_cast(NotifyEvent), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), - "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully", __func__); - - status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallback, reinterpret_cast(NotifyEvent), userdata); - EXPECT_EQ(status, FireboltSDKErrorInUse); - if (status == FireboltSDKErrorInUse) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes this device.name event is already registered with same callback", __func__); - } - status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); - } - - EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); - delete eventControl; - - return status; - } - - - static void NotifyEvent1(const void* userData, const char* data) - { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "NotifyEvent1 data : %s", data); - if (userData) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "NotifyEvent1 userData : %s\n", reinterpret_cast(userData)->Name().c_str()); - } - } - static void NotifyEvent2(const void* userData, const char* data) - { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "NotifyEvent2 data : %s", data); - if (userData) { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "NotifyEvent2 userData : %s\n", reinterpret_cast(userData)->Name().c_str()); - } - } - - template - /* static */ int32_t Tests::SubscribeEventForC(const string& eventName, JsonObject& jsonParameters, CALLBACK& callbackFunc, void* usercb, const void* userdata) - { - return Properties::Subscribe(eventName, jsonParameters, callbackFunc, usercb, userdata); - } - - static void deviceNameChangeMultipleCallback(void* userCB, const void* userData, void* response) - { - WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "Received a new event from deviceNameChangeMultipleCallback: %s", jsonResponse->Value().c_str()); - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - OnNotifyDeviceNameChanged notifyDeviceNameChanged = reinterpret_cast(userCB); - notifyDeviceNameChanged(userData, jsonResponse->Value().c_str()); - - eventControl->NotifyEvent(); - jsonResponse.Release(); - } - - /* static */ int32_t Tests::SubscribeEventWithMultipleCallback() - { - FireboltSDK::Tests::EventControl* eventControl1 = new FireboltSDK::Tests::EventControl("EventControl1"); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl1); - - eventControl1->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent1), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), - "Set %s status = %d", eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered successfully, Waiting for event...", __func__); - } - - if (status == FireboltSDKErrorNone) { - FireboltSDK::Tests::EventControl* eventControl2 = new FireboltSDK::Tests::EventControl("EventControl2"); - userdata = static_cast(eventControl2); - - status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent2), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(Logger::Category::OpenRPC, Logger::Module(), "Set %s status = %d", eventName.c_str(), status); - } else { - status = Properties::Subscribe(eventName, jsonParameters, deviceNameChangeMultipleCallback, reinterpret_cast(NotifyEvent2), userdata); - EXPECT_EQ(status, FireboltSDKErrorInUse); - status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); - - FIREBOLT_LOG_INFO(Logger::Category::OpenRPC, Logger::Module(), - "%s Yes registered second callback also successfully, waiting for events...\n", __func__); - - eventControl1->WaitForEvent(WPEFramework::Core::infinite); - eventControl2->WaitForEvent(WPEFramework::Core::infinite); - } - EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent2)), FireboltSDKErrorNone); - delete eventControl2; - } - EXPECT_EQ(Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent1)), FireboltSDKErrorNone); - - delete eventControl1; - return status; - } - -} - -#ifdef __cplusplus -extern "C" { -#endif - -void test_firebolt_create_instance() -{ - 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); -} - -void test_firebolt_dispose_instance() -{ - FireboltSDK::Accessor::Dispose(); -} - -int32_t test_firebolt_main() -{ - return FireboltSDK::Tests::Main(); -} - -int32_t test_properties_get_device_id() -{ - const string method = _T("device.id"); - WPEFramework::Core::ProxyType response; - int32_t status = FireboltSDK::Properties::Get(method, response); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "DeviceId : %s", response->Value().c_str()); - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Get %s status = %d", method.c_str(), status); - } - - return status; -} - -int32_t test_properties_set() -{ - const string method = _T("lifecycle.close"); - JsonObject parameters; - parameters["reason"] = "remoteButton"; - int32_t status = FireboltSDK::Properties::Set(method, parameters); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Set %s status = %d", method.c_str(), status); - } - - return status; -} - -static void deviceNameChangeCallbackForC(void* userCB, const void* userData, void* response) -{ - WPEFramework::Core::ProxyType& jsonResponse = *(reinterpret_cast*>(response)); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "Received a new event--->: %s", jsonResponse->Value().c_str()); - - FireboltSDK::Tests::EventControl* eventControl = reinterpret_cast(const_cast(userData)); - eventControl->NotifyEvent(); - jsonResponse.Release(); -} - -int32_t test_eventregister() -{ - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - eventControl->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Set %s status = %d", __func__, eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully, Waiting for event...", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); - - return status; -} - -int32_t test_eventregister_with_same_callback() -{ - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - eventControl->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Set %s status = %d", __func__, eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully", __func__); - - status = FireboltSDK::Properties::Subscribe(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); - EXPECT_EQ(status, FireboltSDKErrorInUse); - if (status == FireboltSDKErrorInUse) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes this device.name event is already registered with same callback", __func__); - } - status = ((status == FireboltSDKErrorInUse) ? FireboltSDKErrorNone : status); - } - - delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); - - return status; -} -int32_t test_eventregister_by_providing_callback() -{ - FireboltSDK::Tests::EventControl* eventControl = new FireboltSDK::Tests::EventControl(); - - const string eventName = _T("device.Name"); - const void* userdata = static_cast(eventControl); - - eventControl->ResetEvent(); - - JsonObject jsonParameters; - int32_t status = FireboltSDK::Tests::SubscribeEventForC(eventName, jsonParameters, deviceNameChangeCallbackForC, reinterpret_cast(NotifyEvent), userdata); - - EXPECT_EQ(status, FireboltSDKErrorNone); - if (status != FireboltSDKErrorNone) { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Set %s status = %d", __func__, eventName.c_str(), status); - } else { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - "%s Yes registered successfully, Waiting for event...", __func__); - eventControl->WaitForEvent(WPEFramework::Core::infinite); - } - - delete eventControl; - EXPECT_EQ(FireboltSDK::Properties::Unsubscribe(eventName, reinterpret_cast(NotifyEvent)), FireboltSDKErrorNone); - return status; -} - -#include "TypesPriv.h" -int32_t test_string_set_get_value() -{ - int32_t status = FireboltSDKErrorNone; - FireboltSDK::JSON::String* str = new FireboltSDK::JSON::String(); - WPEFramework::Core::JSON::String wpeJsonStr("TestString"); - Firebolt_String_t handle = reinterpret_cast(str); - - const char* value = Firebolt_String(handle); - EXPECT_EQ(strncmp(value, str->Value().c_str(), str->Value().length()), 0); - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - " ---> type name = %s %s", str->Value().c_str(), value); - - WPEFramework::Core::JSON::EnumType<::TestEnum> testEnum = Test4; - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, "ctest", - " EnumTest = %d %s", testEnum.Value(), testEnum.Data()); - Firebolt_String_Release(handle); - return status; -} - -#ifdef __cplusplus -} -#endif diff --git a/languages/c/src/shared/test/OpenRPCTests.h b/languages/c/src/shared/test/OpenRPCTests.h deleted file mode 100644 index 8eb7fd30..00000000 --- a/languages/c/src/shared/test/OpenRPCTests.h +++ /dev/null @@ -1,118 +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 - */ - -#pragma once - -#include "FireboltSDK.h" -#include "TestUtils.h" - -typedef enum { - Test1, - Test2, - Test3, - Test4 -} TestEnum; - -namespace FireboltSDK { - typedef int32_t (*Func)(); - - class Tests { - public: - class EventControl { - public: - EventControl() - : _event(false, true) - , _name("EventControl") - { - } - EventControl(string name) - : _event(false, true) - , _name(name) - { - } - ~EventControl() = default; - - public: - void NotifyEvent() - { - _event.SetEvent(); - } - uint32_t WaitForEvent(uint32_t waitTime) - { - return _event.Lock(waitTime); - } - void ResetEvent() - { - _event.ResetEvent(); - } - string Name() const - { - return _name; - } - private: - WPEFramework::Core::Event _event; - string _name; - }; - - private: - typedef std::unordered_map TestFunctionMap; - - public: - Tests(); - virtual ~Tests() = default; - - inline TestFunctionMap& TestList() - { - return _functionMap; - } - - template - static int32_t Main() - { - TESTS fireboltTest; - for (auto i = fireboltTest.TestList().begin(); i != fireboltTest.TestList().end(); i++) { - EXECUTE(i->first.c_str(), i->second); - } - - printf("TOTAL: %i tests; %i PASSED, %i FAILED\n", TotalTests, TotalTestsPassed, (TotalTests - TotalTestsPassed)); - - return 0; - } - - static int32_t GetDeviceId(); - static int32_t GetDeviceVersion(); - static int32_t GetUnKnownMethod(); - - static int32_t SetLifeCycleClose(); - static int32_t SetUnKnownMethod(); - - static int32_t SubscribeEvent(); - static int32_t SubscribeEventwithSameCallback(); - static int32_t SubscribeEventWithMultipleCallback(); - - template - static int32_t SubscribeEventForC(const string& eventName, JsonObject& jsonParameters, CALLBACK& callbackFunc, void* usercb, const void* userdata); - - protected: - static void PrintJsonObject(const JsonObject::Iterator& iterator); - - protected: - std::list menu; - TestFunctionMap _functionMap; - }; -} diff --git a/languages/c/src/shared/test/TestUtils.h b/languages/c/src/shared/test/TestUtils.h deleted file mode 100644 index c54db9f0..00000000 --- a/languages/c/src/shared/test/TestUtils.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TEST_UTILS_H -#define TEST_UTILS_H - -#include -#include -#include - -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) - -#define _RESULT(expr, exprorig, result) if (expr) { printf("TestStatus: SUCCESS: %s\n", #exprorig); __pass++; } else printf("TestStatus: FAILED: %s, actual: %lu\n", #exprorig, result) -#define _EVAL(result, expected, op) do { __cnt++; long resval = ((long)(result)); long expval = ((long)(expected)); _RESULT(resval op expval, result op expected, resval); } while(0) -#define _HEAD(name) printf("\n======== %s\n", name); __cnt = 0; __pass = 0 -#define _FOOT(name) printf("\n======== %s - %i PASSED, %i FAILED\n", name, __pass, (__cnt - __pass)); TotalTests += __cnt; TotalTestsPassed += __pass; - -#define EXECUTE(name, test) do { _HEAD(name); test(); _FOOT(name); printf("\n"); } while(0) -#define EXPECT_EQ(result, expected) _EVAL(result, expected, ==) -#define EXPECT_NE(result, expected) _EVAL(result, expected, !=) -#define EXPECT_LT(result, expected) _EVAL(result, expected, <) -#define EXPECT_LE(result, expected) _EVAL(result, expected, <=) -#define EXPECT_GT(result, expected) _EVAL(result, expected, >) -#define EXPECT_GE(result, expected) _EVAL(result, expected, >=) - -#ifdef __cplusplus -extern "C" { -#endif - -extern int __cnt; -extern int __pass; - -extern int TotalTests ; -extern int TotalTestsPassed; - -#ifdef __cplusplus -} -#endif - -#endif // TEST_UTILS_H diff --git a/languages/c/src/types/ImplHelpers.mjs b/languages/c/src/types/ImplHelpers.mjs deleted file mode 100644 index 0ac77dd6..00000000 --- a/languages/c/src/types/ImplHelpers.mjs +++ /dev/null @@ -1,510 +0,0 @@ -import { capitalize, getFireboltStringType } from "./NativeHelpers.mjs" - -const Indent = '\t' - -const getSdkNameSpace = () => 'FireboltSDK' -const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON' -const camelcase = str => str[0].toLowerCase() + str.substr(1) - -const getObjectManagementImpl = (varName, jsonDataName) => { - - let result = `${varName}_t ${varName}_Acquire(void) -{ - WPEFramework::Core::ProxyType<${jsonDataName}>* type = new WPEFramework::Core::ProxyType<${jsonDataName}>(); - *type = WPEFramework::Core::ProxyType<${jsonDataName}>::Create(); - return (reinterpret_cast<${varName}_t>(type)); -} -void ${varName}_Addref(${varName}_t handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - var->AddRef(); -} -void ${varName}_Release(${varName}_t handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); - var->Release(); - if (var->IsValid() != true) { - delete var; - } -} -bool ${varName}_IsValid(${varName}_t handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${jsonDataName}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - return var->IsValid(); -} -` - return result -} - -const getPropertyAccessorsImpl = (objName, modulePropertyType, subPropertyType, subPropertyName, accessorPropertyType, json = {}, options = {readonly:false, optional:false}) => { - let result = '' - result += `${accessorPropertyType} ${objName}_Get_${subPropertyName}(${objName}_t handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); -` + '\n' - if (((json.type === 'object') || (json.type === 'array')) && (accessorPropertyType !== 'char*')) { - result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* element = new WPEFramework::Core::ProxyType<${subPropertyType}>(); - *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); - *(*element) = (*var)->${subPropertyName}; - return (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' - } - else { - if ((typeof json.const === 'string') || (json.type === 'string' && !json.enum) || (accessorPropertyType === 'char*')) { - result += ` return (const_cast<${accessorPropertyType}>((*var)->${subPropertyName}.Value().c_str()));` + '\n' - } - else { - result += ` return (static_cast<${accessorPropertyType}>((*var)->${subPropertyName}.Value()));` + '\n' - } - } - result += `}` + '\n' - - if (!options.readonly) { - let type = (accessorPropertyType === getFireboltStringType()) ? 'char*' : accessorPropertyType - result += `void ${objName}_Set_${subPropertyName}(${objName}_t handle, ${type} value)\n{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); -` + '\n' - - if (((json.type === 'object') || (json.type === 'array')) && (accessorPropertyType !== 'char*')) { - result += ` WPEFramework::Core::ProxyType<${subPropertyType}>* object = reinterpret_cast*>(value); - (*var)->${subPropertyName} = *(*object);` + '\n' - } - else { - result += ` (*var)->${subPropertyName} = value;` + '\n' - } - result += `}` + '\n' - } - - if (options.optional === true) { - result += `bool ${objName}_Has_${subPropertyName}(${objName}_t handle)\n{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - - return ((*var)->${subPropertyName}.IsSet()); -}` + '\n' - result += `void ${objName}_Clear_${subPropertyName}(${objName}_t handle)\n{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - ((*var)->${subPropertyName}.Clear()); -}` + '\n' - } - - return result -} -const getArrayAccessorsImpl = (objName, modulePropertyType, objType, subPropertyType, subPropertyName, accessorPropertyType, json = {}) => { - - let propertyName - if (subPropertyName) { - propertyName = '(*var)->' + `${subPropertyName}` - objName = objName + '_' + subPropertyName - } - else { - propertyName = '(*(*var))' - } - - let result = `uint32_t ${objName}Array_Size(${objType} handle) { - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - - return (${propertyName}.Length()); -}` + '\n' - - result += `${accessorPropertyType} ${objName}Array_Get(${objType} handle, uint32_t index) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid());` + '\n' - - if ((json.type === 'object') || (json.type === 'array')) { - result += `WPEFramework::Core::ProxyType<${subPropertyType}>* object = new WPEFramework::Core::ProxyType<${subPropertyType}>(); - *object = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); - *(*object) = ${propertyName}.Get(index); - - return (reinterpret_cast<${accessorPropertyType}>(object));` + '\n' - } - else { - if ((typeof json.const === 'string') || (json.type === 'string' && !json.enum)) { - result += ` return (const_cast<${accessorPropertyType}>(${propertyName}.Get(index).Value().c_str()));` + '\n' - } - else { - result += ` return (static_cast<${accessorPropertyType}>(${propertyName}.Get(index)));` + '\n' - } - } - result += `}` + '\n' - - let type = (accessorPropertyType === getFireboltStringType()) ? 'char*' : accessorPropertyType - result += `void ${objName}Array_Add(${objType} handle, ${type} value) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid());` + '\n' - - if ((json.type === 'object') || (json.type === 'array')) { - result += ` ${subPropertyType} element; - element = *(*(reinterpret_cast*>(value)));` + '\n' - } - else { - result += ` ${subPropertyType} element;` + '\n' - result += ` element = value;` + '\n' - } - result += ` - ${propertyName}.Add() = element; -}` + '\n' - - result += `void ${objName}Array_Clear(${objType} handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${modulePropertyType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - - ${propertyName}.Clear(); -}` + '\n' - - return result -} - -const getMapAccessorsImpl = (objName, containerType, subPropertyType, accessorPropertyType, json = {}, options = {readonly:false, optional:false}) => { - let result = `uint32_t ${objName}_KeysCount(${objName}_t handle) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - ${containerType}::Iterator elements = (*var)->Variants(); - uint32_t count = 0; - while (elements.Next()) { - count++; - } - return (count); -}` + '\n' - result += `void ${objName}_AddKey(${objName}_t handle, char* key, ${accessorPropertyType} value) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); -` + '\n' - let elementContainer = subPropertyType - if (containerType.includes('VariantContainer')) { - elementContainer = 'WPEFramework::Core::JSON::Variant' - } - if ((json.type === 'object') || (json.type === 'array' && json.items)) { - if (containerType.includes('VariantContainer')) { - result += ` ${subPropertyType}& container = *(*(reinterpret_cast*>(value)));` + '\n' - result += ` string containerStr;` + '\n' - result += ` element.ToString(containerStr);` + '\n' - result += ` WPEFramework::Core::JSON::VariantContainer containerVariant(containerStr);` + '\n' - result += ` WPEFramework::Core::JSON::Variant element = containerVariant;` + '\n' - } - else { - result += ` ${subPropertyType}& element = *(*(reinterpret_cast*>(value)));` + '\n' - } - } else { - result += ` ${elementContainer} element(value);` + '\n' - } - result += ` (*var)->Set(const_cast(key), element); -}` + '\n' - - result += `void ${objName}_RemoveKey(${objName}_t handle, char* key) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid()); - - (*var)->Remove(key); -}` + '\n' - - result += `${accessorPropertyType} ${objName}_FindKey(${objName}_t handle, char* key) -{ - ASSERT(handle != NULL); - WPEFramework::Core::ProxyType<${containerType}>* var = reinterpret_cast*>(handle); - ASSERT(var->IsValid());` + '\n' - if ((json.type === 'object') || (json.type === 'array') || - ((json.type === 'string' || (typeof json.const === 'string')) && !json.enum)) { - result += ` ${accessorPropertyType} status = nullptr;` + '\n' - } - else if (json.type === 'boolean') { - result += ` ${accessorPropertyType} status = false;` + '\n' - } - else { - result += ` ${accessorPropertyType} status = 0;` + '\n' - } - - result += ` - if ((*var)->HasLabel(key) == true) {` - if (json.type === 'object') { - result += ` - string objectStr; - (*var)->Get(key).Object().ToString(objectStr); - ${subPropertyType} objectMap; - objectMap.FromString(objectStr); - - WPEFramework::Core::ProxyType<${subPropertyType}>* element = new WPEFramework::Core::ProxyType<${subPropertyType}>(); - *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); - *(*element) = objectMap; - - status = (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' - } - else if (json.type === 'array' && json.items) { - result += ` - WPEFramework::Core::ProxyType<${subPropertyType}>* element = new WPEFramework::Core::ProxyType<${subPropertyType}>(); - *element = WPEFramework::Core::ProxyType<${subPropertyType}>::Create(); - *(*element) = (*var)->Get(key).Array(); - status = (reinterpret_cast<${accessorPropertyType}>(element));` + '\n' - } - else { - if (json.type === 'string' || (typeof json.const === 'string')) { - if (json.enum) { - result += ` - status = (const_cast<${accessorPropertyType}>((*var)->Get(key).));` + '\n' - } - else { - result += ` - status = (const_cast<${accessorPropertyType}>((*var)->Get(key).String().c_str()));` + '\n' - } - } - else if (json.type === 'boolean') { - result += ` - status = (static_cast<${accessorPropertyType}>((*var)->Get(key).Boolean()));` + '\n' - } - else if (json.type === 'number') { - result += ` - status = (static_cast<${accessorPropertyType}>((*var)->Get(key).Float()));` + '\n' - } - else if (json.type === 'integer') { - result += ` - status = (static_cast<${accessorPropertyType}>((*var)->Get(key).Number()));` + '\n' - } - } - result += ` } - return status; -}` - - return result -} - -/* -paramList = [{name='', nativeType='', jsonType='', required=boolean}] -*/ -function getParameterInstantiation(paramList, container = '') { - - let impl = ` ${container.length>0 ? container : 'JsonObject'} jsonParameters;\n` - paramList.forEach(param => { - impl += `\n` - const jsonType = param.jsonType - const name = param.name - if (jsonType.length) { - if (param.required) { - if (param.nativeType.includes('Firebolt_String_t')) { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = *(reinterpret_cast<${jsonType}*>(${name}));\n` - } - else if (param.nativeType.includes('_t')) { - impl += ` ${jsonType}& ${capitalize(name)}Container = *(*(reinterpret_cast*>(${camelcase(name)})));\n` - impl += ` string ${capitalize(name)}Str;\n` - impl += ` ${capitalize(name)}Container.ToString(${capitalize(name)}Str);\n` - impl += ` WPEFramework::Core::JSON::VariantContainer ${capitalize(name)}VariantContainer(${capitalize(name)}Str);\n` - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${capitalize(name)}VariantContainer;\n` - } - else { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${name};\n` - } - impl += ` jsonParameters.Set(_T("${name}"), ${capitalize(name)});` - } - else { - - impl += ` if (${name} != nullptr) {\n` - if (param.nativeType.includes('char*')) { - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${name};\n` - } - else if (param.nativeType.includes('_t')) { - impl += ` ${jsonType}& ${capitalize(name)}Container = *(*(reinterpret_cast*>(${camelcase(name)})));\n` - impl += ` string ${capitalize(name)}Str;\n` - impl += ` ${capitalize(name)}Container.ToString(${capitalize(name)}Str);\n` - impl += ` WPEFramework::Core::JSON::VariantContainer ${capitalize(name)}VariantContainer(${capitalize(name)}Str);\n` - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = ${capitalize(name)}VariantContainer;\n` - } else { - - impl += ` WPEFramework::Core::JSON::Variant ${capitalize(name)} = *(${name});\n` - } - impl += ` jsonParameters.Set(_T("${name}"), ${capitalize(name)});\n` - impl += ` }` - } - impl += '\n' - } - }) - - return impl -} - -const isNativeType = (type) => (type === 'float' || type === 'char*' || type === 'int32_t' || type === 'bool') - -function getCallbackParametersInstantiation(paramList, container = '') { - - let impl = '' - - if (paramList.length > 0) { - paramList.forEach(param => { - if (param.required !== undefined) { - if (param.nativeType !== 'char*') { - impl += ` ${param.nativeType} ${param.name};\n` - if (param.required === false) { - impl += ` ${param.nativeType}* ${param.name}Ptr = nullptr;\n` - } - } - else { - impl += ` ${getFireboltStringType()} ${param.name};\n` - } - } - }) - impl += `\n WPEFramework::Core::ProxyType<${container}>* jsonResponse;\n` - impl += ` WPEFramework::Core::ProxyType& var = *(reinterpret_cast*>(response)); - - ASSERT(var.IsValid() == true); - if (var.IsValid() == true) { - WPEFramework::Core::JSON::VariantContainer::Iterator elements = var->Variants(); - - while (elements.Next()) { - if (strcmp(elements.Label(), "value") == 0) { - - jsonResponse = new WPEFramework::Core::ProxyType<${container}>(); - string objectStr; - elements.Current().Object().ToString(objectStr); - (*jsonResponse)->FromString(objectStr); - } else if (strcmp(elements.Label(), "context") == 0) { - - WPEFramework::Core::JSON::VariantContainer::Iterator params = elements.Current().Object().Variants(); - while (params.Next()) {\n` - let contextParams = '' - - paramList.forEach(param => { - if (param.required !== undefined) { - if (isNativeType(param.nativeType) === true) { - if (contextParams.length > 0) { - contextParams += ` else if (strcmp(elements.Label(), "${param.name}") == 0) {\n` - } - else { - contextParams += ` if (strcmp(elements.Label(), "${param.name}") == 0) {\n` - } - if (param.nativeType === 'char*') { - contextParams += ` ${getSdkNameSpace()}::JSON::String* ${param.name}Value = new ${getSdkNameSpace()}::JSON::String(); - *${param.name}Value = elements.Current().Value().c_str(); - ${param.name} = reinterpret_cast<${getFireboltStringType()}>(${param.name}Value);\n` - } - else if (param.nativeType === 'bool') { - contextParams += ` ${param.name} = elements.Current().Boolean();\n` - } - else if ((param.nativeType === 'float') || (param.nativeType === 'int32_t')) { - contextParams += ` ${param.name} = elements.Current().Number();\n` - } - if ((param.nativeType !== 'char*') && (param.required === false)) { - contextParams += ` ${param.name}Ptr = &${param.name};\n` - } - contextParams += ` }\n` - } - } - }) - impl += contextParams - impl += ` } - } else { - ASSERT(false); - } - } - }\n` - } else { - - impl +=` WPEFramework::Core::ProxyType<${container}>* jsonResponse = reinterpret_cast*>(response);\n` - } - - return impl -} - -function getCallbackResultInstantiation(nativeType, container = '') { - let impl = '' - if (nativeType === 'char*' || nativeType === 'Firebolt_String_t') { - impl +=` - ${container}* jsonStrResponse = new ${container}(); - *jsonStrResponse = *(*jsonResponse); - jsonResponse->Release();` + '\n' - } - return impl -} - -function getCallbackResponseInstantiation(paramList, nativeType, container = '') { - let impl = '' - - if (paramList.length > 0) { - paramList.forEach(param => { - if (param.required !== undefined) { - if (param.nativeType === 'char*') { - impl += `reinterpret_cast<${getFireboltStringType()}>(${param.name}), ` - } - else if (param.required === true) { - impl += `${param.name}, ` - } - else if (param.required === false) { - impl += `${param.name}Ptr, ` - } - } - }) - } - - if (nativeType === 'char*' || nativeType === 'Firebolt_String_t') { - impl += `reinterpret_cast<${nativeType}>(jsonStrResponse)` - } - else if (nativeType.includes('_t')) { - impl += `reinterpret_cast<${nativeType}>(jsonResponse)` - } - else { - impl += `static_cast<${nativeType}>((*jsonResponse)->Value())` - } - - return impl -} - -function getResultInstantiation (name, nativeType, container, indentLevel = 2) { - - let impl = '' - - if (nativeType) { - impl += `${' '.repeat(indentLevel)}if (${name} != nullptr) {` + '\n' - if (nativeType === 'char*' || nativeType === 'Firebolt_String_t') { - impl += `${' '.repeat(indentLevel + 1)}${container}* strResult = new ${container}(jsonResult);` + '\n' - impl += `${' '.repeat(indentLevel + 1)}*${name} = reinterpret_cast<${getFireboltStringType()}>(strResult);` + '\n' - } else if (nativeType.includes('_t')) { - impl += `${' '.repeat(indentLevel + 1)}WPEFramework::Core::ProxyType<${container}>* resultPtr = new WPEFramework::Core::ProxyType<${container}>();\n` - impl += `${' '.repeat(indentLevel + 1)}*resultPtr = WPEFramework::Core::ProxyType<${container}>::Create();\n` - impl += `${' '.repeat(indentLevel + 1)}*(*resultPtr) = jsonResult;\n` - impl += `${' '.repeat(indentLevel + 1)}*${name} = reinterpret_cast<${nativeType}>(resultPtr);` + '\n' - } else { - impl += `${' '.repeat(indentLevel + 1)}*${name} = jsonResult.Value();` + '\n' - } - impl += `${' '.repeat(indentLevel)}}` + '\n' - } else if (name === 'success') { - impl += `${' '.repeat(indentLevel)}status = (jsonResult.Value() == true) ? FireboltSDKErrorNone : FireboltSDKErrorNotSupported;` - } - - return impl - -} - - -export { - getArrayAccessorsImpl, - getMapAccessorsImpl, - getObjectManagementImpl, - getPropertyAccessorsImpl, - getParameterInstantiation, - getCallbackParametersInstantiation, - getCallbackResultInstantiation, - getCallbackResponseInstantiation, - getResultInstantiation -} diff --git a/languages/c/src/types/JSONHelpers.mjs b/languages/c/src/types/JSONHelpers.mjs deleted file mode 100644 index 1c5e3ea4..00000000 --- a/languages/c/src/types/JSONHelpers.mjs +++ /dev/null @@ -1,57 +0,0 @@ -const capitalize = str => str[0].toUpperCase() + str.substr(1) -const getSdkNameSpace = () => 'FireboltSDK' -const getJsonDataPrefix = () => 'JsonData_' -const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON' - -const getJsonDataStructName = (modName, name, prefix = '') => { - let result =((prefix && prefix.length > 0) && (prefix !== name)) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}_${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}` - - return ((result.includes(wpeJsonNameSpace()) === true) ? result : `${getSdkNameSpace()}::${result}`) -} - -function getJsonContainerDefinition (schema, name, props) { - let c = schema.description ? (' /*\n * ${info.title} - ' + `${schema.description}\n */\n`) : '' - name = getJsonDataPrefix() + capitalize(name) - c += ` class ${name}: public WPEFramework::Core::JSON::Container { - public: - ~${name}() override = default; - - public: - ${name}() - : WPEFramework::Core::JSON::Container() - {` - - props.forEach(prop => { - c += `\n Add(_T("${prop.name}"), &${capitalize(prop.name)});` - }) - c += `\n }\n` - c += `\n ${name}(const ${name}& copy) - {` - props.forEach(prop => { - c += `\n Add(_T("${prop.name}"), &${capitalize(prop.name)});` - c += `\n ${capitalize(prop.name)} = copy.${capitalize(prop.name)};` - }) - c += ` - }\n - ${name}& operator=(const ${name}& rhs) - {` - props.forEach(prop => { - c += `\n ${capitalize(prop.name)} = rhs.${capitalize(prop.name)};` - }) - c += `\n return (*this); - }\n - public:` - - props.forEach(prop => { - c += `\n ${prop.type} ${capitalize(prop.name)};` - }) - - c += '\n };' - return c -} - -export { - getJsonContainerDefinition, - getJsonDataStructName, - getJsonDataPrefix -} diff --git a/languages/c/src/types/NativeHelpers.mjs b/languages/c/src/types/NativeHelpers.mjs deleted file mode 100644 index 061f30b8..00000000 --- a/languages/c/src/types/NativeHelpers.mjs +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2021 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 - */ - -import helpers from 'crocks/helpers/index.js' -const { compose, getPathOr } = helpers -import safe from 'crocks/Maybe/safe.js' -import pointfree from 'crocks/pointfree/index.js' -const { chain, filter, reduce, option, map } = pointfree -import predicates from 'crocks/predicates/index.js' -import { getPath, getExternalSchemaPaths, getSafeEnumKeyName } from '../../../../src/shared/json-schema.mjs' -import deepmerge from 'deepmerge' - -const { isObject, isArray, propEq, pathSatisfies, hasProp, propSatisfies } = predicates - -const getModuleName = json => getPathOr(null, ['info', 'title'], json) || json.title || 'missing' - -const getFireboltStringType = () => 'Firebolt_String_t' - -const capitalize = str => str[0].toUpperCase() + str.substr(1) -const description = (title, str='') => '/* ' + title + (str.length > 0 ? ' - ' + str : '') + ' */' -const isOptional = (prop, json) => (!json.required || !json.required.includes(prop)) - -const SdkTypesPrefix = 'Firebolt' - -const Indent = ' ' - -const getNativeType = (json, fireboltString = false) => { - let type - let jsonType = json.const ? typeof json.const : json.type - if (jsonType === 'string') { - type = 'char*' - if (fireboltString) { - type = getFireboltStringType() - } - } - else if (jsonType === 'number') { - type = 'float' - } - else if (jsonType === 'integer') { - type = 'int32_t' - - } - else if (jsonType === 'boolean') { - type = 'bool' - } - else if (jsonType === 'null' ) { - type = 'void' - } - return type -} - -const getObjectManagement = varName => { - - let result = `typedef struct ${varName}_s* ${varName}_t; -${varName}_t ${varName}_Acquire(void); -void ${varName}_Addref(${varName}_t handle); -void ${varName}_Release(${varName}_t handle); -bool ${varName}_IsValid(${varName}_t handle); -` - return result -} - -const getPropertyAccessors = (objName, propertyName, propertyType, options = {level:0, readonly:false, optional:false}) => { - let result = `${Indent.repeat(options.level)}${propertyType} ${objName}_Get_${propertyName}(${objName}_t handle);` + '\n' - - if (!options.readonly) { - let type = (propertyType === getFireboltStringType()) ? 'char*' : propertyType - result += `${Indent.repeat(options.level)}void ${objName}_Set_${propertyName}(${objName}_t handle, ${type} ${propertyName.toLowerCase()});` + '\n' - } - - if (options.optional === true) { - result += `${Indent.repeat(options.level)}bool ${objName}_Has_${propertyName}(${objName}_t handle);` + '\n' - result += `${Indent.repeat(options.level)}void ${objName}_Clear_${propertyName}(${objName}_t handle);` + '\n' - } - - return result -} - -const getMapAccessors = (typeName, accessorPropertyType, level = 0) => { - - let res - - res = `${Indent.repeat(level)}uint32_t ${typeName}_KeysCount(${typeName}_t handle);` + '\n' - res += `${Indent.repeat(level)}void ${typeName}_AddKey(${typeName}_t handle, char* key, ${accessorPropertyType} value);` + '\n' - res += `${Indent.repeat(level)}void ${typeName}_RemoveKey(${typeName}_t handle, char* key);` + '\n' - res += `${Indent.repeat(level)}${accessorPropertyType} ${typeName}_FindKey(${typeName}_t handle, char* key);` + '\n' - - return res -} - -const getTypeName = (moduleName, varName, prefix = '', upperCase = false, capitalCase = true) => { - - let mName = upperCase ? moduleName.toUpperCase() : capitalize(moduleName) - let vName = upperCase ? varName.toUpperCase() : capitalCase ? capitalize(varName) : varName - if (prefix && prefix.length > 0) { - prefix = (prefix !== varName) ? (upperCase ? prefix.toUpperCase() : capitalize(prefix)) : '' - } - prefix = (prefix && prefix.length > 0) ?(upperCase ? prefix.toUpperCase() : capitalize(prefix)) : prefix - let name = (prefix && prefix.length > 0) ? `${mName}_${prefix}_${vName}` : `${mName}_${vName}` - return name -} - -const getArrayAccessors = (arrayName, propertyType, valueType) => { - - let res = `uint32_t ${arrayName}Array_Size(${propertyType}_t handle);` + '\n' - res += `${valueType} ${arrayName}Array_Get(${propertyType}_t handle, uint32_t index);` + '\n' - res += `void ${arrayName}Array_Add(${propertyType}_t handle, ${valueType} value);` + '\n' - res += `void ${arrayName}Array_Clear(${propertyType}_t handle);` + '\n' - - return res -} - -const enumValue = (val,prefix) => { - const keyName = getSafeEnumKeyName(val) - return ` ${prefix.toUpperCase()}_${keyName.toUpperCase()}` -} - -const generateEnum = (schema, prefix)=> { - if (!schema.enum) { - return '' - } - else { - let str = `typedef enum {\n` - str += schema.enum.map(e => enumValue(e, prefix)).join(',\n') - str += `\n} ${prefix};\n` - return str - } -} - -/* -paramList = [{name='', nativeType='', jsonType='', required=boolean}] -*/ - -const getContextParams = (paramList) => paramList.map(param => param.nativeType + (!param.required ? '*' : '') + ' ' + param.name).join(', ') - -function getPropertyGetterSignature(property, module, propType, paramList = []) { - - let contextParams = '' - contextParams = getContextParams(paramList) - return `int32_t ${capitalize(getModuleName(module))}_Get${capitalize(property.name)}( ${contextParams}${contextParams.length > 0 ? ', ':''}${propType}* ${property.result.name || property.name} )` -} - -export { - getNativeType, - getModuleName, - getPropertyGetterSignature, - getMapAccessors, - getArrayAccessors, - capitalize, - description, - getTypeName, - getObjectManagement, - getPropertyAccessors, - isOptional, - generateEnum, - getFireboltStringType -} diff --git a/languages/c/templates/codeblocks/export.c b/languages/c/templates/codeblocks/export.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/codeblocks/mock-import.c b/languages/c/templates/codeblocks/mock-import.c deleted file mode 100644 index 5d22512a..00000000 --- a/languages/c/templates/codeblocks/mock-import.c +++ /dev/null @@ -1 +0,0 @@ -import { default as _${info.title} } from './${info.title}/defaults.mjs' \ No newline at end of file diff --git a/languages/c/templates/codeblocks/mock-parameter.c b/languages/c/templates/codeblocks/mock-parameter.c deleted file mode 100644 index 63e63902..00000000 --- a/languages/c/templates/codeblocks/mock-parameter.c +++ /dev/null @@ -1 +0,0 @@ - ${info.title}: _${info.title}, \ No newline at end of file diff --git a/languages/c/templates/codeblocks/module.c b/languages/c/templates/codeblocks/module.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/codeblocks/setter.c b/languages/c/templates/codeblocks/setter.c deleted file mode 100644 index f62c8683..00000000 --- a/languages/c/templates/codeblocks/setter.c +++ /dev/null @@ -1,7 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -int32_t ${info.Title}_${method.Name}( ${method.signature.params} ) -{ - const string method = _T("${info.title.lowercase}.${method.rpc.name}"); -${if.params}${method.params.serialization}${end.if.params} - return FireboltSDK::Properties::Set(method, jsonParameters); -} diff --git a/languages/c/templates/declarations/clear.c b/languages/c/templates/declarations/clear.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/declarations/default.c b/languages/c/templates/declarations/default.c deleted file mode 100644 index e6b49808..00000000 --- a/languages/c/templates/declarations/default.c +++ /dev/null @@ -1,4 +0,0 @@ -/* ${method.name} - ${method.description} -${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}${end.if.deprecated} */ -int32_t ${info.Title}_${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}OUT ${method.result.type}* ${method.result.name}${end.if.result}${if.signature.empty}void${end.if.signature.empty} ); - diff --git a/languages/c/templates/declarations/event.c b/languages/c/templates/declarations/event.c deleted file mode 100644 index 3638be52..00000000 --- a/languages/c/templates/declarations/event.c +++ /dev/null @@ -1,5 +0,0 @@ -/* ${method.name} - ${method.description} */ -typedef void (*${info.Title}${method.Name}Callback)( const void* userData, ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${event.result.type} ); -int32_t ${info.Title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}${info.Title}${method.Name}Callback userCB, const void* userData ); -int32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB); - diff --git a/languages/c/templates/declarations/listen.c b/languages/c/templates/declarations/listen.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/declarations/once.c b/languages/c/templates/declarations/once.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/declarations/polymorphic-pull-event.c b/languages/c/templates/declarations/polymorphic-pull-event.c deleted file mode 100644 index b9c7f424..00000000 --- a/languages/c/templates/declarations/polymorphic-pull-event.c +++ /dev/null @@ -1,5 +0,0 @@ -/* ${method.name} - ${method.description} */ -typedef void* (*${info.Title}${method.Name}Callback)( const void* userData, ${method.pulls.param.type} ); -int32_t ${info.Title}_Register_${method.Name}( ${info.Title}${method.Name}Callback userCB, const void* userData ); -int32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB); - diff --git a/languages/c/templates/declarations/polymorphic-pull.c b/languages/c/templates/declarations/polymorphic-pull.c deleted file mode 100644 index 7956f87f..00000000 --- a/languages/c/templates/declarations/polymorphic-pull.c +++ /dev/null @@ -1,3 +0,0 @@ -/* ${method.name} - ${method.description} */ -int32_t ${info.Title}_Push${method.Name}( ${method.signature.params} ); - diff --git a/languages/c/templates/declarations/polymorphic-reducer.c b/languages/c/templates/declarations/polymorphic-reducer.c deleted file mode 100644 index cf974e1a..00000000 --- a/languages/c/templates/declarations/polymorphic-reducer.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * ${method.summary} - * ${method.params} - */ -${method.signature} - -// TODO: generate reducer signature diff --git a/languages/c/templates/declarations/property.c b/languages/c/templates/declarations/property.c deleted file mode 100644 index 3550b45e..00000000 --- a/languages/c/templates/declarations/property.c +++ /dev/null @@ -1,5 +0,0 @@ -/* - * ${method.summary} - * ${method.params} - */ -${method.signature} diff --git a/languages/c/templates/declarations/provide.c b/languages/c/templates/declarations/provide.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/declarations/setter.c b/languages/c/templates/declarations/setter.c deleted file mode 100644 index a40fd4fc..00000000 --- a/languages/c/templates/declarations/setter.c +++ /dev/null @@ -1,2 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -int32_t ${info.Title}_${method.Name}( ${method.signature.params} ); diff --git a/languages/c/templates/defaults/default.c b/languages/c/templates/defaults/default.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/defaults/property.c b/languages/c/templates/defaults/property.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/imports/calls-metrics.cpp b/languages/c/templates/imports/calls-metrics.cpp deleted file mode 100644 index 4ba289b3..00000000 --- a/languages/c/templates/imports/calls-metrics.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "metrics.h" diff --git a/languages/c/templates/imports/default.cpp b/languages/c/templates/imports/default.cpp deleted file mode 100644 index caf84bc9..00000000 --- a/languages/c/templates/imports/default.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "jsondata_${info.title.lowercase}.h" diff --git a/languages/c/templates/imports/default.h b/languages/c/templates/imports/default.h deleted file mode 100644 index 56a97a40..00000000 --- a/languages/c/templates/imports/default.h +++ /dev/null @@ -1 +0,0 @@ -#include "common/${info.title.lowercase}.h" diff --git a/languages/c/templates/imports/default.jsondata b/languages/c/templates/imports/default.jsondata deleted file mode 100644 index caf84bc9..00000000 --- a/languages/c/templates/imports/default.jsondata +++ /dev/null @@ -1 +0,0 @@ -#include "jsondata_${info.title.lowercase}.h" diff --git a/languages/c/templates/json-types/additionalProperties.c b/languages/c/templates/json-types/additionalProperties.c deleted file mode 100644 index b814e5fb..00000000 --- a/languages/c/templates/json-types/additionalProperties.c +++ /dev/null @@ -1 +0,0 @@ -// need cpp code to init, get, set, clear additional properties... \ No newline at end of file diff --git a/languages/c/templates/json-types/anyOf.c b/languages/c/templates/json-types/anyOf.c deleted file mode 100644 index a2682179..00000000 --- a/languages/c/templates/json-types/anyOf.c +++ /dev/null @@ -1 +0,0 @@ -/* AnyOf is not supported in C: ${title} */ \ No newline at end of file diff --git a/languages/c/templates/json-types/array.c b/languages/c/templates/json-types/array.c deleted file mode 100644 index 508a9eac..00000000 --- a/languages/c/templates/json-types/array.c +++ /dev/null @@ -1,4 +0,0 @@ -uint32_t ${info.Title}_${Title}Array_Size(${type} handle); -${type} ${title}Array_Get(${type} handle, uint32_t index); -void ${info.Title}_${Title}Array_Add(${propertyType} handle, ${valueType} value); -void ${info.Title}_${Title}Array_Clear(${propertyType} handle); diff --git a/languages/c/templates/json-types/boolean.c b/languages/c/templates/json-types/boolean.c deleted file mode 100644 index 18bbeec2..00000000 --- a/languages/c/templates/json-types/boolean.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::Boolean \ No newline at end of file diff --git a/languages/c/templates/json-types/const.c b/languages/c/templates/json-types/const.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/json-types/default.cpp b/languages/c/templates/json-types/default.cpp deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c/templates/json-types/default.cpp +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c/templates/json-types/enum.cpp b/languages/c/templates/json-types/enum.cpp deleted file mode 100644 index 6776b41a..00000000 --- a/languages/c/templates/json-types/enum.cpp +++ /dev/null @@ -1,4 +0,0 @@ - /* ${title} ${description} */ - ENUM_CONVERSION_BEGIN(${name}) - { ${NAME}_${key}, _T("${value}") }, - ENUM_CONVERSION_END(${name}) diff --git a/languages/c/templates/json-types/enum.h b/languages/c/templates/json-types/enum.h deleted file mode 100644 index 92108c75..00000000 --- a/languages/c/templates/json-types/enum.h +++ /dev/null @@ -1,4 +0,0 @@ -/* ${title} ${description} */ -typedef enum { - ${NAME}_${key}, -} ${name}; diff --git a/languages/c/templates/json-types/float.c b/languages/c/templates/json-types/float.c deleted file mode 100644 index c38bca91..00000000 --- a/languages/c/templates/json-types/float.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::Float \ No newline at end of file diff --git a/languages/c/templates/json-types/integer.c b/languages/c/templates/json-types/integer.c deleted file mode 100644 index b57fe26e..00000000 --- a/languages/c/templates/json-types/integer.c +++ /dev/null @@ -1 +0,0 @@ -WPEFramework::Core::JSON::DecSInt32 \ No newline at end of file diff --git a/languages/c/templates/json-types/namespace.c b/languages/c/templates/json-types/namespace.c deleted file mode 100644 index 8ea9d7de..00000000 --- a/languages/c/templates/json-types/namespace.c +++ /dev/null @@ -1 +0,0 @@ -FireboltSDK::${info.Title}:: \ No newline at end of file diff --git a/languages/c/templates/json-types/object.cpp b/languages/c/templates/json-types/object.cpp deleted file mode 100644 index db24d12c..00000000 --- a/languages/c/templates/json-types/object.cpp +++ /dev/null @@ -1,25 +0,0 @@ - class ${title}: public WPEFramework::Core::JSON::Container { - public: - ~${title}() override = default; - - public: - ${title}() - : WPEFramework::Core::JSON::Container() - { - ${properties.register} - } - - ${title}(const ${title}& other) - { - ${properties.assign} - } - - ${title}& operator=(const ${title}& other) - { - ${properties.assign} - return (*this); - } - - public: - ${properties} - }; diff --git a/languages/c/templates/json-types/primitive.c b/languages/c/templates/json-types/primitive.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/json-types/property-assign.cpp b/languages/c/templates/json-types/property-assign.cpp deleted file mode 100644 index 88795136..00000000 --- a/languages/c/templates/json-types/property-assign.cpp +++ /dev/null @@ -1,2 +0,0 @@ - Add(_T("${property}"), &${Property}); - ${Property} = other.${Property} diff --git a/languages/c/templates/json-types/property-register.cpp b/languages/c/templates/json-types/property-register.cpp deleted file mode 100644 index 400b4fd5..00000000 --- a/languages/c/templates/json-types/property-register.cpp +++ /dev/null @@ -1,2 +0,0 @@ - Add(_T("${property}"), &${Property}); - \ No newline at end of file diff --git a/languages/c/templates/json-types/property.cpp b/languages/c/templates/json-types/property.cpp deleted file mode 100644 index 49f79c0e..00000000 --- a/languages/c/templates/json-types/property.cpp +++ /dev/null @@ -1 +0,0 @@ - ${title} ${Property}; \ No newline at end of file diff --git a/languages/c/templates/json-types/ref.c b/languages/c/templates/json-types/ref.c deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c/templates/json-types/ref.c +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c/templates/json-types/string.c b/languages/c/templates/json-types/string.c deleted file mode 100644 index 2d60a3c8..00000000 --- a/languages/c/templates/json-types/string.c +++ /dev/null @@ -1 +0,0 @@ -FireboltSDK::JSON::String \ No newline at end of file diff --git a/languages/c/templates/json-types/title.c b/languages/c/templates/json-types/title.c deleted file mode 100644 index ae1512e5..00000000 --- a/languages/c/templates/json-types/title.c +++ /dev/null @@ -1 +0,0 @@ -JsonData_${Title} \ No newline at end of file diff --git a/languages/c/templates/json-types/tuple.c b/languages/c/templates/json-types/tuple.c deleted file mode 100644 index db24d12c..00000000 --- a/languages/c/templates/json-types/tuple.c +++ /dev/null @@ -1,25 +0,0 @@ - class ${title}: public WPEFramework::Core::JSON::Container { - public: - ~${title}() override = default; - - public: - ${title}() - : WPEFramework::Core::JSON::Container() - { - ${properties.register} - } - - ${title}(const ${title}& other) - { - ${properties.assign} - } - - ${title}& operator=(const ${title}& other) - { - ${properties.assign} - return (*this); - } - - public: - ${properties} - }; diff --git a/languages/c/templates/json-types/types/object.c b/languages/c/templates/json-types/types/object.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/json-types/x-method.c b/languages/c/templates/json-types/x-method.c deleted file mode 100644 index 573c9f8e..00000000 --- a/languages/c/templates/json-types/x-method.c +++ /dev/null @@ -1 +0,0 @@ -void* \ No newline at end of file diff --git a/languages/c/templates/language/enum-item.c b/languages/c/templates/language/enum-item.c deleted file mode 100644 index 79aabbeb..00000000 --- a/languages/c/templates/language/enum-item.c +++ /dev/null @@ -1 +0,0 @@ - ${key} diff --git a/languages/c/templates/language/enum.c b/languages/c/templates/language/enum.c deleted file mode 100644 index 0551b99c..00000000 --- a/languages/c/templates/language/enum.c +++ /dev/null @@ -1,3 +0,0 @@ -typedef enum { - ${items} -} F${info.title}_${title}; diff --git a/languages/c/templates/language/parameter.c b/languages/c/templates/language/parameter.c deleted file mode 100644 index 2ff7a678..00000000 --- a/languages/c/templates/language/parameter.c +++ /dev/null @@ -1 +0,0 @@ -${type} ${name} \ No newline at end of file diff --git a/languages/c/templates/language/schema-item.c b/languages/c/templates/language/schema-item.c deleted file mode 100644 index ecded7d5..00000000 --- a/languages/c/templates/language/schema-item.c +++ /dev/null @@ -1 +0,0 @@ - ${type} ${property}; diff --git a/languages/c/templates/language/schema.c b/languages/c/templates/language/schema.c deleted file mode 100644 index 22760540..00000000 --- a/languages/c/templates/language/schema.c +++ /dev/null @@ -1,3 +0,0 @@ -typedef struct { - ${properties} -} F${info.title}_${title}; diff --git a/languages/c/templates/methods/calls-metrics.c b/languages/c/templates/methods/calls-metrics.c deleted file mode 100644 index 3ad9ec0f..00000000 --- a/languages/c/templates/methods/calls-metrics.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -void Metrics_${method.Name}Dispatcher(const void*${if.result} result${end.if.result}) { - Metrics_${method.Name}(${if.result}(static_cast<${method.result.json.type}>(const_cast(result)))${end.if.result}); -} -int32_t ${info.Title}_${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}OUT ${method.result.type}* ${method.result.name}${end.if.result}${if.signature.empty}void${end.if.signature.empty} ) { - - int32_t status = FireboltSDKErrorUnavailable; - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - - ${method.params.serialization.with.indent} - ${method.result.json.type} jsonResult; - status = transport->Invoke("${info.title}.${method.rpc.name}", jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); - ${method.result.instantiation.with.indent} - - void* result = nullptr; - ${if.result}result = static_cast(new ${method.result.json.type});${end.if.result} - WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(Metrics_${method.Name}Dispatcher, result)); - WPEFramework::Core::IWorkerPool::Instance().Submit(job); - } - - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; -} - diff --git a/languages/c/templates/methods/clear.c b/languages/c/templates/methods/clear.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/methods/default.c b/languages/c/templates/methods/default.c deleted file mode 100644 index e1d9e701..00000000 --- a/languages/c/templates/methods/default.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -int32_t ${info.Title}_${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}OUT ${method.result.type}* ${method.result.name}${end.if.result}${if.signature.empty}void${end.if.signature.empty} ) { - - int32_t status = FireboltSDKErrorUnavailable; - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - - ${method.params.serialization.with.indent} - ${method.result.json.type} jsonResult; - status = transport->Invoke("${info.title.lowercase}.${method.rpc.name}", jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); - ${method.result.instantiation.with.indent} - } - - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport err = %d", status); - } - - return status; -} - diff --git a/languages/c/templates/methods/event.c b/languages/c/templates/methods/event.c deleted file mode 100644 index 85ae3b48..00000000 --- a/languages/c/templates/methods/event.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -static void ${info.Title}${method.Name}InnerCallback( void* userCB, const void* userData, void* response ) -{ -${event.callback.params.serialization} - ASSERT(jsonResponse->IsValid() == true); - if (jsonResponse->IsValid() == true) { -${event.callback.result.instantiation} - ${info.Title}${method.Name}Callback callback = reinterpret_cast<${info.Title}${method.Name}Callback>(userCB); - callback(userData, ${event.callback.response.instantiation}); - } -} -int32_t ${info.Title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}${info.Title}${method.Name}Callback userCB, const void* userData ) -{ - const string eventName = _T("${info.title.lowercase}.${method.rpc.name}"); - int32_t status = FireboltSDKErrorNone; - - if (userCB != nullptr) { - ${event.params.serialization} - status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${info.Title}${method.Name}InnerCallback, reinterpret_cast(userCB), userData); - } - return status; -} -int32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB) -{ - return FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title.lowercase}.${method.rpc.name}"), reinterpret_cast(userCB)); -} - diff --git a/languages/c/templates/methods/listen.c b/languages/c/templates/methods/listen.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/methods/once.c b/languages/c/templates/methods/once.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/methods/polymorphic-pull-event.c b/languages/c/templates/methods/polymorphic-pull-event.c deleted file mode 100644 index 49aa1dba..00000000 --- a/languages/c/templates/methods/polymorphic-pull-event.c +++ /dev/null @@ -1,54 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -static void ${info.Title}${method.Name}InnerCallback( void* userCB, const void* userData, void* response ) -{ -${event.callback.params.serialization} - ASSERT(jsonResponse->IsValid() == true); - if (jsonResponse->IsValid() == true) { - - ${info.Title}${method.Name}Callback callback = reinterpret_cast<${info.Title}${method.Name}Callback>(userCB); - - WPEFramework::Core::ProxyType<${method.pulls.param.json.type}>* requestParam = new WPEFramework::Core::ProxyType<${method.pulls.param.json.type}>(); - *requestParam = WPEFramework::Core::ProxyType<${method.pulls.param.json.type}>::Create(); - *(*requestParam) = (*jsonResponse)->${event.pulls.param.name}Parameters; - - ${method.pulls.type} result = reinterpret_cast<${method.pulls.type}>(callback(userData, reinterpret_cast<${method.pulls.param.type}>(requestParam))); - - JsonObject jsonParameters; - WPEFramework::Core::JSON::Variant CorrelationId = (*jsonResponse)->CorrelationId.Value(); - jsonParameters.Set(_T("correlationId"), CorrelationId); - - ${method.pulls.json.type}& resultObj = *(*(reinterpret_cast*>(result))); - string resultStr; - resultObj.ToString(resultStr); - WPEFramework::Core::JSON::VariantContainer resultContainer(resultStr); - WPEFramework::Core::JSON::Variant Result = resultContainer; - jsonParameters.Set(_T("result"), Result); - - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - WPEFramework::Core::JSON::Boolean jsonResult; - int32_t status = transport->Invoke(_T("${info.title.lowercase}.${method.pulls.for}"), jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${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(), "Error in getting Transport"); - } - } -} -int32_t ${info.Title}_Register_${method.Name}( ${info.Title}${method.Name}Callback userCB, const void* userData ) -{ - const string eventName = _T("${info.title.lowercase}.${method.rpc.name}"); - int32_t status = FireboltSDKErrorNone; - - if (userCB != nullptr) { - ${event.params.serialization} - status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${info.Title}${method.Name}InnerCallback, reinterpret_cast(userCB), userData); - } - return status; -} -int32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB) -{ - return FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title.lowercase}.${method.rpc.name}"), reinterpret_cast(userCB)); -} - diff --git a/languages/c/templates/methods/polymorphic-pull.c b/languages/c/templates/methods/polymorphic-pull.c deleted file mode 100644 index d88b49aa..00000000 --- a/languages/c/templates/methods/polymorphic-pull.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -int32_t ${info.Title}_Push${method.Name}( ${method.signature.params} ) -{ - int32_t status = FireboltSDKErrorUnavailable; - - FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); - if (transport != nullptr) { - string correlationId = ""; - ${method.params.serialization.with.indent} - - WPEFramework::Core::JSON::Boolean jsonResult; - status = transport->Invoke(_T("${info.title.lowercase}.${method.rpc.name}"), jsonParameters, jsonResult); - if (status == FireboltSDKErrorNone) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully pushed with status as %d", jsonResult.Value()); - status = (jsonResult.Value() == true) ? FireboltSDKErrorNone : FireboltSDKErrorNotSupported; - } - } else { - FIREBOLT_LOG_ERROR(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "Error in getting Transport"); - } - - return status; -} - diff --git a/languages/c/templates/methods/polymorphic-reducer.c b/languages/c/templates/methods/polymorphic-reducer.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/methods/property.c b/languages/c/templates/methods/property.c deleted file mode 100644 index 8bf6a516..00000000 --- a/languages/c/templates/methods/property.c +++ /dev/null @@ -1,14 +0,0 @@ -/* ${method.rpc.name} - ${method.description} */ -int32_t ${info.Title}_Get${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}OUT ${method.result.type}* ${method.result.name} ) -{ - const string method = _T("${info.title.lowercase}.${method.rpc.name}"); -${if.params}${method.params.serialization}${end.if.params} - ${method.result.json} jsonResult; - ${if.params}int32_t status = FireboltSDK::Properties::Get(method, jsonParameters, jsonResult);${end.if.params} - ${if.params.empty}int32_t status = FireboltSDK::Properties::Get(method, jsonResult);${end.if.params.empty} - if (status == FireboltSDKErrorNone) { -${method.result.instantiation} - } - return status; -} -${method.setter} diff --git a/languages/c/templates/methods/provide.c b/languages/c/templates/methods/provide.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/methods/setter.c b/languages/c/templates/methods/setter.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/modules/include/module.h b/languages/c/templates/modules/include/module.h deleted file mode 100644 index 1c8d427b..00000000 --- a/languages/c/templates/modules/include/module.h +++ /dev/null @@ -1,44 +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 ${info.TITLE}_H -#define ${info.TITLE}_H - -#include -/* ${IMPORTS} */ - -${if.declarations}#ifdef __cplusplus -extern "C" { -#endif - -// Enums -/* ${ENUMS} */ - -// Accessors -/* ${ACCESSORS} */ - - - -// Methods & Events -/* ${DECLARATIONS} */ - -#ifdef __cplusplus -} -#endif${end.if.declarations} - -#endif // Header Include Guard diff --git a/languages/c/templates/modules/src/module.cpp b/languages/c/templates/modules/src/module.cpp deleted file mode 100644 index 19727924..00000000 --- a/languages/c/templates/modules/src/module.cpp +++ /dev/null @@ -1,49 +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 - */ - -#include "FireboltSDK.h" -/* ${IMPORTS} */ -#include "${info.title.lowercase}.h" - -${if.types}namespace FireboltSDK { - namespace ${info.Title} { - // Types - /* ${TYPES} */ - } -}${end.if.types} - -/* ${ENUMS} */ - -${if.definitions}#ifdef __cplusplus -extern "C" { -#endif - -// Accessors -/* ${ACCESSORS} */ - - - -// Methods -/* ${METHODS} */ - -// Events -/* ${EVENTS} */ - -#ifdef __cplusplus -} -#endif${end.if.definitions} diff --git a/languages/c/templates/parameter-serialization/boolean.cpp b/languages/c/templates/parameter-serialization/boolean.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c/templates/parameter-serialization/boolean.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c/templates/parameter-serialization/default.cpp b/languages/c/templates/parameter-serialization/default.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c/templates/parameter-serialization/default.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c/templates/parameter-serialization/object.cpp b/languages/c/templates/parameter-serialization/object.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c/templates/parameter-serialization/object.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c/templates/parameter-serialization/primitive.cpp b/languages/c/templates/parameter-serialization/primitive.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c/templates/parameter-serialization/primitive.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c/templates/parameter-serialization/string.cpp b/languages/c/templates/parameter-serialization/string.cpp deleted file mode 100644 index f924ac94..00000000 --- a/languages/c/templates/parameter-serialization/string.cpp +++ /dev/null @@ -1,2 +0,0 @@ - WPEFramework::Core::JSON::Variant ${Property} = ${property}; - jsonParameters.Set(_T("${property}"), ${Property}); diff --git a/languages/c/templates/parameters/default.c b/languages/c/templates/parameters/default.c deleted file mode 100644 index e6e3b8ba..00000000 --- a/languages/c/templates/parameters/default.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} ${method.param.name} \ No newline at end of file diff --git a/languages/c/templates/parameters/json.c b/languages/c/templates/parameters/json.c deleted file mode 100644 index 5ee36bec..00000000 --- a/languages/c/templates/parameters/json.c +++ /dev/null @@ -1,3 +0,0 @@ - ${json.param.type} ${method.param.Name} = ${method.param.name}; - jsonParameters.Add("_T(${method.param.name})", &${method.param.Name}); - diff --git a/languages/c/templates/parameters/optional.c b/languages/c/templates/parameters/optional.c deleted file mode 100644 index e6e3b8ba..00000000 --- a/languages/c/templates/parameters/optional.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} ${method.param.name} \ No newline at end of file diff --git a/languages/c/templates/parameters/result.c b/languages/c/templates/parameters/result.c deleted file mode 100644 index 699c8b5b..00000000 --- a/languages/c/templates/parameters/result.c +++ /dev/null @@ -1 +0,0 @@ -${method.param.type} *${method.param.name} \ No newline at end of file diff --git a/languages/c/templates/result-instantiation/boolean.cpp b/languages/c/templates/result-instantiation/boolean.cpp deleted file mode 100644 index 036b4a7d..00000000 --- a/languages/c/templates/result-instantiation/boolean.cpp +++ /dev/null @@ -1,2 +0,0 @@ - *${property} = jsonResult.Value(); - \ No newline at end of file diff --git a/languages/c/templates/result-instantiation/default.cpp b/languages/c/templates/result-instantiation/default.cpp deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c/templates/result-instantiation/default.cpp +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c/templates/result-instantiation/object.cpp b/languages/c/templates/result-instantiation/object.cpp deleted file mode 100644 index dcf0b333..00000000 --- a/languages/c/templates/result-instantiation/object.cpp +++ /dev/null @@ -1,4 +0,0 @@ - WPEFramework::Core::ProxyType* resultPtr = new WPEFramework::Core::ProxyType(); - *resultPtr = WPEFramework::Core::ProxyType::Create(); - *(*resultPtr) = jsonResult; - *${property} = static_cast<${info.Title}_${title}>(resultPtr); diff --git a/languages/c/templates/result-instantiation/primitive.cpp b/languages/c/templates/result-instantiation/primitive.cpp deleted file mode 100644 index 23bbace7..00000000 --- a/languages/c/templates/result-instantiation/primitive.cpp +++ /dev/null @@ -1 +0,0 @@ -${type} \ No newline at end of file diff --git a/languages/c/templates/result-instantiation/string.cpp b/languages/c/templates/result-instantiation/string.cpp deleted file mode 100644 index b6c9dcb5..00000000 --- a/languages/c/templates/result-instantiation/string.cpp +++ /dev/null @@ -1,2 +0,0 @@ - FireboltSDK::JSON::String* strResult = new FireboltSDK::JSON::String(jsonResult); - *value = static_cast(strResult); diff --git a/languages/c/templates/schemas/default.c b/languages/c/templates/schemas/default.c deleted file mode 100644 index 9a52cff7..00000000 --- a/languages/c/templates/schemas/default.c +++ /dev/null @@ -1 +0,0 @@ -${schema.shape} diff --git a/languages/c/templates/schemas/include/common/module.h b/languages/c/templates/schemas/include/common/module.h deleted file mode 100644 index 90f1f031..00000000 --- a/languages/c/templates/schemas/include/common/module.h +++ /dev/null @@ -1,39 +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 COMMON_${info.TITLE}_H -#define COMMON_${info.TITLE}_H - -#include -/* ${IMPORTS} */ - -${if.declarations}#ifdef __cplusplus -extern "C" { -#endif - -// Enums -/* ${ENUMS} */ - -// Types -/* ${TYPES} */ - -#ifdef __cplusplus -} -#endif${end.if.declarations} - -#endif // Header Include Guard diff --git a/languages/c/templates/schemas/src/jsondata_module.h b/languages/c/templates/schemas/src/jsondata_module.h deleted file mode 100644 index 81084440..00000000 --- a/languages/c/templates/schemas/src/jsondata_module.h +++ /dev/null @@ -1,30 +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 - */ - -#pragma once - -/* ${IMPORTS} */ -#include "common/${info.title.lowercase}.h" - -${if.schemas}namespace FireboltSDK { - namespace ${info.Title} { - // Types - - /* ${SCHEMAS} */ - } -}${end.if.schemas} diff --git a/languages/c/templates/schemas/src/module_common.cpp b/languages/c/templates/schemas/src/module_common.cpp deleted file mode 100644 index 5bfa7719..00000000 --- a/languages/c/templates/schemas/src/module_common.cpp +++ /dev/null @@ -1,42 +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 - */ - -#include "FireboltSDK.h" -/* ${IMPORTS} */ -#include "jsondata_${info.title.lowercase}.h" - -/* ${ENUMS} */ - -${if.definitions}#ifdef __cplusplus -extern "C" { -#endif - -// Accessors -/* ${ACCESSORS} */ - - - -// Methods -/* ${METHODS} */ - -// Events -/* ${EVENTS} */ - -#ifdef __cplusplus -} -#endif${end.if.definitions} diff --git a/languages/c/templates/sdk/scripts/build.sh b/languages/c/templates/sdk/scripts/build.sh deleted file mode 100755 index 149cd1ae..00000000 --- a/languages/c/templates/sdk/scripts/build.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -usage() -{ - echo "options:" - echo " -p sdk path" - echo " -s sysroot path" - echo " -c clear build" - echo " -l enable static build" - echo " -t enable test" - echo " -h : help" - echo - echo "usage: " - echo " ./build.sh -p path -tc" -} - -SdkPath="." -EnableTest="OFF" -SysrootPath=${SYSROOT_PATH} -ClearBuild="N" -EnableStaticLib="OFF" -while getopts p:s:clth flag -do - case "${flag}" in - p) SdkPath="${OPTARG}";; - s) SysrootPath="${OPTARG}";; - c) ClearBuild="Y";; - l) EnableStaticLib="ON";; - t) EnableTest="ON";; - h) usage && exit 1;; - esac -done - -if [ "${ClearBuild}" == "Y" ]; -then - rm -rf ${SdkPath}/build -fi - -cmake -B${SdkPath}/build -S${SdkPath} -DSYSROOT_PATH=${SysrootPath} -DENABLE_TESTS=${EnableTest} -DHIDE_NON_EXTERNAL_SYMBOLS=OFF -DFIREBOLT_ENABLE_STATIC_LIB=${EnableStaticLib} -cmake --build ${SdkPath}/build -cmake --install ${SdkPath}/build --prefix=${SdkPath}/build/Firebolt/usr diff --git a/languages/c/templates/sdk/scripts/install.sh b/languages/c/templates/sdk/scripts/install.sh deleted file mode 100755 index 9981f9da..00000000 --- a/languages/c/templates/sdk/scripts/install.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -usage() -{ - echo "options:" - echo " -i install path" - echo " -s sdk path" - echo " -m module name. i.e, core/manage" - echo - echo "usage: " - echo " ./install.sh -i path -s sdk path -m core" -} - -SdkPath=".." -InstallPath=".." -ModuleName="core" -while getopts i:s:m:h flag -do - case "${flag}" in - i) InstallPath="${OPTARG}";; - s) SdkPath="${OPTARG}";; - m) ModuleName="${OPTARG}";; - h) usage && exit 1;; - esac -done - -GetVersion() -{ - PackagePath=${SdkPath}/../../../../../../package-lock.json - InputKey="name\": \"@firebolt-js/sdks" - LineNo="$(grep -n "${InputKey}" ${PackagePath} | head -n 1 | cut -d: -f1)" - VersionLine=$((LineNo++)) - eval "array=(`sed -n "${LineNo}p" < ${PackagePath} | sed 's/\"/\n/g'`)" - Version=${array[2]} -} - -Version=0.0 -GetVersion -ReleaseName=firebolt-${ModuleName}-native-sdk-${Version} -ReleasePath=${InstallPath}/${ReleaseName} - -rm -rf ${ReleasePath} -mkdir -p ${ReleasePath} -cp -ar ${SdkPath}/src ${ReleasePath} -cp -ar ${SdkPath}/include ${ReleasePath} -cp -ar ${SdkPath}/cmake ${ReleasePath} -cp -ar ${SdkPath}/scripts/build.sh ${ReleasePath} -cp -ar ${SdkPath}/CMakeLists.txt ${ReleasePath} -cp -ar ${SdkPath}/ctest ${ReleasePath}/test - -sed -i '/EnableTest="ON";;/d' ${ReleasePath}/build.sh -sed -i 's/getopts p:s:tch/getopts p:s:ch/g' ${ReleasePath}/build.sh -sed -i '/enable test/d' ${ReleasePath}/build.sh -sed -i '/EnableTest="OFF"/d' ${ReleasePath}/build.sh -sed -i 's/ -DENABLE_TESTS=${EnableTest}//g' ${ReleasePath}/build.sh - -cd ${ReleasePath}/../ -tar -cvzf ${ReleaseName}.tgz ${ReleaseName}/* -cd - diff --git a/languages/c/templates/sections/accessors.c b/languages/c/templates/sections/accessors.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/accessors.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/sections/declarations.c b/languages/c/templates/sections/declarations.c deleted file mode 100644 index b3ef974d..00000000 --- a/languages/c/templates/sections/declarations.c +++ /dev/null @@ -1 +0,0 @@ -${declaration.list} diff --git a/languages/c/templates/sections/enum.cpp b/languages/c/templates/sections/enum.cpp deleted file mode 100644 index e5165c61..00000000 --- a/languages/c/templates/sections/enum.cpp +++ /dev/null @@ -1,5 +0,0 @@ -namespace WPEFramework { - -${schema.list} - -} diff --git a/languages/c/templates/sections/enums.c b/languages/c/templates/sections/enums.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/enums.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/sections/events.c b/languages/c/templates/sections/events.c deleted file mode 100644 index 5be10409..00000000 --- a/languages/c/templates/sections/events.c +++ /dev/null @@ -1 +0,0 @@ -${event.list} diff --git a/languages/c/templates/sections/methods.c b/languages/c/templates/sections/methods.c deleted file mode 100644 index e8200eb0..00000000 --- a/languages/c/templates/sections/methods.c +++ /dev/null @@ -1 +0,0 @@ -${method.list} diff --git a/languages/c/templates/sections/methods_accessors.c b/languages/c/templates/sections/methods_accessors.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/methods_accessors.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/sections/methods_types.c b/languages/c/templates/sections/methods_types.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/methods_types.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/sections/provider-interfaces.c b/languages/c/templates/sections/provider-interfaces.c deleted file mode 100644 index 418d7abf..00000000 --- a/languages/c/templates/sections/provider-interfaces.c +++ /dev/null @@ -1,11 +0,0 @@ - // Provider Interfaces - - interface ProviderSession { - correlationId(): string // Returns the correlation id of the current provider session - } - - interface FocusableProviderSession extends ProviderSession { - focus(): Promise // Requests that the provider app be moved into focus to prevent a user experience - } - - ${providers.list} \ No newline at end of file diff --git a/languages/c/templates/sections/schemas.c b/languages/c/templates/sections/schemas.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/schemas.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/sections/types.c b/languages/c/templates/sections/types.c deleted file mode 100644 index 9295133c..00000000 --- a/languages/c/templates/sections/types.c +++ /dev/null @@ -1 +0,0 @@ -${schema.list} diff --git a/languages/c/templates/types/additionalProperties.c b/languages/c/templates/types/additionalProperties.c deleted file mode 100644 index ffe5ab54..00000000 --- a/languages/c/templates/types/additionalProperties.c +++ /dev/null @@ -1,4 +0,0 @@ - uint32_t ${parent.title}_KeysCount(${parent.title} handle); - void ${parent.title}_AddKey(${parent.title} handle, char* key, ${title} value); - void ${parent.title}_RemoveKey(${parent.title} handle, char* key); - ${title} ${parent.title}_FindKey(${parent.title} handle, char* key); diff --git a/languages/c/templates/types/anyOf.c b/languages/c/templates/types/anyOf.c deleted file mode 100644 index a2682179..00000000 --- a/languages/c/templates/types/anyOf.c +++ /dev/null @@ -1 +0,0 @@ -/* AnyOf is not supported in C: ${title} */ \ No newline at end of file diff --git a/languages/c/templates/types/array.c b/languages/c/templates/types/array.c deleted file mode 100644 index 0b9863c2..00000000 --- a/languages/c/templates/types/array.c +++ /dev/null @@ -1,4 +0,0 @@ -uint32_t ${info.Title}_${Title}Array_Size(${type} handle); -${type} ${title}Array_Get(${type} handle, uint32_t index); -void ${info.Title}_${Title}Array_Add(${type} handle, ${type} value); -void ${info.Title}_${Title}Array_Clear(${type} handle); diff --git a/languages/c/templates/types/const.c b/languages/c/templates/types/const.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/types/default.c b/languages/c/templates/types/default.c deleted file mode 100644 index 1f1fe89d..00000000 --- a/languages/c/templates/types/default.c +++ /dev/null @@ -1,4 +0,0 @@ -/* - * ${title} - ${description} - */ -${shape} diff --git a/languages/c/templates/types/enum.cpp b/languages/c/templates/types/enum.cpp deleted file mode 100644 index 9c98f888..00000000 --- a/languages/c/templates/types/enum.cpp +++ /dev/null @@ -1,4 +0,0 @@ - /* ${title} ${description} */ - ENUM_CONVERSION_BEGIN(${info.Title}_${name}) - { ${info.TITLE}_${NAME}_${key}, _T("${value}") }, - ENUM_CONVERSION_END(${info.Title}_${name}) diff --git a/languages/c/templates/types/enum.h b/languages/c/templates/types/enum.h deleted file mode 100644 index 906d908d..00000000 --- a/languages/c/templates/types/enum.h +++ /dev/null @@ -1,4 +0,0 @@ -/* ${title} ${description} */ -typedef enum { - ${info.TITLE}_${NAME}_${key}, -} ${info.Title}_${name}; diff --git a/languages/c/templates/types/object.c b/languages/c/templates/types/object.c deleted file mode 100644 index 7ff6a7a9..00000000 --- a/languages/c/templates/types/object.c +++ /dev/null @@ -1,10 +0,0 @@ -/* ${title} */ -typedef void* ${title}; -${title} ${title}_Create(void); -void ${title}_Addref(${title} handle); -void ${title}_Release(${title} handle); -bool ${title}_IsValid(${title} handle); - - -// Property Accessors: -${properties} \ No newline at end of file diff --git a/languages/c/templates/types/primitive.c b/languages/c/templates/types/primitive.c deleted file mode 100644 index e69de29b..00000000 diff --git a/languages/c/templates/types/property.c b/languages/c/templates/types/property.c deleted file mode 100644 index abbba725..00000000 --- a/languages/c/templates/types/property.c +++ /dev/null @@ -1,6 +0,0 @@ -/* ${property} */ -${title} ${parent.title}_Get_${Property}(${parent.title} handle); -void ${parent.title}_Set_${Property}(${parent.title} handle, ${title} ${property}); -${if.optional}bool ${parent.title}_Has_${Property}(${parent.title} handle); -void ${parent.title}_Clear_${Property}(${parent.title} handle, ${title} ${property}); -${end.if.optional} \ No newline at end of file diff --git a/languages/c/templates/types/ref.c b/languages/c/templates/types/ref.c deleted file mode 100644 index 4da5b5d9..00000000 --- a/languages/c/templates/types/ref.c +++ /dev/null @@ -1 +0,0 @@ -${shape} \ No newline at end of file diff --git a/languages/c/templates/types/title.c b/languages/c/templates/types/title.c deleted file mode 100644 index ca6b6897..00000000 --- a/languages/c/templates/types/title.c +++ /dev/null @@ -1 +0,0 @@ -F${info.Title}_${Title} \ No newline at end of file diff --git a/languages/c/templates/types/tuple.c b/languages/c/templates/types/tuple.c deleted file mode 100644 index 96a04034..00000000 --- a/languages/c/templates/types/tuple.c +++ /dev/null @@ -1,8 +0,0 @@ -/* ${title} */ -typedef void* ${title}; -${title} ${title}_Create(void); -void ${title}_Addref(${title} handle); -void ${title}_Release(${title} handle); -bool ${title}_IsValid(${title} handle); - -${properties} diff --git a/languages/c/templates/types/x-method.c b/languages/c/templates/types/x-method.c deleted file mode 100644 index 573c9f8e..00000000 --- a/languages/c/templates/types/x-method.c +++ /dev/null @@ -1 +0,0 @@ -void* \ No newline at end of file