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/frame/XNotifyingDispatch.hpp> 33 #include <com/sun/star/frame/XStatusListener.hpp> 34 #include <com/sun/star/frame/XFrame.hpp> 35 #include <com/sun/star/document/XExtendedFilterDetection.hpp> 36 #include <com/sun/star/media/XPlayer.hpp> 37 #include <com/sun/star/beans/PropertyValue.hpp> 38 #include <com/sun/star/util/URL.hpp> 39 #include <com/sun/star/uno/XComponentContext.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::uno::XComponentContext >& xContext ); 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::uno::XComponentContext >& xContext ) throw( css::uno::Exception ); 127 /* Helper for initialization of service by using own reference! */ 128 virtual void SAL_CALL impl_initService ( ); 129 130 //--------------------------------------------------------------------------------------------------------- 131 // XNotifyingDispatch 132 //--------------------------------------------------------------------------------------------------------- 133 virtual void SAL_CALL dispatchWithNotification(const css::util::URL& aURL , 134 const css::uno::Sequence< css::beans::PropertyValue >& lArguments, 135 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException); 136 137 //--------------------------------------------------------------------------------------------------------- 138 // XDispatch 139 //--------------------------------------------------------------------------------------------------------- 140 virtual void SAL_CALL dispatch ( const css::util::URL& aURL , 141 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ); 142 // not supported ! 143 virtual void SAL_CALL addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , 144 const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; 145 virtual void SAL_CALL removeStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , 146 const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; 147 148 //--------------------------------------------------------------------------------------------------------- 149 // XExtendedFilterDetection 150 //--------------------------------------------------------------------------------------------------------- 151 virtual ::rtl::OUString SAL_CALL detect ( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException ); 152 153 //------------------------------------------------------------------------------------------------------------- 154 // protected methods 155 //------------------------------------------------------------------------------------------------------------- 156 protected: 157 158 //------------------------------------------------------------------------------------------------------------- 159 // private methods 160 //------------------------------------------------------------------------------------------------------------- 161 private: 162 DECL_LINK( implts_PlayerNotify, void* ); 163 164 //------------------------------------------------------------------------------------------------------------- 165 // variables 166 // (should be private everyway!) 167 //------------------------------------------------------------------------------------------------------------- 168 private: 169 170 bool m_bError; 171 css::uno::Reference< css::uno::XComponentContext > m_xContext ; /// component context to create new services 172 css::uno::Reference< css::uno::XInterface > m_xSelfHold ; /// we must protect against dying during async(!) dispatch() call! 173 css::uno::Reference< css::media::XPlayer > m_xPlayer ; /// uses avmedia player to play sounds ... 174 175 css::uno::Reference< css::frame::XDispatchResultListener > m_xListener ; 176 Timer m_aUpdateTimer; 177 178 }; // class SoundHandler 179 180 } // namespace avmedia 181 182 #endif // #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ 183