📄 propman.c
字号:
// This is a sample command type handlerint _sampleCommandHandler(Key_t key, const void *data, int dataLen){ logDEBUG(LOGSRC,"\nExecute command for key 0x%04X ...\n", key); return 0; // bytes used from 'data'}// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// ----------------------------------------------------------------------------// This section implements functions used to access property values from within code./* return maximum index size */Int16 propGetIndexSize(Key_t key){ KeyValue_t *kv = propGetKeyValueEntry(key); return kv? (Int16)kv->maxNdx : -1;}// ----------------------------------------------------------------------------/* get a 32-bit value for the specified KeyValue entry */static utBool _propGetUInt32Value(KeyValue_t *kv, int ndx, UInt32 *val){ if (!val) { // no place to put value return utFalse; } else if ((ndx < 0) || (ndx >= kv->lenNdx)) { // invalid index return utFalse; } else if (KVT_IS_UINT(kv->type)) { KeyData_t *keyDataBuf = _propGetData(kv); UInt16 keyDataSiz = _propGetDataCapacity(kv); if (keyDataSiz >= ((ndx + 1) * sizeof(keyDataBuf->i[0]))) { *val = keyDataBuf->i[ndx]; return utTrue; } else { // insufficient size for index //logWARNING(LOGSRC,"Insufficient size: %d 0x%04X\n", ndx, keyDataSiz); return utFalse; } } else { // unsupported type //logWARNING(LOGSRC,"Unsupported type: 0x%04X\n", kv->type); return utFalse; }}/* set a 32-bit value for the specified KeyValue entry */static utBool _propSetUInt32Value(KeyValue_t *kv, int ndx, UInt32 *val){ if (!val) { // no specified value return utFalse; } else if ((ndx < 0) || (ndx >= kv->maxNdx)) { // invalid index return utFalse; } else if (KVT_IS_UINT(kv->type)) { KeyData_t *keyDataBuf = _propGetData(kv); UInt16 keyDataSiz = _propGetDataCapacity(kv); if (keyDataSiz >= ((ndx + 1) * sizeof(keyDataBuf->i[0]))) { keyDataBuf->i[ndx] = *val; if (kv->lenNdx <= ndx) { kv->lenNdx = ndx + 1; kv->dataSize = kv->lenNdx * KVT_UINT_SIZE(kv->type); } kv->attr |= KVA_NONDEFAULT; kv->attr |= KVA_CHANGED; // set changed return utTrue; } else { // insufficient size return utFalse; } } else { // unsupported type return utFalse; }}/* get a 32-bit value for the specified key at the specified index */UInt32 propGetUInt32AtIndex(Key_t key, int ndx, UInt32 dft){ KeyValue_t *kv = propGetKeyValueEntry(key); if (!kv) { return dft; } else { UInt32 val32 = dft; PROP_LOCK { _propRefresh(PROP_REFRESH_GET, kv, (UInt8*)0, 0); // no args if (kv->lenNdx < (ndx + 1)) { val32 = dft; } else { UInt32 v; utBool ok = _propGetUInt32Value(kv, ndx, &v); val32 = ok? v : dft; } } PROP_UNLOCK return val32; }}/* set a 32-bit value for the specified key at the specified index */utBool propSetUInt32AtIndex(Key_t key, int ndx, UInt32 val){ return propSetUInt32AtIndexRefresh(key, ndx, val, utTrue);}/* set a 32-bit value for the specified key at the specified index */utBool propSetUInt32AtIndexRefresh(Key_t key, int ndx, UInt32 val, utBool refresh){ KeyValue_t *kv = propGetKeyValueEntry(key); if (kv) { if (kv->maxNdx < (ndx + 1)) { return utFalse; } else { utBool ok; PROP_LOCK { ok = _propSetUInt32Value(kv, ndx, &val); if (ok && refresh) { _propRefresh(PROP_REFRESH_SET, kv, (UInt8*)0, 0); } } PROP_UNLOCK return ok; } } else { return utFalse; }}/* add a 32-bit value to the specified key at the specified index */utBool propAddUInt32AtIndex(Key_t key, int ndx, UInt32 *val){ KeyValue_t *kv = propGetKeyValueEntry(key); if (!kv) { return utFalse; } else { utBool ok = utFalse; PROP_LOCK { _propRefresh(PROP_REFRESH_GET, kv, (UInt8*)0, 0); // no args if (kv->lenNdx < (ndx + 1)) { // index is beyond available entries ok = utFalse; } else { UInt32 oldVal; utBool ok = _propGetUInt32Value(kv, ndx, &oldVal); if (ok) { *val += oldVal; ok = _propSetUInt32Value(kv, ndx, val); if (ok) { _propRefresh(PROP_REFRESH_SET, kv, (UInt8*)0, 0); } } else { ok = utFalse; } } } PROP_UNLOCK return ok; }}/* get a 32-bit value for the specified key */UInt32 propGetUInt32(Key_t key, UInt32 dft){ return propGetUInt32AtIndex(key, 0, dft);}/* set a 32-bit value for the specified key */utBool propSetUInt32(Key_t key, UInt32 val){ return propSetUInt32AtIndexRefresh(key, 0, val, utTrue);}/* set a 32-bit value for the specified key */utBool propSetUInt32Refresh(Key_t key, UInt32 val, utBool refresh){ return propSetUInt32AtIndexRefresh(key, 0, val, refresh);}/* add a 32-bit value to the specified key */utBool propAddUInt32(Key_t key, UInt32 val){ return propAddUInt32AtIndex(key, 0, &val);}// ----------------------------------------------------------------------------/* get a boolean value for the specified key at the specified index */utBool propGetBooleanAtIndex(Key_t key, int ndx, utBool dft){ return propGetUInt32AtIndex(key, ndx, (UInt32)dft)? utTrue : utFalse;}/* set a boolean value for the specified key at the specified index */utBool propSetBooleanAtIndex(Key_t key, int ndx, utBool val){ return propSetUInt32AtIndexRefresh(key, ndx, (UInt32)val, utTrue);}/* get a boolean value for the specified key */utBool propGetBoolean(Key_t key, utBool dft){ return propGetBooleanAtIndex(key, 0, dft);}/* set a boolean value for the specified key */utBool propSetBoolean(Key_t key, utBool val){ return propSetBooleanAtIndex(key, 0, val);}// ----------------------------------------------------------------------------/* get a double value for the KeyValue entry at the specified index */static utBool _propGetDoubleValue(KeyValue_t *kv, int ndx, double *val){ if (kv) { UInt32 uval; utBool ok = _propGetUInt32Value(kv, ndx, &uval); if (ok) { if (KVT_IS_SIGNED(kv->type)) { *val = UInt32_to_Double((Int32)uval, kv->type); } else { *val = UInt32_to_Double(uval, kv->type); } return utTrue; } else { return utFalse; } } else { return utFalse; }}/* set a double value for the KeyValue entry at the specified index */static utBool _propSetDoubleValue(KeyValue_t *kv, int ndx, double *val){ UInt32 uval = Double_to_UInt32(*val, kv->type); return _propSetUInt32Value(kv, ndx, &uval);}/* get a double value for the specified key at the specified index */double propGetDoubleAtIndex(Key_t key, int ndx, double dft){ KeyValue_t *kv = propGetKeyValueEntry(key); if (!kv) { return dft; } else { double valDbl = dft; PROP_LOCK { _propRefresh(PROP_REFRESH_GET, kv, (UInt8*)0, 0); // no args if (kv->lenNdx < (ndx + 1)) { valDbl = dft; } else { double v; utBool ok = _propGetDoubleValue(kv, ndx, &v); valDbl = ok? v : dft; } } PROP_UNLOCK return valDbl; }}/* set a double value for the specified key at the specified index */utBool propSetDoubleAtIndex(Key_t key, int ndx, double val){ KeyValue_t *kv = propGetKeyValueEntry(key); if (kv) { if (kv->maxNdx < (ndx + 1)) { return utFalse; } else { utBool ok = utFalse; PROP_LOCK { ok = _propSetDoubleValue(kv, ndx, &val); if (ok) { _propRefresh(PROP_REFRESH_SET, kv, (UInt8*)0, 0); } } PROP_UNLOCK return ok; } } return utFalse;}/* add a double value to the specified key at the specified index */utBool propAddDoubleAtIndex(Key_t key, int ndx, double *val){ KeyValue_t *kv = propGetKeyValueEntry(key); if (!kv) { return utFalse; } else { utBool ok = utFalse; PROP_LOCK { _propRefresh(PROP_REFRESH_GET, kv, (UInt8*)0, 0); // no args if (kv->lenNdx < (ndx + 1)) { ok = utFalse; } else { double oldVal; utBool ok = _propGetDoubleValue(kv, ndx, &oldVal); if (ok) { *val += oldVal; ok = _propSetDoubleValue(kv, ndx, val); if (ok) { _propRefresh(PROP_REFRESH_SET, kv, (UInt8*)0, 0); } } else { ok = utFalse; } } } PROP_UNLOCK return ok; }}/* get a double value for the specified key */double propGetDouble(Key_t key, double dft)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -