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