LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/jobs - jobdata.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 4 100.0 %
Date: 2012-12-27 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10