xref: /trunk/main/framework/source/jobs/jobdispatch.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10cdf0e10cSrcweir  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 //  my own includes
29cdf0e10cSrcweir #include <jobs/jobdispatch.hxx>
30cdf0e10cSrcweir #include <jobs/joburl.hxx>
31cdf0e10cSrcweir #include <jobs/job.hxx>
32cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
33cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
34cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
35cdf0e10cSrcweir #include <classes/converter.hxx>
36cdf0e10cSrcweir #include <general.h>
37cdf0e10cSrcweir #include <services.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //________________________________
40cdf0e10cSrcweir //  interface includes
41cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
42cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
43cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //________________________________
46cdf0e10cSrcweir //  includes of other projects
47cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
48cdf0e10cSrcweir #include <vcl/svapp.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //________________________________
51cdf0e10cSrcweir //  namespace
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace framework{
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //________________________________
56cdf0e10cSrcweir //  non exported const
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //________________________________
59cdf0e10cSrcweir //  non exported definitions
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //________________________________
62cdf0e10cSrcweir //  declarations
63cdf0e10cSrcweir 
DEFINE_XINTERFACE_6(JobDispatch,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::frame::XDispatchProvider),DIRECT_INTERFACE (css::lang::XInitialization),DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::frame::XNotifyingDispatch),DIRECT_INTERFACE (css::frame::XDispatch))64cdf0e10cSrcweir DEFINE_XINTERFACE_6( JobDispatch                                     ,
65cdf0e10cSrcweir                      OWeakObject                                     ,
66cdf0e10cSrcweir                      DIRECT_INTERFACE(css::lang::XTypeProvider      ),
67cdf0e10cSrcweir                      DIRECT_INTERFACE(css::frame::XDispatchProvider ),
68cdf0e10cSrcweir                      DIRECT_INTERFACE(css::lang::XInitialization ),
69cdf0e10cSrcweir                      DIRECT_INTERFACE(css::lang::XServiceInfo),
70cdf0e10cSrcweir                      DIRECT_INTERFACE(css::frame::XNotifyingDispatch),
71cdf0e10cSrcweir                      DIRECT_INTERFACE(css::frame::XDispatch         )
72cdf0e10cSrcweir                    )
73cdf0e10cSrcweir 
74cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_6( JobDispatch                   ,
75cdf0e10cSrcweir                         css::lang::XTypeProvider      ,
76cdf0e10cSrcweir                         css::frame::XDispatchProvider ,
77cdf0e10cSrcweir                         css::frame::XNotifyingDispatch,
78cdf0e10cSrcweir                         css::lang::XInitialization,
79cdf0e10cSrcweir                         css::lang::XServiceInfo,
80cdf0e10cSrcweir                         css::frame::XDispatch
81cdf0e10cSrcweir                       )
82cdf0e10cSrcweir 
83cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE( JobDispatch                   ,
84cdf0e10cSrcweir                                   ::cppu::OWeakObject           ,
85cdf0e10cSrcweir                                   SERVICENAME_PROTOCOLHANDLER   ,
86cdf0e10cSrcweir                                   IMPLEMENTATIONNAME_JOBDISPATCH
87cdf0e10cSrcweir                                 )
88cdf0e10cSrcweir 
89cdf0e10cSrcweir DEFINE_INIT_SERVICE( JobDispatch,
90cdf0e10cSrcweir                      {
91cdf0e10cSrcweir                          /*Attention
92cdf0e10cSrcweir                              I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
93cdf0e10cSrcweir                              to create a new instance of this class by our own supported service factory.
94cdf0e10cSrcweir                              see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
95cdf0e10cSrcweir                          */
96cdf0e10cSrcweir                      }
97cdf0e10cSrcweir                    )
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //________________________________
100cdf0e10cSrcweir /**
101cdf0e10cSrcweir     @short      standard ctor
102cdf0e10cSrcweir     @descr      It initialize this new instance.
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     @param      xSMGR
105cdf0e10cSrcweir                     reference to the uno service manager
106cdf0e10cSrcweir */
107cdf0e10cSrcweir JobDispatch::JobDispatch( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
108cdf0e10cSrcweir     : ThreadHelpBase(&Application::GetSolarMutex())
109cdf0e10cSrcweir     , OWeakObject   (                             )
110cdf0e10cSrcweir     , m_xSMGR       (xSMGR                        )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //________________________________
115cdf0e10cSrcweir /**
116cdf0e10cSrcweir     @short  let this instance die
117816026e9SJohn Bampton     @descr  We have to release all used resources and free used memory.
118cdf0e10cSrcweir */
~JobDispatch()119cdf0e10cSrcweir JobDispatch::~JobDispatch()
120cdf0e10cSrcweir {
121816026e9SJohn Bampton     // release all used resources
122cdf0e10cSrcweir     m_xSMGR  = css::uno::Reference< css::lang::XMultiServiceFactory >();
123cdf0e10cSrcweir     m_xFrame = css::uno::Reference< css::frame::XFrame >();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //________________________________
127cdf0e10cSrcweir /**
1286e9cccf4Smseidel     @short  implementation of XInitialization
129cdf0e10cSrcweir     @descr  A protocol handler can provide this functionality, if it wish to get additional informations
130cdf0e10cSrcweir             about the context it runs. In this case the frame reference would be given by the outside code.
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     @param  lArguments
133cdf0e10cSrcweir                 the list of initialization arguments
134cdf0e10cSrcweir                 First parameter should be the frame reference we need.
135cdf0e10cSrcweir */
initialize(const css::uno::Sequence<css::uno::Any> & lArguments)136cdf0e10cSrcweir void SAL_CALL JobDispatch::initialize( const css::uno::Sequence< css::uno::Any >& lArguments ) throw(css::uno::Exception       ,
137cdf0e10cSrcweir                                                                                                      css::uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     /* SAFE { */
140cdf0e10cSrcweir     WriteGuard aWriteLock(m_aLock);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     for (int a=0; a<lArguments.getLength(); ++a)
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         if (a==0)
145cdf0e10cSrcweir         {
146cdf0e10cSrcweir             lArguments[a] >>= m_xFrame;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             css::uno::Reference< css::frame::XModuleManager > xModuleManager(
149cdf0e10cSrcweir                 m_xSMGR->createInstance(
150cdf0e10cSrcweir                     SERVICENAME_MODULEMANAGER ),
151cdf0e10cSrcweir                 css::uno::UNO_QUERY_THROW );
152cdf0e10cSrcweir             try
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 m_sModuleIdentifier = xModuleManager->identify( m_xFrame );
155cdf0e10cSrcweir             }
156cdf0e10cSrcweir             catch( css::uno::Exception& )
157cdf0e10cSrcweir             {}
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     aWriteLock.unlock();
162cdf0e10cSrcweir     /* } SAFE */
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //________________________________
166cdf0e10cSrcweir /**
167cdf0e10cSrcweir     @short  implementation of XDispatchProvider::queryDispatches()
168cdf0e10cSrcweir     @descr  Every protocol handler will be asked for his agreement, if an URL was queried
169cdf0e10cSrcweir             for which this handler is registered. It's the chance for this handler to validate
170cdf0e10cSrcweir             the given URL and return a dispatch object (may be itself) or not.
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     @param  aURL
173cdf0e10cSrcweir                 the queried URL, which should be checked
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     @param  sTargetFrameName
176cdf0e10cSrcweir                 describes the target frame, in which context this handler will be used
177cdf0e10cSrcweir                 Is mostly set to "", "_self", "_blank", "_default" or a non special one
178cdf0e10cSrcweir                 using SELF/CREATE as search flags.
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     @param  nSearchFlags
181cdf0e10cSrcweir                 Can be SELF or CREATE only and are set only if sTargetFrameName isn't a special target
182cdf0e10cSrcweir */
queryDispatch(const css::util::URL & aURL,const::rtl::OUString &,sal_Int32)183cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > SAL_CALL JobDispatch::queryDispatch( /*IN*/ const css::util::URL&  aURL             ,
184cdf0e10cSrcweir                                                                                   /*IN*/ const ::rtl::OUString& /*sTargetFrameName*/ ,
185cdf0e10cSrcweir                                                                                   /*IN*/       sal_Int32        /*nSearchFlags*/     ) throw(css::uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatch > xDispatch;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     JobURL aAnalyzedURL(aURL.Complete);
190cdf0e10cSrcweir     if (aAnalyzedURL.isValid())
191cdf0e10cSrcweir         xDispatch = css::uno::Reference< css::frame::XDispatch >( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     return xDispatch;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //________________________________
197cdf0e10cSrcweir /**
198cdf0e10cSrcweir     @short  implementation of XDispatchProvider::queryDispatches()
199cdf0e10cSrcweir     @descr  It's an optimized access for remote, so you can ask for
200cdf0e10cSrcweir             multiple dispatch objects at the same time.
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     @param  lDescriptor
203cdf0e10cSrcweir                 a list of queryDispatch() parameter
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     @return A list of corresponding dispatch objects.
206cdf0e10cSrcweir             NULL references are not skipped. Every result
207cdf0e10cSrcweir             match to one given descriptor item.
208cdf0e10cSrcweir */
queryDispatches(const css::uno::Sequence<css::frame::DispatchDescriptor> & lDescriptor)209cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL JobDispatch::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor ) throw(css::uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     // don't pack resulting list!
212cdf0e10cSrcweir     sal_Int32 nCount = lDescriptor.getLength();
213cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatches(nCount);
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     for (sal_Int32 i=0; i<nCount; ++i)
216cdf0e10cSrcweir         lDispatches[i] = queryDispatch( lDescriptor[i].FeatureURL  ,
217cdf0e10cSrcweir                                         lDescriptor[i].FrameName   ,
218cdf0e10cSrcweir                                         lDescriptor[i].SearchFlags );
219cdf0e10cSrcweir     return lDispatches;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //________________________________
223cdf0e10cSrcweir /**
224cdf0e10cSrcweir     @short  implementation of XNotifyingDispatch::dispatchWithNotification()
225cdf0e10cSrcweir     @descr  It creates the job service implementation and call execute on it.
226cdf0e10cSrcweir             Further it starts the life time control of it. (important for async job)
227cdf0e10cSrcweir             For synchonrous job we react for the returned result directly ... for asynchronous
228cdf0e10cSrcweir             ones we do it later inside our callback method. But we use the same impl method
229cdf0e10cSrcweir             doing that to share the code. (see impl_finishJob())
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             If a job is already running, (it can only occure for asynchronous jobs)
232cdf0e10cSrcweir             don't start the same job a second time. Queue in the given dispatch parameter
23307a3d7f1SPedro Giffuni             and return immediately. If the current running job call us back, we will start this
234cdf0e10cSrcweir             new dispatch request.
23507a3d7f1SPedro Giffuni             If no job is running - queue the parameter too! But then start the new job immediately.
236cdf0e10cSrcweir             We have to queue it every time - because it hold us alive by ref count!
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     @param  aURL
239cdf0e10cSrcweir                 describe the job(s), which should be started
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     @param  lArgs
242cdf0e10cSrcweir                 optional arguments for this request
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     @param  xListener
245cdf0e10cSrcweir                 an interested listener for possible results of this operation
246cdf0e10cSrcweir */
dispatchWithNotification(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArgs,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)247cdf0e10cSrcweir void SAL_CALL JobDispatch::dispatchWithNotification( /*IN*/ const css::util::URL&                                             aURL      ,
248cdf0e10cSrcweir                                                      /*IN*/ const css::uno::Sequence< css::beans::PropertyValue >&            lArgs     ,
249cdf0e10cSrcweir                                                      /*IN*/ const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     JobURL aAnalyzedURL(aURL.Complete);
252cdf0e10cSrcweir     if (aAnalyzedURL.isValid())
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         ::rtl::OUString sRequest;
255cdf0e10cSrcweir         if (aAnalyzedURL.getEvent(sRequest))
256cdf0e10cSrcweir             impl_dispatchEvent(sRequest, lArgs, xListener);
257cdf0e10cSrcweir         else
258cdf0e10cSrcweir         if (aAnalyzedURL.getService(sRequest))
259cdf0e10cSrcweir             impl_dispatchService(sRequest, lArgs, xListener);
260cdf0e10cSrcweir         else
261cdf0e10cSrcweir         if (aAnalyzedURL.getAlias(sRequest))
262cdf0e10cSrcweir             impl_dispatchAlias(sRequest, lArgs, xListener);
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //________________________________
267cdf0e10cSrcweir /**
268cdf0e10cSrcweir     @short  dispatch an event
269cdf0e10cSrcweir     @descr  We search all registered jobs for this event and execute it.
270cdf0e10cSrcweir             After doing so, we inform the given listener about the results.
271cdf0e10cSrcweir             (There will be one notify for every executed job!)
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     @param  sEvent
274cdf0e10cSrcweir                 the event, for which jobs can be registered
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     @param  lArgs
277cdf0e10cSrcweir                 optional arguments for this request
278cdf0e10cSrcweir                 Currently not used!
279cdf0e10cSrcweir 
280cdf0e10cSrcweir     @param  xListener
281cdf0e10cSrcweir                 an interested listener for possible results of this operation
282cdf0e10cSrcweir */
impl_dispatchEvent(const::rtl::OUString & sEvent,const css::uno::Sequence<css::beans::PropertyValue> & lArgs,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)283cdf0e10cSrcweir void JobDispatch::impl_dispatchEvent( /*IN*/ const ::rtl::OUString&                                            sEvent    ,
284cdf0e10cSrcweir                                       /*IN*/ const css::uno::Sequence< css::beans::PropertyValue >&            lArgs     ,
285cdf0e10cSrcweir                                       /*IN*/ const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir     // get list of all enabled jobs
288cdf0e10cSrcweir     // The called static helper methods read it from the configuration and
289cdf0e10cSrcweir     // filter disabled jobs using it's time stamp values.
290cdf0e10cSrcweir     /* SAFE { */
291cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
292cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > lJobs = JobData::getEnabledJobsForEvent(m_xSMGR, sEvent);
293cdf0e10cSrcweir     aReadLock.unlock();
294cdf0e10cSrcweir     /* } SAFE */
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchResultListener > xThis( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     // no jobs ... no execution
299cdf0e10cSrcweir     // But a may given listener will know something ...
300*2814ae3cSJohn Bampton     // I think this operation was finished successfully.
30107a3d7f1SPedro Giffuni     // It's not really an error, if no registered jobs could be located.
302cdf0e10cSrcweir     // Step over all found jobs and execute it
303cdf0e10cSrcweir     int nExecutedJobs=0;
304cdf0e10cSrcweir     for (int j=0; j<lJobs.getLength(); ++j)
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         /* SAFE { */
307cdf0e10cSrcweir         aReadLock.lock();
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         JobData aCfg(m_xSMGR);
310cdf0e10cSrcweir         aCfg.setEvent(sEvent, lJobs[j]);
311cdf0e10cSrcweir         aCfg.setEnvironment(JobData::E_DISPATCH);
312cdf0e10cSrcweir         const bool bIsEnabled=aCfg.hasCorrectContext(m_sModuleIdentifier);
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         /*Attention!
315cdf0e10cSrcweir             Jobs implements interfaces and dies by ref count!
316cdf0e10cSrcweir             And freeing of such uno object is done by uno itself.
317cdf0e10cSrcweir             So we have to use dynamic memory everytimes.
318cdf0e10cSrcweir          */
319cdf0e10cSrcweir         Job* pJob = new Job(m_xSMGR, m_xFrame);
320cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > xJob(static_cast< ::cppu::OWeakObject* >(pJob), css::uno::UNO_QUERY);
321cdf0e10cSrcweir         pJob->setJobData(aCfg);
322cdf0e10cSrcweir 
323cdf0e10cSrcweir         aReadLock.unlock();
324cdf0e10cSrcweir         /* } SAFE */
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         if (!bIsEnabled)
327cdf0e10cSrcweir             continue;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir         // Special mode for listener.
33015289133Smseidel         // We don't notify it directly here. We delegate that
331cdf0e10cSrcweir         // to the job implementation. But we must set ourself there too.
33207a3d7f1SPedro Giffuni         // Because this job must fake the source address of the event.
33315289133Smseidel         // Otherwise the listener maybe will ignore it.
334cdf0e10cSrcweir         if (xListener.is())
335cdf0e10cSrcweir             pJob->setDispatchResultFake(xListener, xThis);
336cdf0e10cSrcweir         pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
337cdf0e10cSrcweir         ++nExecutedJobs;
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir     if (nExecutedJobs<1 && xListener.is())
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         css::frame::DispatchResultEvent aEvent;
343cdf0e10cSrcweir         aEvent.Source = xThis;
344cdf0e10cSrcweir         aEvent.State  = css::frame::DispatchResultState::SUCCESS;
345cdf0e10cSrcweir         xListener->dispatchFinished(aEvent);
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir //________________________________
350cdf0e10cSrcweir /**
351cdf0e10cSrcweir     @short  dispatch a service
352cdf0e10cSrcweir     @descr  We use the given name only to create and if possible to initialize
353cdf0e10cSrcweir             it as an uno service. It can be usefully for creating (caching?)
354cdf0e10cSrcweir             of e.g. one instance services.
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     @param  sService
3575e7dbebbSJohn Bampton                 the uno implementation or service name of the job, which should be instantiated
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     @param  lArgs
360cdf0e10cSrcweir                 optional arguments for this request
361cdf0e10cSrcweir                 Currently not used!
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     @param  xListener
364cdf0e10cSrcweir                 an interested listener for possible results of this operation
365cdf0e10cSrcweir */
impl_dispatchService(const::rtl::OUString & sService,const css::uno::Sequence<css::beans::PropertyValue> & lArgs,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)366cdf0e10cSrcweir void JobDispatch::impl_dispatchService( /*IN*/ const ::rtl::OUString&                                            sService  ,
367cdf0e10cSrcweir                                         /*IN*/ const css::uno::Sequence< css::beans::PropertyValue >&            lArgs     ,
368cdf0e10cSrcweir                                         /*IN*/ const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     /* SAFE { */
371cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     JobData aCfg(m_xSMGR);
374cdf0e10cSrcweir     aCfg.setService(sService);
375cdf0e10cSrcweir     aCfg.setEnvironment(JobData::E_DISPATCH);
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     /*Attention!
378cdf0e10cSrcweir         Jobs implements interfaces and dies by ref count!
379cdf0e10cSrcweir         And freeing of such uno object is done by uno itself.
380cdf0e10cSrcweir         So we have to use dynamic memory everytimes.
381cdf0e10cSrcweir      */
382cdf0e10cSrcweir     Job* pJob = new Job(m_xSMGR, m_xFrame);
383cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xJob(static_cast< ::cppu::OWeakObject* >(pJob), css::uno::UNO_QUERY);
384cdf0e10cSrcweir     pJob->setJobData(aCfg);
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     aReadLock.unlock();
387cdf0e10cSrcweir     /* } SAFE */
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchResultListener > xThis( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     // Special mode for listener.
39215289133Smseidel     // We don't notify it directly here. We delegate that
393cdf0e10cSrcweir     // to the job implementation. But we must set ourself there too.
39407a3d7f1SPedro Giffuni     // Because this job must fake the source address of the event.
39515289133Smseidel     // Otherwise the listener maybe will ignore it.
396cdf0e10cSrcweir     if (xListener.is())
397cdf0e10cSrcweir         pJob->setDispatchResultFake(xListener, xThis);
398cdf0e10cSrcweir     pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir //________________________________
402cdf0e10cSrcweir /**
403cdf0e10cSrcweir     @short  dispatch an alias
404cdf0e10cSrcweir     @descr  We use this alias to locate a job inside the configuration
405cdf0e10cSrcweir             and execute it. Further we inform the given listener about the results.
406cdf0e10cSrcweir 
407cdf0e10cSrcweir     @param  sAlias
408cdf0e10cSrcweir                 the alias name of the configured job
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     @param  lArgs
411cdf0e10cSrcweir                 optional arguments for this request
412cdf0e10cSrcweir                 Currently not used!
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     @param  xListener
415cdf0e10cSrcweir                 an interested listener for possible results of this operation
416cdf0e10cSrcweir */
impl_dispatchAlias(const::rtl::OUString & sAlias,const css::uno::Sequence<css::beans::PropertyValue> & lArgs,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)417cdf0e10cSrcweir void JobDispatch::impl_dispatchAlias( /*IN*/ const ::rtl::OUString&                                            sAlias    ,
418cdf0e10cSrcweir                                       /*IN*/ const css::uno::Sequence< css::beans::PropertyValue >&            lArgs     ,
419cdf0e10cSrcweir                                       /*IN*/ const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir     /* SAFE { */
422cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     JobData aCfg(m_xSMGR);
425cdf0e10cSrcweir     aCfg.setAlias(sAlias);
426cdf0e10cSrcweir     aCfg.setEnvironment(JobData::E_DISPATCH);
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     /*Attention!
429cdf0e10cSrcweir         Jobs implements interfaces and dies by ref count!
430cdf0e10cSrcweir         And freeing of such uno object is done by uno itself.
431cdf0e10cSrcweir         So we have to use dynamic memory everytimes.
432cdf0e10cSrcweir      */
433cdf0e10cSrcweir     Job* pJob = new Job(m_xSMGR, m_xFrame);
434cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xJob(static_cast< ::cppu::OWeakObject* >(pJob), css::uno::UNO_QUERY);
435cdf0e10cSrcweir     pJob->setJobData(aCfg);
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     aReadLock.unlock();
438cdf0e10cSrcweir     /* } SAFE */
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchResultListener > xThis( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     // Special mode for listener.
44315289133Smseidel     // We don't notify it directly here. We delegate that
444cdf0e10cSrcweir     // to the job implementation. But we must set ourself there too.
44507a3d7f1SPedro Giffuni     // Because this job must fake the source address of the event.
44615289133Smseidel     // Otherwise the listener maybe will ignore it.
447cdf0e10cSrcweir     if (xListener.is())
448cdf0e10cSrcweir         pJob->setDispatchResultFake(xListener, xThis);
449cdf0e10cSrcweir     pJob->execute(Converter::convert_seqPropVal2seqNamedVal(lArgs));
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir //________________________________
453cdf0e10cSrcweir /**
454cdf0e10cSrcweir     @short  implementation of XDispatch::dispatch()
455cdf0e10cSrcweir     @descr  Because the methods dispatch() and dispatchWithNotification() are different in her parameters
456cdf0e10cSrcweir             only, we can forward this request to dispatchWithNotification() by using an empty listener!
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     @param  aURL
459cdf0e10cSrcweir                 describe the job(s), which should be started
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     @param  lArgs
462cdf0e10cSrcweir                 optional arguments for this request
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     @see    dispatchWithNotification()
465cdf0e10cSrcweir */
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArgs)466cdf0e10cSrcweir void SAL_CALL JobDispatch::dispatch( /*IN*/ const css::util::URL&                                  aURL  ,
467cdf0e10cSrcweir                                      /*IN*/ const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) throw(css::uno::RuntimeException)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir     dispatchWithNotification(aURL, lArgs, css::uno::Reference< css::frame::XDispatchResultListener >());
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir //________________________________
473cdf0e10cSrcweir /**
474cdf0e10cSrcweir     @short  not supported
475cdf0e10cSrcweir */
addStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)476cdf0e10cSrcweir void SAL_CALL JobDispatch::addStatusListener( /*IN*/ const css::uno::Reference< css::frame::XStatusListener >&,
477cdf0e10cSrcweir                                               /*IN*/ const css::util::URL&                                      ) throw(css::uno::RuntimeException)
478cdf0e10cSrcweir {
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir //________________________________
482cdf0e10cSrcweir /**
483cdf0e10cSrcweir     @short  not supported
484cdf0e10cSrcweir */
removeStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)485cdf0e10cSrcweir void SAL_CALL JobDispatch::removeStatusListener( /*IN*/ const css::uno::Reference< css::frame::XStatusListener >&,
486cdf0e10cSrcweir                                                  /*IN*/ const css::util::URL&                                          ) throw(css::uno::RuntimeException)
487cdf0e10cSrcweir {
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir } // namespace framework
491