Skip to content

Commit 47f5b85

Browse files
committed
Enable more flexibility when processing updates to boolean-typed properties.
1 parent 2445761 commit 47f5b85

3 files changed

Lines changed: 39 additions & 16 deletions

File tree

src/map.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,27 +2002,47 @@ int mpr_map_set_from_msg(mpr_map m, mpr_msg msg)
20022002
break;
20032003
}
20042004
case MPR_PROP_USE_INST: {
2005-
int use_inst;
2006-
if (types[0] == 's') {
2007-
const char *str = &(vals[0])->s;
2008-
if (!strchr("TFtf", str[0]))
2005+
int use_inst = -1;
2006+
switch (types[0]) {
2007+
case MPR_STR: {
2008+
const char *str = &(vals[0])->s;
2009+
if (!strchr("TFtf", str[0]))
2010+
break;
2011+
if (strlen(str) == 1)
2012+
use_inst = str[0] == 'T' || str[0] == 't';
2013+
else if (strcmp(str + 1, "rue") == 0)
2014+
use_inst = 1;
2015+
else if (strcmp(str + 1, "alse") == 0)
2016+
use_inst = 0;
2017+
else
2018+
break;
20092019
break;
2010-
if (strlen(str) == 1)
2011-
use_inst = str[0] == 'T' || str[0] == 't';
2012-
else if (strcmp(str + 1, "rue") == 0)
2020+
}
2021+
case MPR_INT32:
2022+
use_inst = 0 != (vals[0])->i32;
2023+
break;
2024+
case MPR_FLT:
2025+
use_inst = 0.f != (vals[0])->f;
2026+
break;
2027+
case MPR_DBL:
2028+
use_inst = 0. != (vals[0])->d;
2029+
break;
2030+
case 'T':
20132031
use_inst = 1;
2014-
else if (strcmp(str + 1, "alse") == 0)
2032+
break;
2033+
case 'F':
20152034
use_inst = 0;
2016-
else
2035+
break;
2036+
default:
20172037
break;
20182038
}
2019-
else
2020-
use_inst = types[0] == 'T';
20212039
if (m->obj.is_local && m->use_inst && !use_inst) {
20222040
/* TODO: release map instances */
20232041
}
2024-
updated += mpr_tbl_add_record(tbl, MPR_PROP_USE_INST, NULL, 1, MPR_BOOL,
2025-
&use_inst, MPR_TBL_MOD_REM);
2042+
if (use_inst >= 0) {
2043+
updated += mpr_tbl_add_record(tbl, MPR_PROP_USE_INST, NULL, 1, MPR_BOOL,
2044+
&use_inst, MPR_TBL_MOD_REM);
2045+
}
20262046
break;
20272047
}
20282048
case MPR_PROP_EXTRA: {

src/mpr_type.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ MPR_INLINE static int mpr_type_get_is_num(mpr_type type)
4040
case MPR_INT32:
4141
case MPR_FLT:
4242
case MPR_DBL:
43+
case MPR_BOOL:
44+
case 'T':
45+
case 'F':
4346
return 1;
4447
default: return 0;
4548
}

src/property.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const static_prop_t static_props[] = {
2525
{ "@data", 1, 0 }, /* MPR_PROP_DATA */
2626
{ "@device", 1, MPR_STR }, /* MPR_PROP_DEVICE */
2727
{ "@direction", 1, MPR_STR }, /* MPR_PROP_DIR */
28-
{ "@ephemeral", 1, MPR_BOOL }, /* MPR_PROP_EPHEM */
28+
{ "@ephemeral", 1, 'n' }, /* MPR_PROP_EPHEM */
2929
{ "@expr", 1, MPR_STR }, /* MPR_PROP_EXPR */
3030
{ "@host", 1, MPR_STR }, /* MPR_PROP_HOST */
3131
{ "@id", 1, MPR_INT64 }, /* MPR_PROP_ID */
@@ -36,7 +36,7 @@ const static_prop_t static_props[] = {
3636
{ "@linked", 0, MPR_STR }, /* MPR_PROP_LINKED */
3737
{ "@max", 0, 'n' }, /* MPR_PROP_MAX */
3838
{ "@min", 0, 'n' }, /* MPR_PROP_MIN */
39-
{ "@muted", 1, MPR_BOOL }, /* MPR_PROP_MUTED */
39+
{ "@muted", 1, 'n' }, /* MPR_PROP_MUTED */
4040
{ "@name", 1, MPR_STR }, /* MPR_PROP_NAME */
4141
{ "@num_inst", 1, MPR_INT32 }, /* MPR_PROP_NUM_INST */
4242
{ "@num_maps", 2, MPR_INT32 }, /* MPR_PROP_NUM_MAPS */
@@ -57,7 +57,7 @@ const static_prop_t static_props[] = {
5757
{ "@synced", 1, MPR_TIME }, /* MPR_PROP_SYNCED */
5858
{ "@type", 1, MPR_TYPE }, /* MPR_PROP_TYPE */
5959
{ "@unit", 1, MPR_STR }, /* MPR_PROP_UNIT */
60-
{ "@use_inst", 1, MPR_BOOL }, /* MPR_PROP_USE_INST */
60+
{ "@use_inst", 1, 'n' }, /* MPR_PROP_USE_INST */
6161
{ "@version", 1, MPR_INT32 }, /* MPR_PROP_VERSION */
6262
{ "@extra", 0, 'a' }, /* MPR_PROP_EXTRA (special case, does not
6363
* represent a specific property name) */

0 commit comments

Comments
 (0)