LCOV - code coverage report
Current view: top level - foo/src - ring_api.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 19 44 43.2 %
Date: 2025-08-24 09:11:10 Functions: 3 6 50.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2025 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #include <asio.hpp>
      18             : #include <string>
      19             : #include <vector>
      20             : #include <map>
      21             : #include <cstdlib>
      22             : 
      23             : #ifdef HAVE_CONFIG_H
      24             : #include "config.h"
      25             : #endif
      26             : 
      27             : #include "manager.h"
      28             : #include "logger.h"
      29             : #include "jami.h"
      30             : #include "callmanager_interface.h"
      31             : #include "configurationmanager_interface.h"
      32             : #include "presencemanager_interface.h"
      33             : #include "client/ring_signal.h"
      34             : 
      35             : #ifdef ENABLE_VIDEO
      36             : #include "client/videomanager.h"
      37             : #endif // ENABLE_VIDEO
      38             : 
      39             : namespace libjami {
      40             : 
      41             : InitFlag initFlags = {};
      42             : 
      43             : bool
      44         265 : init(enum InitFlag flags) noexcept
      45             : {
      46         265 :     initFlags = flags;
      47         265 :     jami::Logger::setDebugMode(LIBJAMI_FLAG_DEBUG == (flags & LIBJAMI_FLAG_DEBUG));
      48         265 :     jami::Logger::setSysLog(LIBJAMI_FLAG_SYSLOG == (flags & LIBJAMI_FLAG_SYSLOG));
      49         265 :     jami::Logger::setConsoleLog(LIBJAMI_FLAG_CONSOLE_LOG == (flags & LIBJAMI_FLAG_CONSOLE_LOG));
      50             : 
      51         265 :     const char* log_file = getenv("JAMI_LOG_FILE");
      52             : 
      53         265 :     if (log_file) {
      54           0 :         jami::Logger::setFileLog(log_file);
      55             :     }
      56             : 
      57             :     // Following function create a local static variable inside
      58             :     // This var must have the same live as Manager.
      59             :     // So we call it now to create this var.
      60         265 :     jami::getSignalHandlers();
      61             : 
      62             :     try {
      63             :         // current implementation use static variable
      64         265 :         auto& manager = jami::Manager::instance();
      65         265 :         manager.setAutoAnswer(flags & LIBJAMI_FLAG_AUTOANSWER);
      66             : 
      67             : #if TARGET_OS_IOS
      68             :         if (flags & LIBJAMI_FLAG_IOS_EXTENSION)
      69             :             manager.isIOSExtension = true;
      70             : #endif
      71         265 :         if (flags & LIBJAMI_FLAG_NO_AUTOSYNC)
      72           0 :             manager.syncOnRegister = false;
      73             : 
      74         265 :         return true;
      75           0 :     } catch (...) {
      76           0 :         return false;
      77           0 :     }
      78             : }
      79             : 
      80             : bool
      81          33 : start(const std::filesystem::path& config_file) noexcept
      82             : {
      83             :     try {
      84          33 :         jami::Manager::instance().init(config_file, initFlags);
      85           0 :     } catch (...) {
      86           0 :         return false;
      87           0 :     }
      88          33 :     return true;
      89             : }
      90             : 
      91             : bool
      92           0 : initialized() noexcept
      93             : {
      94           0 :     return jami::Manager::initialized;
      95             : }
      96             : 
      97             : void
      98         265 : fini() noexcept
      99             : {
     100         265 :     jami::Manager::instance().finish();
     101         265 :     jami::Logger::fini();
     102         265 : }
     103             : 
     104             : void
     105           0 : logging(const std::string& whom, const std::string& action) noexcept
     106             : {
     107           0 :     if ("syslog" == whom) {
     108           0 :         jami::Logger::setSysLog(not action.empty());
     109           0 :     } else if ("console" == whom) {
     110           0 :         jami::Logger::setConsoleLog(not action.empty());
     111           0 :     } else if ("monitor" == whom) {
     112           0 :         jami::Logger::setMonitorLog(not action.empty());
     113           0 :     } else if ("file" == whom) {
     114           0 :         jami::Logger::setFileLog(action);
     115             :     } else {
     116           0 :         JAMI_ERR("Bad log handler %s", whom.c_str());
     117             :     }
     118           0 : }
     119             : 
     120             : void
     121           0 : CallbackWrapperBase::post(std::function<void()> cb)
     122             : {
     123           0 :     if (auto io = jami::Manager::instance().ioContext())
     124           0 :         asio::post(*io, std::move(cb));
     125           0 : }
     126             : 
     127             : } // namespace libjami

Generated by: LCOV version 1.14