Commit fa09e7b4 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Rework MediaDiscoverer

Disable C++11 stuff for now. The code doesn't use it, and I'm not sure
it's a good idea to enforce it if we want a widespread adoption.
Remove references to c_object.
This is unsatisfactory as is, since it enforces using this class as a
pointer to be able to copy it, while we receive our other instances via
reference. We might want to add our own refcounting, or go back to move
semantic, though it's still a usage restriction
parent 6b8cd1df
......@@ -4,6 +4,7 @@
* Copyright © 2014 the VideoLAN team
*
* Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
......@@ -28,58 +29,17 @@
namespace VLC {
MediaDiscoverer::MediaDiscoverer(MediaDiscoverer&& another)
{
m_obj = another.m_obj;
m_own = another.m_own;
another.m_obj = NULL;
another.m_own = false;
}
const MediaDiscoverer& MediaDiscoverer::operator=(MediaDiscoverer&& another)
{
if (this == &another)
{
return *this;
}
if (m_own)
{
libvlc_media_discoverer_release(m_obj);
}
m_obj = another.m_obj;
m_own = another.m_own;
another.m_obj = NULL;
another.m_own = false;
return *this;
}
libvlc_media_discoverer_t* MediaDiscoverer::get_c_object()
{
return m_obj;
}
const libvlc_media_discoverer_t* MediaDiscoverer::get_c_object() const
{
return m_obj;
}
MediaDiscoverer::~MediaDiscoverer()
{
if (m_own)
{
libvlc_media_discoverer_release(m_obj);
}
release();
}
MediaDiscoverer::MediaDiscoverer(Instance & p_inst, const std::string& psz_name)
MediaDiscoverer* MediaDiscoverer::create( Instance &inst, const std::string& name )
{
m_obj = libvlc_media_discoverer_new_from_name(p_inst.get_c_object(), psz_name.c_str());
if (!m_obj)
{
throw Exception("Can't construct MediaDiscoverer");
}
m_own = true;
InternalPtr ptr = libvlc_media_discoverer_new_from_name(inst, name.c_str());
if ( ptr == NULL )
return NULL;
return new MediaDiscoverer( ptr );
}
std::string MediaDiscoverer::localizedName()
......@@ -104,6 +64,11 @@ bool MediaDiscoverer::isRunning()
return result;
}
MediaDiscoverer::MediaDiscoverer(Internal::InternalPtr ptr)
: Internal( ptr )
{
}
void MediaDiscoverer::release()
{
libvlc_media_discoverer_release(m_obj);
......
......@@ -4,6 +4,7 @@
* Copyright © 2014 the VideoLAN team
*
* Authors: Alexey Sokolov <alexey@alexeysokolov.co.cc>
* Hugo Beauzée-Luyssen <hugo@beauzee.fr>
*
* 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
......@@ -37,21 +38,6 @@ namespace VLC
class MediaDiscoverer : public Internal<libvlc_media_discoverer_t>
{
public:
/**
* Move underlying libvlc_media_discoverer_t object from
* MediaDiscoverer another to new MediaDiscoverer.
* \param another existing MediaDiscoverer
*/
MediaDiscoverer(MediaDiscoverer&& another);
/**
* Move underlying libvlc_media_discoverer_t object from
* MediaDiscoverer another to this MediaDiscoverer.
* \param another existing MediaDiscoverer
* \return this
*/
const MediaDiscoverer& operator=(MediaDiscoverer&& another);
~MediaDiscoverer();
// libvlc_media_discoverer_new_from_name
......@@ -62,7 +48,7 @@ public:
*
* \param psz_name service name
*/
MediaDiscoverer(Instance & p_inst, const std::string& psz_name);
static MediaDiscoverer* create(Instance & inst, const std::string& name);
/**
* Get media service discover object its localized name.
......@@ -86,17 +72,15 @@ public:
bool isRunning();
private:
MediaDiscoverer(InternalPtr ptr);
/**
* Release media discover object. If the reference count reaches 0, then
* the object will be released.
*/
void release();
bool m_own;
MediaDiscoverer& operator=(const MediaDiscoverer& another);
MediaDiscoverer(const MediaDiscoverer& another);
bool operator==(const MediaDiscoverer& another);
const MediaDiscoverer& operator=(const MediaDiscoverer& another);
};
} // namespace VLC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment