1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <vlc/libvlc.h>
#include <vlc/libvlc_media.h>
#include <vlc/libvlc_events.h>
#include "EventManager.hxx"
#include "SymbolLoader.hxx"
#include "EventHandler.hxx"
typedef void ( *libvlc_callback_t ) ( const struct libvlc_event_t *, void * );
namespace VLC
{
namespace
{
libvlc_event_manager_t* ( *libvlc_media_player_event_manager ) ( libvlc_media_player_t *p_mi );
int ( *libvlc_event_attach ) ( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *user_data );
void ( *libvlc_event_detach ) ( libvlc_event_manager_t *p_event_manager,
libvlc_event_type_t i_event_type,
libvlc_callback_t f_callback,
void *p_user_data );
ApiMap VLC_EVENT_MANAGER_API[] =
{
SYM_MAP( libvlc_media_player_event_manager ),
SYM_MAP( libvlc_event_attach ),
SYM_MAP( libvlc_event_detach )
};
}
void EventManagerEventHandler( const libvlc_event_t *event, void *pData )
{
EventManager *instance = static_cast<EventManager*>( pData );
switch ( event->type )
{
case libvlc_MediaPlayerPaused:
instance->mEventHandler->mCallbackQueue.push( instance->mOnPaused );
break;
case libvlc_MediaPlayerEndReached:
instance->mEventHandler->mCallbackQueue.push( instance->mOnEndReached );
break;
}
}
EventManager::EventManager( VLC::Player& player, boost::shared_ptr<VLC::EventHandler> eh )
: mEventHandler( eh )
{
InitApiMap( VLC_EVENT_MANAGER_API );
mManager = libvlc_media_player_event_manager( player );
}
EventManager::~EventManager()
{
}
void EventManager::registerSignal( int signal, const Callback& callback )
{
if ( callback.empty() )
libvlc_event_detach( mManager, signal, EventManagerEventHandler, this );
else
libvlc_event_attach( mManager, signal, EventManagerEventHandler, this );
}
void EventManager::onPaused( const EventManager::Callback& callback )
{
mOnPaused = callback;
registerSignal( libvlc_MediaPlayerPaused, callback );
}
void EventManager::onEndReached( const Callback& callback )
{
mOnEndReached = callback;
registerSignal( libvlc_MediaPlayerEndReached, callback );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|