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