diff options
Diffstat (limited to 'framework/inc/jobs')
-rw-r--r-- | framework/inc/jobs/configaccess.hxx | 120 | ||||
-rw-r--r-- | framework/inc/jobs/helponstartup.hxx | 234 | ||||
-rw-r--r-- | framework/inc/jobs/job.hxx | 250 | ||||
-rw-r--r-- | framework/inc/jobs/jobconst.hxx | 76 | ||||
-rw-r--r-- | framework/inc/jobs/jobdata.hxx | 288 | ||||
-rw-r--r-- | framework/inc/jobs/jobdispatch.hxx | 161 | ||||
-rw-r--r-- | framework/inc/jobs/jobexecutor.hxx | 132 | ||||
-rw-r--r-- | framework/inc/jobs/jobresult.hxx | 150 | ||||
-rw-r--r-- | framework/inc/jobs/joburl.hxx | 180 | ||||
-rw-r--r-- | framework/inc/jobs/shelljob.hxx | 172 |
10 files changed, 1763 insertions, 0 deletions
diff --git a/framework/inc/jobs/configaccess.hxx b/framework/inc/jobs/configaccess.hxx new file mode 100644 index 000000000000..3748d65fee9b --- /dev/null +++ b/framework/inc/jobs/configaccess.hxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_CONFIG_CONFIGACCESS_HXX_ +#define __FRAMEWORK_CONFIG_CONFIGACCESS_HXX_ + +//_______________________________________ +// my own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <macros/debug.hxx> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +//_______________________________________ +// other includes +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +/** + @short implements a simple configuration access + @descr Sometimes it's better to have direct config access + instead of using soecialize config items of the svtools + project. This class can wrapp such configuration access. + */ +class ConfigAccess : public ThreadHelpBase +{ + //___________________________________ + // const + + public: + + /** represent the possible modes of the internal wrapped configuration access */ + enum EOpenMode + { + /// config isn't used yet + E_CLOSED, + /// config access is open for reading only + E_READONLY, + /// config access is open for reading/writing data + E_READWRITE + }; + + //___________________________________ + // member + + private: + + /** + reference to the uno service manager + It's neccessary to instanciate own needed services. + */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** hold an opened configuration alive */ + css::uno::Reference< css::uno::XInterface > m_xConfig; + + /** knows the root of the opened config access point */ + ::rtl::OUString m_sRoot; + + /** represent the current open mode */ + EOpenMode m_eMode; + + //___________________________________ + // native interface methods + + public: + + ConfigAccess( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , + const ::rtl::OUString& sRoot ); + virtual ~ConfigAccess(); + + virtual void open ( EOpenMode eMode ); + virtual void close ( ); + virtual EOpenMode getMode( ) const; + + virtual const css::uno::Reference< css::uno::XInterface >& cfg(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_CONFIG_CONFIGACCESS_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/helponstartup.hxx b/framework/inc/jobs/helponstartup.hxx new file mode 100644 index 000000000000..a5d0129f1760 --- /dev/null +++ b/framework/inc/jobs/helponstartup.hxx @@ -0,0 +1,234 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_ +#define __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_ + +//_______________________________________________ +// my own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> + +//_______________________________________________ +// other includes +#include <cppuhelper/implbase3.hxx> + +//_______________________________________________ +// uno includes +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/frame/XModuleManager.hpp> + +//_______________________________________________ +// namespace + +namespace framework{ + +//_______________________________________________ +// declarations + +//_______________________________________________ +/** @short implements a job component, which handle the special + feature to show a suitable help page for every (visible!) + loaded document. + + @author as96863 + */ +class HelpOnStartup : private ThreadHelpBase + ,public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XServiceInfo,::com::sun::star::lang::XEventListener,::com::sun::star::task::XJob > +{ + //------------------------------------------- + // member + private: + + //....................................... + /** @short reference to an uno service manager. */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + //....................................... + /** @short such module manager is used to classify new opened documents. */ + css::uno::Reference< css::frame::XModuleManager > m_xModuleManager; + + //....................................... + /** @short is needed to locate a might open help frame. */ + css::uno::Reference< css::frame::XFrame > m_xDesktop; + + //....................................... + /** @short provides read access to the underlying configuration. */ + css::uno::Reference< css::container::XNameAccess > m_xConfig; + + //....................................... + /** @short knows the current locale of this office session, + which is needed to build complete help URLs. + */ + ::rtl::OUString m_sLocale; + + //....................................... + /** @short knows the current operating system of this office session, + which is needed to build complete help URLs. + */ + ::rtl::OUString m_sSystem; + + //------------------------------------------- + // native interface + public: + + //--------------------------------------- + /** @short create new instance of this class. + + @param xSMGR + reference to the uno service manager, which created this instance. + Can be used later to create own needed uno resources on demand. + */ + HelpOnStartup(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + + //--------------------------------------- + /** @short does nothing real ... + + @descr But it should exists as virtual function, + so this class cant make trouble + related to inline/symbols etcpp.! + */ + virtual ~HelpOnStartup(); + + //------------------------------------------- + // uno interface + public: + + //--------------------------------------- + // css.lang.XServiceInfo + DECLARE_XSERVICEINFO + + // css.task.XJob + virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) + throw(css::lang::IllegalArgumentException, + css::uno::Exception , + css::uno::RuntimeException ); + + // css.lang.XEventListener + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw(css::uno::RuntimeException); + + //------------------------------------------- + // helper + private: + + //--------------------------------------- + /** @short analyze the given job arguments, try to locate a model reference + and try to classify this model. + + @descr As a result of this operation a module identifier will be returned. + It can be used against the module configuration then to retrieve further informations. + + @param lArguments + the list of job arguments which is given on our interface method execute(). + + @return [string] + a module identifier ... or an empty value if no model could be located ... + or if it could not be classified successfully. + */ + ::rtl::OUString its_getModuleIdFromEnv(const css::uno::Sequence< css::beans::NamedValue >& lArguments); + + //--------------------------------------- + /** @short tries to locate the open help module and return + the url of the currently shown help content. + + @descr It returns an empty string, if the help isnt still + open at calling time. + + @return The URL of the current shown help content; + or an empty value if the help isnt still open. + */ + ::rtl::OUString its_getCurrentHelpURL(); + + //--------------------------------------- + /** @short checks if the given help url match to a default help url + of any office module. + + @param sHelpURL + the help url for checking. + + @return [bool] + TRUE if the given URL is any default one ... + FALSE otherwise. + */ + ::sal_Bool its_isHelpUrlADefaultOne(const ::rtl::OUString& sHelpURL); + + //--------------------------------------- + /** @short checks, if the help module should be shown automaticly for the + currently opened office module. + + @descr This value is readed from the module configuration. + In case the help should be shown, this method returns + a help URL, which can be used to show the right help content. + + @param sModule + identifies the used office module. + + @return [string] + A valid help URL in case the help content should be shown; + an empty value if such automatism was disabled for the specified office module. + */ + ::rtl::OUString its_checkIfHelpEnabledAndGetURL(const ::rtl::OUString& sModule); + + //--------------------------------------- + /** @short create a help URL for the given parameters. + + @param sBaseURL + must be the base URL for a requested help content + e.g. "vnd.sun.star.help://swriter/" + or "vnd.sun.star.help://swriter/67351" + + @param sLocale + the current office locale + e.g. "en-US" + + @param sSystem + the current operating system + e.g. "WIN" + + @return The URL which was generated. + e.g. + e.g. "vnd.sun.star.help://swriter/?Language=en-US&System=WIN" + or "vnd.sun.star.help://swriter/67351?Language=en-US&System=WIN" + */ + static ::rtl::OUString ist_createHelpURL(const ::rtl::OUString& sBaseURL, + const ::rtl::OUString& sLocale , + const ::rtl::OUString& sSystem ); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_HELPONSTARTUP_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/job.hxx b/framework/inc/jobs/job.hxx new file mode 100644 index 000000000000..38db96f42377 --- /dev/null +++ b/framework/inc/jobs/job.hxx @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOB_HXX_ +#define __FRAMEWORK_JOBS_JOB_HXX_ + +//_______________________________________ +// my own includes + +#include <jobs/jobresult.hxx> +#include <jobs/jobdata.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <macros/debug.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XDispatchResultListener.hpp> +#include <com/sun/star/task/XJobListener.hpp> +#include <com/sun/star/util/XCloseListener.hpp> +#include <com/sun/star/frame/DispatchResultEvent.hpp> + +//_______________________________________ +// other includes +#include <cppuhelper/weak.hxx> +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +// definitions + +/** + @short it represent a job; execute it and control it's lifetime + + @descr This implemetation can be used to wrapp jobs, execute it + synchronously or asynchronous, control it's lifetime + and differe between jobs with and without configuration. + */ +class Job : public css::lang::XTypeProvider + , public css::task::XJobListener + , public css::frame::XTerminateListener + , public css::util::XCloseListener + , private ThreadHelpBase + , public ::cppu::OWeakObject +{ + //___________________________________ + // structs + + private: + + /** different possible states for the internal wrapped job. + It can be started, stopped by a queryClosing() request or + disposed() by a notifyClosing() request ... + */ + enum ERunState + { + E_NEW, + E_RUNNING, + E_STOPPED_OR_FINISHED, + E_DISPOSED + }; + + //___________________________________ + // member + + private: + + /** + hold all neccessary informations about this job. + It can be used for both modes: with and without configuration. + */ + JobData m_aJobCfg; + + /** + We need it to create own services on demand. + */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** + Hold the (may asynchronous) job alive. + */ + css::uno::Reference< css::uno::XInterface > m_xJob; + + /** + Used to wait for finishing of asynchronous started jobs. + */ + ::osl::Condition m_aAsyncWait; + + /** + For some special cases we must know the environment, in which + this job runs. Means the frame inside which we may was triggered. + We use it too, to listen for closing events of this ressource. + + Please note: If m_xFrame is set - m_xModel should be NULL. + Only one environment can be supported realy. + */ + css::uno::Reference< css::frame::XFrame > m_xFrame; + + /** + For some special cases we must know the environment, in which + this job runs. Means the document inside which we may was triggered. + We use it too, to listen for closing events of this ressource. + + Please note: If m_xModel is set - m_xFrame should be NULL. + Only one environment can be supported realy. + */ + css::uno::Reference< css::frame::XModel > m_xModel; + + /** + We are registered at this instance to listen for office shutdown events. + It's neccessary supress it (if possible) or to react in the right way. + */ + css::uno::Reference< css::frame::XDesktop > m_xDesktop; + + /** + A job can return a dispatch result event after finishing its work. + We have to transport it to any outside interested listener then. + (see m_xResultSourceFake for further informations too!) + */ + css::uno::Reference< css::frame::XDispatchResultListener > m_xResultListener; + + /** + We can't set ourself as source of a dispatch result event ... nor our job. + Because the listener (set as m_xResultListener) expect the original instance, + where it was registered. This original instance is the user of this class. + It must be set explicitly and will be used to fake the source of the event! + */ + css::uno::Reference< css::uno::XInterface > m_xResultSourceFake; + + /** + Holds the state, if we are listen for desktop/frame or model closing events or not. + The used references are not realy enough to detect a valid listener connection. + Thats why we use this additional information here too. + */ + sal_Bool m_bListenOnDesktop; + sal_Bool m_bListenOnFrame; + sal_Bool m_bListenOnModel; + + /** + In case we got a close request from our desktop/frame/model (on which we listen) ... and + the ownership was delivered there ... we have to close ourself and this object + in case the internal wrapped and running job finish his work. + */ + sal_Bool m_bPendingCloseFrame; + sal_Bool m_bPendingCloseModel; + + /** + indicates in which state the internal job currently exist. + + We can use this information to throw any suitable veto exception + to prevent the environment against dieing or supress superflous dispose() + calls at the job. + */ + ERunState m_eRunState; + + //___________________________________ + // native interface + + public: + + Job( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , + const css::uno::Reference< css::frame::XFrame >& xFrame ); + Job( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , + const css::uno::Reference< css::frame::XModel >& xModel ); + virtual ~Job( ); + + void setDispatchResultFake( const css::uno::Reference< css::frame::XDispatchResultListener >& xListener , + const css::uno::Reference< css::uno::XInterface >& xSourceFake ); + void setJobData ( const JobData& aData ); + void execute ( const css::uno::Sequence< css::beans::NamedValue >& lDynamicArgs ); + void die ( ); + + private: + + css::uno::Sequence< css::beans::NamedValue > impl_generateJobArgs ( const css::uno::Sequence< css::beans::NamedValue >& lDynamicArgs ); + void impl_reactForJobResult( const css::uno::Any& aResult ); + void impl_startListening ( ); + void impl_stopListening ( ); + + //___________________________________ + // uno interface + + public: + + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + + // XJobListener + virtual void SAL_CALL jobFinished( const css::uno::Reference< css::task::XAsyncJob >& xJob, + const css::uno::Any& aResult ) throw(css::uno::RuntimeException); + + // XTerminateListener + virtual void SAL_CALL queryTermination ( const css::lang::EventObject& aEvent ) throw(css::frame::TerminationVetoException, + css::uno::RuntimeException ); + virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) throw(css::uno::RuntimeException ); + + // XCloseListener + virtual void SAL_CALL queryClosing ( const css::lang::EventObject& aEvent , + sal_Bool bGetsOwnership ) throw(css::util::CloseVetoException, + css::uno::RuntimeException ); + virtual void SAL_CALL notifyClosing( const css::lang::EventObject& aEvent ) throw(css::uno::RuntimeException ); + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw(css::uno::RuntimeException); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOB_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/jobconst.hxx b/framework/inc/jobs/jobconst.hxx new file mode 100644 index 000000000000..19beca703cad --- /dev/null +++ b/framework/inc/jobs/jobconst.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBCONST_HXX_ +#define __FRAMEWORK_JOBS_JOBCONST_HXX_ + +//_______________________________________ +// my own includes + +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes + +//_______________________________________ +// other includes + +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +/** + @short defines all constant values used within a job environment. + + @descr The protocol between job executor/dispatch and jobs is fix and well defined. + But why every implemented job should write such constant values directly into + it's code. Typos can occure or code will be changed by new developers ... + Shared set of constant values can help to improve the mentainance of this code. + */ +class JobConst +{ + public: + + static const ::rtl::OUString ANSWER_DEACTIVATE_JOB(); + static const ::rtl::OUString ANSWER_SAVE_ARGUMENTS(); + static const ::rtl::OUString ANSWER_SEND_DISPATCHRESULT(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBCONST_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/jobdata.hxx b/framework/inc/jobs/jobdata.hxx new file mode 100644 index 000000000000..247d9c0b53a3 --- /dev/null +++ b/framework/inc/jobs/jobdata.hxx @@ -0,0 +1,288 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBDATA_HXX_ +#define __FRAMEWORK_JOBS_JOBDATA_HXX_ + +//_______________________________________ +// my own includes + +#include <jobs/configaccess.hxx> +#include <jobs/jobresult.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <macros/debug.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/frame/DispatchResultEvent.hpp> + +//_______________________________________ +// other includes +#include <tools/datetime.hxx> +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +// definitions + +/** + @short holds all neccessary informations about a job and + handle it's configuration (if any exist!) + @descr It can be used rom different use cases as a container + (or proxy) for all config data of a registered job. + But it doesn't implement any execute functionality! + */ +class JobData : private ThreadHelpBase +{ + //___________________________________ + // const + + public: + + /// specifies the root package and key to find registered jobs + static const sal_Char* JOBCFG_ROOT; + /// define the cfg key "Arguments" of a job relativ to JOBCFG_ROOT/<job alias> + static const sal_Char* JOBCFG_PROP_ARGUMENTS; + /// define the cfg key "Service" of a job relativ to JOBCFG_ROOT/<job alias> + static const sal_Char* JOBCFG_PROP_SERVICE; + + /// specifies the root package and key to find event registrations + static const sal_Char* EVENTCFG_ROOT; + /// define the cfg key "JobList" of an event relativ to EVENTCFG_ROOT/<event> + static const sal_Char* EVENTCFG_PATH_JOBLIST; + /// define the cfg key "AdminTime" of a job registration relativ to EVENTCFG_ROOT/<event>/EVENTCFG_PROP_JOBLIST/<job alias> + static const sal_Char* EVENTCFG_PROP_ADMINTIME; + /// define the cfg key "UserTime" of a job registration relativ to EVENTCFG_ROOT/<event>/EVENTCFG_PROP_JOBLIST/<job alias> + static const sal_Char* EVENTCFG_PROP_USERTIME; + + /// mark the starting point of static job data inside argument list of job execution + static const sal_Char* PROPSET_CONFIG; + /// mark the starting point of job specific data inside argument list of job execution + static const sal_Char* PROPSET_OWNCONFIG; + /// mark the starting point of environment data inside argument list of job execution + static const sal_Char* PROPSET_ENVIRONMENT; + /// mark the starting point of any other dynamic generated data inside argument list of job execution (e.g. from a dispatch() request) + static const sal_Char* PROPSET_DYNAMICDATA; + + static const sal_Char* PROP_ALIAS; + static const sal_Char* PROP_EVENTNAME; + static const sal_Char* PROP_ENVTYPE; + static const sal_Char* PROP_FRAME; + static const sal_Char* PROP_MODEL; + static const sal_Char* PROP_SERVICE; + + //___________________________________ + // structs + + public: + + /** These values can be used to differe between jobs with and jobs without + a configuration. Of course an "unknown state" should be available too, + to detect a missing initialization. + */ + enum EMode + { + /// indicates a missing initialization + E_UNKNOWN_MODE, + /// indicates a job with configuration (They alias represent the config key name.) + E_ALIAS, + /// indicates a job without configuration (The pure UNO implementation is used only.) + E_SERVICE, + /// indicates a job with configuration, which was triggered by an event + E_EVENT + }; + + /** These values represent the environment type, in which a job can run. + A job must known, from which binding it will be started. Because + it's initialization data depends from that! + */ + enum EEnvironment + { + /// indicates a missing initialization + E_UNKNOWN_ENVIRONMENT, + /// this job is used by the global JobExecutor service + E_EXECUTION, + /// this job is used by the global dispatch framework + E_DISPATCH, + /// this job is used by the global event broadcaster + E_DOCUMENTEVENT + }; + + /** Some jobs can be registered to "logical events", which are generated on demand if another document event + occures. E.g. "onDocumentOpened" in case "OnNew" or "OnLoad" was notified to the JobExecutor instance. + And normaly the original event is transported as parameter set to the executed job. But then such job + cant differ between e.g. "OnNew" and "onDocumentOpened". + That's why we must know, for which type of event the job was realy triggered .-) + + The information "sDocEvent" from this struct must be set on the member JobData::m_sEvent from outside + user of such Jobdata structure. + */ + struct TJob2DocEventBinding + { + ::rtl::OUString m_sJobName; + ::rtl::OUString m_sDocEvent; + + TJob2DocEventBinding(const ::rtl::OUString& sJobName , + const ::rtl::OUString& sDocEvent) + : m_sJobName (sJobName ) + , m_sDocEvent(sDocEvent) + {} + }; + + //___________________________________ + // member + + private: + + /** + reference to the uno service manager. + We need it for creating of own uno services ... e.g. for + opening the configuration. + */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** + An instance of this class can be used in two different modes: + - as a configured job + - as a job without any configuration + First mode is triggered by an alias, which points to the + configuration entries. Second mode is specified by an uno service + or implementation name. Then we does the same things (use the same interfaces) + but don't handle any configuration data. + The effect: This mode can be detected by this member. + */ + EMode m_eMode; + + /** + Because jobs can be bind to different mechanism inside office, a job + should know inside which environment it runs. E.g. a job can be executed + by the global JobExecutor service (triggered by an event) or e.g. as part + of the global dispatch framework (triggered by an UI control e.g. a menu entry). + */ + EEnvironment m_eEnvironment; + + /** + the alias name of this job. + Is used as entry of configuration set for job registration, to find all + neccessary properties of it.. + */ + ::rtl::OUString m_sAlias; + + /** + the uno implementation name of this job. + It's readed from the configuration. Don't set it from outside! + */ + ::rtl::OUString m_sService; + + /** + a job can be registered for an event. + It can be an empty value! But it will be set from outside any times. + Because it's not clear which job this instance should represent if an event + (instaed of an alias) comes in. Because there can be multiple registrations + for this event. We use this information only, to merge it with the job specific + arguments. A job can be called so, with a) it's onw config data and b) some dynamic + environment data. + */ + ::rtl::OUString m_sEvent; + + /** + job specific configuration items ... unknown for us! + It's readed from the configuration. Don't set it from outside! + */ + css::uno::Sequence< css::beans::NamedValue > m_lArguments; + + /** + after a job was sucessfully executed (by any outside code using our + informations) it can return a result. This member make it part of this + container too. So it can be used for further things. + We use it also to update our internal state and the configuration + of the job. But note: only the last result will be saved here! + */ + JobResult m_aLastExecutionResult; + + //___________________________________ + // native interface + + public: + + JobData( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ); + JobData( const JobData& rCopy ); + virtual ~JobData( ); + + void operator=( const JobData& rCopy ); + + EMode getMode () const; + EEnvironment getEnvironment () const; + ::rtl::OUString getEnvironmentDescriptor() const; + ::rtl::OUString getService () const; + ::rtl::OUString getEvent () const; + css::uno::Sequence< css::beans::NamedValue > getConfig () const; + css::uno::Sequence< css::beans::NamedValue > getJobConfig () const; + + sal_Bool hasConfig () const; + + void setEnvironment ( EEnvironment eEnvironment ); + void setAlias ( const ::rtl::OUString& sAlias ); + void setService ( const ::rtl::OUString& sService ); + void setEvent ( const ::rtl::OUString& sEvent , + const ::rtl::OUString& sAlias ); + void setJobConfig ( const css::uno::Sequence< css::beans::NamedValue >& lArguments ); + void setResult ( const JobResult& aResult ); + void disableJob ( ); + + static css::uno::Sequence< ::rtl::OUString > getEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , + const ::rtl::OUString& sEvent ); + + static void appendEnabledJobsForEvent( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , + const ::rtl::OUString& sEvent , + ::comphelper::SequenceAsVector< JobData::TJob2DocEventBinding >& lJobs ); + + //___________________________________ + // private helper + + private: + + void impl_reset(); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBDATA_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/jobdispatch.hxx b/framework/inc/jobs/jobdispatch.hxx new file mode 100644 index 000000000000..374dcaf157a3 --- /dev/null +++ b/framework/inc/jobs/jobdispatch.hxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBDISPATCH_HXX_ +#define __FRAMEWORK_JOBS_JOBDISPATCH_HXX_ + +//_______________________________________ +// my own includes + +#include <jobs/configaccess.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> +#include <macros/debug.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XNotifyingDispatch.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XDispatchResultListener.hpp> +#include <com/sun/star/task/XJobListener.hpp> +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/frame/FeatureStateEvent.hpp> +#include <com/sun/star/frame/DispatchResultEvent.hpp> +#include <com/sun/star/lang/XInitialization.hpp> + +//_______________________________________ +// other includes +#include <unotools/configpathes.hxx> +#include <cppuhelper/weak.hxx> +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +/** + @short implements a dispatch object for jobs + @descr Such dispatch object will be used by the generic dispatch mechanism if + an URL "vnd.sun.star.job:alias=<name>" occures. + Then an instance of this class will be created and used. + This new instance will be called within his method + dispatch() or dispatchWithNotification() for executing the + real job. We do it, control the life cycle of this internal + wrapped job and inform any interested listener if it finish. + */ +class JobDispatch : public css::lang::XTypeProvider + , public css::lang::XServiceInfo + , public css::lang::XInitialization + , public css::frame::XDispatchProvider + , public css::frame::XNotifyingDispatch // => XDispatch + , private ThreadHelpBase + , public ::cppu::OWeakObject +{ + //___________________________________ + // member + + private: + + /** reference to the uno service manager */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** reference to the frame, inside which this dispatch is used */ + css::uno::Reference< css::frame::XFrame > m_xFrame; + + //___________________________________ + // native interface methods + + public: + + JobDispatch( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ); + virtual ~JobDispatch( ); + + void impl_dispatchEvent ( const ::rtl::OUString& sEvent , + const css::uno::Sequence< css::beans::PropertyValue >& lArgs , + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ); + void impl_dispatchService( const ::rtl::OUString& sService , + const css::uno::Sequence< css::beans::PropertyValue >& lArgs , + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ); + void impl_dispatchAlias ( const ::rtl::OUString& sAlias , + const css::uno::Sequence< css::beans::PropertyValue >& lArgs , + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ); + + //___________________________________ + // uno interface methods + + public: + + // XInterface, XTypeProvider, XServiceInfo + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + DECLARE_XSERVICEINFO + + // Xinitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& lArguments ) throw(css::uno::Exception , + css::uno::RuntimeException); + + // XDispatchProvider + virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch ( const css::util::URL& aURL , + const ::rtl::OUString& sTargetFrameName , + sal_Int32 nSearchFlags ) throw(css::uno::RuntimeException); + virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor ) throw(css::uno::RuntimeException); + + // XNotifyingDispatch + virtual void SAL_CALL dispatchWithNotification( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArgs , + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException); + + // XDispatch + virtual void SAL_CALL dispatch ( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) throw(css::uno::RuntimeException); + virtual void SAL_CALL addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& xListener , + const css::util::URL& aURL ) throw(css::uno::RuntimeException); + virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener , + const css::util::URL& aURL ) throw(css::uno::RuntimeException); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBDISPATCH_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/jobexecutor.hxx b/framework/inc/jobs/jobexecutor.hxx new file mode 100644 index 000000000000..7967fd0dab36 --- /dev/null +++ b/framework/inc/jobs/jobexecutor.hxx @@ -0,0 +1,132 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_ +#define __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_ + +//_______________________________________ +// my own includes + +#include <jobs/configaccess.hxx> +#include <threadhelp/threadhelpbase.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> +#include <macros/debug.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/task/XJobExecutor.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/container/XContainerListener.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/document/XEventListener.hpp> + +//_______________________________________ +// other includes +#include <cppuhelper/weak.hxx> +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +/** + @short implements a job executor, which can be triggered from any code + @descr It uses the given trigger event to locate any registered job service + inside the configuration and execute it. Of course it controls the + liftime of such jobs too. + */ +class JobExecutor : public css::lang::XTypeProvider + , public css::lang::XServiceInfo + , public css::task::XJobExecutor + , public css::container::XContainerListener // => lang.XEventListener + , public css::document::XEventListener + , private ThreadHelpBase + , public ::cppu::OWeakObject +{ + //___________________________________ + // member + + private: + + /** reference to the uno service manager */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + /** cached list of all registered event names of cfg for call optimization. */ + OUStringList m_lEvents; + + /** we listen at the configuration for changes at the event list. */ + ConfigAccess m_aConfig; + + //___________________________________ + // native interface methods + + public: + + JobExecutor( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ); + virtual ~JobExecutor( ); + + //___________________________________ + // uno interface methods + + public: + + // XInterface, XTypeProvider, XServiceInfo + FWK_DECLARE_XINTERFACE + FWK_DECLARE_XTYPEPROVIDER + DECLARE_XSERVICEINFO + + // task.XJobExecutor + virtual void SAL_CALL trigger( const ::rtl::OUString& sEvent ) throw(css::uno::RuntimeException); + + // document.XEventListener + virtual void SAL_CALL notifyEvent( const css::document::EventObject& aEvent ) throw(css::uno::RuntimeException); + + // container.XContainerListener + virtual void SAL_CALL elementInserted( const css::container::ContainerEvent& aEvent ) throw(css::uno::RuntimeException); + virtual void SAL_CALL elementRemoved ( const css::container::ContainerEvent& aEvent ) throw(css::uno::RuntimeException); + virtual void SAL_CALL elementReplaced( const css::container::ContainerEvent& aEvent ) throw(css::uno::RuntimeException); + + // lang.XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw(css::uno::RuntimeException); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBEXECUTOR_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/jobresult.hxx b/framework/inc/jobs/jobresult.hxx new file mode 100644 index 000000000000..7fc0b30f242e --- /dev/null +++ b/framework/inc/jobs/jobresult.hxx @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBRESULT_HXX_ +#define __FRAMEWORK_JOBS_JOBRESULT_HXX_ + +//_______________________________________ +// my own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <macros/debug.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/frame/DispatchResultEvent.hpp> + +//_______________________________________ +// other includes +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// public const + +//_______________________________________ +/** + @short represent a result of a finished job execution + @descr Such result instance transport all neccessarry + data from the code place where the job was finished + to the outside code, where e.g. listener must be notified. + */ +class JobResult : private ThreadHelpBase +{ + //___________________________________ + // types + + public: + + /** + These enum values are used to build a flag mask of possible set + parts of an analyzed pure job execution result. + An user of this class can decide, if a member of us can be valid + or not. So it can indicate, if a job used the special part inside + his returned result protocol. + To be usable as flags - it must be values of set {0,1,2,4,8,16 ...}! + */ + enum EParts + { + E_NOPART = 0, + E_ARGUMENTS = 1, + E_DEACTIVATE = 2, + E_DISPATCHRESULT = 4 + }; + + //___________________________________ + // member + + private: + + /** hold the original pure result, which was given back by an + executed job + We analyze it and use it to set all our other members. + */ + css::uno::Any m_aPureResult; + + /** + an user of us must know, which (possible) parts of + a "pure result" was realy set by an executed job. + Means which other members of this class are valid. + This mask can be used to find it out. + */ + sal_uInt32 m_eParts; + + /** + a job can have persistent data + They are part of the pure result and will be used to + write it to the configuration. But that's part of any + user of us. We provide this information here only. + */ + css::uno::Sequence< css::beans::NamedValue > m_lArguments; + + /** + an executed job can force his deactivation + But we provide this information here only. + Doing so is part of any user of us. + */ + sal_Bool m_bDeactivate; + + /** + represent the part "DispatchResult" + It's a full filled event type, which was given + back by the executed job. Any user of us can send + it to his registered result listener directly. + */ + css::frame::DispatchResultEvent m_aDispatchResult; + + //___________________________________ + // native interface + + public: + + JobResult( ); + JobResult( const com::sun::star::uno::Any& aResult ); + JobResult( const JobResult& rCopy ); + virtual ~JobResult( ); + + void operator=( const JobResult& rCopy ); + + sal_Bool existPart ( sal_uInt32 eParts ) const; + css::uno::Sequence< css::beans::NamedValue > getArguments ( ) const; + css::frame::DispatchResultEvent getDispatchResult( ) const; +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBRESULT_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/joburl.hxx b/framework/inc/jobs/joburl.hxx new file mode 100644 index 000000000000..7746ded6efc5 --- /dev/null +++ b/framework/inc/jobs/joburl.hxx @@ -0,0 +1,180 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_JOBURL_HXX_ +#define __FRAMEWORK_JOBS_JOBURL_HXX_ + +//_______________________________________ +// my own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <macros/debug.hxx> +#include <stdtypes.h> +#include <general.h> + +//_______________________________________ +// interface includes + +//_______________________________________ +// other includes +#include <rtl/ustring.hxx> + +//_______________________________________ +// namespace + +namespace framework{ + +//_______________________________________ +// const + +#define JOBURL_PROTOCOL_STR "vnd.sun.star.job:" +#define JOBURL_PROTOCOL_LEN 17 + +#define JOBURL_EVENT_STR "event=" +#define JOBURL_EVENT_LEN 6 + +#define JOBURL_ALIAS_STR "alias=" +#define JOBURL_ALIAS_LEN 6 + +#define JOBURL_SERVICE_STR "service=" +#define JOBURL_SERVICE_LEN 8 + +#define JOBURL_PART_SEPERATOR ';' +#define JOBURL_PARTARGS_SEPERATOR ',' + +//_______________________________________ +/** + @short can be used to parse, validate and work with job URL's + @descr Job URLs are specified by the following syntax: + vnd.sun.star.job:{[event=<name>]|[alias=<name>]|[service=<name>]} + This class can analyze this structure and seperate it into his different parts. + After doing that these parts are accessible by the methods of this class. + */ +class JobURL : private ThreadHelpBase +{ + //___________________________________ + // types + + private: + + /** + possible states of a job URL + Note: These values are used in combination. So they must be + values in form 2^n. + */ + enum ERequest + { + /// mark a job URL as not valid + E_UNKNOWN = 0, + /// it's an event + E_EVENT = 1, + /// it's an alias + E_ALIAS = 2, + /// it's a service + E_SERVICE = 4 + }; + + //___________________________________ + // types + + private: + + /** knows the state of this URL instance */ + sal_uInt32 m_eRequest; + + /** holds the event part of a job URL */ + ::rtl::OUString m_sEvent; + + /** holds the alias part of a job URL */ + ::rtl::OUString m_sAlias; + + /** holds the service part of a job URL */ + ::rtl::OUString m_sService; + + /** holds the event arguments */ + ::rtl::OUString m_sEventArgs; + + /** holds the alias arguments */ + ::rtl::OUString m_sAliasArgs; + + /** holds the service arguments */ + ::rtl::OUString m_sServiceArgs; + + //___________________________________ + // native interface + + public: + + JobURL ( const ::rtl::OUString& sURL ); + sal_Bool isValid ( ) const; + sal_Bool getEvent ( ::rtl::OUString& sEvent ) const; + sal_Bool getAlias ( ::rtl::OUString& sAlias ) const; + sal_Bool getService ( ::rtl::OUString& sService ) const; + + //___________________________________ + // private helper + + private: + + static sal_Bool implst_split( const ::rtl::OUString& sPart , + const sal_Char* pPartIdentifier , + sal_Int32 nPartLength , + ::rtl::OUString& rPartValue , + ::rtl::OUString& rPartArguments ); + + //___________________________________ + // debug methods! + + #ifdef ENABLE_COMPONENT_SELF_CHECK + + public: + static void impldbg_checkIt(); + + private: + static void impldbg_checkURL( const sal_Char* pURL , + sal_uInt32 eExpectedPart , + const sal_Char* pExpectedEvent , + const sal_Char* pExpectedAlias , + const sal_Char* pExpectedService , + const sal_Char* pExpectedEventArgs , + const sal_Char* pExpectedAliasArgs , + const sal_Char* pExpectedServiceArgs ); + ::rtl::OUString impldbg_toString() const; + + sal_Bool getServiceArgs( ::rtl::OUString& sServiceArgs ) const; + sal_Bool getEventArgs ( ::rtl::OUString& sEventArgs ) const; + sal_Bool getAliasArgs ( ::rtl::OUString& sAliasArgs ) const; + + #endif // ENABLE_COMPONENT_SELF_CHECK +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_JOBURL_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/jobs/shelljob.hxx b/framework/inc/jobs/shelljob.hxx new file mode 100644 index 000000000000..9e97fd0e1e69 --- /dev/null +++ b/framework/inc/jobs/shelljob.hxx @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_JOBS_SHELLJOB_HXX_ +#define __FRAMEWORK_JOBS_SHELLJOB_HXX_ + +//_______________________________________________ +// my own includes + +#include <threadhelp/threadhelpbase.hxx> +#include <macros/xinterface.hxx> +#include <macros/xtypeprovider.hxx> +#include <macros/xserviceinfo.hxx> + +//_______________________________________________ +// other includes +#include <cppuhelper/implbase2.hxx> + +//_______________________________________________ +// uno includes +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/frame/XModuleManager.hpp> + +//_______________________________________________ +// namespace + +namespace framework{ + +//_______________________________________________ +// declarations + +//_______________________________________________ +/** @short implements a job component which can be used + to execute system shell commands. + + @descr Because the job will be implemented generic + it can be bound to any event where jobs can be + registered for. Further there is a generic + way to configure the shell command and it's list + of arguments. + + @author as96863 + */ +class ShellJob : private ThreadHelpBase + ,public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XServiceInfo,::com::sun::star::task::XJob > +{ + //------------------------------------------- + // member + private: + + //....................................... + /** @short reference to an uno service manager. */ + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + //------------------------------------------- + // native interface + public: + + //--------------------------------------- + /** @short create new instance of this class. + + @param xSMGR + reference to the uno service manager, which created this instance. + Can be used later to create own needed uno resources on demand. + */ + ShellJob(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + + //--------------------------------------- + /** @short does nothing real ... + + @descr But it should exists as virtual function, + so this class cant make trouble + related to inline/symbols etcpp.! + */ + virtual ~ShellJob(); + + //------------------------------------------- + // uno interface + public: + + //--------------------------------------- + // css.lang.XServiceInfo + DECLARE_XSERVICEINFO + + // css.task.XJob + virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) + throw(css::lang::IllegalArgumentException, + css::uno::Exception , + css::uno::RuntimeException ); + + //------------------------------------------- + // helper + private: + + //--------------------------------------- + /** generate a return value for method execute() + which will force deactivation of this job for further requests. + + @return an Any following the job protocol for deactivation. + */ + static css::uno::Any impl_generateAnswer4Deactivation(); + + //--------------------------------------- + /** substitute all might existing placeholder variables + within the configured command. + + The command is part of the job configuration. + These will make changes more easy (no code changes required). + Further the command can use placeholder as they are supported + by the global substitution service (e.g. $(prog) etcpp) + + @param sCommand + the command containing placeholder variables. + + @return the substituted command. + */ + ::rtl::OUString impl_substituteCommandVariables(const ::rtl::OUString& sCommand); + + //--------------------------------------- + /** executes the command. + + @param sCommand + the absolute command as URL or system path (without any argument !). + + @param lArguments + the complete list of arguments configured for these job. + + @param bCheckExitCode + bind the execution result to the exit code of the started process. + If it's set to false we return false only in case executable couldnt be found + or couldnt be started. + + @return TRUE if command was executed successfully; FALSE otherwise. + */ + ::sal_Bool impl_execute(const ::rtl::OUString& sCommand , + const css::uno::Sequence< ::rtl::OUString >& lArguments , + ::sal_Bool bCheckExitCode); +}; + +} // namespace framework + +#endif // __FRAMEWORK_JOBS_SHELLJOB_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |