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

Revert to using constructors & exceptions to signal errors

parent f845e7e0
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
namespace VLC namespace VLC
{ {
Instance::Instance() Instance::Instance(int argc, const char* const* argv)
: Internal( NULL )
{ {
m_obj = libvlc_new( argc, argv );
} }
Instance::Instance( const Instance& another ) Instance::Instance( const Instance& another )
...@@ -59,12 +59,6 @@ Instance::~Instance() ...@@ -59,12 +59,6 @@ Instance::~Instance()
release(); release();
} }
Instance Instance::create( int argc, const char *const * argv )
{
InternalPtr ptr = libvlc_new( argc, argv );
return Instance( ptr, false );
}
int Instance::addIntf( const std::string& name ) int Instance::addIntf( const std::string& name )
{ {
return libvlc_add_intf( m_obj, name.c_str() ); return libvlc_add_intf( m_obj, name.c_str() );
...@@ -160,13 +154,6 @@ std::vector<AudioOutputDeviceDescription> Instance::audioOutputDeviceList(const ...@@ -160,13 +154,6 @@ std::vector<AudioOutputDeviceDescription> Instance::audioOutputDeviceList(const
return res; return res;
} }
Instance::Instance( Internal::InternalPtr ptr, bool increaseRefCount )
: Internal( ptr )
{
if ( increaseRefCount )
retain();
}
void Instance::release() void Instance::release()
{ {
if ( isValid() ) if ( isValid() )
......
...@@ -36,29 +36,6 @@ namespace VLC ...@@ -36,29 +36,6 @@ namespace VLC
class VLCPP_API Instance : public Internal<libvlc_instance_t> class VLCPP_API Instance : public Internal<libvlc_instance_t>
{ {
public: public:
Instance();
/**
* Copy libvlc_instance_t from another to new Instance object.
* \param another existing Instance
*/
Instance(const Instance& another);
/**
* Copy libvlc_instance_t from another Instance
* to this Instance
* \param another existing Instance
*/
Instance& operator=(const Instance& another);
/**
* Check if 2 Instance objects contain the same libvlc_instance_t.
* \param another another Instance
* \return true if they contain the same libvlc_instance_t
*/
bool operator==(const Instance& another) const;
~Instance();
/** /**
* Create and initialize a libvlc instance. This functions accept a list * Create and initialize a libvlc instance. This functions accept a list
* of "command line" arguments similar to the main(). These arguments * of "command line" arguments similar to the main(). These arguments
...@@ -81,7 +58,29 @@ public: ...@@ -81,7 +58,29 @@ public:
* *
* \param argv list of arguments (should be NULL) * \param argv list of arguments (should be NULL)
*/ */
static Instance create(int argc, const char *const * argv); Instance(int argc, const char *const * argv);
/**
* Copy libvlc_instance_t from another to new Instance object.
* \param another existing Instance
*/
Instance(const Instance& another);
/**
* Copy libvlc_instance_t from another Instance
* to this Instance
* \param another existing Instance
*/
Instance& operator=(const Instance& another);
/**
* Check if 2 Instance objects contain the same libvlc_instance_t.
* \param another another Instance
* \return true if they contain the same libvlc_instance_t
*/
bool operator==(const Instance& another) const;
~Instance();
/** /**
* Try to start a user interface for the libvlc instance. * Try to start a user interface for the libvlc instance.
......
...@@ -22,44 +22,45 @@ ...@@ -22,44 +22,45 @@
*****************************************************************************/ *****************************************************************************/
#include "vlc.hpp" #include "vlc.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
Media::Media() Media::Media(Instance &instance, const std::string &mrl, Media::FromType type)
: Internal( NULL ) : Internal( NULL )
, m_eventManager( NULL )
{
}
Media Media::fromPath(Instance& instance, const std::string& path)
{ {
InternalPtr ptr = libvlc_media_new_path( instance, path.c_str() ); switch (type)
return Media( ptr, false ); {
} case FromLocation:
m_obj = libvlc_media_new_location( instance, mrl.c_str() );
Media Media::fromLocation(Instance& instance, const std::string& location) break;
{ case FromPath:
InternalPtr ptr = libvlc_media_new_location( instance, location.c_str() ); m_obj = libvlc_media_new_path( instance, mrl.c_str() );
return Media( ptr, false ); break;
case AsNode:
m_obj = libvlc_media_new_as_node( instance, mrl.c_str() );
break;
default:
break;
}
if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media");
} }
Media Media::fromFileDescriptor(Instance& instance, int fd)
{
InternalPtr ptr = libvlc_media_new_fd( instance, fd );
return Media( ptr, false );
}
Media Media::fromList(MediaList& list) Media::Media(Instance& instance, int fd)
{ {
InternalPtr ptr = libvlc_media_list_media( list ); m_obj = libvlc_media_new_fd( instance, fd );
return Media( ptr, false ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media");
} }
Media Media::asNode(Instance& instance, const std::string& nodeName) Media::Media(MediaList& list)
{ {
InternalPtr ptr = libvlc_media_new_as_node( instance, nodeName.c_str() ); m_obj = libvlc_media_list_media( list );
return Media( ptr, false ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media");
} }
Media::Media(const Media& another) Media::Media(const Media& another)
......
...@@ -39,32 +39,36 @@ class EventManager; ...@@ -39,32 +39,36 @@ class EventManager;
class VLCPP_API Media : public Internal<libvlc_media_t> class VLCPP_API Media : public Internal<libvlc_media_t>
{ {
public: public:
Media();
/** enum FromType
* Create a media for a certain file path. {
* /**
* \param instance the instance * Create a media for a certain file path.
* \param path local filesystem path */
* \return the newly created media or NULL on error FromPath,
*/ /**
static Media fromPath(Instance& instance, const std::string& path); * Create a media with a certain given media resource location,
* for instance a valid URL.
*
* \note To refer to a local file with this function,
* the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
* We recommend using FromPath instead when dealing with
* local files.
*/
FromLocation,
/**
* Create a media as an empty node with a given name.
*/
AsNode,
};
/** /**
* Create a media with a certain given media resource location, * @brief Media Constructs a libvlc Media instance
* for instance a valid URL. * @param instance A libvlc instance
* * @param mrl A path, location, or node name, depending on the 3rd parameter
* \note To refer to a local file with this function, * @param type The type of the 2nd argument. \sa{FromType}
* the file://... URI syntax <b>must</b> be used (see IETF RFC3986).
* We recommend using libvlc_media_new_path() instead when dealing with
* local files.
*
* \see libvlc_media_release
*
* \param instance the instance
* \param psz_mrl the media location
* \return the newly created media or NULL on error
*/ */
static Media fromLocation(Instance& instance, const std::string& location); Media(Instance& instance, const std::string& mrl, FromType type);
/** /**
* Create a media for an already open file descriptor. * Create a media for an already open file descriptor.
...@@ -86,7 +90,7 @@ public: ...@@ -86,7 +90,7 @@ public:
* \param fd open file descriptor * \param fd open file descriptor
* \return the newly created media or NULL on error * \return the newly created media or NULL on error
*/ */
static Media fromFileDescriptor(Instance& instance, int fd); Media(Instance& instance, int fd);
/** /**
* Get media instance from this media list instance. This action will increase * Get media instance from this media list instance. This action will increase
...@@ -96,16 +100,7 @@ public: ...@@ -96,16 +100,7 @@ public:
* \param p_ml a media list instance * \param p_ml a media list instance
* \return media instance * \return media instance
*/ */
static Media fromList(MediaList& list ); Media(MediaList& list );
/**
* Create a media as an empty node with a given name.
*
* \param p_instance the instance
* \param psz_name the name of the node
* \return the new empty media or NULL on error
*/
static Media asNode(Instance& instance, const std::string& nodeName);
/** /**
* Copy libvlc_media_t from another to new Media object. * Copy libvlc_media_t from another to new Media object.
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "vlc.hpp" #include "vlc.hpp"
#include "EventManager.hpp" #include "EventManager.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
...@@ -34,12 +35,11 @@ MediaDiscoverer::~MediaDiscoverer() ...@@ -34,12 +35,11 @@ MediaDiscoverer::~MediaDiscoverer()
release(); release();
} }
MediaDiscoverer* MediaDiscoverer::create( Instance &inst, const std::string& name ) MediaDiscoverer::MediaDiscoverer( Instance &inst, const std::string& name )
{ {
InternalPtr ptr = libvlc_media_discoverer_new_from_name(inst, name.c_str()); m_obj = libvlc_media_discoverer_new_from_name(inst, name.c_str());
if ( ptr == NULL ) if ( m_obj == NULL )
return NULL; throw std::runtime_error("Failed to construct a media discover");
return new MediaDiscoverer( ptr );
} }
std::string MediaDiscoverer::localizedName() std::string MediaDiscoverer::localizedName()
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "common.hpp" #include "common.hpp"
#include "Internal.hpp" #include "Internal.hpp"
#include <string>
namespace VLC namespace VLC
{ {
...@@ -47,7 +48,7 @@ public: ...@@ -47,7 +48,7 @@ public:
* \warning This is returned as a pointer, as this is not refcounter by VLC, and is * \warning This is returned as a pointer, as this is not refcounter by VLC, and is
* fairly expensive to instantiate. * fairly expensive to instantiate.
*/ */
static MediaDiscoverer* create(Instance & inst, const std::string& name); MediaDiscoverer(Instance & inst, const std::string& name);
/** /**
* Get media service discover object its localized name. * Get media service discover object its localized name.
......
...@@ -23,13 +23,16 @@ ...@@ -23,13 +23,16 @@
#include "vlc.hpp" #include "vlc.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
MediaLibrary MediaLibrary::create(Instance& instance) MediaLibrary::MediaLibrary(Instance& instance)
{ {
InternalPtr ptr = libvlc_media_library_new( instance ); m_obj = libvlc_media_library_new( instance );
return MediaLibrary(ptr); if (m_obj == NULL)
throw std::runtime_error("Failed to construct a media library");
} }
MediaLibrary::MediaLibrary(const MediaLibrary& another) MediaLibrary::MediaLibrary(const MediaLibrary& another)
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
* *
* \param p_instance the libvlc instance * \param p_instance the libvlc instance
*/ */
static MediaLibrary create(Instance & p_instance); MediaLibrary(Instance & p_instance);
/** /**
* Copy libvlc_media_library_t from another to new MediaLibrary object. * Copy libvlc_media_library_t from another to new MediaLibrary object.
* \param another existing MediaLibrary * \param another existing MediaLibrary
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "EventManager.hpp" #include "EventManager.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
...@@ -65,28 +67,36 @@ MediaList::~MediaList() ...@@ -65,28 +67,36 @@ MediaList::~MediaList()
release(); release();
} }
MediaList MediaList::fromMedia(Media& md) MediaList::MediaList(Media& md)
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_subitems( md ); m_obj = libvlc_media_subitems( md );
return MediaList( ptr ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
} }
MediaList MediaList::fromMediaDiscoverer( MediaDiscoverer& mdis ) MediaList::MediaList( MediaDiscoverer& mdis )
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_discoverer_media_list( mdis ); m_obj = libvlc_media_discoverer_media_list( mdis );
return MediaList( ptr ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
} }
MediaList MediaList::fromMediaLibrary(MediaLibrary& mlib) MediaList::MediaList(MediaLibrary& mlib)
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_library_media_list( mlib ); InternalPtr ptr = libvlc_media_library_media_list( mlib );
return MediaList( ptr ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
} }
MediaList MediaList::create( Instance& instance ) MediaList::MediaList( Instance& instance )
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_list_new( instance ); m_obj = libvlc_media_list_new( instance );
return MediaList( ptr ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media list");
} }
void MediaList::setMedia( Media &md ) void MediaList::setMedia( Media &md )
...@@ -150,12 +160,6 @@ EventManager& MediaList::eventManager() ...@@ -150,12 +160,6 @@ EventManager& MediaList::eventManager()
return *m_eventManager; return *m_eventManager;
} }
MediaList::MediaList( Internal::InternalPtr ptr )
: Internal( ptr )
, m_eventManager( NULL )
{
}
void MediaList::release() void MediaList::release()
{ {
libvlc_media_list_release(m_obj); libvlc_media_list_release(m_obj);
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
* *
* \param p_md media descriptor object * \param p_md media descriptor object
*/ */
static VLC::MediaList fromMedia(Media &md); MediaList(Media &md);
// libvlc_media_discoverer_media_list // libvlc_media_discoverer_media_list
/** /**
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
* *
* \param p_mdis media service discover object * \param p_mdis media service discover object
*/ */
static VLC::MediaList fromMediaDiscoverer(MediaDiscoverer & mdis); MediaList(MediaDiscoverer & mdis);
// libvlc_media_library_media_list // libvlc_media_library_media_list
/** /**
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
* *
* \param p_mlib media library object * \param p_mlib media library object
*/ */
static VLC::MediaList fromMediaLibrary( MediaLibrary &mlib ); MediaList( MediaLibrary &mlib );
// libvlc_media_list_new // libvlc_media_list_new
/** /**
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
* *
* \param p_instance libvlc instance * \param p_instance libvlc instance
*/ */
static VLC::MediaList create(Instance &instance); MediaList(Instance &instance);
/** /**
* Associate media instance with this media list instance. If another * Associate media instance with this media list instance. If another
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "vlc.hpp" #include "vlc.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
...@@ -62,10 +64,12 @@ MediaListPlayer::~MediaListPlayer() ...@@ -62,10 +64,12 @@ MediaListPlayer::~MediaListPlayer()
release(); release();
} }
MediaListPlayer MediaListPlayer::create( Instance& instance ) MediaListPlayer::MediaListPlayer( Instance& instance )
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_list_player_new( instance ); m_obj = libvlc_media_list_player_new( instance );
return MediaListPlayer( ptr ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a medialist player");
} }
EventManager& MediaListPlayer::eventManager() EventManager& MediaListPlayer::eventManager()
......
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
* *
* \param p_instance libvlc instance * \param p_instance libvlc instance
*/ */
static MediaListPlayer create(Instance & instance); MediaListPlayer(Instance & instance);
/** /**
* Return the event manager of this media_list_player. * Return the event manager of this media_list_player.
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "vlc.hpp" #include "vlc.hpp"
#include "EventManager.hpp" #include "EventManager.hpp"
#include <stdexcept>
namespace VLC namespace VLC
{ {
...@@ -71,16 +72,20 @@ MediaPlayer::~MediaPlayer() ...@@ -71,16 +72,20 @@ MediaPlayer::~MediaPlayer()
release(); release();
} }
MediaPlayer MediaPlayer::create( Instance& instance ) MediaPlayer::MediaPlayer( Instance& instance )
: m_eventManager( NULL )
{ {
InternalPtr ptr = libvlc_media_player_new( instance ); m_obj = libvlc_media_player_new( instance );
return MediaPlayer( ptr, false ); if ( m_obj == NULL )
throw std::runtime_error("Failed to construct a media player");
} }
MediaPlayer MediaPlayer::fromMedia( Media& md )