LCOV - code coverage report
Current view: top level - src - call_factory.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 10 10 100.0 %
Date: 2024-03-28 08:00:27 Functions: 3 3 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 USA.
      19             :  */
      20             : 
      21             : #pragma once
      22             : 
      23             : #include <map>
      24             : #include <memory>
      25             : #include <mutex>
      26             : #include <vector>
      27             : #include <string>
      28             : #include <utility>
      29             : 
      30             : #include "call.h"
      31             : #include "account.h"
      32             : 
      33             : namespace jami {
      34             : 
      35             : class SIPAccountBase;
      36             : class SIPCall;
      37             : 
      38             : class CallFactory
      39             : {
      40             : public:
      41          38 :     CallFactory(std::mt19937_64& rand)
      42          38 :         : rand_(rand)
      43          38 :     {}
      44             : 
      45             :     std::string getNewCallID() const;
      46             : 
      47             :     /**
      48             :      * Create a new call instance.
      49             :      * @param account Account used to create this call
      50             :      * @param type Set definitely this call as incoming/outgoing
      51             :      * @param mediaList The list of media to include
      52             :      * @return A shared pointer to the created call
      53             :      */
      54             :     std::shared_ptr<SIPCall> newSipCall(const std::shared_ptr<SIPAccountBase>& account,
      55             :                                         Call::CallType type,
      56             :                                         const std::vector<libjami::MediaMap>& mediaList);
      57             : 
      58             :     /**
      59             :      * Forbid creation of new calls.
      60             :      */
      61             :     void forbid();
      62             : 
      63             :     /**
      64             :      * Remove given call instance from call list.
      65             :      */
      66             :     void removeCall(Call& call);
      67             : 
      68             :     /**
      69             :      * Accessor on removeCall with callID than instance.
      70             :      */
      71             :     void removeCall(const std::string& id);
      72             : 
      73             :     /**
      74             :      * Return call pointer associated to given ID.Type can optionally be specified.
      75             :      */
      76             :     std::shared_ptr<Call> getCall(const std::string& id) const;
      77             :     std::shared_ptr<Call> getCall(const std::string& id, Call::LinkType link) const;
      78             : 
      79             :     template<class C>
      80           2 :     std::shared_ptr<C> getCall(const std::string& id)
      81             :     {
      82           2 :         return std::dynamic_pointer_cast<C>(getCall(id, C::LINK_TYPE));
      83             :     }
      84             : 
      85             :     /**
      86             :      * Return if given call exists. Type can optionally be specified.
      87             :      */
      88             :     bool hasCall(const std::string& id) const;
      89             :     bool hasCall(const std::string& id, Call::LinkType link) const;
      90             : 
      91             :     /**
      92             :      * Return if calls exist. Type can optionally be specified.
      93             :      */
      94             :     bool empty() const;
      95             :     bool empty(Call::LinkType link) const;
      96             : 
      97             :     /**
      98             :      * Erase all calls.
      99             :      */
     100             :     void clear();
     101             : 
     102             :     /**
     103             :      * Return all calls. Type can optionally be specified.
     104             :      */
     105             :     std::vector<std::shared_ptr<Call>> getAllCalls() const;
     106             :     std::vector<std::shared_ptr<Call>> getAllCalls(Call::LinkType link) const;
     107             : 
     108             :     /**
     109             :      * Return all call's IDs. Type can optionally be specified.
     110             :      */
     111             :     std::vector<std::string> getCallIDs() const;
     112             :     std::vector<std::string> getCallIDs(Call::LinkType link) const;
     113             : 
     114             :     /**
     115             :      * Return number of calls. Type can optionally be specified.
     116             :      */
     117             :     std::size_t callCount() const;
     118             :     std::size_t callCount(Call::LinkType link) const;
     119             : 
     120             : private:
     121             :     /**
     122             :      * @brief Get the calls map
     123             :      * @param link The call type
     124             :      * @return A pointer to the calls map instance
     125             :      * @warning Concurrency protection must done by the caller.
     126             :      */
     127          35 :     const CallMap* getMap_(Call::LinkType link) const
     128             :     {
     129          35 :         auto const& itermap = callMaps_.find(link);
     130          35 :         if (itermap != callMaps_.cend())
     131           2 :             return &itermap->second;
     132          33 :         return nullptr;
     133             :     }
     134             : 
     135             :     std::mt19937_64& rand_;
     136             : 
     137             :     mutable std::recursive_mutex callMapsMutex_ {};
     138             : 
     139             :     std::atomic_bool allowNewCall_ {true};
     140             : 
     141             :     std::map<Call::LinkType, CallMap> callMaps_ {};
     142             : };
     143             : 
     144             : } // namespace jami

Generated by: LCOV version 1.14