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