update credits
[LibreOffice.git] / framework / source / recording / dispatchrecordersupplier.cxx
blob7102c48c3cbcc1f724de863d75a9ac8b1c3190f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <recording/dispatchrecordersupplier.hxx>
21 #include <threadhelp/writeguard.hxx>
22 #include <threadhelp/readguard.hxx>
23 #include <services.h>
25 #include <com/sun/star/frame/XRecordableDispatch.hpp>
27 #include <vcl/svapp.hxx>
29 namespace framework{
31 //*****************************************************************************************************************
32 // XInterface, XTypeProvider
33 //*****************************************************************************************************************
34 DEFINE_XINTERFACE_3(
35 DispatchRecorderSupplier,
36 OWeakObject,
37 DIRECT_INTERFACE(css::lang::XTypeProvider),
38 DIRECT_INTERFACE(css::lang::XServiceInfo),
39 DIRECT_INTERFACE(css::frame::XDispatchRecorderSupplier))
41 DEFINE_XTYPEPROVIDER_3(
42 DispatchRecorderSupplier,
43 css::lang::XTypeProvider,
44 css::lang::XServiceInfo,
45 css::frame::XDispatchRecorderSupplier)
47 DEFINE_XSERVICEINFO_MULTISERVICE(
48 DispatchRecorderSupplier,
49 ::cppu::OWeakObject,
50 "com.sun.star.frame.DispatchRecorderSupplier",
51 IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
53 DEFINE_INIT_SERVICE(
54 DispatchRecorderSupplier,
56 /*Attention
57 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
58 to create a new instance of this class by our own supported service factory.
59 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
64 //_____________________________________________________________________________
65 /**
66 @short standard constructor to create instance
67 @descr Because an instance will be initialized by her interface methods
68 it's not neccessary to do anything here.
70 DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
71 // init baseclasses first!
72 // Attention: Don't change order of initialization!
73 : ThreadHelpBase ( &Application::GetSolarMutex() )
74 , ::cppu::OWeakObject( )
75 // init member
76 , m_xDispatchRecorder( NULL )
77 , m_xFactory ( xFactory )
81 //_____________________________________________________________________________
82 /**
83 @short standard destructor
84 @descr We are a helper and not a real service. So we doesn't provide
85 dispose() functionality. This supplier dies by ref count mechanism
86 and should release all internal used ones too.
88 DispatchRecorderSupplier::~DispatchRecorderSupplier()
90 m_xFactory = NULL;
91 m_xDispatchRecorder = NULL;
94 //_____________________________________________________________________________
95 /**
96 @short set a new dispatch recorder on this supplier
97 @descr Because there can exist more then one recorder implementations
98 (to generate java/basic/... scripts from recorded data) it must
99 be possible to set it on a supplier.
101 @see getDispatchRecorder()
103 @param xRecorder
104 the new recorder to set it
105 <br><NULL/> isn't recommended, because recording without a
106 valid recorder can't work. But it's not checked here. So user
107 of this supplier can decide that without changing this
108 implementation.
110 @change 09.04.2002 by Andreas Schluens
112 void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException)
114 // SAFE =>
115 WriteGuard aWriteLock(m_aLock);
116 m_xDispatchRecorder=xRecorder;
117 // => SAFE
119 //_____________________________________________________________________________
121 @short provides access to the dispatch recorder of this supplier
122 @descr Such recorder can be used outside to record dispatches.
123 But normaly he is used internaly only. Of course he must used
124 from outside to get the recorded data e.g. for saving it as a
125 script.
127 @see setDispatchRecorder()
129 @return the internal used dispatch recorder
130 <br>May it can be <NULL/> if no one was set before.
132 @change 09.04.2002 by Andreas Schluens
134 css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException)
136 // SAFE =>
137 ReadGuard aReadLock(m_aLock);
138 return m_xDispatchRecorder;
139 // => SAFE
142 //_____________________________________________________________________________
144 @short execute a dispatch request and record it
145 @descr If given dispatch object provides right recording interface it
146 will be used. If it's not supported it record the pure dispatch
147 parameters only. There is no code neither the possibility to
148 check if recording is enabled or not.
150 @param aURL the command URL
151 @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further information)
152 @param xDispatcher the original dispatch object which should be recorded
154 @change 09.04.2002 by Andreas Schluens
156 void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL& aURL ,
157 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ,
158 const css::uno::Reference< css::frame::XDispatch >& xDispatcher ) throw (css::uno::RuntimeException)
160 // SAFE =>
161 ReadGuard aReadLock(m_aLock);
162 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
163 aReadLock.unlock();
164 // => SAFE
166 // clear unspecific situations
167 if (!xDispatcher.is())
168 throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: dispatcher is NULL"), static_cast< ::cppu::OWeakObject* >(this));
170 if (!xRecorder.is())
171 throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: no valid dispatch recorder available"), static_cast< ::cppu::OWeakObject* >(this));
173 // check, if given dispatch supports record functionality by itself ...
174 // or must be wrapped.
175 css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
176 xDispatcher,
177 css::uno::UNO_QUERY);
179 if (xRecordable.is())
180 xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
181 else
183 // There is no reason to wait for information about success
184 // of this request. Because status information of a dispatch
185 // are not guaranteed. So we execute it and record used
186 // parameters only.
187 xDispatcher->dispatch(aURL,lArguments);
188 xRecorder->recordDispatch(aURL,lArguments);
192 } // namespace framework
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */