cpp-common/bt2: don't use wrap in bindings code
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 13 Mar 2024 04:18:06 +0000 (00:18 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Mar 2024 18:56:36 +0000 (14:56 -0400)
Using `wrap()` in bindings code causes cyclic include problems, stop
using it.

For instance, we want to add `wrap(bt_graph *)`, so `wrap.hpp` needs to
include `graph.hpp`.  But `graph.hpp` currently uses and includes
`wrap.hpp`.

Change-Id: I5b7005617ed38eb791edf5802a05a8a8dd3115fd
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12045
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/graph.hpp
src/cpp-common/bt2/internal/comp-cls-bridge.hpp

index 63199bf737de3897f1c0393cef84246beef7ecdf..c1c6ad09ca932c7fa4e02f23492aa1b14e4f2d4d 100644 (file)
@@ -182,7 +182,7 @@ private:
             throw MemoryError {};
         }
 
-        return wrap(libObjPtr);
+        return ConstComponentT {libObjPtr};
     }
 };
 
index a9474b95220efaafe7f79bdd417b20936d83e691..88d871134c9bd4cc6c4f2a19afee3d84472b1c08 100644 (file)
 #include "cpp-common/bt2c/c-string-view.hpp"
 #include "logging/log-api.h"
 
-#include "../wrap.hpp"
+#include "../integer-range-set.hpp"
+#include "../logging.hpp"
+#include "../private-query-executor.hpp"
+#include "../self-component-class.hpp"
+#include "../self-component-port.hpp"
+#include "../self-message-iterator-configuration.hpp"
+#include "../self-message-iterator.hpp"
+#include "../value.hpp"
 
 namespace bt2 {
 namespace internal {
@@ -30,40 +37,43 @@ constexpr bt2c::CStringView unhandledExcLogTag() noexcept
 /*
  * Base class of any component class bridge.
  *
- * `UserCompClsT` is the actual C++ user component class and `LibTypesT`
- * is a structure offering the following specific library types:
+ * `UserCompClsT` is the actual C++ user component class and `TypesT`
+ * is a structure offering the following specific types:
  *
- * `SelfCompCls`:
- *     Self component class.
+ * `LibSelfCompCls`:
+ *     Self component class library type.
  *
- * `SelfComp`:
- *     Self component.
+ * `LibSelfComp`:
+ *     Self component library type.
+ *
+ * `LibSelfCompCfg`:
+ *     Self component configuration library type.
  *
- * `SelfCompCfg`:
- *     Self component configuration.
+ * `SelfComp`:
+ *     Self component type.
  */
-template <typename UserCompClsT, typename LibTypesT>
+template <typename UserCompClsT, typename TypesT>
 class CompClsBridge
 {
 private:
-    using _LibSelfCompPtr = typename LibTypesT::SelfComp *;
+    using _LibSelfCompPtr = typename TypesT::LibSelfComp *;
 
 public:
     static UserCompClsT& userCompFromLibSelfCompPtr(const _LibSelfCompPtr libSelfCompPtr) noexcept
     {
-        return wrap(libSelfCompPtr).template data<UserCompClsT>();
+        return typename TypesT::SelfComp {libSelfCompPtr}.template data<UserCompClsT>();
     }
 
     static bt_component_class_initialize_method_status init(const _LibSelfCompPtr libSelfCompPtr,
-                                                            typename LibTypesT::SelfCompCfg *,
+                                                            typename TypesT::LibSelfCompCfg *,
                                                             const bt_value * const libParamsPtr,
                                                             void * const initData) noexcept
     {
-        const auto selfComp = wrap(libSelfCompPtr);
+        const auto selfComp = typename TypesT::SelfComp {libSelfCompPtr};
 
         try {
             const auto comp =
-                new UserCompClsT {selfComp, wrap(libParamsPtr).asMap(),
+                new UserCompClsT {selfComp, ConstMapValue {libParamsPtr},
                                   static_cast<typename UserCompClsT::InitData *>(initData)};
 
             selfComp.data(*comp);
@@ -86,15 +96,16 @@ public:
     }
 
     static bt_component_class_get_supported_mip_versions_method_status
-    getSupportedMipVersions(typename LibTypesT::SelfCompCls * const libSelfCompClsPtr,
+    getSupportedMipVersions(typename TypesT::LibSelfCompCls * const libSelfCompClsPtr,
                             const bt_value * const libParamsPtr, void *,
                             const bt_logging_level logLevel,
                             bt_integer_range_set_unsigned * const libSupportedVersionsPtr) noexcept
     {
         try {
             UserCompClsT::getSupportedMipVersions(
-                wrap(libSelfCompClsPtr), wrap(libParamsPtr).asMap(),
-                static_cast<LoggingLevel>(logLevel), wrap(libSupportedVersionsPtr));
+                SelfComponentClass {libSelfCompClsPtr}, ConstMapValue {libParamsPtr},
+                static_cast<LoggingLevel>(logLevel),
+                UnsignedIntegerRangeSet {libSupportedVersionsPtr});
             return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_OK;
         } catch (const std::bad_alloc&) {
             return BT_COMPONENT_CLASS_GET_SUPPORTED_MIP_VERSIONS_METHOD_STATUS_MEMORY_ERROR;
@@ -108,17 +119,17 @@ public:
     }
 
     static bt_component_class_query_method_status
-    query(typename LibTypesT::SelfCompCls * const libSelfCompClsPtr,
+    query(typename TypesT::LibSelfCompCls * const libSelfCompClsPtr,
           bt_private_query_executor * const libPrivQueryExecPtr, const char * const object,
           const bt_value * const libParamsPtr, void * const data,
           const bt_value ** const libResultPtr) noexcept
     {
-        const auto privQueryExec = wrap(libPrivQueryExecPtr);
+        const auto privQueryExec = PrivateQueryExecutor {libPrivQueryExecPtr};
 
         try {
             auto result = UserCompClsT::query(
-                wrap(libSelfCompClsPtr), privQueryExec, object, wrap(libParamsPtr),
-                static_cast<typename UserCompClsT::QueryData *>(data));
+                SelfComponentClass {libSelfCompClsPtr}, privQueryExec, object,
+                ConstValue {libParamsPtr}, static_cast<typename UserCompClsT::QueryData *>(data));
 
             *libResultPtr = result.release().libObjPtr();
             return BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
@@ -138,25 +149,27 @@ public:
     }
 };
 
-template <typename SpecCompClsBridgeT, typename LibTypesT>
+template <typename SpecCompClsBridgeT, typename TypesT>
 struct CompClsBridgeWithInputPorts
 {
     static bt_component_class_port_connected_method_status
-    inputPortConnected(typename LibTypesT::SelfComp * const libSelfCompPtr,
+    inputPortConnected(typename TypesT::LibSelfComp * const libSelfCompPtr,
                        bt_self_component_port_input * const libSelfCompPortPtr,
                        const bt_port_output * const libOtherPortPtr) noexcept
     {
         try {
             SpecCompClsBridgeT::userCompFromLibSelfCompPtr(libSelfCompPtr)
-                .inputPortConnected(wrap(libSelfCompPortPtr), wrap(libOtherPortPtr));
+                .inputPortConnected(SelfComponentInputPort {libSelfCompPortPtr},
+                                    ConstOutputPort {libOtherPortPtr});
         } catch (const std::bad_alloc&) {
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR;
         } catch (const Error&) {
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR;
         } catch (...) {
-            BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING,
-                                 static_cast<int>(wrap(libSelfCompPtr).loggingLevel()),
-                                 unhandledExcLogTag(), unhandledExcLogStr());
+            BT_LOG_WRITE_CUR_LVL(
+                BT_LOG_WARNING,
+                static_cast<int>(typename TypesT::SelfComp {libSelfCompPtr}.loggingLevel()),
+                unhandledExcLogTag(), unhandledExcLogStr());
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR;
         }
 
@@ -164,25 +177,27 @@ struct CompClsBridgeWithInputPorts
     }
 };
 
-template <typename SpecCompClsBridgeT, typename LibTypesT>
+template <typename SpecCompClsBridgeT, typename TypesT>
 struct CompClsBridgeWithOutputPorts
 {
     static bt_component_class_port_connected_method_status
-    outputPortConnected(typename LibTypesT::SelfComp * const libSelfCompPtr,
+    outputPortConnected(typename TypesT::LibSelfComp * const libSelfCompPtr,
                         bt_self_component_port_output * const libSelfCompPortPtr,
                         const bt_port_input * const libOtherPortPtr) noexcept
     {
         try {
             SpecCompClsBridgeT::userCompFromLibSelfCompPtr(libSelfCompPtr)
-                .outputPortConnected(wrap(libSelfCompPortPtr), wrap(libOtherPortPtr));
+                .outputPortConnected(SelfComponentOutputPort {libSelfCompPortPtr},
+                                     ConstInputPort {libOtherPortPtr});
         } catch (const std::bad_alloc&) {
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_MEMORY_ERROR;
         } catch (const Error&) {
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR;
         } catch (...) {
-            BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING,
-                                 static_cast<int>(wrap(libSelfCompPtr).loggingLevel()),
-                                 unhandledExcLogTag(), unhandledExcLogStr());
+            BT_LOG_WRITE_CUR_LVL(
+                BT_LOG_WARNING,
+                static_cast<int>(typename TypesT::SelfComp {libSelfCompPtr}.loggingLevel()),
+                unhandledExcLogTag(), unhandledExcLogStr());
             return BT_COMPONENT_CLASS_PORT_CONNECTED_METHOD_STATUS_ERROR;
         }
 
@@ -190,49 +205,52 @@ struct CompClsBridgeWithOutputPorts
     }
 };
 
-struct SrcCompClsLibTypes final
+struct SrcCompClsTypes final
 {
-    using SelfCompCls = bt_self_component_class_source;
-    using SelfComp = bt_self_component_source;
-    using SelfCompCfg = bt_self_component_source_configuration;
+    using LibSelfCompCls = bt_self_component_class_source;
+    using LibSelfComp = bt_self_component_source;
+    using LibSelfCompCfg = bt_self_component_source_configuration;
+    using SelfComp = SelfSourceComponent;
 };
 
 template <typename UserCompClsT>
 class SrcCompClsBridge final :
-    public CompClsBridge<UserCompClsT, SrcCompClsLibTypes>,
-    public CompClsBridgeWithOutputPorts<SrcCompClsBridge<UserCompClsT>, SrcCompClsLibTypes>
+    public CompClsBridge<UserCompClsT, SrcCompClsTypes>,
+    public CompClsBridgeWithOutputPorts<SrcCompClsBridge<UserCompClsT>, SrcCompClsTypes>
 {
 };
 
-struct FltCompClsLibTypes final
+struct FltCompClsTypes final
 {
-    using SelfCompCls = bt_self_component_class_filter;
-    using SelfComp = bt_self_component_filter;
-    using SelfCompCfg = bt_self_component_filter_configuration;
+    using LibSelfCompCls = bt_self_component_class_filter;
+    using LibSelfComp = bt_self_component_filter;
+    using LibSelfCompCfg = bt_self_component_filter_configuration;
+    using SelfComp = SelfFilterComponent;
 };
 
 template <typename UserCompClsT>
 class FltCompClsBridge final :
-    public CompClsBridge<UserCompClsT, FltCompClsLibTypes>,
-    public CompClsBridgeWithInputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsLibTypes>,
-    public CompClsBridgeWithOutputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsLibTypes>
+    public CompClsBridge<UserCompClsT, FltCompClsTypes>,
+    public CompClsBridgeWithInputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsTypes>,
+    public CompClsBridgeWithOutputPorts<FltCompClsBridge<UserCompClsT>, FltCompClsTypes>
 {
 };
 
-struct SinkCompClsLibTypes final
+struct SinkCompClsTypes final
 {
-    using SelfCompCls = bt_self_component_class_sink;
-    using SelfComp = bt_self_component_sink;
-    using SelfCompCfg = bt_self_component_sink_configuration;
+    using LibSelfCompCls = bt_self_component_class_sink;
+    using LibSelfComp = bt_self_component_sink;
+    using LibSelfCompCfg = bt_self_component_sink_configuration;
+    using SelfComp = SelfSinkComponent;
 };
 
 template <typename UserCompClsT>
 class SinkCompClsBridge final :
-    public CompClsBridge<UserCompClsT, SinkCompClsLibTypes>,
-    public CompClsBridgeWithInputPorts<SinkCompClsBridge<UserCompClsT>, SinkCompClsLibTypes>
+    public CompClsBridge<UserCompClsT, SinkCompClsTypes>,
+    public CompClsBridgeWithInputPorts<SinkCompClsBridge<UserCompClsT>, SinkCompClsTypes>
 {
 public:
-    using CompClsBridge<UserCompClsT, SinkCompClsLibTypes>::userCompFromLibSelfCompPtr;
+    using CompClsBridge<UserCompClsT, SinkCompClsTypes>::userCompFromLibSelfCompPtr;
 
     static bt_component_class_sink_consume_method_status
     consume(bt_self_component_sink * const libSelfCompPtr) noexcept
@@ -250,9 +268,9 @@ public:
         } catch (const Error&) {
             return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
         } catch (...) {
-            BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING,
-                                 static_cast<int>(wrap(libSelfCompPtr).loggingLevel()),
-                                 unhandledExcLogTag(), unhandledExcLogStr());
+            BT_LOG_WRITE_CUR_LVL(
+                BT_LOG_WARNING, static_cast<int>(SelfSinkComponent {libSelfCompPtr}.loggingLevel()),
+                unhandledExcLogTag(), unhandledExcLogStr());
             return BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
         }
     }
@@ -268,9 +286,9 @@ public:
         } catch (const Error&) {
             return BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
         } catch (...) {
-            BT_LOG_WRITE_CUR_LVL(BT_LOG_WARNING,
-                                 static_cast<int>(wrap(libSelfCompPtr).loggingLevel()),
-                                 unhandledExcLogTag(), unhandledExcLogStr());
+            BT_LOG_WRITE_CUR_LVL(
+                BT_LOG_WARNING, static_cast<int>(SelfSinkComponent {libSelfCompPtr}.loggingLevel()),
+                unhandledExcLogTag(), unhandledExcLogStr());
             return BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR;
         }
     }
@@ -283,7 +301,7 @@ public:
     static UserMsgIterT&
     userMsgIterFromLibSelfMsgIterPtr(bt_self_message_iterator * const libSelfMsgIterPtr) noexcept
     {
-        return wrap(libSelfMsgIterPtr).data<UserMsgIterT>();
+        return SelfMessageIterator {libSelfMsgIterPtr}.data<UserMsgIterT>();
     }
 
     static bt_message_iterator_class_initialize_method_status
@@ -291,11 +309,12 @@ public:
          bt_self_message_iterator_configuration * const libSelfMsgIterConfigPtr,
          bt_self_component_port_output * const libSelfCompPortPtr) noexcept
     {
-        const auto selfMsgIter = wrap(libSelfMsgIterPtr);
+        const auto selfMsgIter = SelfMessageIterator {libSelfMsgIterPtr};
 
         try {
-            const auto msgIter = new UserMsgIterT {selfMsgIter, wrap(libSelfMsgIterConfigPtr),
-                                                   wrap(libSelfCompPortPtr)};
+            const auto msgIter = new UserMsgIterT {
+                selfMsgIter, SelfMessageIteratorConfiguration {libSelfMsgIterConfigPtr},
+                SelfComponentOutputPort {libSelfCompPortPtr}};
 
             selfMsgIter.data(*msgIter);
         } catch (const std::bad_alloc&) {
@@ -305,7 +324,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
         }
@@ -343,7 +363,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR;
         }
@@ -365,7 +386,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_ERROR;
         }
@@ -387,7 +409,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_ERROR;
         }
@@ -411,7 +434,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR;
         }
@@ -434,7 +458,8 @@ public:
         } catch (...) {
             BT_LOG_WRITE_CUR_LVL(
                 BT_LOG_WARNING,
-                static_cast<int>(wrap(libSelfMsgIterPtr).component().loggingLevel()),
+                static_cast<int>(
+                    SelfMessageIterator {libSelfMsgIterPtr}.component().loggingLevel()),
                 unhandledExcLogTag(), unhandledExcLogStr());
             return BT_MESSAGE_ITERATOR_CLASS_SEEK_NS_FROM_ORIGIN_METHOD_STATUS_ERROR;
         }
This page took 0.031415 seconds and 4 git commands to generate.