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