LCOV - code coverage report
Current view: top level - modules/intra - intra_conf.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 34 36 94.4 %
Date: 2026-06-27 19:56:04 Functions: 14 15 93.3 %
Branches: 32 50 64.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2026 by Thun Lu. All rights reserved.
       3                 :            :  * Author: Thun Lu <thun.lu@zohomail.cn>
       4                 :            :  * Repo:   https://github.com/thun-res/vlink
       5                 :            :  *  _    __   __      _           __
       6                 :            :  * | |  / /  / /     (_) ____    / /__
       7                 :            :  * | | / /  / /     / / / __ \  / //_/
       8                 :            :  * | |/ /  / /___  / / / / / / / ,<
       9                 :            :  * |___/  /_____/ /_/ /_/ /_/ /_/|_|
      10                 :            :  *
      11                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
      12                 :            :  * you may not use this file except in compliance with the License.
      13                 :            :  * You may obtain a copy of the License at
      14                 :            :  *
      15                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
      16                 :            :  *
      17                 :            :  * Unless required by applicable law or agreed to in writing, software
      18                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      19                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      20                 :            :  * See the License for the specific language governing permissions and
      21                 :            :  * limitations under the License.
      22                 :            :  */
      23                 :            : 
      24                 :            : #include "./modules/intra_conf.h"
      25                 :            : 
      26                 :            : #include <memory>
      27                 :            : 
      28                 :            : #include "./base/helpers.h"
      29                 :            : #include "./base/logger.h"
      30                 :            : #include "./impl/conf_plugin_interface.h"
      31                 :            : #include "./impl/url.h"
      32                 :            : #include "./intra_client_impl.h"
      33                 :            : #include "./intra_getter_impl.h"
      34                 :            : #include "./intra_publisher_impl.h"
      35                 :            : #include "./intra_server_impl.h"
      36                 :            : #include "./intra_setter_impl.h"
      37                 :            : #include "./intra_subscriber_impl.h"
      38                 :            : 
      39                 :            : namespace vlink {
      40                 :            : 
      41                 :            : VLINK_DEFINE_GLOBAL_PROPERTY(IntraConf)
      42                 :            : 
      43                 :            : // IntraConf
      44                 :          2 : void IntraConf::global_init() { IntraFactory::get(); }
      45                 :            : 
      46                 :        202 : bool IntraConf::parse_protocol(struct Protocol* protocol) {
      47         [ -  + ]:        202 :   if VUNLIKELY (get_impl_type() == kUnknownImplType) {
      48   [ #  #  #  # ]:          0 :     VLOG_F("IntraConf: Unknown node type, cannot parse protocol.");
      49                 :            : 
      50                 :          0 :     return false;
      51                 :            :   }
      52                 :            : 
      53         [ +  + ]:        202 :   if VUNLIKELY (protocol->host.empty()) {
      54                 :          2 :     return false;
      55                 :            :   }
      56                 :            : 
      57   [ +  +  +  -  :        200 :   address = protocol->host + (protocol->path.empty() ? "" : "/" + protocol->path);
          +  -  +  -  +  
                +  -  - ]
      58   [ +  -  +  -  :        200 :   event = protocol->dictionary["event"];
                   +  - ]
      59   [ +  -  +  - ]:        200 :   pipeline = Helpers::to_int(protocol->dictionary["pipeline"], 0);
      60                 :            : 
      61         [ +  + ]:        200 :   if (!protocol->fragment.empty()) {
      62                 :         12 :     type = protocol->fragment;
      63                 :            :   }
      64                 :            : 
      65                 :        200 :   return true;
      66                 :            : }
      67                 :            : 
      68                 :        383 : bool IntraConf::is_valid() const {
      69         [ +  + ]:        383 :   if VUNLIKELY (address.empty()) {
      70                 :          2 :     return false;
      71                 :            :   }
      72                 :            : 
      73   [ +  +  +  +  :        381 :   if VUNLIKELY (type != "queue" && type != "direct") {
                   +  + ]
      74                 :          2 :     return false;
      75                 :            :   }
      76                 :            : 
      77                 :        379 :   return true;
      78                 :            : }
      79                 :            : 
      80                 :         39 : std::unique_ptr<ServerImpl> IntraConf::create_server() const { return std::make_unique<IntraServerImpl>(*this); }
      81                 :            : 
      82                 :         41 : std::unique_ptr<ClientImpl> IntraConf::create_client() const { return std::make_unique<IntraClientImpl>(*this); }
      83                 :            : 
      84                 :        130 : std::unique_ptr<PublisherImpl> IntraConf::create_publisher() const {
      85                 :        130 :   return std::make_unique<IntraPublisherImpl>(*this);
      86                 :            : }
      87                 :            : 
      88                 :        146 : std::unique_ptr<SubscriberImpl> IntraConf::create_subscriber() const {
      89                 :        146 :   return std::make_unique<IntraSubscriberImpl>(*this);
      90                 :            : }
      91                 :            : 
      92                 :          9 : std::unique_ptr<SetterImpl> IntraConf::create_setter() const { return std::make_unique<IntraSetterImpl>(*this); }
      93                 :            : 
      94                 :         13 : std::unique_ptr<GetterImpl> IntraConf::create_getter() const { return std::make_unique<IntraGetterImpl>(*this); }
      95                 :            : 
      96                 :          2 : std::ostream& operator<<(std::ostream& ostream, const IntraConf& conf) noexcept {
      97                 :          2 :   std::ios_base::fmtflags f = ostream.flags();
      98                 :            : 
      99                 :            :   ostream << "IntraConf:"
     100                 :          2 :           << "[type]" << +conf.get_impl_type() << "[address]" << conf.address << "[event]" << conf.event << "[pipeline]"
     101                 :          2 :           << conf.pipeline << "[type]" << conf.type;
     102                 :            : 
     103                 :          2 :   ostream.flags(f);
     104                 :            : 
     105                 :          2 :   return ostream;
     106                 :            : }
     107                 :            : 
     108                 :            : class ConfPluginIntra : public ConfPluginInterface {
     109                 :            :  protected:
     110                 :          1 :   TransportType get_transport_type() const override { return TransportType::kIntra; }
     111                 :            : 
     112                 :          1 :   std::unique_ptr<Conf> create() const override { return std::make_unique<IntraConf>(); }
     113                 :            : };
     114                 :            : 
     115                 :            : #ifdef VLINK_LIBRARY
     116   [ +  +  +  -  :          3 : VLINK_PLUGIN_DECLARE(ConfPluginIntra, 1, 0)
          +  -  +  -  +  
                      + ]
     117                 :            : #endif
     118                 :            : 
     119                 :            : }  // namespace vlink

Generated by: LCOV version 1.14