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

cppcx: Expose logSet

parent aa2e4cc3
......@@ -118,6 +118,25 @@ namespace libVLCX
m_instance.setAppId(VLCString(id), VLCString(version), VLCString(icon));
}
void Instance::logUnset()
{
m_instance.logUnset();
}
void Instance::logSet(LogCallback^ logCb)
{
m_instance.logSet([logCb](int logLevel, const libvlc_log_t* Log, std::string msgStr)
{
size_t len = MultiByteToWideChar(CP_UTF8, 0, msgStr.c_str(), -1, nullptr, 0);
if (len == 0)
return;
wchar_t *out = new wchar_t[len];
std::unique_ptr<wchar_t[]> out_u(out);
MultiByteToWideChar(CP_UTF8, 0, msgStr.c_str(), -1, out, len);
logCb(logLevel, ref new Platform::String(out));
});
}
Windows::Foundation::Collections::IVector<ModuleDescription^>^ Instance::audioFilterList()
{
return MarshallVector<ModuleDescription, VLC::ModuleDescription>(m_instance.audioFilterList());
......
......@@ -32,6 +32,7 @@
namespace libVLCX
{
public delegate void LogCallback(int, Platform::String^);
public ref class Instance sealed
{
public:
......@@ -100,6 +101,35 @@ namespace libVLCX
*/
void setAppId(Platform::String^ id, Platform::String^ version, Platform::String^ icon);
/**
* Unsets the logging callback for a LibVLC instance. This is rarely
* needed: the callback is implicitly unset when the instance is
* destroyed. This function will wait for any pending callbacks
* invocation to complete (causing a deadlock if called from within the
* callback).
*
* \version LibVLC 2.1.0 or later
*/
void logUnset();
/**
* Sets the logging callback for a LibVLC instance. This function is
* thread-safe: it will wait for any pending callbacks invocation to
* complete.
*
* \note Some log messages (especially debug) are emitted by LibVLC while
* is being initialized. These messages cannot be captured with this
* interface.
*
* \param logCb A delegate of the form void(int logLevel, String message)
*
* \warning A deadlock may occur if this function is called from the
* callback.
*
* \version LibVLC 2.1.0 or later
*/
void logSet(LogCallback^ logCb);
/**
* Returns a list of audio filters that are available.
*
......
......@@ -192,17 +192,24 @@ public:
static_assert(signature_match<LogCb, void(int, const libvlc_log_t*, std::string)>::value,
"Mismatched log callback" );
auto wrapper = [logCb](int level, const libvlc_log_t* ctx, const char* format, va_list va) {
VaCopy vaCopy( va );
int len = vsnprintf( nullptr, 0, format, vaCopy.va );
if ( len > 0 )
#ifndef _MSC_VER
VaCopy vaCopy(va);
int len = vsnprintf(nullptr, 0, format, vaCopy.va);
if (len > 0)
{
std::unique_ptr<char[]> message{ new char[len] };
if ( vsnprintf( message.get(), len, format, va ) != -1 )
logCb( level, ctx, std::string{ message.get() } );
if (vsnprintf(message.get(), len, format, va) != -1)
logCb(level, ctx, std::string{ message.get() });
}
#else
//MSVC treats passing nullptr as 1st vsnprintf(_s) as an error
char buff[512];
vsnprintf(buff, sizeof(buff) - 1, format, va);
logCb(level, ctx, std::string{ buff });
#endif
};
libvlc_log_set( *this, CallbackWrapper<(unsigned int)CallbackIdx::Log, libvlc_log_cb>::wrap( this, std::move( wrapper ) ),
static_cast<CallbackOwner<2>*>( this ) );
libvlc_log_set(*this, CallbackWrapper<(unsigned int)CallbackIdx::Log, libvlc_log_cb>::wrap(this, std::move(wrapper)),
static_cast<CallbackOwner<2>*>(this));
}
/**
......
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