xref: /aoo42x/main/framework/inc/jobs/jobdata.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef __FRAMEWORK_JOBS_JOBDATA_HXX_
29*cdf0e10cSrcweir #define __FRAMEWORK_JOBS_JOBDATA_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_______________________________________
32*cdf0e10cSrcweir // my own includes
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <jobs/configaccess.hxx>
35*cdf0e10cSrcweir #include <jobs/jobresult.hxx>
36*cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
37*cdf0e10cSrcweir #include <macros/debug.hxx>
38*cdf0e10cSrcweir #include <stdtypes.h>
39*cdf0e10cSrcweir #include <general.h>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //_______________________________________
42*cdf0e10cSrcweir // interface includes
43*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultEvent.hpp>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //_______________________________________
48*cdf0e10cSrcweir // other includes
49*cdf0e10cSrcweir #include <tools/datetime.hxx>
50*cdf0e10cSrcweir #include <rtl/ustring.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //_______________________________________
53*cdf0e10cSrcweir // namespace
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace framework{
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir //_______________________________________
58*cdf0e10cSrcweir // public const
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //_______________________________________
61*cdf0e10cSrcweir // definitions
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir /**
64*cdf0e10cSrcweir     @short  holds all neccessary informations about a job and
65*cdf0e10cSrcweir             handle it's configuration (if any exist!)
66*cdf0e10cSrcweir     @descr  It can be used rom different use cases as a container
67*cdf0e10cSrcweir             (or proxy) for all config data of a registered job.
68*cdf0e10cSrcweir             But it doesn't implement any execute functionality!
69*cdf0e10cSrcweir  */
70*cdf0e10cSrcweir class JobData : private ThreadHelpBase
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir     //___________________________________
73*cdf0e10cSrcweir     // const
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     public:
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir         /// specifies the root package and key to find registered jobs
78*cdf0e10cSrcweir         static const sal_Char* JOBCFG_ROOT;
79*cdf0e10cSrcweir         /// define the cfg key "Arguments" of a job relativ to JOBCFG_ROOT/<job alias>
80*cdf0e10cSrcweir         static const sal_Char* JOBCFG_PROP_ARGUMENTS;
81*cdf0e10cSrcweir         /// define the cfg key "Service" of a job relativ to JOBCFG_ROOT/<job alias>
82*cdf0e10cSrcweir         static const sal_Char* JOBCFG_PROP_SERVICE;
83*cdf0e10cSrcweir         /// define the cfg key "Context" of a job relativ to JOBCFG_ROOT/<job alias>
84*cdf0e10cSrcweir         static const sal_Char* JOBCFG_PROP_CONTEXT;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         /// specifies the root package and key to find event registrations
87*cdf0e10cSrcweir         static const sal_Char* EVENTCFG_ROOT;
88*cdf0e10cSrcweir         /// define the cfg key "JobList" of an event relativ to EVENTCFG_ROOT/<event>
89*cdf0e10cSrcweir         static const sal_Char* EVENTCFG_PATH_JOBLIST;
90*cdf0e10cSrcweir         /// define the cfg key "AdminTime" of a job registration relativ to EVENTCFG_ROOT/<event>/EVENTCFG_PROP_JOBLIST/<job alias>
91*cdf0e10cSrcweir         static const sal_Char* EVENTCFG_PROP_ADMINTIME;
92*cdf0e10cSrcweir         /// define the cfg key "UserTime" of a job registration relativ to EVENTCFG_ROOT/<event>/EVENTCFG_PROP_JOBLIST/<job alias>
93*cdf0e10cSrcweir         static const sal_Char* EVENTCFG_PROP_USERTIME;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         /// mark the starting point of static job data inside argument list of job execution
96*cdf0e10cSrcweir         static const sal_Char* PROPSET_CONFIG;
97*cdf0e10cSrcweir         /// mark the starting point of job specific data inside argument list of job execution
98*cdf0e10cSrcweir         static const sal_Char* PROPSET_OWNCONFIG;
99*cdf0e10cSrcweir         /// mark the starting point of environment data inside argument list of job execution
100*cdf0e10cSrcweir         static const sal_Char* PROPSET_ENVIRONMENT;
101*cdf0e10cSrcweir         /// mark the starting point of any other dynamic generated data inside argument list of job execution (e.g. from a dispatch() request)
102*cdf0e10cSrcweir         static const sal_Char* PROPSET_DYNAMICDATA;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         static const sal_Char* PROP_ALIAS;
105*cdf0e10cSrcweir         static const sal_Char* PROP_EVENTNAME;
106*cdf0e10cSrcweir         static const sal_Char* PROP_ENVTYPE;
107*cdf0e10cSrcweir         static const sal_Char* PROP_FRAME;
108*cdf0e10cSrcweir         static const sal_Char* PROP_MODEL;
109*cdf0e10cSrcweir         static const sal_Char* PROP_SERVICE;
110*cdf0e10cSrcweir         static const sal_Char* PROP_CONTEXT;
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     //___________________________________
113*cdf0e10cSrcweir     // structs
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     public:
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         /** These values can be used to differe between jobs with and jobs without
118*cdf0e10cSrcweir             a configuration. Of course an "unknown state" should be available too,
119*cdf0e10cSrcweir             to detect a missing initialization.
120*cdf0e10cSrcweir          */
121*cdf0e10cSrcweir         enum EMode
122*cdf0e10cSrcweir         {
123*cdf0e10cSrcweir             /// indicates a missing initialization
124*cdf0e10cSrcweir             E_UNKNOWN_MODE,
125*cdf0e10cSrcweir             /// indicates a job with configuration (They alias represent the config key name.)
126*cdf0e10cSrcweir             E_ALIAS,
127*cdf0e10cSrcweir             /// indicates a job without configuration (The pure UNO implementation is used only.)
128*cdf0e10cSrcweir             E_SERVICE,
129*cdf0e10cSrcweir             /// indicates a job with configuration, which was triggered by an event
130*cdf0e10cSrcweir             E_EVENT
131*cdf0e10cSrcweir         };
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir         /** These values represent the environment type, in which a job can run.
134*cdf0e10cSrcweir             A job must known, from which binding it will be started. Because
135*cdf0e10cSrcweir             it's initialization data depends from that!
136*cdf0e10cSrcweir          */
137*cdf0e10cSrcweir         enum EEnvironment
138*cdf0e10cSrcweir         {
139*cdf0e10cSrcweir             /// indicates a missing initialization
140*cdf0e10cSrcweir             E_UNKNOWN_ENVIRONMENT,
141*cdf0e10cSrcweir             /// this job is used by the global JobExecutor service
142*cdf0e10cSrcweir             E_EXECUTION,
143*cdf0e10cSrcweir             /// this job is used by the global dispatch framework
144*cdf0e10cSrcweir             E_DISPATCH,
145*cdf0e10cSrcweir             /// this job is used by the global event broadcaster
146*cdf0e10cSrcweir             E_DOCUMENTEVENT
147*cdf0e10cSrcweir         };
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         /** Some jobs can be registered to "logical events", which are generated on demand if another document event
150*cdf0e10cSrcweir             occures. E.g. "onDocumentOpened" in case "OnNew" or "OnLoad" was notified to the JobExecutor instance.
151*cdf0e10cSrcweir             And normaly the original event is transported as parameter set to the executed job. But then such job
152*cdf0e10cSrcweir             cant differ between e.g. "OnNew" and "onDocumentOpened".
153*cdf0e10cSrcweir             That's why we must know, for which type of event the job was realy triggered .-)
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir             The information "sDocEvent" from this struct must be set on the member JobData::m_sEvent from outside
156*cdf0e10cSrcweir             user of such Jobdata structure.
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         struct TJob2DocEventBinding
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             ::rtl::OUString m_sJobName;
161*cdf0e10cSrcweir             ::rtl::OUString m_sDocEvent;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir             TJob2DocEventBinding(const ::rtl::OUString& sJobName ,
164*cdf0e10cSrcweir                                  const ::rtl::OUString& sDocEvent)
165*cdf0e10cSrcweir                 : m_sJobName (sJobName )
166*cdf0e10cSrcweir                 , m_sDocEvent(sDocEvent)
167*cdf0e10cSrcweir             {}
168*cdf0e10cSrcweir         };
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     //___________________________________
171*cdf0e10cSrcweir     // member
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     private:
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         /**
176*cdf0e10cSrcweir             reference to the uno service manager.
177*cdf0e10cSrcweir             We need it for creating of own uno services ... e.g. for
178*cdf0e10cSrcweir             opening the configuration.
179*cdf0e10cSrcweir          */
180*cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         /**
183*cdf0e10cSrcweir             An instance of this class can be used in two different modes:
184*cdf0e10cSrcweir                 - as a configured job
185*cdf0e10cSrcweir                 - as a job without any configuration
186*cdf0e10cSrcweir             First mode is triggered by an alias, which points to the
187*cdf0e10cSrcweir             configuration entries. Second mode is specified by an uno service
188*cdf0e10cSrcweir             or implementation name. Then we does the same things (use the same interfaces)
189*cdf0e10cSrcweir             but don't handle any configuration data.
190*cdf0e10cSrcweir             The effect: This mode can be detected by this member.
191*cdf0e10cSrcweir          */
192*cdf0e10cSrcweir         EMode m_eMode;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         /**
195*cdf0e10cSrcweir             Because jobs can be bind to different mechanism inside office, a job
196*cdf0e10cSrcweir             should know inside which environment it runs. E.g. a job can be executed
197*cdf0e10cSrcweir             by the global JobExecutor service (triggered by an event) or e.g. as part
198*cdf0e10cSrcweir             of the global dispatch framework (triggered by an UI control e.g. a menu entry).
199*cdf0e10cSrcweir          */
200*cdf0e10cSrcweir         EEnvironment m_eEnvironment;
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         /**
203*cdf0e10cSrcweir             the alias name of this job.
204*cdf0e10cSrcweir             Is used as entry of configuration set for job registration, to find all
205*cdf0e10cSrcweir             neccessary properties of it..
206*cdf0e10cSrcweir          */
207*cdf0e10cSrcweir         ::rtl::OUString m_sAlias;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         /**
210*cdf0e10cSrcweir             the uno implementation name of this job.
211*cdf0e10cSrcweir             It's readed from the configuration. Don't set it from outside!
212*cdf0e10cSrcweir          */
213*cdf0e10cSrcweir         ::rtl::OUString m_sService;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir         /**
216*cdf0e10cSrcweir             the module context list of this job.
217*cdf0e10cSrcweir             It's readed from the configuration. Don't set it from outside!
218*cdf0e10cSrcweir          */
219*cdf0e10cSrcweir         ::rtl::OUString m_sContext;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir         /**
222*cdf0e10cSrcweir             a job can be registered for an event.
223*cdf0e10cSrcweir             It can be an empty value! But it will be set from outside any times.
224*cdf0e10cSrcweir             Because it's not clear which job this instance should represent if an event
225*cdf0e10cSrcweir             (instaed of an alias) comes in. Because there can be multiple registrations
226*cdf0e10cSrcweir             for this event. We use this information only, to merge it with the job specific
227*cdf0e10cSrcweir             arguments. A job can be called so, with a) it's onw config data and b) some dynamic
228*cdf0e10cSrcweir             environment data.
229*cdf0e10cSrcweir          */
230*cdf0e10cSrcweir         ::rtl::OUString m_sEvent;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         /**
233*cdf0e10cSrcweir             job specific configuration items ... unknown for us!
234*cdf0e10cSrcweir             It's readed from the configuration. Don't set it from outside!
235*cdf0e10cSrcweir          */
236*cdf0e10cSrcweir         css::uno::Sequence< css::beans::NamedValue > m_lArguments;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir         /**
239*cdf0e10cSrcweir             after a job was sucessfully executed (by any outside code using our
240*cdf0e10cSrcweir             informations) it can return a result. This member make it part of this
241*cdf0e10cSrcweir             container too. So it can be used for further things.
242*cdf0e10cSrcweir             We use it also to update our internal state and the configuration
243*cdf0e10cSrcweir             of the job. But note: only the last result will be saved here!
244*cdf0e10cSrcweir          */
245*cdf0e10cSrcweir         JobResult m_aLastExecutionResult;
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     //___________________________________
248*cdf0e10cSrcweir     // native interface
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     public:
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir                  JobData( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR );
253*cdf0e10cSrcweir                  JobData( const JobData&                                                rCopy );
254*cdf0e10cSrcweir         virtual ~JobData(                                                                     );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         void operator=( const JobData& rCopy );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         EMode                                        getMode                 () const;
259*cdf0e10cSrcweir         EEnvironment                                 getEnvironment          () const;
260*cdf0e10cSrcweir         ::rtl::OUString                              getEnvironmentDescriptor() const;
261*cdf0e10cSrcweir         ::rtl::OUString                              getService              () const;
262*cdf0e10cSrcweir         ::rtl::OUString                              getEvent                () const;
263*cdf0e10cSrcweir         css::uno::Sequence< css::beans::NamedValue > getConfig               () const;
264*cdf0e10cSrcweir         css::uno::Sequence< css::beans::NamedValue > getJobConfig            () const;
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         sal_Bool                                     hasConfig               () const;
267*cdf0e10cSrcweir         sal_Bool                                     hasCorrectContext       ( const ::rtl::OUString& rModuleIdent ) const;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir         void                                         setEnvironment (       EEnvironment                                  eEnvironment );
270*cdf0e10cSrcweir         void                                         setAlias       ( const ::rtl::OUString&                              sAlias       );
271*cdf0e10cSrcweir         void                                         setService     ( const ::rtl::OUString&                              sService     );
272*cdf0e10cSrcweir         void                                         setEvent       ( const ::rtl::OUString&                              sEvent       ,
273*cdf0e10cSrcweir                                                                       const ::rtl::OUString&                              sAlias       );
274*cdf0e10cSrcweir         void                                         setJobConfig   ( const css::uno::Sequence< css::beans::NamedValue >& lArguments   );
275*cdf0e10cSrcweir         void                                         setResult      ( const JobResult&                                    aResult      );
276*cdf0e10cSrcweir         void                                         disableJob     (                                                                  );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir         static css::uno::Sequence< ::rtl::OUString > getEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR  ,
279*cdf0e10cSrcweir                                                                              const ::rtl::OUString&                                        sEvent );
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         static void appendEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >&          xSMGR  ,
282*cdf0e10cSrcweir                                                const ::rtl::OUString&                                                 sEvent ,
283*cdf0e10cSrcweir                                                      ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs  );
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     //___________________________________
286*cdf0e10cSrcweir     // private helper
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     private:
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir         void impl_reset();
291*cdf0e10cSrcweir };
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir } // namespace framework
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir #endif // __FRAMEWORK_JOBS_JOBDATA_HXX_
296