LCOV - code coverage report
Current view: top level - src/ipc/libmultiprocess/include/mp - type-interface.h (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 54.8 % 31 17
Test Date: 2025-08-25 05:11:47 Functions: 17.6 % 34 6
Branches: 32.5 % 40 13

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #ifndef MP_PROXY_TYPE_INTERFACE_H
       6                 :             : #define MP_PROXY_TYPE_INTERFACE_H
       7                 :             : 
       8                 :             : #include <mp/util.h>
       9                 :             : 
      10                 :             : namespace mp {
      11                 :             : template <typename Interface, typename Impl>
      12                 :           6 : kj::Own<typename Interface::Server> MakeProxyServer(InvokeContext& context, std::shared_ptr<Impl> impl)
      13                 :             : {
      14         [ +  - ]:          12 :     return kj::heap<ProxyServer<Interface>>(std::move(impl), context.connection);
      15                 :           0 : }
      16                 :             : 
      17                 :             : template <typename Interface, typename Impl>
      18         [ +  - ]:           6 : kj::Own<typename Interface::Server> CustomMakeProxyServer(InvokeContext& context, std::shared_ptr<Impl>&& impl)
      19                 :             : {
      20   [ +  -  -  + ]:           6 :     return MakeProxyServer<Interface, Impl>(context, std::move(impl));
      21                 :             : }
      22                 :             : 
      23                 :             : template <typename Impl, typename Value, typename Output>
      24         [ +  - ]:           6 : void CustomBuildField(TypeList<std::unique_ptr<Impl>>,
      25                 :             :     Priority<1>,
      26                 :             :     InvokeContext& invoke_context,
      27                 :             :     Value&& value,
      28                 :             :     Output&& output,
      29                 :             :     typename Decay<decltype(output.get())>::Calls* enable = nullptr)
      30                 :             : {
      31         [ +  - ]:           6 :     if (value) {
      32                 :             :         using Interface = typename decltype(output.get())::Calls;
      33   [ +  -  +  -  :          12 :         output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::shared_ptr<Impl>(value.release())));
                   -  + ]
      34                 :             :     }
      35                 :           6 : }
      36                 :             : 
      37                 :             : template <typename Impl, typename Value, typename Output>
      38                 :           0 : void CustomBuildField(TypeList<std::shared_ptr<Impl>>,
      39                 :             :     Priority<2>,
      40                 :             :     InvokeContext& invoke_context,
      41                 :             :     Value&& value,
      42                 :             :     Output&& output,
      43                 :             :     typename Decay<decltype(output.get())>::Calls* enable = nullptr)
      44                 :             : {
      45         [ #  # ]:           0 :     if (value) {
      46                 :             :         using Interface = typename decltype(output.get())::Calls;
      47         [ #  # ]:           0 :         output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::forward<Value>(value)));
      48                 :             :     }
      49                 :           0 : }
      50                 :             : 
      51                 :             : template <typename Impl, typename Output>
      52                 :           0 : void CustomBuildField(TypeList<Impl&>,
      53                 :             :     Priority<1>,
      54                 :             :     InvokeContext& invoke_context,
      55                 :             :     Impl& value,
      56                 :             :     Output&& output,
      57                 :             :     typename decltype(output.get())::Calls* enable = nullptr)
      58                 :             : {
      59                 :             :     // Disable deleter so proxy server object doesn't attempt to delete the
      60                 :             :     // wrapped implementation when the proxy client is destroyed or
      61                 :             :     // disconnected.
      62                 :             :     using Interface = typename decltype(output.get())::Calls;
      63   [ #  #  #  #  :           0 :     output.set(CustomMakeProxyServer<Interface, Impl>(invoke_context, std::shared_ptr<Impl>(&value, [](Impl*){})));
                   #  # ]
      64                 :           0 : }
      65                 :             : 
      66                 :             : template <typename Interface, typename Impl>
      67                 :           6 : std::unique_ptr<Impl> MakeProxyClient(InvokeContext& context, typename Interface::Client&& client)
      68                 :             : {
      69         [ -  + ]:           6 :     return std::make_unique<ProxyClient<Interface>>(
      70         [ -  + ]:           6 :         std::move(client), &context.connection, /* destroy_connection= */ false);
      71                 :             : }
      72                 :             : 
      73                 :             : template <typename Interface, typename Impl>
      74                 :           6 : std::unique_ptr<Impl> CustomMakeProxyClient(InvokeContext& context, typename Interface::Client&& client)
      75                 :             : {
      76                 :           6 :     return MakeProxyClient<Interface, Impl>(context, kj::mv(client));
      77                 :             : }
      78                 :             : 
      79                 :             : template <typename LocalType, typename Input, typename ReadDest>
      80                 :           6 : decltype(auto) CustomReadField(TypeList<std::unique_ptr<LocalType>>,
      81                 :             :     Priority<1>,
      82                 :             :     InvokeContext& invoke_context,
      83                 :             :     Input&& input,
      84                 :             :     ReadDest&& read_dest,
      85                 :             :     typename Decay<decltype(input.get())>::Calls* enable = nullptr)
      86                 :             : {
      87                 :             :     using Interface = typename Decay<decltype(input.get())>::Calls;
      88         [ +  - ]:           6 :     if (input.has()) {
      89                 :           6 :         return read_dest.construct(
      90         [ +  - ]:          12 :                                    CustomMakeProxyClient<Interface, LocalType>(invoke_context, std::move(input.get())));
      91                 :             :     }
      92                 :           0 :     return read_dest.construct();
      93                 :             : }
      94                 :             : 
      95                 :             : template <typename LocalType, typename Input, typename ReadDest>
      96                 :           0 : decltype(auto) CustomReadField(TypeList<std::shared_ptr<LocalType>>,
      97                 :             :     Priority<1>,
      98                 :             :     InvokeContext& invoke_context,
      99                 :             :     Input&& input,
     100                 :             :     ReadDest&& read_dest,
     101                 :             :     typename Decay<decltype(input.get())>::Calls* enable = nullptr)
     102                 :             : {
     103                 :             :     using Interface = typename Decay<decltype(input.get())>::Calls;
     104         [ #  # ]:           0 :     if (input.has()) {
     105                 :           0 :         return read_dest.construct(
     106         [ #  # ]:           0 :             CustomMakeProxyClient<Interface, LocalType>(invoke_context, std::move(input.get())));
     107                 :             :     }
     108                 :           0 :     return read_dest.construct();
     109                 :             : }
     110                 :             : } // namespace mp
     111                 :             : 
     112                 :             : #endif // MP_PROXY_TYPE_INTERFACE_H
        

Generated by: LCOV version 2.0-1