1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_AVMEDIA_SOURCE_FRAMEWORK_SOUNDHANDLER_HXX
21 #define INCLUDED_AVMEDIA_SOURCE_FRAMEWORK_SOUNDHANDLER_HXX
22 
23 #include <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
25 #include <com/sun/star/frame/XStatusListener.hpp>
26 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
27 #include <com/sun/star/media/XPlayer.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/util/URL.hpp>
30 
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
33 
34 #include <cppuhelper/weak.hxx>
35 
36 #include <vcl/timer.hxx>
37 #include <vcl/idle.hxx>
38 #include <tools/link.hxx>
39 #include <avmedia/mediawindow.hxx>
40 #include <osl/mutex.hxx>
41 
42 namespace avmedia{
43 
44 struct ThreadHelpBase
45 {
46     public:
47         mutable ::osl::Mutex m_aLock;
48 };
49 
50 /*-************************************************************************************************************
51     @short          handler to detect and play sounds ("wav" and "au" only!)
52     @descr          Register this implementation as a content handler to detect and/or play wav- and au-sounds.
53                     It doesn't depend from the target platform. But one instance of this class
54                     can play one sound at the same time only. Means every new dispatch request will stop the
55                     might still running one. So we support one operation/one URL/one listener at the same time
56                     only.
57 
58     @devstatus      ready
59     @threadsafe     yes
60 *//*-*************************************************************************************************************/
61 class SoundHandler  :   // interfaces
62                         public  css::lang::XTypeProvider
63                     ,   public  css::lang::XServiceInfo
64                     ,   public  css::frame::XNotifyingDispatch // => XDispatch
65                     ,   public  css::document::XExtendedFilterDetection
66                         // baseclasses
67                         // Order is necessary for right initialization!
68                     ,   private ThreadHelpBase
69                     ,   public  ::cppu::OWeakObject
70 {
71     // public methods
72     public:
73 
74         // constructor / destructor
75                  SoundHandler();
76         virtual ~SoundHandler(                                                                        ) override;
77 
78         //  XInterface, XTypeProvider, XServiceInfo
79         virtual css::uno::Any  SAL_CALL queryInterface( const css::uno::Type& aType   ) override;
80         virtual void SAL_CALL acquire() throw() override;
81         virtual void SAL_CALL release() throw() override;
82         virtual css::uno::Sequence< css::uno::Type >  SAL_CALL getTypes () override;
83         virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
84 
85     /* interface XServiceInfo */
86        virtual OUString                                               SAL_CALL getImplementationName              (                                                                               ) override;
87        virtual sal_Bool                                               SAL_CALL supportsService                    ( const OUString&                                               sServiceName    ) override;
88        virtual css::uno::Sequence< OUString >                         SAL_CALL getSupportedServiceNames           (                                                                               ) override;
89 
90         //  XNotifyingDispatch
91         virtual void SAL_CALL dispatchWithNotification(const css::util::URL&                                             aURL      ,
92                                                        const css::uno::Sequence< css::beans::PropertyValue >&            lArguments,
93                                                        const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) override;
94 
95         //  XDispatch
96         virtual void SAL_CALL dispatch              (   const   css::util::URL&                                     aURL        ,
97                                                         const   css::uno::Sequence< css::beans::PropertyValue >&    lArguments  ) override;
98         // not supported !
addStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)99         virtual void SAL_CALL addStatusListener     (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
100                                                         const   css::util::URL&                                     /*aURL*/        ) override {};
removeStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)101         virtual void SAL_CALL removeStatusListener  (   const   css::uno::Reference< css::frame::XStatusListener >& /*xListener*/   ,
102                                                         const   css::util::URL&                                     /*aURL*/        ) override {};
103 
104         //  XExtendedFilterDetection
105         virtual OUString SAL_CALL detect           (           css::uno::Sequence< css::beans::PropertyValue >&    lDescriptor ) override;
106 
107     //  protected methods
108     protected:
109 
110     //  private methods
111     private:
112         DECL_LINK( implts_PlayerNotify, Timer*, void );
113 
114     //  variables
115     //  (should be private everyway!)
116     private:
117 
118         bool m_bError;
119         css::uno::Reference< css::uno::XInterface >                m_xSelfHold         ;   // we must protect us against dying during async(!) dispatch() call!
120         css::uno::Reference< css::media::XPlayer >                 m_xPlayer           ;   // uses avmedia player to play sounds...
121 
122         css::uno::Reference< css::frame::XDispatchResultListener > m_xListener         ;
123         Idle m_aUpdateIdle;
124 
125 };      //  class SoundHandler
126 
127 }       //  namespace avmedia
128 
129 #endif // INCLUDED_AVMEDIA_SOURCE_FRAMEWORK_SOUNDHANDLER_HXX
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
132