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