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