Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <jobs/jobresult.hxx>
21 : #include <jobs/jobconst.hxx>
22 : #include <general.h>
23 : #include <services.h>
24 :
25 : #include <rtl/ustrbuf.hxx>
26 : #include <vcl/svapp.hxx>
27 : #include <comphelper/sequenceashashmap.hxx>
28 :
29 : namespace framework{
30 :
31 : /**
32 : @short standard dtor
33 : @descr It does nothing else ...
34 : but it marks this new instance as non valid!
35 : */
36 637 : JobResult::JobResult()
37 637 : : m_bDeactivate(false)
38 : {
39 : // reset the flag mask!
40 : // It will reset the accessible state of this object.
41 : // That can be useful if something will fail here ...
42 637 : m_eParts = E_NOPART;
43 637 : }
44 :
45 : /**
46 : @short special ctor
47 : @descr It initialize this new instance with a pure job execution result
48 : and analyze it. Doing so, we update our other members.
49 :
50 : <p>
51 : It's a list of named values, packed inside this any.
52 : Following protocol is used:
53 : <p>
54 : <ul>
55 : <li>
56 : "SaveArguments" [sequence< css.beans.NamedValue >]
57 : <br>
58 : The returned list of (for this generic implementation unknown!)
59 : properties, will be written directly to the configuration and replace
60 : any old values there. There will no check for changes and we don't
61 : support any mege feature here. They are written only. The job has
62 : to modify this list.
63 : </li>
64 : <li>
65 : "SendDispatchResult" [css.frame.DispatchResultEvent]
66 : <br>
67 : The given event is send to all current registered listener.
68 : But it's not guaranteed. In case no listener are available or
69 : this job isn't part of the dispatch environment (because it was used
70 : by the css..task.XJobExecutor->trigger() implementation) this option
71 : will be ignored.
72 : </li>
73 : <li>
74 : "Deactivate" [boolean]
75 : <br>
76 : The job wish to be disabled. But note: There is no way, to enable it later
77 : again by using this implementation. It can be done by using the configuration
78 : only. (Means to register this job again.)
79 : If a job knows, that there exist some status or result listener, it must use
80 : the options "SendDispatchStatus" and "SendDispatchResult" (see before) too, to
81 : inform it about the deactivation of this service.
82 : </li>
83 : </ul>
84 :
85 : @param aResult
86 : the job result
87 : */
88 13 : JobResult::JobResult( /*IN*/ const css::uno::Any& aResult )
89 13 : : m_bDeactivate(false)
90 : {
91 : // safe the pure result
92 : // May someone need it later ...
93 13 : m_aPureResult = aResult;
94 :
95 : // reset the flag mask!
96 : // It will reset the accessible state of this object.
97 : // That can be useful if something will fail here ...
98 13 : m_eParts = E_NOPART;
99 :
100 : // analyze the result and update our other members
101 13 : ::comphelper::SequenceAsHashMap aProtocol(aResult);
102 13 : if ( aProtocol.empty() )
103 26 : return;
104 :
105 0 : ::comphelper::SequenceAsHashMap::const_iterator pIt = aProtocol.find(JobConst::ANSWER_DEACTIVATE_JOB());
106 0 : if (pIt != aProtocol.end())
107 : {
108 0 : pIt->second >>= m_bDeactivate;
109 0 : if (m_bDeactivate)
110 0 : m_eParts |= E_DEACTIVATE;
111 : }
112 :
113 0 : pIt = aProtocol.find(JobConst::ANSWER_SAVE_ARGUMENTS());
114 0 : if (pIt != aProtocol.end())
115 : {
116 0 : pIt->second >>= m_lArguments;
117 0 : if (m_lArguments.getLength() > 0)
118 0 : m_eParts |= E_ARGUMENTS;
119 : }
120 :
121 0 : pIt = aProtocol.find(JobConst::ANSWER_SEND_DISPATCHRESULT());
122 0 : if (pIt != aProtocol.end())
123 : {
124 0 : if (pIt->second >>= m_aDispatchResult)
125 0 : m_eParts |= E_DISPATCHRESULT;
126 0 : }
127 : }
128 :
129 : /**
130 : @short copy dtor
131 : */
132 0 : JobResult::JobResult( const JobResult& rCopy )
133 : {
134 0 : m_aPureResult = rCopy.m_aPureResult;
135 0 : m_eParts = rCopy.m_eParts;
136 0 : m_lArguments = rCopy.m_lArguments;
137 0 : m_bDeactivate = rCopy.m_bDeactivate;
138 0 : m_aDispatchResult = rCopy.m_aDispatchResult;
139 0 : }
140 :
141 : /**
142 : @short standard dtor
143 : @descr Free all internally used resources at the end of living.
144 : */
145 650 : JobResult::~JobResult()
146 : {
147 : // Nothing really to do here.
148 650 : }
149 :
150 : /**
151 : @short =operator
152 : @descr Must be implemented to overwrite this instance with another one.
153 :
154 : @param rCopy
155 : reference to the other instance, which should be used for copying.
156 : */
157 13 : void JobResult::operator=( const JobResult& rCopy )
158 : {
159 13 : SolarMutexGuard g;
160 13 : m_aPureResult = rCopy.m_aPureResult;
161 13 : m_eParts = rCopy.m_eParts;
162 13 : m_lArguments = rCopy.m_lArguments;
163 13 : m_bDeactivate = rCopy.m_bDeactivate;
164 13 : m_aDispatchResult = rCopy.m_aDispatchResult;
165 13 : }
166 :
167 : /**
168 : @short checks for existing parts of the analyzed result
169 : @descr The internal flag mask was set after analyzing of the pure result.
170 : An user of us can check here, if the required part was really part
171 : of this result. Otherwise it would use invalid information ...
172 : by using our other members!
173 :
174 : @param eParts
175 : a flag mask too, which will be compared with our internally set one.
176 :
177 : @return We return true only, if any set flag of the given mask match.
178 : */
179 26 : bool JobResult::existPart( sal_uInt32 eParts ) const
180 : {
181 26 : SolarMutexGuard g;
182 26 : return ((m_eParts & eParts) == eParts);
183 : }
184 :
185 : /**
186 : @short provides access to our internal members
187 : @descr The return value will be valid only in case a call of
188 : existPart(E_...) before returned true!
189 :
190 : @return It returns the state of the internal member
191 : without any checks!
192 : */
193 0 : css::uno::Sequence< css::beans::NamedValue > JobResult::getArguments() const
194 : {
195 0 : SolarMutexGuard g;
196 0 : return m_lArguments;
197 : }
198 :
199 0 : css::frame::DispatchResultEvent JobResult::getDispatchResult() const
200 : {
201 0 : SolarMutexGuard g;
202 0 : return m_aDispatchResult;
203 : }
204 :
205 : } // namespace framework
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|