Skip to content

Commit

Permalink
add interface for wedpr-front-c-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjseagull committed Aug 26, 2024
1 parent 3f202ae commit 4cad628
Show file tree
Hide file tree
Showing 76 changed files with 398 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cpp_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ jobs:
if: runner.os == 'macos'
with:
name: libppc-crypto-sdk-jni.dylib
path: ./cpp/ppc-crypto-c-sdk/bindings/java/src/main/resources/META-INF/native/libppc-crypto-sdk-jni.dylib
path: ./cpp/wedpr-component-sdk/bindings/java/src/main/resources/META-INF/native/libppc-crypto-sdk-jni.dylib
- uses: actions/upload-artifact@v2
if: runner.os == 'Windows'
with:
name: libppc-crypto-sdk-jni.dylib
path: D:\a\WeDPR-Component\cpp\ppc-crypto-c-sdk\bindings\java\src\main\resources\META-INF\native\Release\ppc-crypto-sdk-jni.dll
path: D:\a\WeDPR-Component\cpp\wedpr-component-sdk\bindings\java\src\main\resources\META-INF\native\Release\ppc-crypto-sdk-jni.dll

build_centos:
name: build_centos full node
Expand Down Expand Up @@ -221,4 +221,4 @@ jobs:
- uses: actions/upload-artifact@v2
with:
name: libppc-crypto-sdk-jni.so
path: ./cpp/ppc-crypto-c-sdk/bindings/java/src/main/resources/META-INF/native/libppc-crypto-sdk-jni.so
path: ./cpp/wedpr-component-sdk/bindings/java/src/main/resources/META-INF/native/libppc-crypto-sdk-jni.so
17 changes: 15 additions & 2 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ include(TargetSettings)
include(Dependencies)

########### set the sources ###########
set(JNI_SOURCE_PATH ppc-crypto-c-sdk/bindings/java/src/main/c)
set(SDK_SOURCE_LIST ppc-homo ppc-crypto-core ppc-crypto-c-sdk ${JNI_SOURCE_PATH})
set(JNI_SOURCE_PATH wedpr-component-sdk/bindings/java/src/main/c)
set(SDK_SOURCE_LIST ppc-homo ppc-crypto-core wedpr-component-sdk ${JNI_SOURCE_PATH})
# Note: the udf depends on mysql, not enabled in the full node mode
set(UDF_SOURCE_LIST ${SDK_SOURCE_LIST} ppc-udf)
set(ALL_SOURCE_LIST
Expand All @@ -79,6 +79,19 @@ if(BUILD_CEM)
set(CEM_SOURCE "ppc-cem")
endif()

if(BUILD_WEDPR_TOOLKIT)
# fetch the python dependencies
option(FETCH_PYTHON_DEPS "Install python required modules if not available" ON)
message(STATUS "Python fetch dependencies: ${FETCH_PYTHON_DEPS}")
include(python)
if(WIN32)
message(STATUS "Getting SWIG for Windows: ...")
include(swig)
message(STATUS "Getting SWIG for Windows: ...DONE")
endif()
add_subdirectory(wedpr-toolkit-wrapper)
endif()

if(BUILD_ALL)
add_sources("${ALL_SOURCE_LIST}")
elseif(BUILD_UDF)
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/IncludeDirectories.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-front)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-gateway)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-crypto-c-sdk)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/wedpr-component-c-sdk)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ppc-tars-protocol)

set(VCPKG_INCLUDE_PATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
Expand Down
1 change: 1 addition & 0 deletions cpp/cmake/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ macro(configure_project)
default_option(BUILD_ALL ON)
default_option(BUILD_SDK OFF)
default_option(BUILD_UDF OFF)
default_option(BUILD_WEDPR_TOOLKIT OFF)

# Suffix like "-rc1" e.t.c. to append to versions wherever needed.
if (NOT DEFINED VERSION_SUFFIX)
Expand Down
14 changes: 11 additions & 3 deletions cpp/cmake/TargetSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,22 @@ if (ENABLE_CPU_FEATURES)
set(CPU_FEATURES_LIB CpuFeatures::cpu_features)
endif ()

#====== ppc-crypto-c-sdk ===========
#====== wedpr-component-sdk ===========
set(PPC_CRYPTO_C_SDK_STATIC_TARGET ppc-crypto-c-sdk-static)
set(PPC_CRYPTO_C_SDK_TARGET ppc-crypto-c-sdk)

set(PPC_FRONT_C_SDK_STATIC_TARGET ppc-front-c-sdk-static)
set(PPC_FRONT_C_SDK_TARGET ppc-front-c-sdk)

# add suffix for arm
if(ARCH_NATIVE)
message(STATUS "Building arm architecture, CMAKE_HOST_SYSTEM_PROCESSOR => ${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(PPC_CRYPTO_C_SDK_STATIC_TARGET "ppc-crypto-c-sdk-aarch64")
set(PPC_CRYPTO_C_SDK_TARGET "ppc-crypto-c-sdk-static-aarch64")
set(PPC_FRONT_C_SDK_STATIC_TARGET ppc-front-c-sdk-static-aarch64)
set(PPC_FRONT_C_SDK_TARGET ppc-front-c-sdk-aarch64)
endif()
#====== ppc-crypto-c-sdk ===========
#====== wedpr-component-sdk ===========


#====== ppc-crypto-sdk-jni ===========
Expand All @@ -119,4 +124,7 @@ if(ARCH_NATIVE)
endif()
# ========== ppc-udf ===========

set(BOOST_UNIT_TEST Boost::unit_test_framework)
set(BOOST_UNIT_TEST Boost::unit_test_framework)

# ==== the swig wrapper =====
set(WEDPR_PYTHON_TOOLKIT "wedpr_python_toolkit")
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
project(wedpr-component-c-sdk VERSION ${VERSION})
project(wedpr-component-sdk VERSION ${VERSION})

# export windows dll symbol
if(WIN32)
message(STATUS "Compile on Windows")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS "ON")
endif()
add_subdirectory(ppc-crypto-c-sdk)
add_subdirectory(ppc-front-c-sdk)
add_subdirectory(wedpr-front-cpp-sdk)

if (TESTS)
enable_testing()
set(CTEST_OUTPUT_ON_FAILURE TRUE)
add_subdirectory(tests)
endif()
endif()
File renamed without changes.
9 changes: 9 additions & 0 deletions cpp/wedpr-component-sdk/wedpr-front-cpp-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
file(GLOB_RECURSE SRCS *.cpp *.c)

# generate the static lib
add_library(${PPC_FRONT_C_SDK_STATIC_TARGET} ${SRCS})
target_link_libraries(${PPC_FRONT_C_SDK_STATIC_TARGET} PUBLIC ${BCOS_UTILITIES_TARGET})

# generate the shared lib
add_library(${PPC_FRONT_C_SDK_TARGET} SHARED ${SRCS})
target_link_libraries(${PPC_FRONT_C_SDK_TARGET} PUBLIC ${BCOS_UTILITIES_TARGET})
92 changes: 92 additions & 0 deletions cpp/wedpr-component-sdk/wedpr-front-cpp-sdk/wedpr_front_c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (C) 2023 WeDPR.
* SPDX-License-Identifier: Apache-2.0
* 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.
*
* @file wedpr_front_c.h
* @author: yujiechen
* @date 2024-08-22
*/
#include "wedpr_front_c.h"

/**
* @brief create the wedpr_front using specified config
*
* @param config the config used to build the wedpr_front
* @return void* the created wedpr_front
*/
void* wedpr_front_create(struct wedpr_front_config* config)
{
return nullptr;
}

/**
* @brief start the wedpr_front
*
* @param front the front to start
*/
void wedpr_front_start(void* front) {}

/**
* @brief stop the wedpr_front
*
* @param front the front to stop
*/
void wedpr_front_stop(void* front) {}

/**
* @brief destroy the wedpr_front
*
* @param front the front to destroy
*/
void wedpr_front_destroy(void* front) {}

/**
* @brief register the topic handler
*
* @param front the front object
* @param topic the topic
* @param callback the callback called when receive specified topic
*/
void register_topic_handler(void* front, InputBuffer const* topic, wedpr_msg_handler_cb callback) {}

/**
* @brief async send message
*
* @param front the front to send the message
* @param routerPolicy the router policy:
* 0: route by nodeID
* 1: route by component
* 2: route by agency
* @param topic the topic
* @param dstInst the dst agency(must set when 'route by agency' and 'route by
* component')
* @param dstNodeID the dst nodeID(must set when 'route by nodeID')
* @param componentType the componentType(must set when 'route by component')
* @param payload the payload to send
* @param seq the message seq
* @param timeout timeout
* @param callback callback
*/
void async_send_message(void* front, int routerPolicy, InputBuffer const* topic,
InputBuffer const* dstInst, InputBuffer const* dstNodeID, uint8_t componentType,
InputBuffer const* payload, int seq, long timeout, wedpr_msg_handler_cb callback)
{}

// the sync interface for async_send_message
wedpr_msg* push(void* front, int routerPolicy, InputBuffer const* topic, InputBuffer const* dstInst,
InputBuffer const* dstNodeID, uint8_t componentType, InputBuffer const* payload, int seq,
long timeout)
{
return nullptr;
}
98 changes: 98 additions & 0 deletions cpp/wedpr-component-sdk/wedpr-front-cpp-sdk/wedpr_front_c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (C) 2023 WeDPR.
* SPDX-License-Identifier: Apache-2.0
* 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.
*
* @file wedpr_front_c.h
* @author: yujiechen
* @date 2024-08-22
*/
#ifndef __WEDPR_FRONT_C_H__
#define __WEDPR_FRONT_C_H__
#include "ppc-framework/libwrapper/Buffer.h"
#include "wedpr_front_common.h"
#include "wedpr_front_config.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief create the wedpr_front using specified config
*
* @param config the config used to build the wedpr_front
* @return void* the created wedpr_front
*/
void* wedpr_front_create(struct wedpr_front_config* config);

/**
* @brief start the wedpr_front
*
* @param front the front to start
*/
void wedpr_front_start(void* front);

/**
* @brief stop the wedpr_front
*
* @param front the front to stop
*/
void wedpr_front_stop(void* front);

/**
* @brief destroy the wedpr_front
*
* @param front the front to destroy
*/
void wedpr_front_destroy(void* front);

/**
* @brief register the topic handler
*
* @param front the front object
* @param topic the topic
* @param callback the callback called when receive specified topic
*/
void register_topic_handler(void* front, InputBuffer const* topic, wedpr_msg_handler_cb callback);

/**
* @brief async send message
*
* @param front the front to send the message
* @param routerPolicy the router policy:
* 0: route by nodeID
* 1: route by component
* 2: route by agency
* @param topic the topic
* @param dstInst the dst agency(must set when 'route by agency' and 'route by
* component')
* @param dstNodeID the dst nodeID(must set when 'route by nodeID')
* @param componentType the componentType(must set when 'route by component')
* @param payload the payload to send
* @param seq the message seq
* @param timeout timeout
* @param callback callback
*/
void async_send_message(void* front, int routerPolicy, InputBuffer const* topic,
InputBuffer const* dstInst, InputBuffer const* dstNodeID, uint8_t componentType,
InputBuffer const* payload, int seq, long timeout, wedpr_msg_handler_cb callback);

// the sync interface for async_send_message
wedpr_msg* push(void* front, int routerPolicy, InputBuffer const* topic, InputBuffer const* dstInst,
InputBuffer const* dstNodeID, uint8_t componentType, InputBuffer const* payload, int seq,
long timeout);

#ifdef __cplusplus
}
#endif
#endif
28 changes: 28 additions & 0 deletions cpp/wedpr-component-sdk/wedpr-front-cpp-sdk/wedpr_front_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2023 WeDPR.
* SPDX-License-Identifier: Apache-2.0
* 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.
*
* @file wedpr_front_common.h
* @author: yujiechen
* @date 2024-08-22
*/

#ifndef __WEDPR_FRONT_COMMON_H__
#define __WEDPR_FRONT_COMMON_H__

#include "wedpr_msg.h"

typedef void (*wedpr_msg_handler_cb)(struct wedpr_msg* response, void* context);

#endif
Loading

0 comments on commit 4cad628

Please sign in to comment.