📄 npolibvlc.cpp
字号:
memcpy(retval, _msg.psz_message, len); STRINGN_TO_NPVARIANT(retval, len, result); } } else { NULL_TO_NPVARIANT(result); } return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR;}const NPUTF8 * const LibvlcMessageNPObject::methodNames[] ={ /* no methods */};const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);/*** implementation of libvlc message iterator object*/LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) : RuntimeNPObject(instance, aClass), _p_iter(NULL){ /* is plugin still running */ if( instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata); libvlc_log_t *p_log = p_plugin->getLog(); if( p_log ) { _p_iter = libvlc_log_get_iterator(p_log, NULL); } }};LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject(){ if( _p_iter ) libvlc_log_iterator_free(_p_iter, NULL);}const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] = { "hasNext",};const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);enum LibvlcMessageIteratorNPObjectPropertyIds{ ID_messageiterator_hasNext,};RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); switch( index ) { case ID_messageiterator_hasNext: { if( _p_iter && p_plugin->getLog() ) { libvlc_exception_t ex; libvlc_exception_init(&ex); BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } } else { BOOLEAN_TO_NPVARIANT(0, result); } return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR;}const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] ={ "next",};const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);enum LibvlcMessageIteratorNPObjectMethodIds{ ID_messageiterator_next,};RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { case ID_messageiterator_next: if( argCount == 0 ) { if( _p_iter && p_plugin->getLog() ) { struct libvlc_log_message_t buffer; buffer.sizeof_msg = sizeof(buffer); libvlc_log_iterator_next(_p_iter, &buffer, &ex); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } else { LibvlcMessageNPObject* message = static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass())); if( message ) { message->setMessage(buffer); OBJECT_TO_NPVARIANT(message, result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_OUT_OF_MEMORY; } } return INVOKERESULT_GENERIC_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; default: ; } } return INVOKERESULT_GENERIC_ERROR;} /*** implementation of libvlc message object*/const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] = { "count",};const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);enum LibvlcMessagesNPObjectPropertyIds{ ID_messages_count,};RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); switch( index ) { case ID_messages_count: { libvlc_log_t *p_log = p_plugin->getLog(); if( p_log ) { libvlc_exception_t ex; libvlc_exception_init(&ex); INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } } else { INT32_TO_NPVARIANT(0, result); } return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR;}const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] ={ "clear", "iterator",};const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);enum LibvlcMessagesNPObjectMethodIds{ ID_messages_clear, ID_messages_iterator,};RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { case ID_messages_clear: if( argCount == 0 ) { libvlc_log_t *p_log = p_plugin->getLog(); if( p_log ) { libvlc_log_clear(p_log, &ex); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } } return INVOKERESULT_NO_ERROR; } return INVOKERESULT_NO_SUCH_METHOD; case ID_messages_iterator: if( argCount == 0 ) { LibvlcMessageIteratorNPObject* iter = static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass())); if( iter ) { OBJECT_TO_NPVARIANT(iter, result); return INVOKERESULT_NO_ERROR; } return INVOKERESULT_OUT_OF_MEMORY; } return INVOKERESULT_NO_SUCH_METHOD; default: ; } } return INVOKERESULT_GENERIC_ERROR;} /*** implementation of libvlc message object*/LibvlcLogNPObject::~LibvlcLogNPObject(){ if( isValid() ) { if( messagesObj ) NPN_ReleaseObject(messagesObj); }};const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = { "messages", "verbosity",};const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);enum LibvlcLogNPObjectPropertyIds{ ID_log_messages, ID_log_verbosity,};RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { case ID_log_messages: { // create child object in lazyman fashion to avoid ownership problem with firefox if( ! messagesObj ) messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()); OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result); return INVOKERESULT_NO_ERROR; } case ID_log_verbosity: { if( p_plugin->getLog() ) { INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(), &ex), result); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } } else { /* log is not enabled, return -1 */ DOUBLE_TO_NPVARIANT(-1.0, result); } return INVOKERESULT_NO_ERROR; } default: ; } } return INVOKERESULT_GENERIC_ERROR;}RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value){ /* is plugin still running */ if( _instance->pdata ) { VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata); libvlc_exception_t ex; libvlc_exception_init(&ex); switch( index ) { case ID_log_verbosity: if( isNumberValue(value) ) { libvlc_instance_t* p_libvlc = p_plugin->getVLC(); libvlc_log_t *p_log = p_plugin->getLog(); int verbosity = numberValue(value); if( verbosity >= 0 ) { if( ! p_log ) { p_log = libvlc_log_open(p_libvlc, &ex); if( libvlc_exception_raised(&ex) ) { NPN_SetException(this, libvlc_exception_get_message(&ex)); libvlc_exception_clear(&ex); return INVOKERESULT_GENERIC_ERROR; } p_plugin->setLog(p_log); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -