1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_JOBS_SHELLJOB_HXX_ 29 #define __FRAMEWORK_JOBS_SHELLJOB_HXX_ 30 31 //_______________________________________________ 32 // my own includes 33 34 #include <threadhelp/threadhelpbase.hxx> 35 #include <macros/xinterface.hxx> 36 #include <macros/xtypeprovider.hxx> 37 #include <macros/xserviceinfo.hxx> 38 39 //_______________________________________________ 40 // other includes 41 #include <cppuhelper/implbase2.hxx> 42 43 //_______________________________________________ 44 // uno includes 45 #include <com/sun/star/frame/XFrame.hpp> 46 #include <com/sun/star/task/XJob.hpp> 47 #include <com/sun/star/lang/XEventListener.hpp> 48 #include <com/sun/star/container/XNameAccess.hpp> 49 #include <com/sun/star/frame/XModuleManager.hpp> 50 51 //_______________________________________________ 52 // namespace 53 54 namespace framework{ 55 56 //_______________________________________________ 57 // declarations 58 59 //_______________________________________________ 60 /** @short implements a job component which can be used 61 to execute system shell commands. 62 63 @descr Because the job will be implemented generic 64 it can be bound to any event where jobs can be 65 registered for. Further there is a generic 66 way to configure the shell command and it's list 67 of arguments. 68 69 @author as96863 70 */ 71 class ShellJob : private ThreadHelpBase 72 ,public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XServiceInfo,::com::sun::star::task::XJob > 73 { 74 //------------------------------------------- 75 // member 76 private: 77 78 //....................................... 79 /** @short reference to an uno service manager. */ 80 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 81 82 //------------------------------------------- 83 // native interface 84 public: 85 86 //--------------------------------------- 87 /** @short create new instance of this class. 88 89 @param xSMGR 90 reference to the uno service manager, which created this instance. 91 Can be used later to create own needed uno resources on demand. 92 */ 93 ShellJob(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 94 95 //--------------------------------------- 96 /** @short does nothing real ... 97 98 @descr But it should exists as virtual function, 99 so this class cant make trouble 100 related to inline/symbols etcpp.! 101 */ 102 virtual ~ShellJob(); 103 104 //------------------------------------------- 105 // uno interface 106 public: 107 108 //--------------------------------------- 109 // css.lang.XServiceInfo 110 DECLARE_XSERVICEINFO 111 112 // css.task.XJob 113 virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) 114 throw(css::lang::IllegalArgumentException, 115 css::uno::Exception , 116 css::uno::RuntimeException ); 117 118 //------------------------------------------- 119 // helper 120 private: 121 122 //--------------------------------------- 123 /** generate a return value for method execute() 124 which will force deactivation of this job for further requests. 125 126 @return an Any following the job protocol for deactivation. 127 */ 128 static css::uno::Any impl_generateAnswer4Deactivation(); 129 130 //--------------------------------------- 131 /** substitute all might existing placeholder variables 132 within the configured command. 133 134 The command is part of the job configuration. 135 These will make changes more easy (no code changes required). 136 Further the command can use placeholder as they are supported 137 by the global substitution service (e.g. $(prog) etcpp) 138 139 @param sCommand 140 the command containing placeholder variables. 141 142 @return the substituted command. 143 */ 144 ::rtl::OUString impl_substituteCommandVariables(const ::rtl::OUString& sCommand); 145 146 //--------------------------------------- 147 /** executes the command. 148 149 @param sCommand 150 the absolute command as URL or system path (without any argument !). 151 152 @param lArguments 153 the complete list of arguments configured for these job. 154 155 @param bCheckExitCode 156 bind the execution result to the exit code of the started process. 157 If it's set to false we return false only in case executable couldnt be found 158 or couldnt be started. 159 160 @return sal_True if command was executed successfully; sal_False otherwise. 161 */ 162 ::sal_Bool impl_execute(const ::rtl::OUString& sCommand , 163 const css::uno::Sequence< ::rtl::OUString >& lArguments , 164 ::sal_Bool bCheckExitCode); 165 }; 166 167 } // namespace framework 168 169 #endif // __FRAMEWORK_JOBS_SHELLJOB_HXX_ 170