From 04e9fe31c69e5a6427975b6fab81dd8e11ad13d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrgen=20Hannappel?= <juergen.hannappel@desy.de>
Date: Tue, 13 Jul 2021 16:58:35 +0200
Subject: [PATCH] have type save handles in the c api

---
 common/cpp/include/asapo/common/common_c.h | 30 +++++++++++++++-------
 common/cpp/src/common/common_c_glue.cpp    |  2 +-
 consumer/api/c/include/asapo/consumer_c.h  | 28 +++++++++++++++-----
 producer/api/c/include/asapo/producer_c.h  | 12 ++++++---
 4 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/common/cpp/include/asapo/common/common_c.h b/common/cpp/include/asapo/common/common_c.h
index 8755312a2..d9920cbf6 100644
--- a/common/cpp/include/asapo/common/common_c.h
+++ b/common/cpp/include/asapo/common/common_c.h
@@ -4,15 +4,27 @@
 #include <stdint.h>
 #include <time.h>
 
-const unsigned AsapoHandleSize = 24;
+#define AsapoHandleSize 24
 typedef int AsapoBool;
 #ifndef __COMMON_C_INTERFACE_IMPLEMENTATION__
-typedef void* AsapoSourceCredentialsHandle;
-typedef void* AsapoErrorHandle;
-typedef void* AsapoStringHandle;
-typedef void* AsapoStreamInfoHandle;
-typedef void* AsapoStreamInfosHandle;
-typedef void* AsapoMessageDataHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoSourceCredentialsHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoErrorHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoStringHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoStreamInfoHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoStreamInfosHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoMessageDataHandle;
 #endif
 
 //! c version of asapo::SourceType
@@ -21,8 +33,8 @@ enum AsapoSourceType {
     kRaw
 };
 
-
-void asapo_free_handle(void** handle);
+#define asapo_free_handle(handle) asapo_free_handle__((void**)handle);
+void asapo_free_handle__(void** handle);
 void* asapo_new_handle();
 
 
diff --git a/common/cpp/src/common/common_c_glue.cpp b/common/cpp/src/common/common_c_glue.cpp
index 009dd5706..4d942d707 100644
--- a/common/cpp/src/common/common_c_glue.cpp
+++ b/common/cpp/src/common/common_c_glue.cpp
@@ -56,7 +56,7 @@ extern "C" {
 
 //! free handle memory, set handle to NULL
 /// \param[in] pointer to an ASAPO handle
-    void asapo_free_handle(void** handle) {
+    void asapo_free_handle__(void** handle) {
         if (*handle == nullptr) {
             return;
         }
diff --git a/consumer/api/c/include/asapo/consumer_c.h b/consumer/api/c/include/asapo/consumer_c.h
index 069a4d7b9..cf88fefe6 100644
--- a/consumer/api/c/include/asapo/consumer_c.h
+++ b/consumer/api/c/include/asapo/consumer_c.h
@@ -3,13 +3,27 @@
 
 #include <asapo/common/common_c.h>
 #ifndef __CONSUMER_C_INTERFACE_IMPLEMENTATION__
-typedef void* AsapoConsumerHandle;
-typedef void* AsapoMessageMetaHandle;
-typedef void* AsapoMessageMetasHandle;
-typedef void* AsapoIdListHandle;
-typedef void* AsapoDataSetHandle;
-typedef void* AsapoPartialErrorDataHandle;
-typedef void* AsapoConsumerErrorDataHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoConsumerHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoMessageMetaHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoMessageMetasHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoIdListHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoDataSetHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoPartialErrorDataHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoConsumerErrorDataHandle;
 
 #include <time.h>
 #include <stdint.h>
diff --git a/producer/api/c/include/asapo/producer_c.h b/producer/api/c/include/asapo/producer_c.h
index e3f64bab8..f29bc92b5 100644
--- a/producer/api/c/include/asapo/producer_c.h
+++ b/producer/api/c/include/asapo/producer_c.h
@@ -3,9 +3,15 @@
 #include "asapo/common/common_c.h"
 #ifndef __PRODUCER_C_INTERFACE_IMPLEMENTATION__
 
-typedef void* AsapoProducerHandle;
-typedef void* AsapoRequestCallbackPayloadHandle;
-typedef void* AsapoMessageHeaderHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoProducerHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoRequestCallbackPayloadHandle;
+typedef struct {
+    char _[AsapoHandleSize];
+}* AsapoMessageHeaderHandle;
 #endif
 
 typedef void(*AsapoRequestCallback)(AsapoRequestCallbackPayloadHandle, AsapoErrorHandle);
-- 
GitLab