22#include <com/sun/star/frame/XNotifyingDispatch.hpp>
23#include <com/sun/star/util/URLTransformer.hpp>
24#include <com/sun/star/util/XURLTransformer.hpp>
36OUString SAL_CALL DispatchHelper::getImplementationName()
38 return "com.sun.star.comp.framework.services.DispatchHelper";
41sal_Bool SAL_CALL DispatchHelper::supportsService(
const OUString& sServiceName)
46css::uno::Sequence<OUString> SAL_CALL DispatchHelper::getSupportedServiceNames()
48 return {
"com.sun.star.frame.DispatchHelper" };
55DispatchHelper::DispatchHelper(css::uno::Reference<css::uno::XComponentContext> xContext)
63DispatchHelper::~DispatchHelper() {}
84css::uno::Any SAL_CALL DispatchHelper::executeDispatch(
85 const css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider,
86 const OUString& sURL,
const OUString& sTargetFrameName, sal_Int32 nSearchFlags,
87 const css::uno::Sequence<css::beans::PropertyValue>& lArguments)
90 if ((!xDispatchProvider.is()) || (!
m_xContext.is()) || (sURL.isEmpty()))
92 return css::uno::Any();
96 css::uno::Reference<css::util::XURLTransformer> xParser;
99 std::scoped_lock aReadLock(
m_mutex);
100 xParser = css::util::URLTransformer::create(
m_xContext);
105 aURL.Complete = sURL;
106 xParser->parseStrict(aURL);
109 css::uno::Reference<css::frame::XDispatch>
xDispatch
110 = xDispatchProvider->queryDispatch(aURL, sTargetFrameName, nSearchFlags);
113 bool bOnMainThread = aDescriptor.getUnpackedValueOrDefault(
"OnMainThread",
false);
117 return executeDispatch(xDispatch, aURL,
true, lArguments);
120 return executeDispatch(xDispatch, aURL,
true, lArguments);
124DispatchHelper::executeDispatch(
const css::uno::Reference<css::frame::XDispatch>& xDispatch,
125 const css::util::URL& aURL,
bool SyncronFlag,
126 const css::uno::Sequence<css::beans::PropertyValue>& lArguments)
129 css::uno::Reference<css::uno::XInterface> xTHIS(
static_cast<::
cppu::OWeakObject*
>(
this),
130 css::uno::UNO_QUERY);
136 css::uno::Reference<css::frame::XNotifyingDispatch> xNotifyDispatch(xDispatch,
137 css::uno::UNO_QUERY);
140 css::uno::Sequence<css::beans::PropertyValue>
aArguments(lArguments);
141 sal_Int32
nLength = lArguments.getLength();
144 pArguments[
nLength].Name =
"SynchronMode";
145 pArguments[
nLength].Value <<= SyncronFlag;
147 if (xNotifyDispatch.is())
151 css::uno::Reference<css::frame::XDispatchResultListener> xListener(xTHIS,
152 css::uno::UNO_QUERY);
155 std::scoped_lock aWriteLock(
m_mutex);
156 m_xBroadcaster = xNotifyDispatch;
157 m_aBlockFlag =
false;
163 xNotifyDispatch->dispatchWithNotification(aURL, aArguments, xListener);
165 std::unique_lock aWriteLock(
m_mutex);
166 m_aBlock.wait(aWriteLock, [
this] {
return m_aBlockFlag; });
187void SAL_CALL DispatchHelper::dispatchFinished(
const css::frame::DispatchResultEvent& aResult)
192 m_aBlock.notify_one();
193 m_xBroadcaster.clear();
201void SAL_CALL DispatchHelper::disposing(
const css::lang::EventObject&)
206 m_aBlock.notify_one();
207 m_xBroadcaster.clear();
211extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
213 css::uno::Sequence<css::uno::Any>
const&)
215 return cppu::acquire(
new framework::DispatchHelper(context));
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_DispatchHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XDispatch > xDispatch
css::uno::Reference< css::uno::XComponentContext > m_xContext
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
auto syncExecute(FuncT const &func) -> decltype(func())