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

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 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         308 : init(enum InitFlag flags) noexcept
      45             : {
      46         308 :     initFlags = flags;
      47         308 :     jami::Logger::setDebugMode(LIBJAMI_FLAG_DEBUG == (flags & LIBJAMI_FLAG_DEBUG));
      48             : 
      49         308 :     jami::Logger::setSysLog(true);
      50         308 :     jami::Logger::setConsoleLog(LIBJAMI_FLAG_CONSOLE_LOG == (flags & LIBJAMI_FLAG_CONSOLE_LOG));
      51             : 
      52         308 :     const char* log_file = getenv("JAMI_LOG_FILE");
      53             : 
      54         308 :     if (log_file) {
      55           0 :         jami::Logger::setFileLog(log_file);
      56             :     }
      57             : 
      58             :     // Following function create a local static variable inside
      59             :     // This var must have the same live as Manager.
      60             :     // So we call it now to create this var.
      61         308 :     jami::getSignalHandlers();
      62             : 
      63             :     try {
      64             :         // current implementation use static variable
      65         308 :         auto& manager = jami::Manager::instance();
      66         308 :         manager.setAutoAnswer(flags & LIBJAMI_FLAG_AUTOANSWER);
      67             : 
      68             : #if TARGET_OS_IOS
      69             :         if (flags & LIBJAMI_FLAG_IOS_EXTENSION)
      70             :             manager.isIOSExtension = true;
      71             : #endif
      72         308 :         if (flags & LIBJAMI_FLAG_NO_AUTOSYNC)
      73           0 :             manager.syncOnRegister = false;
      74             : 
      75         308 :         return true;
      76           0 :     } catch (...) {
      77           0 :         return false;
      78           0 :     }
      79             : }
      80             : 
      81             : bool
      82          33 : start(const std::filesystem::path& config_file) noexcept
      83             : {
      84             :     try {
      85          33 :         jami::Manager::instance().init(config_file, initFlags);
      86           0 :     } catch (...) {
      87           0 :         return false;
      88           0 :     }
      89          33 :     return true;
      90             : }
      91             : 
      92             : bool
      93           0 : initialized() noexcept
      94             : {
      95           0 :     return jami::Manager::initialized;
      96             : }
      97             : 
      98             : void
      99         308 : fini() noexcept
     100             : {
     101         308 :     jami::Manager::instance().finish();
     102         308 :     jami::Logger::fini();
     103         308 : }
     104             : 
     105             : void
     106           0 : logging(const std::string& whom, const std::string& action) noexcept
     107             : {
     108           0 :     if ("syslog" == whom) {
     109           0 :         jami::Logger::setSysLog(not action.empty());
     110           0 :     } else if ("console" == whom) {
     111           0 :         jami::Logger::setConsoleLog(not action.empty());
     112           0 :     } else if ("monitor" == whom) {
     113           0 :         jami::Logger::setMonitorLog(not action.empty());
     114           0 :     } else if ("file" == whom) {
     115           0 :         jami::Logger::setFileLog(action);
     116             :     } else {
     117           0 :         JAMI_ERR("Bad log handler %s", whom.c_str());
     118             :     }
     119           0 : }
     120             : 
     121             : void
     122           0 : CallbackWrapperBase::post(std::function<void()> cb)
     123             : {
     124           0 :     if (auto io = jami::Manager::instance().ioContext())
     125           0 :         io->post(std::move(cb));
     126           0 : }
     127             : 
     128             : } // namespace libjami

Generated by: LCOV version 1.14