xref: /aoo41x/main/framework/inc/jobs/shelljob.hxx (revision f8e07b45)
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 exists as virtual function,
95                     so this class cant 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             throw(css::lang::IllegalArgumentException,
111                   css::uno::Exception                ,
112                   css::uno::RuntimeException         );
113 
114     //-------------------------------------------
115     // helper
116     private:
117 
118         //---------------------------------------
119         /** generate a return value for method execute()
120             which will force deactivation of this job for further requests.
121 
122             @return an Any following the job protocol for deactivation.
123          */
124         static css::uno::Any impl_generateAnswer4Deactivation();
125 
126         //---------------------------------------
127         /** substitute all might existing placeholder variables
128             within the configured command.
129 
130             The command is part of the job configuration.
131             These will make changes more easy (no code changes required).
132             Further the command can use placeholder as they are supported
133             by the global substitution service (e.g. $(prog) etcpp)
134 
135             @param  sCommand
136                     the command containing placeholder variables.
137 
138             @return the substituted command.
139          */
140         ::rtl::OUString impl_substituteCommandVariables(const ::rtl::OUString& sCommand);
141 
142         //---------------------------------------
143         /** executes the command.
144 
145             @param  sCommand
146                     the absolute command as URL or system path (without any argument !).
147 
148             @param  lArguments
149                     the complete list of arguments configured for these job.
150 
151             @param  bCheckExitCode
152                     bind the execution result to the exit code of the started process.
153                     If it's set to false we return false only in case executable couldnt be found
154                     or couldnt be started.
155 
156             @return sal_True if command was executed successfully; sal_False otherwise.
157          */
158         ::sal_Bool impl_execute(const ::rtl::OUString&                       sCommand      ,
159                                 const css::uno::Sequence< ::rtl::OUString >& lArguments    ,
160                                       ::sal_Bool                             bCheckExitCode);
161 };
162 
163 } // namespace framework
164 
165 #endif // __FRAMEWORK_JOBS_SHELLJOB_HXX_
166