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
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
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.
196d739b60SAndrew Rist  *
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/jobexecutor.hxx>
30cdf0e10cSrcweir #include <jobs/job.hxx>
31cdf0e10cSrcweir #include <jobs/joburl.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASS_CONVERTER_HXX_
34cdf0e10cSrcweir #include <classes/converter.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <threadhelp/transactionguard.hxx>
37cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
38cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
39cdf0e10cSrcweir #include <general.h>
40cdf0e10cSrcweir #include <services.h>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //________________________________
43cdf0e10cSrcweir //	interface includes
44cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //________________________________
49cdf0e10cSrcweir //	includes of other projects
50cdf0e10cSrcweir #include <unotools/configpathes.hxx>
51cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
52cdf0e10cSrcweir #include <vcl/svapp.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <rtl/logfile.hxx>
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //________________________________
57cdf0e10cSrcweir //	namespace
58cdf0e10cSrcweir 
59cdf0e10cSrcweir namespace framework{
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //________________________________
62cdf0e10cSrcweir //	non exported const
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //________________________________
65cdf0e10cSrcweir //	non exported definitions
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //________________________________
68cdf0e10cSrcweir //	declarations
69cdf0e10cSrcweir 
70cdf0e10cSrcweir DEFINE_XINTERFACE_6( JobExecutor                                                               ,
71cdf0e10cSrcweir                      OWeakObject                                                               ,
72cdf0e10cSrcweir                      DIRECT_INTERFACE(css::lang::XTypeProvider                                ),
73cdf0e10cSrcweir                      DIRECT_INTERFACE(css::lang::XServiceInfo                                 ),
74cdf0e10cSrcweir                      DIRECT_INTERFACE(css::task::XJobExecutor                                 ),
75cdf0e10cSrcweir                      DIRECT_INTERFACE(css::container::XContainerListener                      ),
76cdf0e10cSrcweir                      DIRECT_INTERFACE(css::document::XEventListener                           ),
77cdf0e10cSrcweir                      DERIVED_INTERFACE(css::lang::XEventListener,css::document::XEventListener)
78cdf0e10cSrcweir                    )
79cdf0e10cSrcweir 
80cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_6( JobExecutor                       ,
81cdf0e10cSrcweir                         css::lang::XTypeProvider          ,
82cdf0e10cSrcweir                         css::lang::XServiceInfo           ,
83cdf0e10cSrcweir                         css::task::XJobExecutor           ,
84cdf0e10cSrcweir                         css::container::XContainerListener,
85cdf0e10cSrcweir                         css::document::XEventListener     ,
86cdf0e10cSrcweir                         css::lang::XEventListener
87cdf0e10cSrcweir                       )
88cdf0e10cSrcweir 
89cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE( JobExecutor                   ,
90cdf0e10cSrcweir                                         ::cppu::OWeakObject           ,
91cdf0e10cSrcweir                                         SERVICENAME_JOBEXECUTOR       ,
92cdf0e10cSrcweir                                         IMPLEMENTATIONNAME_JOBEXECUTOR
93cdf0e10cSrcweir                                       )
94cdf0e10cSrcweir 
95cdf0e10cSrcweir DEFINE_INIT_SERVICE( JobExecutor,
96cdf0e10cSrcweir                      {
97cdf0e10cSrcweir                          m_xModuleManager = css::uno::Reference< css::frame::XModuleManager >(
98cdf0e10cSrcweir                              m_xSMGR->createInstance(
99cdf0e10cSrcweir                                  SERVICENAME_MODULEMANAGER ),
100cdf0e10cSrcweir                              css::uno::UNO_QUERY_THROW );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                          /*Attention
103cdf0e10cSrcweir                              I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
104cdf0e10cSrcweir                              to create a new instance of this class by our own supported service factory.
105cdf0e10cSrcweir                              see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
106cdf0e10cSrcweir                          */
107cdf0e10cSrcweir                         // read the list of all currently registered events inside configuration.
108cdf0e10cSrcweir                         // e.g. "/org.openoffice.Office.Jobs/Events/<event name>"
109cdf0e10cSrcweir                         // We need it later to check if an incoming event request can be executed successfully
110cdf0e10cSrcweir                         // or must be rejected. It's an optimization! Of course we must implement updating of this
111cdf0e10cSrcweir                         // list too ... Be listener at the configuration.
112cdf0e10cSrcweir 
113cdf0e10cSrcweir                         m_aConfig.open(ConfigAccess::E_READONLY);
114cdf0e10cSrcweir                         if (m_aConfig.getMode() == ConfigAccess::E_READONLY)
115cdf0e10cSrcweir                         {
116cdf0e10cSrcweir                             css::uno::Reference< css::container::XNameAccess > xRegistry(m_aConfig.cfg(), css::uno::UNO_QUERY);
117cdf0e10cSrcweir                             if (xRegistry.is())
118cdf0e10cSrcweir                                 m_lEvents = Converter::convert_seqOUString2OUStringList(xRegistry->getElementNames());
119cdf0e10cSrcweir 
120cdf0e10cSrcweir                             css::uno::Reference< css::container::XContainer > xNotifier(m_aConfig.cfg(), css::uno::UNO_QUERY);
121cdf0e10cSrcweir                             if (xNotifier.is())
122cdf0e10cSrcweir                             {
123cdf0e10cSrcweir                                 css::uno::Reference< css::container::XContainerListener > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
124cdf0e10cSrcweir                                 xNotifier->addContainerListener(xThis);
125cdf0e10cSrcweir                             }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir                             // don't close cfg here!
128cdf0e10cSrcweir                             // It will be done inside disposing ...
129cdf0e10cSrcweir                         }
130cdf0e10cSrcweir                      }
131cdf0e10cSrcweir                    )
132cdf0e10cSrcweir 
133cdf0e10cSrcweir //________________________________
134cdf0e10cSrcweir 
135cdf0e10cSrcweir /**
136cdf0e10cSrcweir     @short      standard ctor
137cdf0e10cSrcweir     @descr      It initialize this new instance.
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     @param      xSMGR
140cdf0e10cSrcweir                     reference to the uno service manager
141cdf0e10cSrcweir  */
142cdf0e10cSrcweir JobExecutor::JobExecutor( /*IN*/ const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
143cdf0e10cSrcweir     : ThreadHelpBase      (&Application::GetSolarMutex()                                   )
144cdf0e10cSrcweir     , ::cppu::OWeakObject (                                                                )
145cdf0e10cSrcweir     , m_xSMGR             (xSMGR                                                           )
146cdf0e10cSrcweir     , m_xModuleManager    (                                                                )
147cdf0e10cSrcweir     , m_aConfig           (xSMGR, ::rtl::OUString::createFromAscii(JobData::EVENTCFG_ROOT) )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     // Don't do any reference related code here! Do it inside special
150cdf0e10cSrcweir     // impl_ method() ... see DEFINE_INIT_SERVICE() macro for further informations.
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir JobExecutor::~JobExecutor()
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     LOG_ASSERT(m_aConfig.getMode() == ConfigAccess::E_CLOSED, "JobExecutor::~JobExecutor()\nConfiguration don't send dispoing() message!\n")
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //________________________________
159cdf0e10cSrcweir 
160cdf0e10cSrcweir /**
161cdf0e10cSrcweir     @short  implementation of XJobExecutor interface
162cdf0e10cSrcweir     @descr  We use the given event to locate any registered job inside our configuration
163*07a3d7f1SPedro Giffuni             and execute it. Further we control the lifetime of it and suppress
164cdf0e10cSrcweir             shutdown of the office till all jobs was finished.
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     @param  sEvent
167cdf0e10cSrcweir                 is used to locate registered jobs
168cdf0e10cSrcweir  */
169cdf0e10cSrcweir void SAL_CALL JobExecutor::trigger( const ::rtl::OUString& sEvent ) throw(css::uno::RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT(aLog, "fwk (as96863) JobExecutor::trigger()");
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     /* SAFE { */
174cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // Optimization!
177cdf0e10cSrcweir     // Check if the given event name exist inside configuration and reject wrong requests.
178*07a3d7f1SPedro Giffuni     // This optimization suppress using of the cfg api for getting event and job descriptions ...
179cdf0e10cSrcweir     if (m_lEvents.find(sEvent) == m_lEvents.end())
180cdf0e10cSrcweir         return;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     // get list of all enabled jobs
183cdf0e10cSrcweir     // The called static helper methods read it from the configuration and
184cdf0e10cSrcweir     // filter disabled jobs using it's time stamp values.
185cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > lJobs = JobData::getEnabledJobsForEvent(m_xSMGR, sEvent);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     aReadLock.unlock();
188cdf0e10cSrcweir     /* } SAFE */
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     // step over all enabled jobs and execute it
191cdf0e10cSrcweir     sal_Int32 c = lJobs.getLength();
192cdf0e10cSrcweir     for (sal_Int32 j=0; j<c; ++j)
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         /* SAFE { */
195cdf0e10cSrcweir         aReadLock.lock();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         JobData aCfg(m_xSMGR);
198cdf0e10cSrcweir         aCfg.setEvent(sEvent, lJobs[j]);
199cdf0e10cSrcweir         aCfg.setEnvironment(JobData::E_EXECUTION);
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         /*Attention!
202cdf0e10cSrcweir             Jobs implements interfaces and dies by ref count!
203cdf0e10cSrcweir             And freeing of such uno object is done by uno itself.
204cdf0e10cSrcweir             So we have to use dynamic memory everytimes.
205cdf0e10cSrcweir          */
206cdf0e10cSrcweir         Job* pJob = new Job(m_xSMGR, css::uno::Reference< css::frame::XFrame >());
207cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > xJob(static_cast< ::cppu::OWeakObject* >(pJob), css::uno::UNO_QUERY);
208cdf0e10cSrcweir         pJob->setJobData(aCfg);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         aReadLock.unlock();
211cdf0e10cSrcweir         /* } SAFE */
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         pJob->execute(css::uno::Sequence< css::beans::NamedValue >());
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir //________________________________
218cdf0e10cSrcweir 
219cdf0e10cSrcweir void SAL_CALL JobExecutor::notifyEvent( const css::document::EventObject& aEvent ) throw(css::uno::RuntimeException)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_NEW             = DECLARE_ASCII("OnNew"             ); // Doc UI  event
222cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_LOAD            = DECLARE_ASCII("OnLoad"            ); // Doc UI  event
223cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_CREATE          = DECLARE_ASCII("OnCreate"          ); // Doc API event
224cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_LOAD_FINISHED   = DECLARE_ASCII("OnLoadFinished"    ); // Doc API event
225cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_DOCUMENT_OPENED = DECLARE_ASCII("onDocumentOpened"  ); // Job UI  event : OnNew    or OnLoad
226cdf0e10cSrcweir     static ::rtl::OUString EVENT_ON_DOCUMENT_ADDED  = DECLARE_ASCII("onDocumentAdded"   ); // Job API event : OnCreate or OnLoadFinished
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     /* SAFE { */
229cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding > lJobs;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     // Optimization!
234cdf0e10cSrcweir     // Check if the given event name exist inside configuration and reject wrong requests.
235*07a3d7f1SPedro Giffuni     // This optimization suppress using of the cfg api for getting event and job descriptions.
236cdf0e10cSrcweir     // see using of m_lEvents.find() below ...
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // retrieve event context from event source
239cdf0e10cSrcweir     rtl::OUString aModuleIdentifier;
240cdf0e10cSrcweir     try
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         aModuleIdentifier = m_xModuleManager->identify( aEvent.Source );
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir     catch( css::uno::Exception& )
245cdf0e10cSrcweir     {}
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     // Special feature: If the events "OnNew" or "OnLoad" occures - we generate our own event "onDocumentOpened".
248cdf0e10cSrcweir     if (
249cdf0e10cSrcweir         (aEvent.EventName.equals(EVENT_ON_NEW )) ||
250cdf0e10cSrcweir         (aEvent.EventName.equals(EVENT_ON_LOAD))
251cdf0e10cSrcweir        )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         if (m_lEvents.find(EVENT_ON_DOCUMENT_OPENED) != m_lEvents.end())
254cdf0e10cSrcweir             JobData::appendEnabledJobsForEvent(m_xSMGR, EVENT_ON_DOCUMENT_OPENED, lJobs);
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     // Special feature: If the events "OnCreate" or "OnLoadFinished" occures - we generate our own event "onDocumentAdded".
258cdf0e10cSrcweir     if (
259cdf0e10cSrcweir         (aEvent.EventName.equals(EVENT_ON_CREATE       )) ||
260cdf0e10cSrcweir         (aEvent.EventName.equals(EVENT_ON_LOAD_FINISHED))
261cdf0e10cSrcweir        )
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         if (m_lEvents.find(EVENT_ON_DOCUMENT_ADDED) != m_lEvents.end())
264cdf0e10cSrcweir             JobData::appendEnabledJobsForEvent(m_xSMGR, EVENT_ON_DOCUMENT_ADDED, lJobs);
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     // Add all jobs for "real" notified event too .-)
268cdf0e10cSrcweir     if (m_lEvents.find(aEvent.EventName) != m_lEvents.end())
269cdf0e10cSrcweir         JobData::appendEnabledJobsForEvent(m_xSMGR, aEvent.EventName, lJobs);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     aReadLock.unlock();
272cdf0e10cSrcweir     /* } SAFE */
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // step over all enabled jobs and execute it
275cdf0e10cSrcweir     ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >::const_iterator pIt;
276cdf0e10cSrcweir     for (  pIt  = lJobs.begin();
277cdf0e10cSrcweir            pIt != lJobs.end()  ;
278cdf0e10cSrcweir          ++pIt                 )
279cdf0e10cSrcweir     {
280cdf0e10cSrcweir         /* SAFE { */
281cdf0e10cSrcweir         aReadLock.lock();
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         const JobData::TJob2DocEventBinding& rBinding = *pIt;
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         JobData aCfg(m_xSMGR);
286cdf0e10cSrcweir         aCfg.setEvent(rBinding.m_sDocEvent, rBinding.m_sJobName);
287cdf0e10cSrcweir         aCfg.setEnvironment(JobData::E_DOCUMENTEVENT);
288cdf0e10cSrcweir 
289cdf0e10cSrcweir         if (!aCfg.hasCorrectContext(aModuleIdentifier))
290cdf0e10cSrcweir             continue;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         /*Attention!
293cdf0e10cSrcweir             Jobs implements interfaces and dies by ref count!
294cdf0e10cSrcweir             And freeing of such uno object is done by uno itself.
295cdf0e10cSrcweir             So we have to use dynamic memory everytimes.
296cdf0e10cSrcweir          */
297cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel > xModel(aEvent.Source, css::uno::UNO_QUERY);
298cdf0e10cSrcweir         Job* pJob = new Job(m_xSMGR, xModel);
299cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > xJob(static_cast< ::cppu::OWeakObject* >(pJob), css::uno::UNO_QUERY);
300cdf0e10cSrcweir         pJob->setJobData(aCfg);
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         aReadLock.unlock();
303cdf0e10cSrcweir         /* } SAFE */
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         pJob->execute(css::uno::Sequence< css::beans::NamedValue >());
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //________________________________
310cdf0e10cSrcweir 
311cdf0e10cSrcweir void SAL_CALL JobExecutor::elementInserted( const css::container::ContainerEvent& aEvent ) throw(css::uno::RuntimeException)
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     ::rtl::OUString sValue;
314cdf0e10cSrcweir     if (aEvent.Accessor >>= sValue)
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         ::rtl::OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue);
317cdf0e10cSrcweir         if (sEvent.getLength() > 0)
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             OUStringList::iterator pEvent = m_lEvents.find(sEvent);
320cdf0e10cSrcweir             if (pEvent == m_lEvents.end())
321cdf0e10cSrcweir                 m_lEvents.push_back(sEvent);
322cdf0e10cSrcweir         }
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir void SAL_CALL JobExecutor::elementRemoved ( const css::container::ContainerEvent& aEvent ) throw(css::uno::RuntimeException)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     ::rtl::OUString sValue;
329cdf0e10cSrcweir     if (aEvent.Accessor >>= sValue)
330cdf0e10cSrcweir     {
331cdf0e10cSrcweir         ::rtl::OUString sEvent = ::utl::extractFirstFromConfigurationPath(sValue);
332cdf0e10cSrcweir         if (sEvent.getLength() > 0)
333cdf0e10cSrcweir         {
334cdf0e10cSrcweir             OUStringList::iterator pEvent = m_lEvents.find(sEvent);
335cdf0e10cSrcweir             if (pEvent != m_lEvents.end())
336cdf0e10cSrcweir                 m_lEvents.erase(pEvent);
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir void SAL_CALL JobExecutor::elementReplaced( const css::container::ContainerEvent& ) throw(css::uno::RuntimeException)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     // I'm not interested on changed items :-)
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir //________________________________
347cdf0e10cSrcweir 
348cdf0e10cSrcweir /** @short  the used cfg changes notifier wish to be released in its reference.
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     @descr  We close our internal used configuration instance to
351cdf0e10cSrcweir             free this reference.
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     @attention  For the special feature "bind global document event broadcaster to job execution"
354cdf0e10cSrcweir                 this job executor instance was registered from outside code as
355cdf0e10cSrcweir                 css.document.XEventListener. So it can be, that this disposing call comes from
356cdf0e10cSrcweir                 the global event broadcaster service. But we don't hold any reference to this service
357cdf0e10cSrcweir                 which can or must be released. Because this broadcaster itself is an one instance service
358cdf0e10cSrcweir                 too, we can ignore this request. On the other side we must relase our internal CFG
359cdf0e10cSrcweir                 reference ... SOLUTION => check the given event source and react only, if it's our internal
360cdf0e10cSrcweir                 hold configuration object!
361cdf0e10cSrcweir  */
362cdf0e10cSrcweir void SAL_CALL JobExecutor::disposing( const css::lang::EventObject& aEvent ) throw(css::uno::RuntimeException)
363cdf0e10cSrcweir {
364cdf0e10cSrcweir     /* SAFE { */
365cdf0e10cSrcweir     ReadGuard aReadLock(m_aLock);
366cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xCFG(m_aConfig.cfg(), css::uno::UNO_QUERY);
367cdf0e10cSrcweir     if (
368cdf0e10cSrcweir         (xCFG                == aEvent.Source        ) &&
369cdf0e10cSrcweir         (m_aConfig.getMode() != ConfigAccess::E_CLOSED)
370cdf0e10cSrcweir        )
371cdf0e10cSrcweir     {
372cdf0e10cSrcweir         m_aConfig.close();
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir     aReadLock.unlock();
375cdf0e10cSrcweir     /* } SAFE */
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir } // namespace framework
379