MediaDiscoverer.hpp 3.02 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1
/*****************************************************************************
2
 * MediaDiscoverer.hpp: MediaDiscoverer API
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
3
 *****************************************************************************
4
 * Copyright © 2015 libvlcpp authors & VideoLAN
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
5 6
 *
 * Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
7
 *          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef LIBVLC_CXX_MEDIADISCOVERER_H
#define LIBVLC_CXX_MEDIADISCOVERER_H

27 28
#include "common.hpp"

29
#include <string>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
30

31
namespace VLC
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
32 33
{

34
class MediaDiscovererEventManager;
35
class Instance;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
36

37
class MediaDiscoverer : public Internal<libvlc_media_discoverer_t>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38 39 40 41 42 43 44 45 46
{
public:
    // libvlc_media_discoverer_new_from_name
    /**
     * Discover media service by name.
     *
     * \param p_inst  libvlc instance
     *
     * \param psz_name  service name
47 48
     * \warning This is returned as a pointer, as this is not refcounter by VLC, and is
     *          fairly expensive to instantiate.
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
49
     */
50 51
    MediaDiscoverer(Instance& inst, const std::string& name)
        : Internal{ libvlc_media_discoverer_new_from_name(getInternalPtr<libvlc_instance_t>( inst ), name.c_str()),
52 53 54
                    libvlc_media_discoverer_release }
    {
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
55 56 57 58 59 60

    /**
     * Get media service discover object its localized name.
     *
     * \return localized name
     */
61 62
    std::string localizedName()
    {
63 64 65 66
        auto str = wrapCStr( libvlc_media_discoverer_localized_name(*this) );
        if ( str == nullptr )
            return {};
        return str.get();
67
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
68 69 70 71 72 73

    /**
     * Get event manager from media service discover object.
     *
     * \return event manager object.
     */
74
    MediaDiscovererEventManager& eventManager()
75 76 77
    {
        if ( m_eventManager )
        {
78
            libvlc_event_manager_t* obj = libvlc_media_discoverer_event_manager( *this );
79
            m_eventManager = std::make_shared<MediaDiscovererEventManager>( obj );
80
        }
81
        return *m_eventManager;
82
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
83 84 85 86 87 88

    /**
     * Query if media service discover object is running.
     *
     * \return true if running, false if not
     */
89 90
    bool isRunning()
    {
91
        return libvlc_media_discoverer_is_running(*this);
92
    }
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93 94

private:
95
    std::shared_ptr<MediaDiscovererEventManager> m_eventManager;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
96 97 98 99 100 101
};

} // namespace VLC

#endif