/src/libreoffice/framework/source/jobs/jobresult.cxx
Line | Count | Source |
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 | | |
23 | | #include <vcl/svapp.hxx> |
24 | | #include <comphelper/sequenceashashmap.hxx> |
25 | | #include <comphelper/sequence.hxx> |
26 | | |
27 | | namespace framework |
28 | | { |
29 | | /** |
30 | | @short special ctor |
31 | | @descr It initialize this new instance with a pure job execution result |
32 | | and analyze it. Doing so, we update our other members. |
33 | | |
34 | | <p> |
35 | | It's a list of named values, packed inside this any. |
36 | | Following protocol is used: |
37 | | <p> |
38 | | <ul> |
39 | | <li> |
40 | | "SaveArguments" [sequence< css.beans.NamedValue >] |
41 | | <br> |
42 | | The returned list of (for this generic implementation unknown!) |
43 | | properties, will be written directly to the configuration and replace |
44 | | any old values there. There will no check for changes and we don't |
45 | | support any merge feature here. They are written only. The job has |
46 | | to modify this list. |
47 | | </li> |
48 | | <li> |
49 | | "SendDispatchResult" [css.frame.DispatchResultEvent] |
50 | | <br> |
51 | | The given event is send to all current registered listener. |
52 | | But it's not guaranteed. In case no listener are available or |
53 | | this job isn't part of the dispatch environment (because it was used |
54 | | by the css..task.XJobExecutor->trigger() implementation) this option |
55 | | will be ignored. |
56 | | </li> |
57 | | <li> |
58 | | "Deactivate" [boolean] |
59 | | <br> |
60 | | The job wish to be disabled. But note: There is no way, to enable it later |
61 | | again by using this implementation. It can be done by using the configuration |
62 | | only. (Means to register this job again.) |
63 | | If a job knows, that there exist some status or result listener, it must use |
64 | | the options "SendDispatchStatus" and "SendDispatchResult" (see before) too, to |
65 | | inform it about the deactivation of this service. |
66 | | </li> |
67 | | </ul> |
68 | | |
69 | | @param aResult |
70 | | the job result |
71 | | */ |
72 | | JobResult::JobResult(/*IN*/ const css::uno::Any& aResult) |
73 | 0 | { |
74 | | // reset the flag mask! |
75 | | // It will reset the accessible state of this object. |
76 | | // That can be useful if something will fail here ... |
77 | 0 | m_eParts = E_NOPART; |
78 | | |
79 | | // analyze the result and update our other members |
80 | 0 | ::comphelper::SequenceAsHashMap aProtocol(aResult); |
81 | 0 | if (aProtocol.empty()) |
82 | 0 | return; |
83 | | |
84 | 0 | ::comphelper::SequenceAsHashMap::const_iterator pIt |
85 | 0 | = aProtocol.find(JobConst::ANSWER_DEACTIVATE_JOB); |
86 | 0 | if (pIt != aProtocol.end()) |
87 | 0 | { |
88 | | /** |
89 | | an executed job can force his deactivation |
90 | | But we provide this information here only. |
91 | | Doing so is part of any user of us. |
92 | | */ |
93 | 0 | bool bDeactivate(false); |
94 | 0 | pIt->second >>= bDeactivate; |
95 | 0 | if (bDeactivate) |
96 | 0 | m_eParts |= E_DEACTIVATE; |
97 | 0 | } |
98 | |
|
99 | 0 | pIt = aProtocol.find(JobConst::ANSWER_SAVE_ARGUMENTS); |
100 | 0 | if (pIt != aProtocol.end()) |
101 | 0 | { |
102 | 0 | css::uno::Sequence<css::beans::NamedValue> aTmp; |
103 | 0 | pIt->second >>= aTmp; |
104 | 0 | comphelper::sequenceToContainer(m_lArguments, aTmp); |
105 | 0 | if (m_lArguments.empty()) |
106 | 0 | m_eParts |= E_ARGUMENTS; |
107 | 0 | } |
108 | |
|
109 | 0 | pIt = aProtocol.find(JobConst::ANSWER_SEND_DISPATCHRESULT); |
110 | 0 | if (pIt != aProtocol.end()) |
111 | 0 | { |
112 | 0 | if (pIt->second >>= m_aDispatchResult) |
113 | 0 | m_eParts |= E_DISPATCHRESULT; |
114 | 0 | } |
115 | 0 | } |
116 | | |
117 | | /** |
118 | | @short copy dtor |
119 | | */ |
120 | | JobResult::JobResult(const JobResult& rCopy) |
121 | 0 | { |
122 | 0 | m_eParts = rCopy.m_eParts; |
123 | 0 | m_lArguments = rCopy.m_lArguments; |
124 | 0 | m_aDispatchResult = rCopy.m_aDispatchResult; |
125 | 0 | } |
126 | | |
127 | | /** |
128 | | @short standard dtor |
129 | | @descr Free all internally used resources at the end of living. |
130 | | */ |
131 | | JobResult::~JobResult() |
132 | 0 | { |
133 | | // Nothing really to do here. |
134 | 0 | } |
135 | | |
136 | | /** |
137 | | @short =operator |
138 | | @descr Must be implemented to overwrite this instance with another one. |
139 | | |
140 | | @param rCopy |
141 | | reference to the other instance, which should be used for copying. |
142 | | */ |
143 | | JobResult& JobResult::operator=(const JobResult& rCopy) |
144 | 0 | { |
145 | 0 | m_eParts = rCopy.m_eParts; |
146 | 0 | m_lArguments = rCopy.m_lArguments; |
147 | 0 | m_aDispatchResult = rCopy.m_aDispatchResult; |
148 | 0 | return *this; |
149 | 0 | } |
150 | | |
151 | | /** |
152 | | @short checks for existing parts of the analyzed result |
153 | | @descr The internal flag mask was set after analyzing of the pure result. |
154 | | An user of us can check here, if the required part was really part |
155 | | of this result. Otherwise it would use invalid information ... |
156 | | by using our other members! |
157 | | |
158 | | @param eParts |
159 | | a flag mask too, which will be compared with our internally set one. |
160 | | |
161 | | @return We return true only, if any set flag of the given mask match. |
162 | | */ |
163 | 0 | bool JobResult::existPart(sal_uInt32 eParts) const { return ((m_eParts & eParts) == eParts); } |
164 | | |
165 | | /** |
166 | | @short provides access to our internal members |
167 | | @descr The return value will be valid only in case a call of |
168 | | existPart(E_...) before returned true! |
169 | | |
170 | | @return It returns the state of the internal member |
171 | | without any checks! |
172 | | */ |
173 | 0 | const std::vector<css::beans::NamedValue>& JobResult::getArguments() const { return m_lArguments; } |
174 | | |
175 | | const css::frame::DispatchResultEvent& JobResult::getDispatchResult() const |
176 | 0 | { |
177 | 0 | return m_aDispatchResult; |
178 | 0 | } |
179 | | |
180 | | } // namespace framework |
181 | | |
182 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |