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