Skip to content

Commit

Permalink
feat: C Language Support (#130)
Browse files Browse the repository at this point in the history
* chore: Copy JS templates to C and create language.config.json
* feat(languages): Add support for a distinct JSON-type for each schema
Also started tweaking C templates and adding a few useful macros.
* chore: Dropped debug logs
* fix: Stop passing non-schemas in to getSchemaType
* feat(accessors): New macro section for schema property accessors
* fix: Sort the macrofied schemas based on schema refs (#90)
* fix: Sort the macrofied schemas based on schema refs
* fix: Sort the schemas before macrofying
* fix: Handle the schemas part
* Enum fixes (#93)
* Types and Accessor related fixes (#94)
* Static code implementation updates (#96)
* Add support to generate file inclusion for common schema also (#97)
* C-Language: Templates based property methods (#100)
* feat: Add method templates for properties
* feat: Property setters using templates
* fix: Macro name correction
* Add support to keep original file permissions of template/sdk files (#99)
* Event template implementation added (#101)
* Template for Polymorphic pull method (#102)
* feat: Add method templates for properties
* feat: Property setters using templates
* fix: Macro name correction
* feat: Add template for polymorphic-pull

* fix: Promote and name sub-schemas in one place

* fix: Add extractSubSchemas flag to C language

* fix: Uncomment writeFilePermissions

* polymorphic-pull: method and event implementation added (#107)

* SchemaSorting: logic updated to consider all schemas (#106)

* fix: Fix the reentrancy of methods from callback (#105)

* Default template implementation added (#103)

Default template implementation added

* Naming + void* to struct* changes based on sky review, removed redundant code, array handling fix (#109)

Naming + void* to struct* changes based on sky review, removed redundant code, array handling fix

* language-c: re-arrange files locations (#112)

language-c: re-arrange files locations

* fixes to generate array inside subschemas (#111)

* include test always (#113)

* use String type if there is any issue with anyOf merge (#114)

* calls-metrics: support added (#115)

* Generate polymorphci methods for anyOf param/result case (#110)

* Create namespaces only if there is value to put (#117)

* Changes to avoid duplication of sub-array schema with same reference (#116)

* detach setter declaration from property template and add setter templ… (#118)

Detach setter declaration from property template and add setter template, remove unredundant warnings
Cleanup changes, add separator between prefix and subSchema name generation
Introduce excludeDeclarations flag to handle declaration exclusion specific to language
Alignement changes + cleanup + OUT params support added to differentiate method signature parameters
Update in static code

* SubArray generation issue fix (#121)

* cmake changes to install proper files (#119)

* chore: Copy JS templates to C and create language.config.json

* feat(languages): Add support for a distinct JSON-type for each schema

Also started tweaking C templates and adding a few useful macros.

* chore: Dropped debug logs

* fix: Stop passing non-schemas in to getSchemaType

* feat(accessors): New macro section for schema property accessors

* fix: Sort the macrofied schemas based on schema refs (#90)

* fix: Sort the macrofied schemas based on schema refs

* fix: Sort the schemas before macrofying

* fix: Handle the schemas part

* Enum fixes (#93)

Enum fixes :
1. missing description added
2. alignment fixes
3. implementation added for enum inside properties
4. Enum to String value Conversion logic added for C

* Types and Accessor related fixes (#94)

Types and Accessor related fixes:
1. Accessor creation
2. JsonContainer creation
3. Types order placed based on depenedencies
4. filtered redundant new lines
5. UnamedSchema issue fixes
6. Types and Accessors:  generation added for objects inside methods result/params
7. AnyOf support added

* Static code implementation updates (#96)

Static code implementation updates
Co-authored-by: Jeremy LaCivita <[email protected]>

* Add support to generate file inclusion for common schema also (#97)

Add support to generate file inclusion for common schema also

* C-Language: Templates based property methods (#100)

* feat: Add method templates for properties

* feat: Property setters using templates

* fix: Macro name correction

* Add support to keep original file permissions of template/sdk files (#99)

* Event template implementation added (#101)

* Template for Polymorphic pull method (#102)

* feat: Add method templates for properties

* feat: Property setters using templates

* fix: Macro name correction

* feat: Add template for polymorphic-pull

* fix: Promote and name sub-schemas in one place

* fix: Add extractSubSchemas flag to C language

* fix: Uncomment writeFilePermissions

* polymorphic-pull: method and event implementation added (#107)

* SchemaSorting: logic updated to consider all schemas (#106)

* fix: Fix the reentrancy of methods from callback (#105)

* Default template implementation added (#103)

Default template implementation added

* Naming + void* to struct* changes based on sky review, removed redundant code, array handling fix (#109)

Naming + void* to struct* changes based on sky review, removed redundant code, array handling fix

* language-c: re-arrange files locations (#112)

language-c: re-arrange files locations

* fixes to generate array inside subschemas (#111)

* include test always (#113)

* use String type if there is any issue with anyOf merge (#114)

* calls-metrics: support added (#115)

* Generate polymorphci methods for anyOf param/result case (#110)

* Create namespaces only if there is value to put (#117)

* Changes to avoid duplication of sub-array schema with same reference (#116)

* detach setter declaration from property template and add setter templ… (#118)

Detach setter declaration from property template and add setter template, remove unredundant warnings
Cleanup changes, add separator between prefix and subSchema name generation
Introduce excludeDeclarations flag to handle declaration exclusion specific to language
Alignement changes + cleanup + OUT params support added to differentiate method signature parameters
Update in static code

* SubArray generation issue fix (#121)

* cmake changes to install proper files (#119)

* native code: changed return type from uint32_t to int32_t (#127)

---------

Co-authored-by: sramani-metro <[email protected]>
Co-authored-by: HaseenaSainul <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2023
1 parent e59d461 commit 33db98c
Show file tree
Hide file tree
Showing 101 changed files with 6,237 additions and 312 deletions.
789 changes: 789 additions & 0 deletions languages/c/Types.mjs

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions languages/c/language.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"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
}
19 changes: 19 additions & 0 deletions languages/c/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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'
56 changes: 56 additions & 0 deletions languages/c/src/shared/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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)
72 changes: 72 additions & 0 deletions languages/c/src/shared/cmake/HelperFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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)
35 changes: 35 additions & 0 deletions languages/c/src/shared/cmake/project.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 ()

41 changes: 41 additions & 0 deletions languages/c/src/shared/include/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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
68 changes: 68 additions & 0 deletions languages/c/src/shared/include/firebolt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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
37 changes: 37 additions & 0 deletions languages/c/src/shared/include/types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 <stdint.h>
#include <stdbool.h>

#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
Loading

0 comments on commit 33db98c

Please sign in to comment.