Branch data Line data Source code
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 : : #include <recording/dispatchrecordersupplier.hxx>
21 : : #include <threadhelp/writeguard.hxx>
22 : : #include <threadhelp/readguard.hxx>
23 : : #include <services.h>
24 : :
25 : : #include <com/sun/star/frame/XRecordableDispatch.hpp>
26 : :
27 : : #include <vcl/svapp.hxx>
28 : :
29 : : namespace framework{
30 : :
31 : : //*****************************************************************************************************************
32 : : // XInterface, XTypeProvider
33 : : //*****************************************************************************************************************
34 [ + + ][ + - ]: 142 : 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))
40 : :
41 [ # # ][ # # ]: 0 : DEFINE_XTYPEPROVIDER_3(
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
42 : : DispatchRecorderSupplier,
43 : : css::lang::XTypeProvider,
44 : : css::lang::XServiceInfo,
45 : : css::frame::XDispatchRecorderSupplier)
46 : :
47 [ + - ][ + - ]: 34 : DEFINE_XSERVICEINFO_MULTISERVICE(
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
48 : : DispatchRecorderSupplier,
49 : : ::cppu::OWeakObject,
50 : : SERVICENAME_DISPATCHRECORDERSUPPLIER,
51 : : IMPLEMENTATIONNAME_DISPATCHRECORDERSUPPLIER)
52 : :
53 : 4 : DEFINE_INIT_SERVICE(
54 : : DispatchRecorderSupplier,
55 : : {
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 informations!
60 : : */
61 : : }
62 : : )
63 : :
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.
69 : : */
70 : 4 : DispatchRecorderSupplier::DispatchRecorderSupplier( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
71 : : // init baseclasses first!
72 : : // Attention: Don't change order of initialization!
73 [ + - ]: 4 : : ThreadHelpBase ( &Application::GetSolarMutex() )
74 : : , ::cppu::OWeakObject( )
75 : : // init member
76 : : , m_xDispatchRecorder( NULL )
77 [ + - ][ + - ]: 8 : , m_xFactory ( xFactory )
78 : : {
79 : 4 : }
80 : :
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.
87 : : */
88 [ + - ][ + - ]: 4 : DispatchRecorderSupplier::~DispatchRecorderSupplier()
89 : : {
90 [ + - ]: 4 : m_xFactory = NULL;
91 [ + - ]: 4 : m_xDispatchRecorder = NULL;
92 [ - + ]: 8 : }
93 : :
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.
100 : :
101 : : @see getDispatchRecorder()
102 : :
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.
109 : :
110 : : @change 09.04.2002 by Andreas Schluens
111 : : */
112 : 14 : void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder ) throw (css::uno::RuntimeException)
113 : : {
114 : : // SAFE =>
115 [ + - ]: 14 : WriteGuard aWriteLock(m_aLock);
116 [ + - ][ + - ]: 14 : m_xDispatchRecorder=xRecorder;
117 : : // => SAFE
118 : 14 : }
119 : : //_____________________________________________________________________________
120 : : /**
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.
126 : :
127 : : @see setDispatchRecorder()
128 : :
129 : : @return the internal used dispatch recorder
130 : : <br>May it can be <NULL/> if no one was set before.
131 : :
132 : : @change 09.04.2002 by Andreas Schluens
133 : : */
134 : 10 : css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder() throw (css::uno::RuntimeException)
135 : : {
136 : : // SAFE =>
137 [ + - ]: 10 : ReadGuard aReadLock(m_aLock);
138 [ + - ]: 10 : return m_xDispatchRecorder;
139 : : // => SAFE
140 : : }
141 : :
142 : : //_____________________________________________________________________________
143 : : /**
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.
149 : :
150 : : @param aURL the command URL
151 : : @param lArguments optional arguments (see com.sun.star.document.MediaDescriptor for further informations)
152 : : @param xDispatcher the original dispatch object which should be recorded
153 : :
154 : : @change 09.04.2002 by Andreas Schluens
155 : : */
156 : 6 : 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)
159 : : {
160 : : // SAFE =>
161 [ + - ]: 6 : ReadGuard aReadLock(m_aLock);
162 : 6 : css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
163 [ + - ]: 6 : aReadLock.unlock();
164 : : // => SAFE
165 : :
166 : : // clear unspecific situations
167 [ + + ]: 6 : if (!xDispatcher.is())
168 [ + - ][ + - ]: 2 : throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: dispatcher is NULL"), static_cast< ::cppu::OWeakObject* >(this));
[ + - ]
169 : :
170 [ + + ]: 4 : if (!xRecorder.is())
171 [ + - ][ + - ]: 2 : throw css::uno::RuntimeException(DECLARE_ASCII("specification violation: no valid dispatch recorder available"), static_cast< ::cppu::OWeakObject* >(this));
[ + - ]
172 : :
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 [ + - ]: 2 : css::uno::UNO_QUERY);
178 : :
179 [ - + ]: 2 : if (xRecordable.is())
180 [ # # ][ # # ]: 0 : xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
181 : : else
182 : : {
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 [ + - ][ + - ]: 2 : xDispatcher->dispatch(aURL,lArguments);
188 [ + - ][ + - ]: 2 : xRecorder->recordDispatch(aURL,lArguments);
189 [ + - ]: 6 : }
190 : 2 : }
191 : :
192 : : } // namespace framework
193 : :
194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|