blob: 7987ecb15c3ff1d84e4438e430e5c00cc1479318 [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli065264a2011-11-20 15:46:41 +01002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli065264a2011-11-20 15:46:41 +010022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli065264a2011-11-20 15:46:41 +010024 */
25#include "ParameterHandle.h"
26#include "ParameterAccessContext.h"
27#include "BaseParameter.h"
28#include "Subsystem.h"
29#include <assert.h>
30#include "ParameterMgr.h"
31#include "AutoLock.h"
32
33CParameterHandle::CParameterHandle(const CBaseParameter* pParameter, CParameterMgr* pParameterMgr)
34 : _pBaseParameter(pParameter), _pParameterMgr(pParameterMgr), _bBigEndianSubsystem(pParameter->getBelongingSubsystem()->isBigEndian())
35{
36}
37
38// Parameter features
39bool CParameterHandle::isRogue() const
40{
41 return _pBaseParameter->isRogue();
42}
43
44bool CParameterHandle::isArray() const
45{
46 return !_pBaseParameter->isScalar();
47}
48
49// Array Length
50uint32_t CParameterHandle::getArrayLength() const
51{
52 return _pBaseParameter->getArrayLength();
53}
54
55// Parameter path
56string CParameterHandle::getPath() const
57{
58 return _pBaseParameter->getPath();
59}
60
61// Parameter kind
62string CParameterHandle::getKind() const
63{
64 return _pBaseParameter->getKind();
65}
66
67// Boolean access
68bool CParameterHandle::setAsBoolean(bool bValue, string& strError)
69{
70 // Check operation validity
71 if (!checkAccessValidity(true, 0, strError)) {
72
73 return false;
74 }
75 // Ensure we're safe against blackboard foreign access
76 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
77
78 // When in tuning mode, silently skip the request
79 if (_pParameterMgr->tuningModeOn()) {
80
81 return true;
82 }
83
84 // Define access context
85 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
86
87 return _pBaseParameter->accessAsBoolean(bValue, true, parameterAccessContext);
88}
89
90bool CParameterHandle::getAsBoolean(bool bValue, string& strError) const
91{
92 // Check operation validity
93 if (!checkAccessValidity(false, 0, strError)) {
94
95 return false;
96 }
97 // Ensure we're safe against blackboard foreign access
98 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
99
100 // Define access context
101 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
102
103 return _pBaseParameter->accessAsBoolean(bValue, false, parameterAccessContext);
104}
105
106bool CParameterHandle::setAsBooleanArray(const vector<bool>& abValues, string& strError)
107{
108 // Check operation validity
109 if (!checkAccessValidity(true, abValues.size(), strError)) {
110
111 return false;
112 }
113 // Ensure we're safe against blackboard foreign access
114 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
115
116 // When in tuning mode, silently skip the request
117 if (_pParameterMgr->tuningModeOn()) {
118
119 return true;
120 }
121
122 // Define access context
123 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
124
125 // Copy values for type adaptation
126 vector<bool> abUserValues = abValues;
127
128 return _pBaseParameter->accessAsBooleanArray(abUserValues, true, parameterAccessContext);
129}
130
131bool CParameterHandle::getAsBooleanArray(vector<bool>& abValues, string& strError) const
132{
133 // Check operation validity
134 if (!checkAccessValidity(false, -1, strError)) {
135
136 return false;
137 }
138 // Ensure we're safe against blackboard foreign access
139 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
140
141 // Define access context
142 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
143
144 return _pBaseParameter->accessAsBooleanArray(abValues, false, parameterAccessContext);
145}
146
147// Integer Access
148bool CParameterHandle::setAsInteger(uint32_t uiValue, string& strError)
149{
150 // Check operation validity
151 if (!checkAccessValidity(true, 0, strError)) {
152
153 return false;
154 }
155 // Ensure we're safe against blackboard foreign access
156 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
157
158 // When in tuning mode, silently skip the request
159 if (_pParameterMgr->tuningModeOn()) {
160
161 return true;
162 }
163
164 // Define access context
165 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
166
167 return _pBaseParameter->accessAsInteger(uiValue, true, parameterAccessContext);
168}
169
170bool CParameterHandle::getAsInteger(uint32_t& uiValue, string& strError) const
171{
172 // Check operation validity
173 if (!checkAccessValidity(false, 0, strError)) {
174
175 return false;
176 }
177 // Ensure we're safe against blackboard foreign access
178 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
179
180 // Define access context
181 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
182
183 return _pBaseParameter->accessAsInteger(uiValue, false, parameterAccessContext);
184}
185
186bool CParameterHandle::setAsIntegerArray(const vector<uint32_t>& auiValues, string& strError)
187{
188 // Check operation validity
189 if (!checkAccessValidity(true, auiValues.size(), strError)) {
190
191 return false;
192 }
193 // Ensure we're safe against blackboard foreign access
194 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
195
196 // When in tuning mode, silently skip the request
197 if (_pParameterMgr->tuningModeOn()) {
198
199 return true;
200 }
201
202 // Define access context
203 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
204
205 // Copy values for type adaptation
206 vector<uint32_t> auiUserValues = auiValues;
207
208 return _pBaseParameter->accessAsIntegerArray(auiUserValues, true, parameterAccessContext);
209}
210
211bool CParameterHandle::getAsIntegerArray(vector<uint32_t>& auiValues, string& strError) const
212{
213 // Check operation validity
214 if (!checkAccessValidity(false, -1, strError)) {
215
216 return false;
217 }
218 // Ensure we're safe against blackboard foreign access
219 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
220
221 // Define access context
222 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
223
224 return _pBaseParameter->accessAsIntegerArray(auiValues, false, parameterAccessContext);
225}
226
227// Signed Integer Access
228bool CParameterHandle::setAsSignedInteger(int32_t iValue, string& strError)
229{
230 // Check operation validity
231 if (!checkAccessValidity(true, 0, strError)) {
232
233 return false;
234 }
235 // Ensure we're safe against blackboard foreign access
236 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
237
238 // When in tuning mode, silently skip the request
239 if (_pParameterMgr->tuningModeOn()) {
240
241 return true;
242 }
243
244 // Define access context
245 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
246
247 return _pBaseParameter->accessAsSignedInteger(iValue, true, parameterAccessContext);
248}
249
250bool CParameterHandle::getAsSignedInteger(int32_t& iValue, string& strError) const
251{
252 // Check operation validity
253 if (!checkAccessValidity(false, 0, strError)) {
254
255 return false;
256 }
257 // Ensure we're safe against blackboard foreign access
258 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
259
260 // Define access context
261 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
262
263 return _pBaseParameter->accessAsSignedInteger(iValue, false, parameterAccessContext);
264}
265
266bool CParameterHandle::setAsSignedIntegerArray(const vector<int32_t>& aiValues, string& strError)
267{
268 // Check operation validity
269 if (!checkAccessValidity(true, aiValues.size(), strError)) {
270
271 return false;
272 }
273 // Ensure we're safe against blackboard foreign access
274 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
275
276 // When in tuning mode, silently skip the request
277 if (_pParameterMgr->tuningModeOn()) {
278
279 return true;
280 }
281
282 // Define access context
283 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
284
285 // Copy values for type adaptation
286 vector<int32_t> aiUserValues = aiValues;
287
288 return _pBaseParameter->accessAsSignedIntegerArray(aiUserValues, true, parameterAccessContext);
289}
290
291bool CParameterHandle::getAsSignedIntegerArray(vector<int32_t>& aiValues, string& strError) const
292{
293 // Check operation validity
294 if (!checkAccessValidity(false, -1, strError)) {
295
296 return false;
297 }
298 // Ensure we're safe against blackboard foreign access
299 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
300
301 // Define access context
302 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
303
304 return _pBaseParameter->accessAsSignedIntegerArray(aiValues, false, parameterAccessContext);
305}
306
307// Double Access
308bool CParameterHandle::setAsDouble(double dValue, string& strError)
309{
310 // Check operation validity
311 if (!checkAccessValidity(true, 0, strError)) {
312
313 return false;
314 }
315 // Ensure we're safe against blackboard foreign access
316 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
317
318 // When in tuning mode, silently skip the request
319 if (_pParameterMgr->tuningModeOn()) {
320
321 return true;
322 }
323
324 // Define access context
325 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
326
327 return _pBaseParameter->accessAsDouble(dValue, true, parameterAccessContext);
328}
329
330bool CParameterHandle::getAsDouble(double& dValue, string& strError) const
331{
332 // Check operation validity
333 if (!checkAccessValidity(false, 0, strError)) {
334
335 return false;
336 }
337 // Ensure we're safe against blackboard foreign access
338 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
339
340 // Define access context
341 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
342
343 return _pBaseParameter->accessAsDouble(dValue, false, parameterAccessContext);
344}
345
346bool CParameterHandle::setAsDoubleArray(const vector<double>& adValues, string& strError)
347{
348 // Check operation validity
349 if (!checkAccessValidity(true, adValues.size(), strError)) {
350
351 return false;
352 }
353 // Ensure we're safe against blackboard foreign access
354 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
355
356 // When in tuning mode, silently skip the request
357 if (_pParameterMgr->tuningModeOn()) {
358
359 return true;
360 }
361
362 // Define access context
363 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
364
365 // Copy values for type adaptation
366 vector<double> adUserValues = adValues;
367
368 return _pBaseParameter->accessAsDoubleArray(adUserValues, true, parameterAccessContext);
369}
370
371bool CParameterHandle::getAsDoubleArray(vector<double>& adValues, string& strError) const
372{
373 // Check operation validity
374 if (!checkAccessValidity(false, -1, strError)) {
375
376 return false;
377 }
378 // Ensure we're safe against blackboard foreign access
379 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
380
381 // Define access context
382 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
383
384 return _pBaseParameter->accessAsDoubleArray(adValues, false, parameterAccessContext);
385}
386
387// String Access
388bool CParameterHandle::setAsString(const string& strValue, string& strError)
389{
390 // Check operation validity
391 if (!checkAccessValidity(true, 0, strError)) {
392
393 return false;
394 }
395 // Ensure we're safe against blackboard foreign access
396 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
397
398 // When in tuning mode, silently skip the request
399 if (_pParameterMgr->tuningModeOn()) {
400
401 return true;
402 }
403
404 // Define access context
405 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
406
407 // Copy value for type adaptation
408 string strUserValue = strValue;
409
410 return _pBaseParameter->accessAsString(strUserValue, true, parameterAccessContext);
411}
412
413bool CParameterHandle::getAsString(string& strValue, string& strError) const
414{
415 // Check operation validity
416 if (!checkAccessValidity(false, 0, strError)) {
417
418 return false;
419 }
420 // Ensure we're safe against blackboard foreign access
421 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
422
423 // Define access context
424 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
425
426 return _pBaseParameter->accessAsString(strValue, false, parameterAccessContext);
427}
428
429bool CParameterHandle::setAsStringArray(const vector<string>& astrValues, string& strError)
430{
431 // Check operation validity
432 if (!checkAccessValidity(true, astrValues.size(), strError)) {
433
434 return false;
435 }
436 // Ensure we're safe against blackboard foreign access
437 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
438
439 // When in tuning mode, silently skip the request
440 if (_pParameterMgr->tuningModeOn()) {
441
442 return true;
443 }
444
445 // Define access context
446 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
447
448 // Copy values for type adaptation
449 vector<string> astrUserValues = astrValues;
450
451 return _pBaseParameter->accessAsStringArray(astrUserValues, true, parameterAccessContext);
452}
453
454bool CParameterHandle::getAsStringArray(vector<string>& astrValues, string& strError) const
455{
456 // Check operation validity
457 if (!checkAccessValidity(false, -1, strError)) {
458
459 return false;
460 }
461 // Ensure we're safe against blackboard foreign access
462 CAutoLock autoLock(_pParameterMgr->getBlackboardMutex());
463
464 // Define access context
465 CParameterAccessContext parameterAccessContext(strError, _bBigEndianSubsystem, _pParameterMgr->getParameterBlackboard());
466
467 return _pBaseParameter->accessAsStringArray(astrValues, false, parameterAccessContext);
468}
469
470// Access validity
471bool CParameterHandle::checkAccessValidity(bool bSet, uint32_t uiArrayLength, string& strError) const
472{
473 if (bSet && !isRogue()) {
474
475 strError = "Parameter is not rogue: ";
476
477 strError += getPath();
478
479 return false;
480 }
481
482 if (uiArrayLength && !isArray()) {
483
484 strError = "Parameter is scalar: ";
485
486 strError += getPath();
487
488 return false;
489 }
490
491 if (!uiArrayLength && isArray()) {
492
493 strError = "Parameter is an array: ";
494
495 strError += getPath();
496
497 return false;
498 }
499
500 if (bSet && uiArrayLength && (uiArrayLength != getArrayLength())) {
501
502 strError = "Array length mismatch: ";
503
504 strError += getPath();
505
506 return false;
507 }
508
509 return true;
510}