LibreOffice Module framework (master) 1
dispatchrecordersupplier.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/frame/XRecordableDispatch.hpp>
23
24#include <vcl/svapp.hxx>
26
27namespace framework{
28
29// XInterface, XTypeProvider, XServiceInfo
30
32{
33 return "com.sun.star.comp.framework.DispatchRecorderSupplier";
34}
35
36sal_Bool SAL_CALL DispatchRecorderSupplier::supportsService( const OUString& sServiceName )
37{
39}
40
41css::uno::Sequence< OUString > SAL_CALL DispatchRecorderSupplier::getSupportedServiceNames()
42{
43 return { "com.sun.star.frame.DispatchRecorderSupplier" };
44}
45
46
48{
49}
50
58{
59 m_xDispatchRecorder = nullptr;
60}
61
79void SAL_CALL DispatchRecorderSupplier::setDispatchRecorder( const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder )
80{
82 m_xDispatchRecorder=xRecorder;
83}
84
99css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL DispatchRecorderSupplier::getDispatchRecorder()
100{
102 return m_xDispatchRecorder;
103}
104
118void SAL_CALL DispatchRecorderSupplier::dispatchAndRecord( const css::util::URL& aURL ,
119 const css::uno::Sequence< css::beans::PropertyValue >& lArguments ,
120 const css::uno::Reference< css::frame::XDispatch >& xDispatcher )
121{
122 SolarMutexClearableGuard aReadLock;
123 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = m_xDispatchRecorder;
124 aReadLock.clear();
125
126 // clear unspecific situations
127 if (!xDispatcher.is())
128 throw css::uno::RuntimeException("specification violation: dispatcher is NULL", static_cast< ::cppu::OWeakObject* >(this));
129
130 if (!xRecorder.is())
131 throw css::uno::RuntimeException("specification violation: no valid dispatch recorder available", static_cast< ::cppu::OWeakObject* >(this));
132
133 // check, if given dispatch supports record functionality by itself ...
134 // or must be wrapped.
135 css::uno::Reference< css::frame::XRecordableDispatch > xRecordable(
136 xDispatcher,
137 css::uno::UNO_QUERY);
138
139 if (xRecordable.is())
140 xRecordable->dispatchAndRecord(aURL,lArguments,xRecorder);
141 else
142 {
143 // There is no reason to wait for information about success
144 // of this request. Because status information of a dispatch
145 // are not guaranteed. So we execute it and record used
146 // parameters only.
147 xDispatcher->dispatch(aURL,lArguments);
148 xRecorder->recordDispatch(aURL,lArguments);
149 }
150}
151
152} // namespace framework
153
154extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
156 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const& )
157{
158 return cppu::acquire(new framework::DispatchRecorderSupplier());
159}
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
implement a supplier for dispatch recorder @descr This supplier can be set on property "DispatchRecor...
virtual void SAL_CALL dispatchAndRecord(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Reference< css::frame::XDispatch > &xDispatcher) override
execute a dispatch request and record it @descr If given dispatch object provides right recording int...
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::frame::XDispatchRecorder > SAL_CALL getDispatchRecorder() override
provides access to the dispatch recorder of this supplier @descr Such recorder can be used outside to...
css::uno::Reference< css::frame::XDispatchRecorder > m_xDispatchRecorder
provided dispatch recorder of this supplier instance
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void SAL_CALL setDispatchRecorder(const css::uno::Reference< css::frame::XDispatchRecorder > &xRecorder) override
set a new dispatch recorder on this supplier @descr Because there can exist more than one recorder im...
virtual ~DispatchRecorderSupplier() override
standard destructor @descr We are a helper and not a real service.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_DispatchRecorderSupplier_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
URL aURL
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool