1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*6d739b60SAndrew Rist * distributed with this work for additional information
6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10*6d739b60SAndrew Rist *
11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist *
13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the
17*6d739b60SAndrew Rist * specific language governing permissions and limitations
18*6d739b60SAndrew Rist * under the License.
19*6d739b60SAndrew Rist *
20*6d739b60SAndrew Rist *************************************************************/
21*6d739b60SAndrew Rist
22*6d739b60SAndrew 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/jobdata.hxx>
30cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
31cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
32cdf0e10cSrcweir #include <classes/converter.hxx>
33cdf0e10cSrcweir #include <general.h>
34cdf0e10cSrcweir #include <services.h>
35cdf0e10cSrcweir
36cdf0e10cSrcweir //________________________________
37cdf0e10cSrcweir // interface includes
38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XMultiHierarchicalPropertySet.hpp>
40cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
41cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
42cdf0e10cSrcweir
43cdf0e10cSrcweir //________________________________
44cdf0e10cSrcweir // includes of other projects
45cdf0e10cSrcweir #include <tools/wldcrd.hxx>
46cdf0e10cSrcweir #include <unotools/configpathes.hxx>
47cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
48cdf0e10cSrcweir #include <vcl/svapp.hxx>
49cdf0e10cSrcweir
50cdf0e10cSrcweir //________________________________
51cdf0e10cSrcweir // namespace
52cdf0e10cSrcweir
53cdf0e10cSrcweir namespace framework{
54cdf0e10cSrcweir
55cdf0e10cSrcweir //________________________________
56cdf0e10cSrcweir // exported const
57cdf0e10cSrcweir
58cdf0e10cSrcweir const sal_Char* JobData::JOBCFG_ROOT = "/org.openoffice.Office.Jobs/Jobs/" ;
59cdf0e10cSrcweir const sal_Char* JobData::JOBCFG_PROP_SERVICE = "Service" ;
60cdf0e10cSrcweir const sal_Char* JobData::JOBCFG_PROP_CONTEXT = "Context" ;
61cdf0e10cSrcweir const sal_Char* JobData::JOBCFG_PROP_ARGUMENTS = "Arguments" ;
62cdf0e10cSrcweir
63cdf0e10cSrcweir const sal_Char* JobData::EVENTCFG_ROOT = "/org.openoffice.Office.Jobs/Events/" ;
64cdf0e10cSrcweir const sal_Char* JobData::EVENTCFG_PATH_JOBLIST = "/JobList" ;
65cdf0e10cSrcweir const sal_Char* JobData::EVENTCFG_PROP_ADMINTIME = "AdminTime" ;
66cdf0e10cSrcweir const sal_Char* JobData::EVENTCFG_PROP_USERTIME = "UserTime" ;
67cdf0e10cSrcweir
68cdf0e10cSrcweir const sal_Char* JobData::PROPSET_CONFIG = "Config" ;
69cdf0e10cSrcweir const sal_Char* JobData::PROPSET_OWNCONFIG = "JobConfig" ;
70cdf0e10cSrcweir const sal_Char* JobData::PROPSET_ENVIRONMENT = "Environment" ;
71cdf0e10cSrcweir const sal_Char* JobData::PROPSET_DYNAMICDATA = "DynamicData" ;
72cdf0e10cSrcweir
73cdf0e10cSrcweir const sal_Char* JobData::PROP_ALIAS = "Alias" ;
74cdf0e10cSrcweir const sal_Char* JobData::PROP_EVENTNAME = "EventName" ;
75cdf0e10cSrcweir const sal_Char* JobData::PROP_ENVTYPE = "EnvType" ;
76cdf0e10cSrcweir const sal_Char* JobData::PROP_FRAME = "Frame" ;
77cdf0e10cSrcweir const sal_Char* JobData::PROP_MODEL = "Model" ;
78cdf0e10cSrcweir const sal_Char* JobData::PROP_SERVICE = "Service" ;
79cdf0e10cSrcweir const sal_Char* JobData::PROP_CONTEXT = "Context" ;
80cdf0e10cSrcweir
81cdf0e10cSrcweir //________________________________
82cdf0e10cSrcweir // non exported definitions
83cdf0e10cSrcweir
84cdf0e10cSrcweir //________________________________
85cdf0e10cSrcweir // declarations
86cdf0e10cSrcweir
87cdf0e10cSrcweir //________________________________
88cdf0e10cSrcweir /**
89cdf0e10cSrcweir @short standard ctor
90cdf0e10cSrcweir @descr It initialize this new instance.
91cdf0e10cSrcweir But for real working it's neccessary to call setAlias() or setService() later.
92cdf0e10cSrcweir Because we need the job data ...
93cdf0e10cSrcweir
94cdf0e10cSrcweir @param xSMGR
95cdf0e10cSrcweir reference to the uno service manager
96cdf0e10cSrcweir */
JobData(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)97cdf0e10cSrcweir JobData::JobData( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
98cdf0e10cSrcweir : ThreadHelpBase(&Application::GetSolarMutex())
99cdf0e10cSrcweir , m_xSMGR (xSMGR )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir // share code for member initialization with defaults!
102cdf0e10cSrcweir impl_reset();
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
105cdf0e10cSrcweir //________________________________
106cdf0e10cSrcweir /**
107cdf0e10cSrcweir @short copy ctor
108cdf0e10cSrcweir @descr Sometimes such job data container must be moved from one using place
109cdf0e10cSrcweir to another one. Then a copy ctor and copy operator must be available.
110cdf0e10cSrcweir
111cdf0e10cSrcweir @param rCopy
112cdf0e10cSrcweir the original instance, from which we must copy all data
113cdf0e10cSrcweir */
JobData(const JobData & rCopy)114cdf0e10cSrcweir JobData::JobData( const JobData& rCopy )
115cdf0e10cSrcweir : ThreadHelpBase(&Application::GetSolarMutex())
116cdf0e10cSrcweir {
117cdf0e10cSrcweir // use the copy operator to share the same code
118cdf0e10cSrcweir *this = rCopy;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir //________________________________
122cdf0e10cSrcweir /**
123cdf0e10cSrcweir @short operator for coping JobData instances
124cdf0e10cSrcweir @descr Sometimes such job data container must be moved from one using place
125cdf0e10cSrcweir to another one. Then a copy ctor and copy operator must be available.
126cdf0e10cSrcweir
127cdf0e10cSrcweir @param rCopy
128cdf0e10cSrcweir the original instance, from which we must copy all data
129cdf0e10cSrcweir */
operator =(const JobData & rCopy)130cdf0e10cSrcweir void JobData::operator=( const JobData& rCopy )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir /* SAFE { */
133cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
134cdf0e10cSrcweir // Please don't copy the uno service manager reference.
135cdf0e10cSrcweir // That can change the uno context, which isn't a good idea!
136cdf0e10cSrcweir m_eMode = rCopy.m_eMode ;
137cdf0e10cSrcweir m_eEnvironment = rCopy.m_eEnvironment ;
138cdf0e10cSrcweir m_sAlias = rCopy.m_sAlias ;
139cdf0e10cSrcweir m_sService = rCopy.m_sService ;
140cdf0e10cSrcweir m_sContext = rCopy.m_sContext ;
141cdf0e10cSrcweir m_sEvent = rCopy.m_sEvent ;
142cdf0e10cSrcweir m_lArguments = rCopy.m_lArguments ;
143cdf0e10cSrcweir m_aLastExecutionResult = rCopy.m_aLastExecutionResult;
144cdf0e10cSrcweir aWriteLock.unlock();
145cdf0e10cSrcweir /* } SAFE */
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir //________________________________
149cdf0e10cSrcweir /**
150cdf0e10cSrcweir @short let this instance die
151cdf0e10cSrcweir @descr There is no chance any longer to work. We have to
152cdf0e10cSrcweir release all used ressources and free used memory.
153cdf0e10cSrcweir */
~JobData()154cdf0e10cSrcweir JobData::~JobData()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir impl_reset();
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir //________________________________
160cdf0e10cSrcweir /**
161cdf0e10cSrcweir @short initalize this instance as a job with configuration
162cdf0e10cSrcweir @descr They given alias can be used to adress some configuraton data.
163cdf0e10cSrcweir We read it and fill our internal structures. Of course old informations
164cdf0e10cSrcweir will be lost doing so.
165cdf0e10cSrcweir
166cdf0e10cSrcweir @param sAlias
167cdf0e10cSrcweir the alias name of this job, used to locate job properties inside cfg
168cdf0e10cSrcweir */
setAlias(const::rtl::OUString & sAlias)169cdf0e10cSrcweir void JobData::setAlias( const ::rtl::OUString& sAlias )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir /* SAFE { */
172cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
173cdf0e10cSrcweir // delete all old informations! Otherwhise we mix it with the new one ...
174cdf0e10cSrcweir impl_reset();
175cdf0e10cSrcweir
176cdf0e10cSrcweir // take over the new informations
177cdf0e10cSrcweir m_sAlias = sAlias;
178cdf0e10cSrcweir m_eMode = E_ALIAS;
179cdf0e10cSrcweir
180cdf0e10cSrcweir // try to open the configuration set of this job directly and get a property access to it
181cdf0e10cSrcweir // We open it readonly here
182cdf0e10cSrcweir ::rtl::OUString sKey;
183cdf0e10cSrcweir sKey = ::rtl::OUString::createFromAscii(JOBCFG_ROOT);
184cdf0e10cSrcweir sKey += ::utl::wrapConfigurationElementName(m_sAlias);
185cdf0e10cSrcweir
186cdf0e10cSrcweir ConfigAccess aConfig(m_xSMGR, sKey);
187cdf0e10cSrcweir aConfig.open(ConfigAccess::E_READONLY);
188cdf0e10cSrcweir if (aConfig.getMode()==ConfigAccess::E_CLOSED)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir impl_reset();
191cdf0e10cSrcweir return;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xJobProperties(aConfig.cfg(), css::uno::UNO_QUERY);
195cdf0e10cSrcweir if (xJobProperties.is())
196cdf0e10cSrcweir {
197cdf0e10cSrcweir css::uno::Any aValue;
198cdf0e10cSrcweir
199cdf0e10cSrcweir // read uno implementation name
200cdf0e10cSrcweir aValue = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_SERVICE));
201cdf0e10cSrcweir aValue >>= m_sService;
202cdf0e10cSrcweir
203cdf0e10cSrcweir // read module context list
204cdf0e10cSrcweir aValue = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_CONTEXT));
205cdf0e10cSrcweir aValue >>= m_sContext;
206cdf0e10cSrcweir
207cdf0e10cSrcweir // read whole argument list
208cdf0e10cSrcweir aValue = xJobProperties->getPropertyValue(::rtl::OUString::createFromAscii(JOBCFG_PROP_ARGUMENTS));
209cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xArgumentList;
210cdf0e10cSrcweir if (
211cdf0e10cSrcweir (aValue >>= xArgumentList) &&
212cdf0e10cSrcweir (xArgumentList.is() )
213cdf0e10cSrcweir )
214cdf0e10cSrcweir {
215cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lArgumentNames = xArgumentList->getElementNames();
216cdf0e10cSrcweir sal_Int32 nCount = lArgumentNames.getLength();
217cdf0e10cSrcweir m_lArguments.realloc(nCount);
218cdf0e10cSrcweir for (sal_Int32 i=0; i<nCount; ++i)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir m_lArguments[i].Name = lArgumentNames[i];
221cdf0e10cSrcweir m_lArguments[i].Value = xArgumentList->getByName(m_lArguments[i].Name);
222cdf0e10cSrcweir }
223cdf0e10cSrcweir }
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir aConfig.close();
227cdf0e10cSrcweir aWriteLock.unlock();
228cdf0e10cSrcweir /* } SAFE */
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
231cdf0e10cSrcweir //________________________________
232cdf0e10cSrcweir /**
233cdf0e10cSrcweir @short initalize this instance as a job without configuration
234cdf0e10cSrcweir @descr This job has no configuration data. We have to forget all old informations
235cdf0e10cSrcweir and set only some of them new, so this instance can work.
236cdf0e10cSrcweir
237cdf0e10cSrcweir @param sService
238cdf0e10cSrcweir the uno service name of this "non configured" job
239cdf0e10cSrcweir */
setService(const::rtl::OUString & sService)240cdf0e10cSrcweir void JobData::setService( const ::rtl::OUString& sService )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir /* SAFE { */
243cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
244cdf0e10cSrcweir
245cdf0e10cSrcweir // delete all old informations! Otherwhise we mix it with the new one ...
246cdf0e10cSrcweir impl_reset();
247cdf0e10cSrcweir // take over the new informations
248cdf0e10cSrcweir m_sService = sService;
249cdf0e10cSrcweir m_eMode = E_SERVICE;
250cdf0e10cSrcweir
251cdf0e10cSrcweir aWriteLock.unlock();
252cdf0e10cSrcweir /* } SAFE */
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
255cdf0e10cSrcweir //________________________________
256cdf0e10cSrcweir /**
257cdf0e10cSrcweir @short initialize this instance with new job values.
258cdf0e10cSrcweir @descr It reads automaticly all properties of the specified
259cdf0e10cSrcweir job (using it's alias name) and "register it" for the
260cdf0e10cSrcweir given event. This registration will not be validated against
261cdf0e10cSrcweir the underlying configuration! (That must be done from outside.
262cdf0e10cSrcweir Because the caller must have the configuration already open to
263cdf0e10cSrcweir get the values for sEvent and sAlias! And doing so it can perform
264cdf0e10cSrcweir only, if the time stanp values are readed outside too.
265cdf0e10cSrcweir Further it make no sense to initialize and start a disabled job.
266cdf0e10cSrcweir So this initialization method will be called for enabled jobs only.)
267cdf0e10cSrcweir
268cdf0e10cSrcweir @param sEvent
269cdf0e10cSrcweir the triggered event, for which this job should be started
270cdf0e10cSrcweir
271cdf0e10cSrcweir @param sAlias
272cdf0e10cSrcweir mark the required job inside event registration list
273cdf0e10cSrcweir */
setEvent(const::rtl::OUString & sEvent,const::rtl::OUString & sAlias)274cdf0e10cSrcweir void JobData::setEvent( const ::rtl::OUString& sEvent ,
275cdf0e10cSrcweir const ::rtl::OUString& sAlias )
276cdf0e10cSrcweir {
277cdf0e10cSrcweir // share code to read all job properties!
278cdf0e10cSrcweir setAlias(sAlias);
279cdf0e10cSrcweir
280cdf0e10cSrcweir /* SAFE { */
281cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
282cdf0e10cSrcweir
283cdf0e10cSrcweir // take over the new informations - which differ against set on of method setAlias()!
284cdf0e10cSrcweir m_sEvent = sEvent;
285cdf0e10cSrcweir m_eMode = E_EVENT;
286cdf0e10cSrcweir
287cdf0e10cSrcweir aWriteLock.unlock();
288cdf0e10cSrcweir /* } SAFE */
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir //________________________________
292cdf0e10cSrcweir /**
293cdf0e10cSrcweir @short set the new job specific arguments
294cdf0e10cSrcweir @descr If a job finish his work, it can give us a new list of arguments (which
295cdf0e10cSrcweir will not interpreted by us). We write it back to the configuration only
296cdf0e10cSrcweir (if this job has it's own configuration!).
297cdf0e10cSrcweir So a job can have persistent data without implementing anything
298cdf0e10cSrcweir or define own config areas for that.
299cdf0e10cSrcweir
300cdf0e10cSrcweir @param lArguments
301cdf0e10cSrcweir list of arguments, which should be set for this job
302cdf0e10cSrcweir */
setJobConfig(const css::uno::Sequence<css::beans::NamedValue> & lArguments)303cdf0e10cSrcweir void JobData::setJobConfig( const css::uno::Sequence< css::beans::NamedValue >& lArguments )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir /* SAFE { */
306cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
307cdf0e10cSrcweir
308cdf0e10cSrcweir // update member
309cdf0e10cSrcweir m_lArguments = lArguments;
310cdf0e10cSrcweir
311cdf0e10cSrcweir // update the configuration ... if possible!
312cdf0e10cSrcweir if (m_eMode==E_ALIAS)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir // It doesn't matter if this config object was already opened before.
315cdf0e10cSrcweir // It doesn nothing here then ... or it change the mode automaticly, if
316cdf0e10cSrcweir // it was opened using another one before.
317cdf0e10cSrcweir ::rtl::OUString sKey;
318cdf0e10cSrcweir sKey = ::rtl::OUString::createFromAscii(JOBCFG_ROOT);
319cdf0e10cSrcweir sKey += ::utl::wrapConfigurationElementName(m_sAlias);
320cdf0e10cSrcweir
321cdf0e10cSrcweir ConfigAccess aConfig(m_xSMGR, sKey);
322cdf0e10cSrcweir aConfig.open(ConfigAccess::E_READWRITE);
323cdf0e10cSrcweir if (aConfig.getMode()==ConfigAccess::E_CLOSED)
324cdf0e10cSrcweir return;
325cdf0e10cSrcweir
326cdf0e10cSrcweir css::uno::Reference< css::beans::XMultiHierarchicalPropertySet > xArgumentList(aConfig.cfg(), css::uno::UNO_QUERY);
327cdf0e10cSrcweir if (xArgumentList.is())
328cdf0e10cSrcweir {
329cdf0e10cSrcweir sal_Int32 nCount = m_lArguments.getLength();
330cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lNames (nCount);
331cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lValues(nCount);
332cdf0e10cSrcweir
333cdf0e10cSrcweir for (sal_Int32 i=0; i<nCount; ++i)
334cdf0e10cSrcweir {
335cdf0e10cSrcweir lNames [i] = m_lArguments[i].Name ;
336cdf0e10cSrcweir lValues[i] = m_lArguments[i].Value;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir xArgumentList->setHierarchicalPropertyValues(lNames, lValues);
340cdf0e10cSrcweir }
341cdf0e10cSrcweir aConfig.close();
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir aWriteLock.unlock();
345cdf0e10cSrcweir /* } SAFE */
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348cdf0e10cSrcweir //________________________________
349cdf0e10cSrcweir /**
350cdf0e10cSrcweir @short set a new excution result
351cdf0e10cSrcweir @descr Every executed job can have returned a result.
352cdf0e10cSrcweir We set it here, so our user can use it may be later.
353cdf0e10cSrcweir But the outside code can use it too, to analyze it and
354cdf0e10cSrcweir adopt the configuration of this job too. Because the
355cdf0e10cSrcweir result uses a protocol, which allow that. And we provide
356cdf0e10cSrcweir right functionality to save it.
357cdf0e10cSrcweir
358cdf0e10cSrcweir @param aResult
359cdf0e10cSrcweir the result of last execution
360cdf0e10cSrcweir */
setResult(const JobResult & aResult)361cdf0e10cSrcweir void JobData::setResult( const JobResult& aResult )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir /* SAFE { */
364cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
365cdf0e10cSrcweir
366cdf0e10cSrcweir // overwrite the last saved result
367cdf0e10cSrcweir m_aLastExecutionResult = aResult;
368cdf0e10cSrcweir
369cdf0e10cSrcweir // Don't use his informations to update
370cdf0e10cSrcweir // e.g. the arguments of this job. It must be done
371cdf0e10cSrcweir // from outside! Here we save this information only.
372cdf0e10cSrcweir
373cdf0e10cSrcweir aWriteLock.unlock();
374cdf0e10cSrcweir /* } SAFE */
375cdf0e10cSrcweir }
376cdf0e10cSrcweir
377cdf0e10cSrcweir //________________________________
378cdf0e10cSrcweir /**
379cdf0e10cSrcweir @short set a new environment descriptor for this job
380cdf0e10cSrcweir @descr It must(!) be done everytime this container is initialized
381cdf0e10cSrcweir with new job datas e.g.: setAlias()/setEvent()/setService() ...
382cdf0e10cSrcweir Otherwhise the environment will be unknown!
383cdf0e10cSrcweir */
setEnvironment(EEnvironment eEnvironment)384cdf0e10cSrcweir void JobData::setEnvironment( EEnvironment eEnvironment )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir /* SAFE { */
387cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
388cdf0e10cSrcweir m_eEnvironment = eEnvironment;
389cdf0e10cSrcweir aWriteLock.unlock();
390cdf0e10cSrcweir /* } SAFE */
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir //________________________________
394cdf0e10cSrcweir /**
395cdf0e10cSrcweir @short these functions provides access to our internal members
396cdf0e10cSrcweir @descr These member represent any information about the job
397cdf0e10cSrcweir and can be used from outside to e.g. start a job.
398cdf0e10cSrcweir */
getMode() const399cdf0e10cSrcweir JobData::EMode JobData::getMode() const
400cdf0e10cSrcweir {
401cdf0e10cSrcweir /* SAFE { */
402cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
403cdf0e10cSrcweir return m_eMode;
404cdf0e10cSrcweir /* } SAFE */
405cdf0e10cSrcweir }
406cdf0e10cSrcweir
407cdf0e10cSrcweir //________________________________
408cdf0e10cSrcweir
getEnvironment() const409cdf0e10cSrcweir JobData::EEnvironment JobData::getEnvironment() const
410cdf0e10cSrcweir {
411cdf0e10cSrcweir /* SAFE { */
412cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
413cdf0e10cSrcweir return m_eEnvironment;
414cdf0e10cSrcweir /* } SAFE */
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
417cdf0e10cSrcweir //________________________________
418cdf0e10cSrcweir
getEnvironmentDescriptor() const419cdf0e10cSrcweir ::rtl::OUString JobData::getEnvironmentDescriptor() const
420cdf0e10cSrcweir {
421cdf0e10cSrcweir ::rtl::OUString sDescriptor;
422cdf0e10cSrcweir /* SAFE { */
423cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
424cdf0e10cSrcweir switch(m_eEnvironment)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir case E_EXECUTION :
427cdf0e10cSrcweir sDescriptor = ::rtl::OUString::createFromAscii("EXECUTOR");
428cdf0e10cSrcweir break;
429cdf0e10cSrcweir
430cdf0e10cSrcweir case E_DISPATCH :
431cdf0e10cSrcweir sDescriptor = ::rtl::OUString::createFromAscii("DISPATCH");
432cdf0e10cSrcweir break;
433cdf0e10cSrcweir
434cdf0e10cSrcweir case E_DOCUMENTEVENT :
435cdf0e10cSrcweir sDescriptor = ::rtl::OUString::createFromAscii("DOCUMENTEVENT");
436cdf0e10cSrcweir break;
437cdf0e10cSrcweir default:
438cdf0e10cSrcweir break;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir /* } SAFE */
441cdf0e10cSrcweir return sDescriptor;
442cdf0e10cSrcweir }
443cdf0e10cSrcweir
444cdf0e10cSrcweir //________________________________
445cdf0e10cSrcweir
getService() const446cdf0e10cSrcweir ::rtl::OUString JobData::getService() const
447cdf0e10cSrcweir {
448cdf0e10cSrcweir /* SAFE { */
449cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
450cdf0e10cSrcweir return m_sService;
451cdf0e10cSrcweir /* } SAFE */
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir //________________________________
455cdf0e10cSrcweir
getEvent() const456cdf0e10cSrcweir ::rtl::OUString JobData::getEvent() const
457cdf0e10cSrcweir {
458cdf0e10cSrcweir /* SAFE { */
459cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
460cdf0e10cSrcweir return m_sEvent;
461cdf0e10cSrcweir /* } SAFE */
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir //________________________________
465cdf0e10cSrcweir
getJobConfig() const466cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > JobData::getJobConfig() const
467cdf0e10cSrcweir {
468cdf0e10cSrcweir /* SAFE { */
469cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
470cdf0e10cSrcweir return m_lArguments;
471cdf0e10cSrcweir /* } SAFE */
472cdf0e10cSrcweir }
473cdf0e10cSrcweir
474cdf0e10cSrcweir //________________________________
475cdf0e10cSrcweir
getConfig() const476cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > JobData::getConfig() const
477cdf0e10cSrcweir {
478cdf0e10cSrcweir /* SAFE { */
479cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
480cdf0e10cSrcweir css::uno::Sequence< css::beans::NamedValue > lConfig;
481cdf0e10cSrcweir if (m_eMode==E_ALIAS)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir lConfig.realloc(3);
484cdf0e10cSrcweir sal_Int32 i = 0;
485cdf0e10cSrcweir
486cdf0e10cSrcweir lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_ALIAS);
487cdf0e10cSrcweir lConfig[i].Value <<= m_sAlias;
488cdf0e10cSrcweir ++i;
489cdf0e10cSrcweir
490cdf0e10cSrcweir lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_SERVICE);
491cdf0e10cSrcweir lConfig[i].Value <<= m_sService;
492cdf0e10cSrcweir ++i;
493cdf0e10cSrcweir
494cdf0e10cSrcweir lConfig[i].Name = ::rtl::OUString::createFromAscii(PROP_CONTEXT);
495cdf0e10cSrcweir lConfig[i].Value <<= m_sContext;
496cdf0e10cSrcweir ++i;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir aReadLock.unlock();
499cdf0e10cSrcweir /* } SAFE */
500cdf0e10cSrcweir return lConfig;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir //________________________________
504cdf0e10cSrcweir /**
505cdf0e10cSrcweir @short return information, if this job is part of the global configuration package
506cdf0e10cSrcweir org.openoffice.Office.Jobs
507cdf0e10cSrcweir @descr Because jobs can be executed by the dispatch framework using an uno service name
508cdf0e10cSrcweir directly - an executed job must not have any configuration realy. Such jobs
509cdf0e10cSrcweir must provide the right interfaces only! But after finishing jobs can return
510cdf0e10cSrcweir some informations (e.g. for updating her configuration ...). We must know
511cdf0e10cSrcweir if such request is valid or not then.
512cdf0e10cSrcweir
513cdf0e10cSrcweir @return sal_True if the represented job is part of the underlying configuration package.
514cdf0e10cSrcweir */
hasConfig() const515cdf0e10cSrcweir sal_Bool JobData::hasConfig() const
516cdf0e10cSrcweir {
517cdf0e10cSrcweir /* SAFE { */
518cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
519cdf0e10cSrcweir return (m_eMode==E_ALIAS || m_eMode==E_EVENT);
520cdf0e10cSrcweir /* } SAFE */
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir //________________________________
524cdf0e10cSrcweir /**
525cdf0e10cSrcweir @short mark a job as non startable for further requests
526cdf0e10cSrcweir @descr We don't remove the configuration entry! We set a timestamp value only.
527cdf0e10cSrcweir And there exist two of them: one for an administrator ... and one for the
528cdf0e10cSrcweir current user. We change it for the user layer only. So this JobDispatch can't be
529cdf0e10cSrcweir started any more ... till the administrator change his timestamp.
530cdf0e10cSrcweir That can be usefull for post setup scenarios, which must run one time only.
531cdf0e10cSrcweir
532cdf0e10cSrcweir Note: This method don't do anything, if ths represented job doesn't have a configuration!
533cdf0e10cSrcweir */
disableJob()534cdf0e10cSrcweir void JobData::disableJob()
535cdf0e10cSrcweir {
536cdf0e10cSrcweir /* SAFE { */
537cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
538cdf0e10cSrcweir
539cdf0e10cSrcweir // No configuration - not used from EXECUTOR and not triggered from an event => no chance!
540cdf0e10cSrcweir if (m_eMode!=E_EVENT)
541cdf0e10cSrcweir return;
542cdf0e10cSrcweir
543cdf0e10cSrcweir // update the configuration
544cdf0e10cSrcweir // It doesn't matter if this config object was already opened before.
545cdf0e10cSrcweir // It doesn nothing here then ... or it change the mode automaticly, if
546cdf0e10cSrcweir // it was opened using another one before.
547cdf0e10cSrcweir ::rtl::OUStringBuffer sKey(256);
548cdf0e10cSrcweir sKey.appendAscii(JobData::EVENTCFG_ROOT );
549cdf0e10cSrcweir sKey.append (::utl::wrapConfigurationElementName(m_sEvent));
550cdf0e10cSrcweir sKey.appendAscii(JobData::EVENTCFG_PATH_JOBLIST );
551cdf0e10cSrcweir sKey.appendAscii("/" );
552cdf0e10cSrcweir sKey.append (::utl::wrapConfigurationElementName(m_sAlias));
553cdf0e10cSrcweir
554cdf0e10cSrcweir ConfigAccess aConfig(m_xSMGR, sKey.makeStringAndClear());
555cdf0e10cSrcweir aConfig.open(ConfigAccess::E_READWRITE);
556cdf0e10cSrcweir if (aConfig.getMode()==ConfigAccess::E_CLOSED)
557cdf0e10cSrcweir return;
558cdf0e10cSrcweir
559cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPropSet(aConfig.cfg(), css::uno::UNO_QUERY);
560cdf0e10cSrcweir if (xPropSet.is())
561cdf0e10cSrcweir {
562cdf0e10cSrcweir // Convert and write the user timestamp to the configuration.
563cdf0e10cSrcweir css::uno::Any aValue;
564cdf0e10cSrcweir aValue <<= Converter::convert_DateTime2ISO8601(DateTime());
565cdf0e10cSrcweir xPropSet->setPropertyValue(::rtl::OUString::createFromAscii(EVENTCFG_PROP_USERTIME), aValue);
566cdf0e10cSrcweir }
567cdf0e10cSrcweir
568cdf0e10cSrcweir aConfig.close();
569cdf0e10cSrcweir
570cdf0e10cSrcweir aWriteLock.unlock();
571cdf0e10cSrcweir /* } SAFE */
572cdf0e10cSrcweir }
573cdf0e10cSrcweir
574cdf0e10cSrcweir //________________________________
575cdf0e10cSrcweir /**
576cdf0e10cSrcweir */
isEnabled(const::rtl::OUString & sAdminTime,const::rtl::OUString & sUserTime)577cdf0e10cSrcweir sal_Bool isEnabled( const ::rtl::OUString& sAdminTime ,
578cdf0e10cSrcweir const ::rtl::OUString& sUserTime )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir /*Attention!
581cdf0e10cSrcweir To prevent interpreting of TriGraphs inside next const string value,
582cdf0e10cSrcweir we have to encode all '?' signs. Otherwhise e.g. "??-" will be translated
583cdf0e10cSrcweir to "~" ...
584cdf0e10cSrcweir */
585cdf0e10cSrcweir static ::rtl::OUString PATTERN_ISO8601 = ::rtl::OUString::createFromAscii("\?\?\?\?-\?\?-\?\?*\0");
586cdf0e10cSrcweir WildCard aISOPattern(PATTERN_ISO8601);
587cdf0e10cSrcweir
588cdf0e10cSrcweir sal_Bool bValidAdmin = aISOPattern.Matches(sAdminTime);
589cdf0e10cSrcweir sal_Bool bValidUser = aISOPattern.Matches(sUserTime );
590cdf0e10cSrcweir
591cdf0e10cSrcweir // We check for "isEnabled()" here only.
592cdf0e10cSrcweir // Note further: ISO8601 formated strings can be compared as strings directly!
593cdf0e10cSrcweir return (
594cdf0e10cSrcweir (!bValidAdmin && !bValidUser ) ||
595cdf0e10cSrcweir ( bValidAdmin && bValidUser && sAdminTime>=sUserTime)
596cdf0e10cSrcweir );
597cdf0e10cSrcweir }
598cdf0e10cSrcweir
599cdf0e10cSrcweir //________________________________
600cdf0e10cSrcweir /**
601cdf0e10cSrcweir */
appendEnabledJobsForEvent(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR,const::rtl::OUString & sEvent,::comphelper::SequenceAsVector<JobData::TJob2DocEventBinding> & lJobs)602cdf0e10cSrcweir void JobData::appendEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
603cdf0e10cSrcweir const ::rtl::OUString& sEvent ,
604cdf0e10cSrcweir ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs )
605cdf0e10cSrcweir {
606cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lAdditionalJobs = JobData::getEnabledJobsForEvent(xSMGR, sEvent);
607cdf0e10cSrcweir sal_Int32 c = lAdditionalJobs.getLength();
608cdf0e10cSrcweir sal_Int32 i = 0;
609cdf0e10cSrcweir
610cdf0e10cSrcweir for (i=0; i<c; ++i)
611cdf0e10cSrcweir {
612cdf0e10cSrcweir JobData::TJob2DocEventBinding aBinding(lAdditionalJobs[i], sEvent);
613cdf0e10cSrcweir lJobs.push_back(aBinding);
614cdf0e10cSrcweir }
615cdf0e10cSrcweir }
616cdf0e10cSrcweir
617cdf0e10cSrcweir //________________________________
618cdf0e10cSrcweir /**
619cdf0e10cSrcweir */
hasCorrectContext(const::rtl::OUString & rModuleIdent) const620cdf0e10cSrcweir sal_Bool JobData::hasCorrectContext(const ::rtl::OUString& rModuleIdent) const
621cdf0e10cSrcweir {
622cdf0e10cSrcweir sal_Int32 nContextLen = m_sContext.getLength();
623cdf0e10cSrcweir sal_Int32 nModuleIdLen = rModuleIdent.getLength();
624cdf0e10cSrcweir
625cdf0e10cSrcweir if ( nContextLen == 0 )
626cdf0e10cSrcweir return sal_True;
627cdf0e10cSrcweir
628cdf0e10cSrcweir if ( nModuleIdLen > 0 )
629cdf0e10cSrcweir {
630cdf0e10cSrcweir sal_Int32 nIndex = m_sContext.indexOf( rModuleIdent );
631cdf0e10cSrcweir if ( nIndex >= 0 && ( nIndex+nModuleIdLen <= nContextLen ))
632cdf0e10cSrcweir {
633cdf0e10cSrcweir ::rtl::OUString sContextModule = m_sContext.copy( nIndex, nModuleIdLen );
634cdf0e10cSrcweir return sContextModule.equals( rModuleIdent );
635cdf0e10cSrcweir }
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
638cdf0e10cSrcweir return sal_False;
639cdf0e10cSrcweir }
640cdf0e10cSrcweir
641cdf0e10cSrcweir //________________________________
642cdf0e10cSrcweir /**
643cdf0e10cSrcweir */
getEnabledJobsForEvent(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR,const::rtl::OUString & sEvent)644cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > JobData::getEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
645cdf0e10cSrcweir const ::rtl::OUString& sEvent )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir // these static values may perform following loop for reading time stamp values ...
648cdf0e10cSrcweir static ::rtl::OUString ADMINTIME = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PROP_ADMINTIME);
649cdf0e10cSrcweir static ::rtl::OUString USERTIME = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PROP_USERTIME );
650cdf0e10cSrcweir static ::rtl::OUString ROOT = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_ROOT );
651cdf0e10cSrcweir static ::rtl::OUString JOBLIST = ::rtl::OUString::createFromAscii(JobData::EVENTCFG_PATH_JOBLIST );
652cdf0e10cSrcweir
653cdf0e10cSrcweir // create a config access to "/org.openoffice.Office.Jobs/Events"
654cdf0e10cSrcweir ConfigAccess aConfig(xSMGR,ROOT);
655cdf0e10cSrcweir aConfig.open(ConfigAccess::E_READONLY);
656cdf0e10cSrcweir if (aConfig.getMode()==ConfigAccess::E_CLOSED)
657cdf0e10cSrcweir return css::uno::Sequence< ::rtl::OUString >();
658cdf0e10cSrcweir
659cdf0e10cSrcweir css::uno::Reference< css::container::XHierarchicalNameAccess > xEventRegistry(aConfig.cfg(), css::uno::UNO_QUERY);
660cdf0e10cSrcweir if (!xEventRegistry.is())
661cdf0e10cSrcweir return css::uno::Sequence< ::rtl::OUString >();
662cdf0e10cSrcweir
663cdf0e10cSrcweir // check if the given event exist inside list of registered ones
664cdf0e10cSrcweir ::rtl::OUString sPath(sEvent);
665cdf0e10cSrcweir sPath += JOBLIST;
666cdf0e10cSrcweir if (!xEventRegistry->hasByHierarchicalName(sPath))
667cdf0e10cSrcweir return css::uno::Sequence< ::rtl::OUString >();
668cdf0e10cSrcweir
669cdf0e10cSrcweir // step to the job list, which is a child of the event node inside cfg
670cdf0e10cSrcweir // e.g. "/org.openoffice.Office.Jobs/Events/<event name>/JobList"
671cdf0e10cSrcweir css::uno::Any aJobList = xEventRegistry->getByHierarchicalName(sPath);
672cdf0e10cSrcweir css::uno::Reference< css::container::XNameAccess > xJobList;
673cdf0e10cSrcweir if (!(aJobList >>= xJobList) || !xJobList.is())
674cdf0e10cSrcweir return css::uno::Sequence< ::rtl::OUString >();
675cdf0e10cSrcweir
676cdf0e10cSrcweir // get all alias names of jobs, which are part of this job list
677cdf0e10cSrcweir // But Some of them can be disabled by it's time stamp values.
678cdf0e10cSrcweir // We create an additional job name list iwth the same size, then the original list ...
679cdf0e10cSrcweir // step over all job entries ... check her time stamps ... and put only job names to the
680cdf0e10cSrcweir // destination list, which represent an enabled job.
681cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lAllJobs = xJobList->getElementNames();
682cdf0e10cSrcweir ::rtl::OUString* pAllJobs = lAllJobs.getArray();
683cdf0e10cSrcweir sal_Int32 c = lAllJobs.getLength();
684cdf0e10cSrcweir
685cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > lEnabledJobs(c);
686cdf0e10cSrcweir ::rtl::OUString* pEnabledJobs = lEnabledJobs.getArray();
687cdf0e10cSrcweir sal_Int32 d = 0;
688cdf0e10cSrcweir
689cdf0e10cSrcweir for (sal_Int32 s=0; s<c; ++s)
690cdf0e10cSrcweir {
691cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xJob;
692cdf0e10cSrcweir if (
693cdf0e10cSrcweir !(xJobList->getByName(pAllJobs[s]) >>= xJob) ||
694cdf0e10cSrcweir !(xJob.is() )
695cdf0e10cSrcweir )
696cdf0e10cSrcweir {
697cdf0e10cSrcweir continue;
698cdf0e10cSrcweir }
699cdf0e10cSrcweir
700cdf0e10cSrcweir ::rtl::OUString sAdminTime;
701cdf0e10cSrcweir xJob->getPropertyValue(ADMINTIME) >>= sAdminTime;
702cdf0e10cSrcweir
703cdf0e10cSrcweir ::rtl::OUString sUserTime;
704cdf0e10cSrcweir xJob->getPropertyValue(USERTIME) >>= sUserTime;
705cdf0e10cSrcweir
706cdf0e10cSrcweir if (!isEnabled(sAdminTime, sUserTime))
707cdf0e10cSrcweir continue;
708cdf0e10cSrcweir
709cdf0e10cSrcweir pEnabledJobs[d] = pAllJobs[s];
710cdf0e10cSrcweir ++d;
711cdf0e10cSrcweir }
712cdf0e10cSrcweir lEnabledJobs.realloc(d);
713cdf0e10cSrcweir
714cdf0e10cSrcweir aConfig.close();
715cdf0e10cSrcweir
716cdf0e10cSrcweir return lEnabledJobs;
717cdf0e10cSrcweir }
718cdf0e10cSrcweir
719cdf0e10cSrcweir //________________________________
720cdf0e10cSrcweir /**
721cdf0e10cSrcweir @short reset all internal structures
722cdf0e10cSrcweir @descr If somehwere recycle this instance, he can switch from one
723cdf0e10cSrcweir using mode to another one. But then we have to reset all currently
724cdf0e10cSrcweir used informations. Otherwhise we mix it and they can make trouble.
725cdf0e10cSrcweir
726cdf0e10cSrcweir But note: that does not set defaults for internal used members, which
727cdf0e10cSrcweir does not relate to any job property! e.g. the reference to the global
728cdf0e10cSrcweir uno service manager. Such informations are used for internal processes only
729cdf0e10cSrcweir and are neccessary for our work.
730cdf0e10cSrcweir */
impl_reset()731cdf0e10cSrcweir void JobData::impl_reset()
732cdf0e10cSrcweir {
733cdf0e10cSrcweir /* SAFE { */
734cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
735cdf0e10cSrcweir m_eMode = E_UNKNOWN_MODE;
736cdf0e10cSrcweir m_eEnvironment = E_UNKNOWN_ENVIRONMENT;
737cdf0e10cSrcweir m_sAlias = ::rtl::OUString();
738cdf0e10cSrcweir m_sService = ::rtl::OUString();
739cdf0e10cSrcweir m_sContext = ::rtl::OUString();
740cdf0e10cSrcweir m_sEvent = ::rtl::OUString();
741cdf0e10cSrcweir m_lArguments = css::uno::Sequence< css::beans::NamedValue >();
742cdf0e10cSrcweir aWriteLock.unlock();
743cdf0e10cSrcweir /* } SAFE */
744cdf0e10cSrcweir }
745cdf0e10cSrcweir
746cdf0e10cSrcweir } // namespace framework
747