Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 53a53f9

Browse files
committed
Add option to pack events from eventlist in NotifyRequest before trait data
properties from datalist.
1 parent 6a32d64 commit 53a53f9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/lib/core/WeaveConfig.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,25 @@
23552355
#define WEAVE_CONFIG_MAX_SOFTWARE_VERSION_LENGTH 32
23562356
#endif // WEAVE_CONFIG_MAX_SOFTWARE_VERSION_LENGTH
23572357

2358+
/**
2359+
* @def WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
2360+
*
2361+
* @brief
2362+
* Enable offloading of events before trait properties
2363+
*
2364+
* When this option is enabled, WeaveDataManagement will first
2365+
* attempt to pack events from the eventlist into the NotifyRequest
2366+
* message before adding modified trait data properties from
2367+
* the datalist.
2368+
*
2369+
* This feature can be useful in systems that might need
2370+
* the events to be dispatched as early as possible.
2371+
*
2372+
*/
2373+
#ifndef WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
2374+
#define WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST 0
2375+
#endif // WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
2376+
23582377
/**
23592378
* @def WEAVE_NON_PRODUCTION_MARKER
23602379
*

src/lib/profiles/data-management/Current/NotificationEngine.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,18 @@ WEAVE_ERROR NotificationEngine::BuildSingleNotifyRequestDataList(SubscriptionHan
14211421

14221422
// Ensure we're in the DataList element. May allocate memory.
14231423
err = aNotifyRequest.MoveToState(kNotifyRequestBuilder_BuildDataList);
1424+
1425+
#if WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
1426+
// if we did not have enough space for data list at all,
1427+
// squash the error and exit immediately. This check is necessary here
1428+
// when we are loading from the datalist after having loaded the event
1429+
// list into the buffer already.
1430+
if ((err == WEAVE_ERROR_NO_MEMORY) || (err == WEAVE_ERROR_BUFFER_TOO_SMALL))
1431+
{
1432+
err = WEAVE_NO_ERROR;
1433+
ExitNow();
1434+
}
1435+
#endif // WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
14241436
SuccessOrExit(err);
14251437

14261438
// Make a back-up of the writer so that we can rewind back if the next retrieval fails due to the packet getting full.
@@ -1550,6 +1562,20 @@ WEAVE_ERROR NotificationEngine::BuildSingleNotifyRequest(SubscriptionHandler * a
15501562
// Fill in the DataList. Allocation may take place
15511563
subClean = true;
15521564

1565+
#if WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
1566+
1567+
#if WEAVE_CONFIG_EVENT_LOGGING_WDM_OFFLOAD
1568+
// Fill in the EventList. Allocation may take place
1569+
err = BuildSingleNotifyRequestEventList(aSubHandler, notifyRequest, subClean, neWriteInProgress);
1570+
SuccessOrExit(err);
1571+
#endif
1572+
1573+
aIsSubscriptionClean &= subClean;
1574+
subClean = true;
1575+
1576+
err = BuildSingleNotifyRequestDataList(aSubHandler, notifyRequest, subClean, neWriteInProgress);
1577+
SuccessOrExit(err);
1578+
#else
15531579
err = BuildSingleNotifyRequestDataList(aSubHandler, notifyRequest, subClean, neWriteInProgress);
15541580
SuccessOrExit(err);
15551581

@@ -1561,6 +1587,7 @@ WEAVE_ERROR NotificationEngine::BuildSingleNotifyRequest(SubscriptionHandler * a
15611587
err = BuildSingleNotifyRequestEventList(aSubHandler, notifyRequest, subClean, neWriteInProgress);
15621588
SuccessOrExit(err);
15631589
#endif
1590+
#endif // WEAVE_CONFIG_ENABLE_OFFLOAD_EVENTS_FIRST
15641591

15651592
aIsSubscriptionClean &= subClean;
15661593

0 commit comments

Comments
 (0)