LCOV - code coverage report
Current view: top level - src/plugin - pluginloader.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 6 14 42.9 %
Date: 2024-04-26 09:41:19 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, write to the Free Software
      18             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
      19             :  * USA.
      20             :  */
      21             : 
      22             : #include "pluginloader.h"
      23             : 
      24             : namespace jami {
      25             : 
      26             : Plugin*
      27           8 : Plugin::load(const std::string& path, std::string& error)
      28             : {
      29           8 :     if (path.empty()) {
      30           0 :         error = "Empty path";
      31           0 :         return nullptr;
      32             :     }
      33             : 
      34             :     // Clear any existing error
      35           8 :     ::dlerror();
      36             : 
      37           8 :     void* handle = ::dlopen(path.c_str(), RTLD_NOW);
      38           8 :     if (!handle) {
      39           0 :         error += "Failed to load \"" + path + '"';
      40             : 
      41           0 :         std::string dlError = ::dlerror();
      42           0 :         if (dlError.size())
      43           0 :             error += " (" + dlError + ")";
      44           0 :         return nullptr;
      45           0 :     }
      46             : 
      47           8 :     return new DLPlugin(handle, path);
      48             : }
      49             : } // namespace jami

Generated by: LCOV version 1.14