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 INCLUDED_FRAMEWORK_INC_JOBS_JOBDATA_HXX 21 #define INCLUDED_FRAMEWORK_INC_JOBS_JOBDATA_HXX 22 23 #include <com/sun/star/uno/XComponentContext.hpp> 24 #include <com/sun/star/beans/NamedValue.hpp> 25 26 #include <rtl/ustring.hxx> 27 28 #include <vector> 29 30 namespace framework{ 31 32 /** 33 @short holds all necessary information about a job and 34 handle it's configuration (if any exist!) 35 @descr It can be used from different use cases as a container 36 (or proxy) for all config data of a registered job. 37 But it doesn't implement any execute functionality! 38 */ 39 class JobData final 40 { 41 public: 42 43 /** These values can be used to differe between jobs with and jobs without 44 a configuration. Of course an "unknown state" should be available too, 45 to detect a missing initialization. 46 */ 47 enum EMode 48 { 49 /// indicates a missing initialization 50 E_UNKNOWN_MODE, 51 /// indicates a job with configuration (They alias represent the config key name.) 52 E_ALIAS, 53 /// indicates a job without configuration (The pure UNO implementation is used only.) 54 E_SERVICE, 55 /// indicates a job with configuration, which was triggered by an event 56 E_EVENT 57 }; 58 59 /** These values represent the environment type, in which a job can run. 60 A job must known, from which binding it will be started. Because 61 it's initialization data depends from that! 62 */ 63 enum EEnvironment 64 { 65 /// indicates a missing initialization 66 E_UNKNOWN_ENVIRONMENT, 67 /// this job is used by the global JobExecutor service 68 E_EXECUTION, 69 /// this job is used by the global dispatch framework 70 E_DISPATCH, 71 /// this job is used by the global event broadcaster 72 E_DOCUMENTEVENT 73 }; 74 75 /** Some jobs can be registered to "logical events", which are generated on demand if another document event 76 occurs. E.g. "onDocumentOpened" in case "OnNew" or "OnLoad" was notified to the JobExecutor instance. 77 And normally the original event is transported as parameter set to the executed job. But then such job 78 can't differ between e.g. "OnNew" and "onDocumentOpened". 79 That's why we must know, for which type of event the job was really triggered .-) 80 81 The information "sDocEvent" from this struct must be set on the member JobData::m_sEvent from outside 82 user of such Jobdata structure. 83 */ 84 struct TJob2DocEventBinding 85 { 86 OUString m_sJobName; 87 OUString m_sDocEvent; 88 TJob2DocEventBindingframework::JobData::TJob2DocEventBinding89 TJob2DocEventBinding(const OUString& sJobName , 90 const OUString& sDocEvent) 91 : m_sJobName (sJobName ) 92 , m_sDocEvent(sDocEvent) 93 {} 94 }; 95 96 // member 97 98 private: 99 100 /** 101 reference to the uno service manager. 102 We need it for creating of own uno services ... e.g. for 103 opening the configuration. 104 */ 105 css::uno::Reference< css::uno::XComponentContext > m_xContext; 106 107 /** 108 An instance of this class can be used in two different modes: 109 - as a configured job 110 - as a job without any configuration 111 First mode is triggered by an alias, which points to the 112 configuration entries. Second mode is specified by a uno service 113 or implementation name. Then we do the same things (use the same interfaces) 114 but don't handle any configuration data. 115 The effect: This mode can be detected by this member. 116 */ 117 EMode m_eMode; 118 119 /** 120 Because jobs can be bind to different mechanism inside office, a job 121 should know inside which environment it runs. E.g. a job can be executed 122 by the global JobExecutor service (triggered by an event) or e.g. as part 123 of the global dispatch framework (triggered by an UI control e.g. a menu entry). 124 */ 125 EEnvironment m_eEnvironment; 126 127 /** 128 the alias name of this job. 129 Is used as entry of configuration set for job registration, to find all 130 necessary properties of it... 131 */ 132 OUString m_sAlias; 133 134 /** 135 the uno implementation name of this job. 136 It's read from the configuration. Don't set it from outside! 137 */ 138 OUString m_sService; 139 140 /** 141 the module context list of this job. 142 It's read from the configuration. Don't set it from outside! 143 */ 144 OUString m_sContext; 145 146 /** 147 a job can be registered for an event. 148 It can be an empty value! But it will be set from outside any times. 149 Because it's not clear which job this instance should represent if an event 150 (instead of an alias) comes in. Because there can be multiple registrations 151 for this event. We use this information only, to merge it with the job specific 152 arguments. A job can be called so, with a) its own config data and b) some dynamic 153 environment data. 154 */ 155 OUString m_sEvent; 156 157 /** 158 job specific configuration items... unknown for us! 159 It's read from the configuration. Don't set it from outside! 160 */ 161 std::vector< css::beans::NamedValue > m_lArguments; 162 163 // native interface 164 165 public: 166 167 JobData( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); 168 JobData( const JobData& rCopy ); 169 ~JobData( ); 170 171 JobData& operator=( const JobData& rCopy ); 172 173 EMode getMode () const; 174 EEnvironment getEnvironment () const; 175 OUString getEnvironmentDescriptor() const; 176 OUString getService () const; 177 OUString getEvent () const; 178 css::uno::Sequence< css::beans::NamedValue > getConfig () const; 179 std::vector< css::beans::NamedValue > getJobConfig () const; 180 181 bool hasConfig () const; 182 bool hasCorrectContext ( const OUString& rModuleIdent ) const; 183 184 void setEnvironment ( EEnvironment eEnvironment ); 185 void setAlias ( const OUString& sAlias ); 186 void setService ( const OUString& sService ); 187 void setEvent ( const OUString& sEvent , 188 const OUString& sAlias ); 189 void setJobConfig ( const std::vector< css::beans::NamedValue >& lArguments ); 190 void disableJob ( ); 191 192 static std::vector< OUString > getEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext, 193 const OUString& sEvent ); 194 195 static void appendEnabledJobsForEvent( const css::uno::Reference< css::uno::XComponentContext >& rxContext, 196 const OUString& sEvent , 197 ::std::vector< JobData::TJob2DocEventBinding >& lJobs ); 198 199 // private helper 200 201 private: 202 203 void impl_reset(); 204 }; 205 206 } // namespace framework 207 208 #endif // INCLUDED_FRAMEWORK_INC_JOBS_JOBDATA_HXX 209 210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 211