1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
29 #define __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	interface includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <com/sun/star/lang/XTypeProvider.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
38 #include <com/sun/star/frame/XStatusListener.hpp>
39 #include <com/sun/star/frame/XFrame.hpp>
40 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
41 #include <com/sun/star/media/XPlayer.hpp>
42 #include <com/sun/star/beans/PropertyValue.hpp>
43 #include <com/sun/star/util/URL.hpp>
44 
45 #include <com/sun/star/lang/XServiceInfo.hpp>
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 
48 //_________________________________________________________________________________________________________________
49 //	other includes
50 //_________________________________________________________________________________________________________________
51 #include <cppuhelper/weak.hxx>
52 
53 #include <vcl/timer.hxx>
54 #include <tools/link.hxx>
55 #include <avmedia/mediawindow.hxx>
56 #include <vos/mutex.hxx>
57 
58 namespace css = ::com::sun::star;
59 
60 //_________________________________________________________________________________________________________________
61 //	namespace
62 //_________________________________________________________________________________________________________________
63 
64 namespace avmedia{
65 
66 //_________________________________________________________________________________________________________________
67 //	exported const
68 //_________________________________________________________________________________________________________________
69 
70 //_________________________________________________________________________________________________________________
71 //	exported definitions
72 //_________________________________________________________________________________________________________________
73 
74 struct ThreadHelpBase
75 {
76     public:
77         mutable ::vos::OMutex m_aLock;
78 };
79 
80 /*-************************************************************************************************************//**
81     @short          handler to detect and play sounds ("wav" and "au" only!)
82     @descr          Register this implementation as a content handler to detect and/or play wav- and au-sounds.
83                     It doesn't depend from the target platform. But one instance of this class
84                     can play one sound at the same time only. Means every new dispatch request will stop the
85                     might still running one. So we support one operation/one URL/one listener at the same time
86                     only.
87 
88     @devstatus      ready
89     @threadsafe     yes
90 *//*-*************************************************************************************************************/
91 class SoundHandler  :   // interfaces
92                         public  css::lang::XTypeProvider
93                     ,   public  css::lang::XServiceInfo
94                     ,   public  css::frame::XNotifyingDispatch // => XDispatch
95                     ,   public  css::document::XExtendedFilterDetection
96                         // baseclasses
97                         // Order is neccessary for right initialization!
98                     ,   private ThreadHelpBase
99                     ,   public  ::cppu::OWeakObject
100 {
101 	//-------------------------------------------------------------------------------------------------------------
102 	//	public methods
103 	//-------------------------------------------------------------------------------------------------------------
104 	public:
105 
106 		//---------------------------------------------------------------------------------------------------------
107 		//	constructor / destructor
108 		//---------------------------------------------------------------------------------------------------------
109                  SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
110         virtual ~SoundHandler(                                                                        );
111 
112 		//---------------------------------------------------------------------------------------------------------
113         //  XInterface, XTypeProvider, XServiceInfo
114 		//---------------------------------------------------------------------------------------------------------
115         virtual css::uno::Any  SAL_CALL queryInterface( const css::uno::Type& aType   ) throw( css::uno::RuntimeException );
116         virtual void SAL_CALL acquire() throw();
117         virtual void SAL_CALL release() throw();
118         virtual css::uno::Sequence< css::uno::Type >  SAL_CALL getTypes () throw( css::uno::RuntimeException );
119         virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw( css::uno::RuntimeException );
120 
121 
122     /* interface XServiceInfo */
123        virtual ::rtl::OUString                                        SAL_CALL getImplementationName              (                                                                               ) throw( css::uno::RuntimeException );
124        virtual sal_Bool                                               SAL_CALL supportsService                    ( const ::rtl::OUString&                                        sServiceName    ) throw( css::uno::RuntimeException );
125        virtual css::uno::Sequence< ::rtl::OUString >                  SAL_CALL getSupportedServiceNames           (                                                                               ) throw( css::uno::RuntimeException );
126     /* Helper for XServiceInfo */
127        static css::uno::Sequence< ::rtl::OUString >                   SAL_CALL impl_getStaticSupportedServiceNames(                                                                               );
128        static ::rtl::OUString                                         SAL_CALL impl_getStaticImplementationName   (                                                                               );
129     /* Helper for registry */
130        static css::uno::Reference< css::uno::XInterface >             SAL_CALL impl_createInstance                ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception );
131        static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL impl_createFactory                 ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
132     /* Helper for initialization of service by using own reference! */
133        virtual void                                                   SAL_CALL impl_initService                   (                                                                               );
134 
135         //---------------------------------------------------------------------------------------------------------
136         //  XNotifyingDispatch
137         //---------------------------------------------------------------------------------------------------------
138         virtual void SAL_CALL dispatchWithNotification(const css::util::URL&                                             aURL      ,
139                                                        const css::uno::Sequence< css::beans::PropertyValue >&            lArguments,
140                                                        const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException);
141 
142 		//---------------------------------------------------------------------------------------------------------
143 		//	XDispatch
144 		//---------------------------------------------------------------------------------------------------------
145         virtual void SAL_CALL dispatch              (   const   css::util::URL&                                     aURL        ,
146                                                         const   css::uno::Sequence< css::beans::PropertyValue >&    lArguments  ) throw( css::uno::RuntimeException );
147         // not supported !
148         virtual void SAL_CALL addStatusListener     (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
149                                                         const   css::util::URL&                                     /*aURL*/        ) throw( css::uno::RuntimeException ) {};
150         virtual void SAL_CALL removeStatusListener  (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
151                                                         const   css::util::URL&                                     /*aURL*/        ) throw( css::uno::RuntimeException ) {};
152 
153 		//---------------------------------------------------------------------------------------------------------
154         //  XExtendedFilterDetection
155 		//---------------------------------------------------------------------------------------------------------
156         virtual ::rtl::OUString SAL_CALL detect     (           css::uno::Sequence< css::beans::PropertyValue >&    lDescriptor ) throw( css::uno::RuntimeException );
157 
158 	//-------------------------------------------------------------------------------------------------------------
159 	//	protected methods
160 	//-------------------------------------------------------------------------------------------------------------
161 	protected:
162 
163 	//-------------------------------------------------------------------------------------------------------------
164 	//	private methods
165 	//-------------------------------------------------------------------------------------------------------------
166 	private:
167         DECL_LINK( implts_PlayerNotify, void* );
168 
169 	//-------------------------------------------------------------------------------------------------------------
170 	//	variables
171 	//	(should be private everyway!)
172 	//-------------------------------------------------------------------------------------------------------------
173 	private:
174 
175 		bool m_bError;
176         css::uno::Reference< css::lang::XMultiServiceFactory >     m_xFactory          ;   /// global uno service factory to create new services
177         css::uno::Reference< css::uno::XInterface >                m_xSelfHold         ;   /// we must protect us against dieing during async(!) dispatch() call!
178         css::uno::Reference< css::media::XPlayer >                 m_xPlayer           ;   /// uses avmedia player to play sounds ...
179 
180         css::uno::Reference< css::frame::XDispatchResultListener > m_xListener         ;
181         Timer m_aUpdateTimer;
182 
183 };      //  class SoundHandler
184 
185 }		//	namespace avmedia
186 
187 #endif  //  #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
188