1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
25 #define __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	interface includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <com/sun/star/lang/XTypeProvider.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
34 #include <com/sun/star/frame/XStatusListener.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
37 #include <com/sun/star/media/XPlayer.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/util/URL.hpp>
40 
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 
44 //_________________________________________________________________________________________________________________
45 //	other includes
46 //_________________________________________________________________________________________________________________
47 #include <cppuhelper/weak.hxx>
48 
49 #include <vcl/timer.hxx>
50 #include <tools/link.hxx>
51 #include <avmedia/mediawindow.hxx>
52 #include <vos/mutex.hxx>
53 
54 namespace css = ::com::sun::star;
55 
56 //_________________________________________________________________________________________________________________
57 //	namespace
58 //_________________________________________________________________________________________________________________
59 
60 namespace avmedia{
61 
62 //_________________________________________________________________________________________________________________
63 //	exported const
64 //_________________________________________________________________________________________________________________
65 
66 //_________________________________________________________________________________________________________________
67 //	exported definitions
68 //_________________________________________________________________________________________________________________
69 
70 struct ThreadHelpBase
71 {
72     public:
73         mutable ::vos::OMutex m_aLock;
74 };
75 
76 /*-************************************************************************************************************//**
77     @short          handler to detect and play sounds ("wav" and "au" only!)
78     @descr          Register this implementation as a content handler to detect and/or play wav- and au-sounds.
79                     It doesn't depend from the target platform. But one instance of this class
80                     can play one sound at the same time only. Means every new dispatch request will stop the
81                     might still running one. So we support one operation/one URL/one listener at the same time
82                     only.
83 
84     @devstatus      ready
85     @threadsafe     yes
86 *//*-*************************************************************************************************************/
87 class SoundHandler  :   // interfaces
88                         public  css::lang::XTypeProvider
89                     ,   public  css::lang::XServiceInfo
90                     ,   public  css::frame::XNotifyingDispatch // => XDispatch
91                     ,   public  css::document::XExtendedFilterDetection
92                         // baseclasses
93                         // Order is necessary for right initialization!
94                     ,   private ThreadHelpBase
95                     ,   public  ::cppu::OWeakObject
96 {
97 	//-------------------------------------------------------------------------------------------------------------
98 	//	public methods
99 	//-------------------------------------------------------------------------------------------------------------
100 	public:
101 
102 		//---------------------------------------------------------------------------------------------------------
103 		//	constructor / destructor
104 		//---------------------------------------------------------------------------------------------------------
105                  SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
106         virtual ~SoundHandler(                                                                        );
107 
108 		//---------------------------------------------------------------------------------------------------------
109         //  XInterface, XTypeProvider, XServiceInfo
110 		//---------------------------------------------------------------------------------------------------------
111         virtual css::uno::Any  SAL_CALL queryInterface( const css::uno::Type& aType   ) throw( css::uno::RuntimeException );
112         virtual void SAL_CALL acquire() throw();
113         virtual void SAL_CALL release() throw();
114         virtual css::uno::Sequence< css::uno::Type >  SAL_CALL getTypes () throw( css::uno::RuntimeException );
115         virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw( css::uno::RuntimeException );
116 
117 
118     /* interface XServiceInfo */
119        virtual ::rtl::OUString                                        SAL_CALL getImplementationName              (                                                                               ) throw( css::uno::RuntimeException );
120        virtual sal_Bool                                               SAL_CALL supportsService                    ( const ::rtl::OUString&                                        sServiceName    ) throw( css::uno::RuntimeException );
121        virtual css::uno::Sequence< ::rtl::OUString >                  SAL_CALL getSupportedServiceNames           (                                                                               ) throw( css::uno::RuntimeException );
122     /* Helper for XServiceInfo */
123        static css::uno::Sequence< ::rtl::OUString >                   SAL_CALL impl_getStaticSupportedServiceNames(                                                                               );
124        static ::rtl::OUString                                         SAL_CALL impl_getStaticImplementationName   (                                                                               );
125     /* Helper for registry */
126        static css::uno::Reference< css::uno::XInterface >             SAL_CALL impl_createInstance                ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception );
127        static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL impl_createFactory                 ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager );
128     /* Helper for initialization of service by using own reference! */
129        virtual void                                                   SAL_CALL impl_initService                   (                                                                               );
130 
131         //---------------------------------------------------------------------------------------------------------
132         //  XNotifyingDispatch
133         //---------------------------------------------------------------------------------------------------------
134         virtual void SAL_CALL dispatchWithNotification(const css::util::URL&                                             aURL      ,
135                                                        const css::uno::Sequence< css::beans::PropertyValue >&            lArguments,
136                                                        const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException);
137 
138 		//---------------------------------------------------------------------------------------------------------
139 		//	XDispatch
140 		//---------------------------------------------------------------------------------------------------------
141         virtual void SAL_CALL dispatch              (   const   css::util::URL&                                     aURL        ,
142                                                         const   css::uno::Sequence< css::beans::PropertyValue >&    lArguments  ) throw( css::uno::RuntimeException );
143         // not supported !
144         virtual void SAL_CALL addStatusListener     (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
145                                                         const   css::util::URL&                                     /*aURL*/        ) throw( css::uno::RuntimeException ) {};
146         virtual void SAL_CALL removeStatusListener  (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
147                                                         const   css::util::URL&                                     /*aURL*/        ) throw( css::uno::RuntimeException ) {};
148 
149 		//---------------------------------------------------------------------------------------------------------
150         //  XExtendedFilterDetection
151 		//---------------------------------------------------------------------------------------------------------
152         virtual ::rtl::OUString SAL_CALL detect     (           css::uno::Sequence< css::beans::PropertyValue >&    lDescriptor ) throw( css::uno::RuntimeException );
153 
154 	//-------------------------------------------------------------------------------------------------------------
155 	//	protected methods
156 	//-------------------------------------------------------------------------------------------------------------
157 	protected:
158 
159 	//-------------------------------------------------------------------------------------------------------------
160 	//	private methods
161 	//-------------------------------------------------------------------------------------------------------------
162 	private:
163         DECL_LINK( implts_PlayerNotify, void* );
164 
165 	//-------------------------------------------------------------------------------------------------------------
166 	//	variables
167 	//	(should be private everyway!)
168 	//-------------------------------------------------------------------------------------------------------------
169 	private:
170 
171 		bool m_bError;
172         css::uno::Reference< css::lang::XMultiServiceFactory >     m_xFactory          ;   /// global uno service factory to create new services
173         css::uno::Reference< css::uno::XInterface >                m_xSelfHold         ;   /// we must protect us against dieing during async(!) dispatch() call!
174         css::uno::Reference< css::media::XPlayer >                 m_xPlayer           ;   /// uses avmedia player to play sounds ...
175 
176         css::uno::Reference< css::frame::XDispatchResultListener > m_xListener         ;
177         Timer m_aUpdateTimer;
178 
179 };      //  class SoundHandler
180 
181 }		//	namespace avmedia
182 
183 #endif  //  #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_
184