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-04-25 08:05:53 Functions: 3 6 50.0 %

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

Generated by: LCOV version 1.14