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