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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26
27 //________________________________
28 // my own includes
29
30 #include <jobs/jobresult.hxx>
31 #include <jobs/jobconst.hxx>
32 #include <threadhelp/readguard.hxx>
33 #include <threadhelp/writeguard.hxx>
34 #include <general.h>
35 #include <services.h>
36
37 //________________________________
38 // interface includes
39
40 //________________________________
41 // includes of other projects
42
43 #include <rtl/ustrbuf.hxx>
44 #include <vcl/svapp.hxx>
45 #include <comphelper/sequenceashashmap.hxx>
46
47 //________________________________
48 // namespace
49
50 namespace framework{
51
52 //________________________________
53 // non exported const
54
55 //________________________________
56 // non exported definitions
57
58 //________________________________
59 // declarations
60
61 //________________________________
62 /**
63 @short standard dtor
64 @descr It does nothing else ...
65 but it marks this new instance as non valid!
66 */
JobResult()67 JobResult::JobResult()
68 : ThreadHelpBase(&Application::GetSolarMutex())
69 {
70 // reset the flag mask!
71 // It will reset the accessible state of this object.
72 // That can be useful if something will fail here ...
73 m_eParts = E_NOPART;
74 }
75
76 //________________________________
77 /**
78 @short special ctor
79 @descr It initialize this new instance with a pure job execution result
80 and analyze it. Doing so, we update our other members.
81
82 <p>
83 It's a list of named values, packed inside this any.
84 Following protocol is used:
85 <p>
86 <ul>
87 <li>
88 "SaveArguments" [sequence< css.beans.NamedValue >]
89 <br>
90 The returned list of (for this generic implementation unknown!)
91 properties, will be written directly to the configuration and replace
92 any old values there. There will no check for changes and we doesn't
93 support any mege feature here. They are written only. The job has
94 to modify this list.
95 </li>
96 <li>
97 "SendDispatchResult" [css.frame.DispatchResultEvent]
98 <br>
99 The given event is send to all current registered listener.
100 But it's not guaranteed. In case no listener are available or
101 this job isn't part of the dispatch environment (because it was used
102 by the css..task.XJobExecutor->trigger() implementation) this option
103 will be ignored.
104 </li>
105 <li>
106 "Deactivate" [boolean]
107 <br>
108 The job whish to be disabled. But note: There is no way, to enable it later
109 again by using this implementation. It can be done by using the configuration
110 only. (Means to register this job again.)
111 If a job knows, that there exist some status or result listener, it must use
112 the options "SendDispatchStatus" and "SendDispatchResult" (see before) too, to
113 inform it about the deactivation of this service.
114 </li>
115 </ul>
116
117 @param aResult
118 the job result
119 */
JobResult(const css::uno::Any & aResult)120 JobResult::JobResult( /*IN*/ const css::uno::Any& aResult )
121 : ThreadHelpBase(&Application::GetSolarMutex())
122 {
123 // safe the pure result
124 // May someone need it later ...
125 m_aPureResult = aResult;
126
127 // reset the flag mask!
128 // It will reset the accessible state of this object.
129 // That can be useful if something will fail here ...
130 m_eParts = E_NOPART;
131
132 // analyze the result and update our other members
133 ::comphelper::SequenceAsHashMap aProtocol(aResult);
134 if ( aProtocol.empty() )
135 return;
136
137 ::comphelper::SequenceAsHashMap::const_iterator pIt = aProtocol.end();
138
139 pIt = aProtocol.find(JobConst::ANSWER_DEACTIVATE_JOB());
140 if (pIt != aProtocol.end())
141 {
142 pIt->second >>= m_bDeactivate;
143 if (m_bDeactivate)
144 m_eParts |= E_DEACTIVATE;
145 }
146
147 pIt = aProtocol.find(JobConst::ANSWER_SAVE_ARGUMENTS());
148 if (pIt != aProtocol.end())
149 {
150 pIt->second >>= m_lArguments;
151 if (m_lArguments.getLength() > 0)
152 m_eParts |= E_ARGUMENTS;
153 }
154
155 pIt = aProtocol.find(JobConst::ANSWER_SEND_DISPATCHRESULT());
156 if (pIt != aProtocol.end())
157 {
158 if (pIt->second >>= m_aDispatchResult)
159 m_eParts |= E_DISPATCHRESULT;
160 }
161 }
162
163 //________________________________
164 /**
165 @short copy dtor
166 @descr -
167 */
JobResult(const JobResult & rCopy)168 JobResult::JobResult( const JobResult& rCopy )
169 : ThreadHelpBase(&Application::GetSolarMutex())
170 {
171 m_aPureResult = rCopy.m_aPureResult ;
172 m_eParts = rCopy.m_eParts ;
173 m_lArguments = rCopy.m_lArguments ;
174 m_bDeactivate = rCopy.m_bDeactivate ;
175 m_aDispatchResult = rCopy.m_aDispatchResult ;
176 }
177
178 //________________________________
179 /**
180 @short standard dtor
181 @descr Free all internally used resources at the end of living.
182 */
~JobResult()183 JobResult::~JobResult()
184 {
185 // Nothing really to do here.
186 }
187
188 //________________________________
189 /**
190 @short =operator
191 @descr Must be implemented to overwrite this instance with another one.
192
193 @param rCopy
194 reference to the other instance, which should be used for copying.
195 */
operator =(const JobResult & rCopy)196 void JobResult::operator=( const JobResult& rCopy )
197 {
198 /* SAFE { */
199 WriteGuard aWriteLock(m_aLock);
200 m_aPureResult = rCopy.m_aPureResult ;
201 m_eParts = rCopy.m_eParts ;
202 m_lArguments = rCopy.m_lArguments ;
203 m_bDeactivate = rCopy.m_bDeactivate ;
204 m_aDispatchResult = rCopy.m_aDispatchResult ;
205 aWriteLock.unlock();
206 /* } SAFE */
207 }
208
209 //________________________________
210 /**
211 @short checks for existing parts of the analyzed result
212 @descr The internal flag mask was set after analyzing of the pure result.
213 A user of us can check here, if the required part was really part
214 of this result. Otherwise it would use invalid informations ...
215 by using our other members!
216
217 @param eParts
218 a flag mask too, which will be compared with our internally set one.
219
220 @return We return true only, if any set flag of the given mask match.
221 */
existPart(sal_uInt32 eParts) const222 sal_Bool JobResult::existPart( sal_uInt32 eParts ) const
223 {
224 /* SAFE { */
225 ReadGuard aReadLock(m_aLock);
226 return ((m_eParts & eParts) == eParts);
227 /* } SAFE */
228 }
229
230 //________________________________
231 /**
232 @short provides access to our internal members
233 @descr The return value will be valid only in case a call of
234 existPart(E_...) before returned true!
235
236 @return It returns the state of the internal member
237 without any checks!
238 */
getArguments() const239 css::uno::Sequence< css::beans::NamedValue > JobResult::getArguments() const
240 {
241 /* SAFE { */
242 ReadGuard aReadLock(m_aLock);
243 return m_lArguments;
244 /* } SAFE */
245 }
246
247 //________________________________
248
getDispatchResult() const249 css::frame::DispatchResultEvent JobResult::getDispatchResult() const
250 {
251 /* SAFE { */
252 ReadGuard aReadLock(m_aLock);
253 return m_aDispatchResult;
254 /* } SAFE */
255 }
256
257 } // namespace framework
258