diff --git a/common/cpp/include/asapo/common/common_c.h b/common/cpp/include/asapo/common/common_c.h new file mode 100644 index 0000000000000000000000000000000000000000..a08e9ac2a788e3e5e4bded878398bf5482353682 --- /dev/null +++ b/common/cpp/include/asapo/common/common_c.h @@ -0,0 +1,8 @@ +#ifndef __COMMON_C_H__ +#define __COMMON_C_H__ + +#ifndef __COMMON_C_INTERFACE_IMPLEMENTATION__ +typedef void* AsapoConsumerHandle; +#endif + +#endif diff --git a/common/cpp/include/asapo/common/internal/asapo_common_c_glue.h b/common/cpp/include/asapo/common/internal/asapo_common_c_glue.h new file mode 100644 index 0000000000000000000000000000000000000000..889a32115a270c3e28a2a317c24bab43374b5b0d --- /dev/null +++ b/common/cpp/include/asapo/common/internal/asapo_common_c_glue.h @@ -0,0 +1,25 @@ +#ifndef __COMMON_C_GLUE_H__ +#define __COMMON_C_GLUE_H__ +#include <memory> + +class AsapoHandle { + public: + virtual ~AsapoHandle() {}; +}; + +template<class T> +class AsapoHandlerHolder final : public AsapoHandle { + public: + AsapoHandlerHolder(bool manage_memory = true) : handle{nullptr}, manage_memory_{manage_memory} {}; + AsapoHandlerHolder(T* handle_i, bool manage_memory = true) : handle{handle_i}, manage_memory_{manage_memory} {}; + ~AsapoHandlerHolder() override { + if (!manage_memory_) { + handle.release(); + } + } + std::unique_ptr<T> handle{nullptr}; + protected: + bool manage_memory_{true}; +}; + +#endif diff --git a/common/cpp/src/common/common_c_glue.cpp b/common/cpp/src/common/common_c_glue.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b60c1dfb34a8cbc0bdc3ae53712da7e82388f5b --- /dev/null +++ b/common/cpp/src/common/common_c_glue.cpp @@ -0,0 +1,29 @@ +#define __COMMON_C_INTERFACE_IMPLEMENTATION__ +#include "asapo/asapo_common_c_glue.h + +//! handle for credentials to access a source from a producer +/// created by asapo_create_source_credentials() +/// free after use with asapo_free_handle() +/// \sa asapo::SourceCredentials +typedef AsapoHandlerHolder<asapo::SourceCredentials>* AsapoSourceCredentialsHandle; + +extern "C" { + +//! free handle memory, set handle to NULL +/// \param[in] pointer to an ASAPO handle + void asapo_free_handle(void** handle) { + if (*handle == nullptr) { + return; + } + auto a_handle = static_cast<AsapoHandle*>(*handle); + delete a_handle; + *handle = nullptr; + } + +//! creates a new ASAPO handle +/// \return initialized ASAPO handle + void* asapo_new_handle() { + return NULL; + } + +} diff --git a/consumer/api/c/include/asapo/consumer_c.h b/consumer/api/c/include/asapo/consumer_c.h index 442e39aa466bc48d6c6b31807bfe30e8ac18f1f7..f033896c6eccf9c9d781bcd8431055b30d7c9bba 100644 --- a/consumer/api/c/include/asapo/consumer_c.h +++ b/consumer/api/c/include/asapo/consumer_c.h @@ -3,8 +3,7 @@ #ifndef __CONSUMER_C_INTERFACE_IMPLEMENTATION__ typedef int AsapoBool; - -typedef void* AsapoConsumerHandle; +#include <asapo/common_c.h> typedef void* AsapoSourceCredentialsHandle; typedef void* AsapoErrorHandle; typedef void* AsapoMessageMetaHandle; diff --git a/consumer/api/cpp/src/consumer_c_glue.cpp b/consumer/api/cpp/src/consumer_c_glue.cpp index a4a2e5937a388935a73e2d1a5a1666fc411ba0a5..3c8d11fe679ee30547537b8f8168d3441d34abc6 100644 --- a/consumer/api/cpp/src/consumer_c_glue.cpp +++ b/consumer/api/cpp/src/consumer_c_glue.cpp @@ -1,28 +1,10 @@ #define __CONSUMER_C_INTERFACE_IMPLEMENTATION__ #include "asapo/asapo_consumer.h" +#include "asapo/common/internal/asapo_common_c_glue.h" //! boolean type typedef int AsapoBool; -class AsapoHandle { - public: - virtual ~AsapoHandle() {}; -}; - -template<class T> -class AsapoHandlerHolder final : public AsapoHandle { - public: - AsapoHandlerHolder(bool manage_memory = true) : handle{nullptr}, manage_memory_{manage_memory} {}; - AsapoHandlerHolder(T* handle_i, bool manage_memory = true) : handle{handle_i}, manage_memory_{manage_memory} {}; - ~AsapoHandlerHolder() override { - if (!manage_memory_) { - handle.release(); - } - } - std::unique_ptr<T> handle{nullptr}; - protected: - bool manage_memory_{true}; -}; //! handle for an asapo consumer /// created by asapo_create_consumer() diff --git a/producer/CMakeLists.txt b/producer/CMakeLists.txt index 7f0b9114f04668ed140ef2b67f53e17928b286a9..2a4bbf8c7c0de8e3941b3e136558ea0973a30b50 100644 --- a/producer/CMakeLists.txt +++ b/producer/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(api/cpp) +add_subdirectory(api/c) if (BUILD_PYTHON) add_subdirectory(api/python) diff --git a/producer/api/c/CMakeLists.txt b/producer/api/c/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3aa21699d5633845cea87bd64fcc67cfb1c824cd --- /dev/null +++ b/producer/api/c/CMakeLists.txt @@ -0,0 +1 @@ +install(DIRECTORY include/ DESTINATION include) diff --git a/producer/api/c/include/asapo/producer_c.h b/producer/api/c/include/asapo/producer_c.h new file mode 100644 index 0000000000000000000000000000000000000000..cc4d942e2f59ad0e957317a288b0b432813fb927 --- /dev/null +++ b/producer/api/c/include/asapo/producer_c.h @@ -0,0 +1,10 @@ +#ifndef __PRODUCER_C_H__ +#define __PRODUCER_C_H__ +#include "asapo/common_c.h" +#ifndef __PRODUCER_C_INTERFACE_IMPLEMENTATION__ + +typedef void* AsapoProducerHandle; +#endif + + +#endif diff --git a/producer/api/cpp/CMakeLists.txt b/producer/api/cpp/CMakeLists.txt index 24b5722350e4392b898e3d4b350055184c8b8c4b..f7bbf1bb4921fd538f991b2d32b0b82c21a2af66 100644 --- a/producer/api/cpp/CMakeLists.txt +++ b/producer/api/cpp/CMakeLists.txt @@ -7,7 +7,8 @@ set(SOURCE_FILES src/request_handler_filesystem.cpp src/receiver_discovery_service.cpp src/receiver_data_server_request_handler_factory.cpp - src/producer_request.cpp) + src/producer_request.cpp + src/producer_c_glue.cpp) ################################ diff --git a/producer/api/cpp/src/producer_c_glue.cpp b/producer/api/cpp/src/producer_c_glue.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad46ac2da0f945e2a0ea000c325138c3f4370a16 --- /dev/null +++ b/producer/api/cpp/src/producer_c_glue.cpp @@ -0,0 +1,17 @@ +#define __PRODUCER_C_INTERFACE_IMPLEMENTATION__ + +#include "asapo/common/internal/asapo_common_c_glue.h" +#include "asapo/asapo_producer.h" + + +//! handle for an asapo producer +/// created by asapo_create_producer() +/// free after use with asapo_free_handle() +/// all operations are done with asapo_producer_xxx() functions +/// \sa asapo::Producer +typedef AsapoHandlerHolder<asapo::Producer>* AsapoProducerHandle; + +extern "C" { + + +}