16d739b60SAndrew Rist /**************************************************************
2*a79a404bSmseidel *
36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
56d739b60SAndrew Rist * distributed with this work for additional information
66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10*a79a404bSmseidel *
116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*a79a404bSmseidel *
136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist * software distributed under the License is distributed on an
156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist * KIND, either express or implied. See the License for the
176d739b60SAndrew Rist * specific language governing permissions and limitations
186d739b60SAndrew Rist * under the License.
19*a79a404bSmseidel *
206d739b60SAndrew Rist *************************************************************/
216d739b60SAndrew Rist
226d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir // include own things
29cdf0e10cSrcweir #include <recording/dispatchrecordersupplier.hxx>
30cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
31cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
32cdf0e10cSrcweir #include <services.h>
33cdf0e10cSrcweir
34cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35cdf0e10cSrcweir // include interfaces
36cdf0e10cSrcweir #include <com/sun/star/frame/XRecordableDispatch.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir // include other projects
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir // namespace
44cdf0e10cSrcweir
45cdf0e10cSrcweir namespace framework{
46cdf0e10cSrcweir
47cdf0e10cSrcweir //_________________________________________________________________________________________________________________
48cdf0e10cSrcweir // non exported const
49cdf0e10cSrcweir
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir // non exported definitions
52cdf0e10cSrcweir
53cdf0e10cSrcweir //_________________________________________________________________________________________________________________
54cdf0e10cSrcweir // declarations
55cdf0e10cSrcweir
56cdf0e10cSrcweir //*****************************************************************************************************************
57*a79a404bSmseidel // XInterface, XTypeProvider
58cdf0e10cSrcweir //*****************************************************************************************************************
DEFINE_XINTERFACE_3(DispatchRecorderSupplier,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::frame::XDispatchRecorderSupplier))59cdf0e10cSrcweir DEFINE_XINTERFACE_3(
60cdf0e10cSrcweir DispatchRecorderSupplier,
61cdf0e10cSrcweir OWeakObject,
62cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XTypeProvider),
63cdf0e10cSrcweir DIRECT_INTERFACE(css::lang::XServiceInfo),
64cdf0e10cSrcweir DIRECT_INTERFACE(css::frame::XDispatchRecorderSupplier))
65cdf0e10cSrcweir
66cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_3(
67cdf0e10cSrcweir DispatchRecorderSupplier,
68cdf0e10cSrcweir css::lang::XTypeProvider,
69cdf0e10cSrcweir css::lang::XServiceInfo,
70cdf0e10cSrcweir css::frame::XDispatchRecorderSupplier)
71cdf0e10cSrcweir
72cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE(
73cdf0e10cSrcweir DispatchRecorderSupplier,
74cdf0e10cSrcweir ::cppu::OWeakObject,
75cdf0e10cSrcweir SERVICENAME_DISPATCHRECORDERSUPPLIER,
76cdf0e10cSrcweir IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
77cdf0e10cSrcweir
78cdf0e10cSrcweir DEFINE_INIT_SERVICE(
79cdf0e10cSrcweir DispatchRecorderSupplier,
80cdf0e10cSrcweir {
81cdf0e10cSrcweir /*Attention
82*a79a404bSmseidel I think we don't need any mutex or lock here... because we are called by our own static method impl_createInstance()
83cdf0e10cSrcweir to create a new instance of this class by our own supported service factory.
84cdf0e10cSrcweir see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
85cdf0e10cSrcweir */
86cdf0e10cSrcweir }
87cdf0e10cSrcweir )
88cdf0e10cSrcweir
89cdf0e10cSrcweir //_____________________________________________________________________________
90cdf0e10cSrcweir /**
91cdf0e10cSrcweir @short standard constructor to create instance
92cdf0e10cSrcweir @descr Because an instance will be initialized by her interface methods
9307a3d7f1SPedro Giffuni it's not necessary to do anything here.
94cdf0e10cSrcweir */
95cdf0e10cSrcweir DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
96cdf0e10cSrcweir // init baseclasses first!
97cdf0e10cSrcweir // Attention: Don't change order of initialization!
98cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() )
99cdf0e10cSrcweir , ::cppu::OWeakObject( )
100cdf0e10cSrcweir // init member
101cdf0e10cSrcweir , m_xDispatchRecorder( NULL )
102cdf0e10cSrcweir , m_xFactory ( xFactory )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
106cdf0e10cSrcweir //_____________________________________________________________________________
107cdf0e10cSrcweir /**
108cdf0e10cSrcweir @short standard destructor
109*a79a404bSmseidel @descr We are a helper and not a real service. So we don't provide
110cdf0e10cSrcweir dispose() functionality. This supplier dies by ref count mechanism
111cdf0e10cSrcweir and should release all internal used ones too.
112cdf0e10cSrcweir */
~DispatchRecorderSupplier()113cdf0e10cSrcweir DispatchRecorderSupplier::~DispatchRecorderSupplier()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir m_xFactory = NULL;
116cdf0e10cSrcweir m_xDispatchRecorder = NULL;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir //_____________________________________________________________________________
120cdf0e10cSrcweir /**
121cdf0e10cSrcweir @short set a new dispatch recorder on this supplier
122*a79a404bSmseidel @descr Because there can exist more than one recorder implementations
123cdf0e10cSrcweir (to generate java/basic/... scripts from recorded data) it must
124cdf0e10cSrcweir be possible to set it on a supplier.
125cdf0e10cSrcweir
126cdf0e10cSrcweir @see getDispatchRecorder()
127cdf0e10cSrcweir
128cdf0e10cSrcweir @param xRecorder
129cdf0e10cSrcweir the new recorder to set it
130cdf0e10cSrcweir <br><NULL/> isn't recommended, because recording without a
131cdf0e10cSrcweir valid recorder can't work. But it's not checked here. So user
132cdf0e10cSrcweir of this supplier can decide that without changing this
133cdf0e10cSrcweir implementation.
134cdf0e10cSrcweir
135cdf0e10cSrcweir @change 09.04.2002 by Andreas Schluens
136cdf0e10cSrcweir */
setDispatchRecorder(const css::uno::Reference<css::frame::XDispatchRecorder> & xRecorder)137cdf0e10cSrcweir void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir // SAFE =>
140cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
141cdf0e10cSrcweir m_xDispatchRecorder=xRecorder;
142cdf0e10cSrcweir // => SAFE
143cdf0e10cSrcweir }
144cdf0e10cSrcweir //_____________________________________________________________________________
145cdf0e10cSrcweir /**
146cdf0e10cSrcweir @short provides access to the dispatch recorder of this supplier
147cdf0e10cSrcweir @descr Such recorder can be used outside to record dispatches.
14806fea5ebSmseidel But normally he is used internally only. Of course he must be used
149cdf0e10cSrcweir from outside to get the recorded data e.g. for saving it as a
150cdf0e10cSrcweir script.
151cdf0e10cSrcweir
152cdf0e10cSrcweir @see setDispatchRecorder()
153cdf0e10cSrcweir
154cdf0e10cSrcweir @return the internal used dispatch recorder
155cdf0e10cSrcweir <br>May it can be <NULL/> if no one was set before.
156cdf0e10cSrcweir
157cdf0e10cSrcweir @change 09.04.2002 by Andreas Schluens
158cdf0e10cSrcweir */
getDispatchRecorder()159cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir // SAFE =>
162cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
163cdf0e10cSrcweir return m_xDispatchRecorder;
164cdf0e10cSrcweir // => SAFE
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir //_____________________________________________________________________________
168cdf0e10cSrcweir /**
169cdf0e10cSrcweir @short execute a dispatch request and record it
170cdf0e10cSrcweir @descr If given dispatch object provides right recording interface it
171*a79a404bSmseidel will be used. If it's not supported it records the pure dispatch
172cdf0e10cSrcweir parameters only. There is no code neither the possibility to
173cdf0e10cSrcweir check if recording is enabled or not.
174cdf0e10cSrcweir
175cdf0e10cSrcweir @param aURL the command URL
176cdf0e10cSrcweir @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further informations)
177cdf0e10cSrcweir @param xDispatcher the original dispatch object which should be recorded
178cdf0e10cSrcweir
179cdf0e10cSrcweir @change 09.04.2002 by Andreas Schluens
180cdf0e10cSrcweir */
dispatchAndRecord(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArguments,const css::uno::Reference<css::frame::XDispatch> & xDispatcher)181cdf0e10cSrcweir void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL& aURL ,
182cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ,
183cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatch >& xDispatcher ) throw (css::uno::RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir // SAFE =>
186cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
187cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
188cdf0e10cSrcweir aReadLock.unlock();
189cdf0e10cSrcweir // => SAFE
190cdf0e10cSrcweir
191cdf0e10cSrcweir // clear unspecific situations
192cdf0e10cSrcweir if (!xDispatcher.is())
193cdf0e10cSrcweir throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: dispatcher is NULL"), static_cast< ::cppu::OWeakObject* >(this));
194cdf0e10cSrcweir
195cdf0e10cSrcweir if (!xRecorder.is())
196cdf0e10cSrcweir throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: no valid dispatch recorder available"), static_cast< ::cppu::OWeakObject* >(this));
197cdf0e10cSrcweir
198*a79a404bSmseidel // check, if given dispatch supports record functionality by itself...
199cdf0e10cSrcweir // or must be wrapped.
200cdf0e10cSrcweir css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
201cdf0e10cSrcweir xDispatcher,
202cdf0e10cSrcweir css::uno::UNO_QUERY);
203cdf0e10cSrcweir
204cdf0e10cSrcweir if (xRecordable.is())
205cdf0e10cSrcweir xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
206cdf0e10cSrcweir else
207cdf0e10cSrcweir {
208cdf0e10cSrcweir // There is no reason to wait for information about success
209cdf0e10cSrcweir // of this request. Because status information of a dispatch
210*a79a404bSmseidel // is not guaranteed. So we execute it and record used
211cdf0e10cSrcweir // parameters only.
212cdf0e10cSrcweir xDispatcher->dispatch(aURL,lArguments);
213cdf0e10cSrcweir xRecorder->recordDispatch(aURL,lArguments);
214cdf0e10cSrcweir }
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir } // namespace framework
218