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