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