Skip to content

Commit 1e77663

Browse files
rlubosfabiobaltieri
authored andcommitted
net: lwm2m: Optimize value attributes verification
As lwm2m_notify_observer_path() now reads attributes for the updated resource, value_conditions_satisfied() does not need to read the attributes again, it can just reuse the already available data. Signed-off-by: Robert Lubos <[email protected]>
1 parent b633f3a commit 1e77663

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

subsys/net/lib/lwm2m/lwm2m_observation.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,9 @@ static int resource_value_as_double(const struct lwm2m_obj_path *path,
550550
}
551551

552552
static bool value_conditions_satisfied(const struct lwm2m_obj_path *path,
553-
uint16_t srv_obj_inst)
553+
struct notification_attrs *attrs)
554554
{
555555
struct lwm2m_notify_value_register *last_notified;
556-
struct notification_attrs attrs = { 0 };
557556
double res_value, old_value;
558557
void *ref;
559558
int ret;
@@ -563,15 +562,10 @@ static bool value_conditions_satisfied(const struct lwm2m_obj_path *path,
563562
return true;
564563
}
565564

566-
ret = engine_observe_get_attributes(path, &attrs, srv_obj_inst);
567-
if (ret < 0) {
568-
return true;
569-
}
570-
571565
/* Check if any of the value attributes is actually set. */
572-
if ((attrs.flags & (BIT(LWM2M_ATTR_GT) |
573-
BIT(LWM2M_ATTR_LT) |
574-
BIT(LWM2M_ATTR_STEP))) == 0) {
566+
if ((attrs->flags & (BIT(LWM2M_ATTR_GT) |
567+
BIT(LWM2M_ATTR_LT) |
568+
BIT(LWM2M_ATTR_STEP))) == 0) {
575569
return true;
576570
}
577571

@@ -603,25 +597,25 @@ static bool value_conditions_satisfied(const struct lwm2m_obj_path *path,
603597
return true;
604598
}
605599

606-
if ((attrs.flags & BIT(LWM2M_ATTR_STEP)) != 0) {
600+
if ((attrs->flags & BIT(LWM2M_ATTR_STEP)) != 0) {
607601
double res_diff = old_value > res_value ?
608602
old_value - res_value : res_value - old_value;
609603

610-
if (res_diff >= attrs.st) {
604+
if (res_diff >= attrs->st) {
611605
return true;
612606
}
613607
}
614608

615-
if ((attrs.flags & BIT(LWM2M_ATTR_GT)) != 0) {
616-
if ((old_value <= attrs.gt && res_value > attrs.gt) ||
617-
(old_value >= attrs.gt && res_value < attrs.gt)) {
609+
if ((attrs->flags & BIT(LWM2M_ATTR_GT)) != 0) {
610+
if ((old_value <= attrs->gt && res_value > attrs->gt) ||
611+
(old_value >= attrs->gt && res_value < attrs->gt)) {
618612
return true;
619613
}
620614
}
621615

622-
if ((attrs.flags & BIT(LWM2M_ATTR_LT)) != 0) {
623-
if ((old_value <= attrs.lt && res_value > attrs.lt) ||
624-
(old_value >= attrs.lt && res_value < attrs.lt)) {
616+
if ((attrs->flags & BIT(LWM2M_ATTR_LT)) != 0) {
617+
if ((old_value <= attrs->lt && res_value > attrs->lt) ||
618+
(old_value >= attrs->lt && res_value < attrs->lt)) {
625619
return true;
626620
}
627621
}
@@ -661,7 +655,7 @@ int lwm2m_notify_observer_path(const struct lwm2m_obj_path *path)
661655
return ret;
662656
}
663657

664-
if (!value_conditions_satisfied(path, sock_ctx[i]->srv_obj_inst)) {
658+
if (!value_conditions_satisfied(path, &res_attrs)) {
665659
continue;
666660
}
667661

0 commit comments

Comments
 (0)