xref: /aoo4110/main/framework/inc/jobs/shelljob.hxx (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #ifndef __FRAMEWORK_JOBS_SHELLJOB_HXX_
25*b1cdbd2cSJim Jagielski #define __FRAMEWORK_JOBS_SHELLJOB_HXX_
26*b1cdbd2cSJim Jagielski 
27*b1cdbd2cSJim Jagielski //_______________________________________________
28*b1cdbd2cSJim Jagielski // my own includes
29*b1cdbd2cSJim Jagielski 
30*b1cdbd2cSJim Jagielski #include <threadhelp/threadhelpbase.hxx>
31*b1cdbd2cSJim Jagielski #include <macros/xinterface.hxx>
32*b1cdbd2cSJim Jagielski #include <macros/xtypeprovider.hxx>
33*b1cdbd2cSJim Jagielski #include <macros/xserviceinfo.hxx>
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski //_______________________________________________
36*b1cdbd2cSJim Jagielski // other includes
37*b1cdbd2cSJim Jagielski #include <cppuhelper/implbase2.hxx>
38*b1cdbd2cSJim Jagielski 
39*b1cdbd2cSJim Jagielski //_______________________________________________
40*b1cdbd2cSJim Jagielski // uno includes
41*b1cdbd2cSJim Jagielski #include <com/sun/star/frame/XFrame.hpp>
42*b1cdbd2cSJim Jagielski #include <com/sun/star/task/XJob.hpp>
43*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XEventListener.hpp>
44*b1cdbd2cSJim Jagielski #include <com/sun/star/container/XNameAccess.hpp>
45*b1cdbd2cSJim Jagielski #include <com/sun/star/frame/XModuleManager.hpp>
46*b1cdbd2cSJim Jagielski 
47*b1cdbd2cSJim Jagielski //_______________________________________________
48*b1cdbd2cSJim Jagielski // namespace
49*b1cdbd2cSJim Jagielski 
50*b1cdbd2cSJim Jagielski namespace framework{
51*b1cdbd2cSJim Jagielski 
52*b1cdbd2cSJim Jagielski //_______________________________________________
53*b1cdbd2cSJim Jagielski // declarations
54*b1cdbd2cSJim Jagielski 
55*b1cdbd2cSJim Jagielski //_______________________________________________
56*b1cdbd2cSJim Jagielski /** @short  implements a job component which can be used
57*b1cdbd2cSJim Jagielski             to execute system shell commands.
58*b1cdbd2cSJim Jagielski 
59*b1cdbd2cSJim Jagielski     @descr  Because the job will be implemented generic
60*b1cdbd2cSJim Jagielski             it can be bound to any event where jobs can be
61*b1cdbd2cSJim Jagielski             registered for. Further there is a generic
62*b1cdbd2cSJim Jagielski             way to configure the shell command and it's list
63*b1cdbd2cSJim Jagielski             of arguments.
64*b1cdbd2cSJim Jagielski 
65*b1cdbd2cSJim Jagielski     @author as96863
66*b1cdbd2cSJim Jagielski  */
67*b1cdbd2cSJim Jagielski class ShellJob : private ThreadHelpBase
68*b1cdbd2cSJim Jagielski                ,public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XServiceInfo,::com::sun::star::task::XJob >
69*b1cdbd2cSJim Jagielski {
70*b1cdbd2cSJim Jagielski     //-------------------------------------------
71*b1cdbd2cSJim Jagielski     // member
72*b1cdbd2cSJim Jagielski     private:
73*b1cdbd2cSJim Jagielski 
74*b1cdbd2cSJim Jagielski         //.......................................
75*b1cdbd2cSJim Jagielski         /** @short  reference to an uno service manager. */
76*b1cdbd2cSJim Jagielski         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
77*b1cdbd2cSJim Jagielski 
78*b1cdbd2cSJim Jagielski     //-------------------------------------------
79*b1cdbd2cSJim Jagielski     // native interface
80*b1cdbd2cSJim Jagielski     public:
81*b1cdbd2cSJim Jagielski 
82*b1cdbd2cSJim Jagielski         //---------------------------------------
83*b1cdbd2cSJim Jagielski         /** @short  create new instance of this class.
84*b1cdbd2cSJim Jagielski 
85*b1cdbd2cSJim Jagielski             @param  xSMGR
86*b1cdbd2cSJim Jagielski                     reference to the uno service manager, which created this instance.
87*b1cdbd2cSJim Jagielski                     Can be used later to create own needed uno resources on demand.
88*b1cdbd2cSJim Jagielski          */
89*b1cdbd2cSJim Jagielski         ShellJob(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
90*b1cdbd2cSJim Jagielski 
91*b1cdbd2cSJim Jagielski         //---------------------------------------
92*b1cdbd2cSJim Jagielski         /** @short  does nothing real ...
93*b1cdbd2cSJim Jagielski 
94*b1cdbd2cSJim Jagielski             @descr  But it should exists as virtual function,
95*b1cdbd2cSJim Jagielski                     so this class cant make trouble
96*b1cdbd2cSJim Jagielski                     related to inline/symbols etcpp.!
97*b1cdbd2cSJim Jagielski          */
98*b1cdbd2cSJim Jagielski         virtual ~ShellJob();
99*b1cdbd2cSJim Jagielski 
100*b1cdbd2cSJim Jagielski     //-------------------------------------------
101*b1cdbd2cSJim Jagielski     // uno interface
102*b1cdbd2cSJim Jagielski     public:
103*b1cdbd2cSJim Jagielski 
104*b1cdbd2cSJim Jagielski         //---------------------------------------
105*b1cdbd2cSJim Jagielski         // css.lang.XServiceInfo
106*b1cdbd2cSJim Jagielski         DECLARE_XSERVICEINFO
107*b1cdbd2cSJim Jagielski 
108*b1cdbd2cSJim Jagielski         // css.task.XJob
109*b1cdbd2cSJim Jagielski         virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
110*b1cdbd2cSJim Jagielski             throw(css::lang::IllegalArgumentException,
111*b1cdbd2cSJim Jagielski                   css::uno::Exception                ,
112*b1cdbd2cSJim Jagielski                   css::uno::RuntimeException         );
113*b1cdbd2cSJim Jagielski 
114*b1cdbd2cSJim Jagielski     //-------------------------------------------
115*b1cdbd2cSJim Jagielski     // helper
116*b1cdbd2cSJim Jagielski     private:
117*b1cdbd2cSJim Jagielski 
118*b1cdbd2cSJim Jagielski         //---------------------------------------
119*b1cdbd2cSJim Jagielski         /** generate a return value for method execute()
120*b1cdbd2cSJim Jagielski             which will force deactivation of this job for further requests.
121*b1cdbd2cSJim Jagielski 
122*b1cdbd2cSJim Jagielski             @return an Any following the job protocol for deactivation.
123*b1cdbd2cSJim Jagielski          */
124*b1cdbd2cSJim Jagielski         static css::uno::Any impl_generateAnswer4Deactivation();
125*b1cdbd2cSJim Jagielski 
126*b1cdbd2cSJim Jagielski         //---------------------------------------
127*b1cdbd2cSJim Jagielski         /** substitute all might existing placeholder variables
128*b1cdbd2cSJim Jagielski             within the configured command.
129*b1cdbd2cSJim Jagielski 
130*b1cdbd2cSJim Jagielski             The command is part of the job configuration.
131*b1cdbd2cSJim Jagielski             These will make changes more easy (no code changes required).
132*b1cdbd2cSJim Jagielski             Further the command can use placeholder as they are supported
133*b1cdbd2cSJim Jagielski             by the global substitution service (e.g. $(prog) etcpp)
134*b1cdbd2cSJim Jagielski 
135*b1cdbd2cSJim Jagielski             @param  sCommand
136*b1cdbd2cSJim Jagielski                     the command containing placeholder variables.
137*b1cdbd2cSJim Jagielski 
138*b1cdbd2cSJim Jagielski             @return the substituted command.
139*b1cdbd2cSJim Jagielski          */
140*b1cdbd2cSJim Jagielski         ::rtl::OUString impl_substituteCommandVariables(const ::rtl::OUString& sCommand);
141*b1cdbd2cSJim Jagielski 
142*b1cdbd2cSJim Jagielski         //---------------------------------------
143*b1cdbd2cSJim Jagielski         /** executes the command.
144*b1cdbd2cSJim Jagielski 
145*b1cdbd2cSJim Jagielski             @param  sCommand
146*b1cdbd2cSJim Jagielski                     the absolute command as URL or system path (without any argument !).
147*b1cdbd2cSJim Jagielski 
148*b1cdbd2cSJim Jagielski             @param  lArguments
149*b1cdbd2cSJim Jagielski                     the complete list of arguments configured for these job.
150*b1cdbd2cSJim Jagielski 
151*b1cdbd2cSJim Jagielski             @param  bCheckExitCode
152*b1cdbd2cSJim Jagielski                     bind the execution result to the exit code of the started process.
153*b1cdbd2cSJim Jagielski                     If it's set to false we return false only in case executable couldnt be found
154*b1cdbd2cSJim Jagielski                     or couldnt be started.
155*b1cdbd2cSJim Jagielski 
156*b1cdbd2cSJim Jagielski             @return sal_True if command was executed successfully; sal_False otherwise.
157*b1cdbd2cSJim Jagielski          */
158*b1cdbd2cSJim Jagielski         ::sal_Bool impl_execute(const ::rtl::OUString&                       sCommand      ,
159*b1cdbd2cSJim Jagielski                                 const css::uno::Sequence< ::rtl::OUString >& lArguments    ,
160*b1cdbd2cSJim Jagielski                                       ::sal_Bool                             bCheckExitCode);
161*b1cdbd2cSJim Jagielski };
162*b1cdbd2cSJim Jagielski 
163*b1cdbd2cSJim Jagielski } // namespace framework
164*b1cdbd2cSJim Jagielski 
165*b1cdbd2cSJim Jagielski #endif // __FRAMEWORK_JOBS_SHELLJOB_HXX_
166