1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
21 #define __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
23 #include <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
26 #include <com/sun/star/frame/XStatusListener.hpp>
27 #include <com/sun/star/frame/XFrame.hpp>
28 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
29 #include <com/sun/star/media/XPlayer.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/util/URL.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36 #include <cppuhelper/weak.hxx>
38 #include <vcl/timer.hxx>
39 #include <tools/link.hxx>
40 #include <avmedia/mediawindow.hxx>
41 #include <osl/mutex.hxx>
48 mutable ::osl::Mutex m_aLock
;
51 /*-************************************************************************************************************//**
52 @short handler to detect and play sounds ("wav" and "au" only!)
53 @descr Register this implementation as a content handler to detect and/or play wav- and au-sounds.
54 It doesn't depend from the target platform. But one instance of this class
55 can play one sound at the same time only. Means every new dispatch request will stop the
56 might still running one. So we support one operation/one URL/one listener at the same time
61 *//*-*************************************************************************************************************/
62 class SoundHandler
: // interfaces
63 public css::lang::XTypeProvider
64 , public css::lang::XServiceInfo
65 , public css::frame::XNotifyingDispatch
// => XDispatch
66 , public css::document::XExtendedFilterDetection
68 // Order is neccessary for right initialization!
69 , private ThreadHelpBase
70 , public ::cppu::OWeakObject
72 //-------------------------------------------------------------------------------------------------------------
74 //-------------------------------------------------------------------------------------------------------------
77 //---------------------------------------------------------------------------------------------------------
78 // constructor / destructor
79 //---------------------------------------------------------------------------------------------------------
80 SoundHandler( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xFactory
);
81 virtual ~SoundHandler( );
83 //---------------------------------------------------------------------------------------------------------
84 // XInterface, XTypeProvider, XServiceInfo
85 //---------------------------------------------------------------------------------------------------------
86 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) throw( css::uno::RuntimeException
);
87 virtual void SAL_CALL
acquire() throw();
88 virtual void SAL_CALL
release() throw();
89 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes () throw( css::uno::RuntimeException
);
90 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw( css::uno::RuntimeException
);
92 /* interface XServiceInfo */
93 virtual OUString SAL_CALL
getImplementationName ( ) throw( css::uno::RuntimeException
);
94 virtual sal_Bool SAL_CALL
supportsService ( const OUString
& sServiceName
) throw( css::uno::RuntimeException
);
95 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames ( ) throw( css::uno::RuntimeException
);
96 /* Helper for XServiceInfo */
97 static css::uno::Sequence
< OUString
> SAL_CALL
impl_getStaticSupportedServiceNames( );
98 static OUString SAL_CALL
impl_getStaticImplementationName ( );
99 /* Helper for registry */
100 static css::uno::Reference
< css::uno::XInterface
> SAL_CALL
impl_createInstance ( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xServiceManager
) throw( css::uno::Exception
);
101 static css::uno::Reference
< css::lang::XSingleServiceFactory
> SAL_CALL
impl_createFactory ( const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xServiceManager
);
102 /* Helper for initialization of service by using own reference! */
103 virtual void SAL_CALL
impl_initService ( );
105 //---------------------------------------------------------------------------------------------------------
106 // XNotifyingDispatch
107 //---------------------------------------------------------------------------------------------------------
108 virtual void SAL_CALL
dispatchWithNotification(const css::util::URL
& aURL
,
109 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
110 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
) throw(css::uno::RuntimeException
);
112 //---------------------------------------------------------------------------------------------------------
114 //---------------------------------------------------------------------------------------------------------
115 virtual void SAL_CALL
dispatch ( const css::util::URL
& aURL
,
116 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) throw( css::uno::RuntimeException
);
118 virtual void SAL_CALL
addStatusListener ( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
119 const css::util::URL
& /*aURL*/ ) throw( css::uno::RuntimeException
) {};
120 virtual void SAL_CALL
removeStatusListener ( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
121 const css::util::URL
& /*aURL*/ ) throw( css::uno::RuntimeException
) {};
123 //---------------------------------------------------------------------------------------------------------
124 // XExtendedFilterDetection
125 //---------------------------------------------------------------------------------------------------------
126 virtual OUString SAL_CALL
detect ( css::uno::Sequence
< css::beans::PropertyValue
>& lDescriptor
) throw( css::uno::RuntimeException
);
128 //-------------------------------------------------------------------------------------------------------------
130 //-------------------------------------------------------------------------------------------------------------
133 //-------------------------------------------------------------------------------------------------------------
135 //-------------------------------------------------------------------------------------------------------------
137 DECL_LINK( implts_PlayerNotify
, void* );
139 //-------------------------------------------------------------------------------------------------------------
141 // (should be private everyway!)
142 //-------------------------------------------------------------------------------------------------------------
146 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xFactory
; /// global uno service factory to create new services
147 css::uno::Reference
< css::uno::XInterface
> m_xSelfHold
; /// we must protect us against dieing during async(!) dispatch() call!
148 css::uno::Reference
< css::media::XPlayer
> m_xPlayer
; /// uses avmedia player to play sounds ...
150 css::uno::Reference
< css::frame::XDispatchResultListener
> m_xListener
;
151 Timer m_aUpdateTimer
;
153 }; // class SoundHandler
155 } // namespace avmedia
157 #endif // #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */