BroadbandForum / obuspa

OB-USP-AGENT is a system daemon providing a User Services Platform (USP) Agent. https://github.com/BroadbandForum/obuspa/wiki
BSD 3-Clause "New" or "Revised" License
93 stars 62 forks source link

A question about USP_REGISTER_Object_RefreshInstances #74

Closed wildmeng closed 1 year ago

wildmeng commented 1 year ago

Hi, I am tying to implement the event for the ObjectCreation and ObjectDeletion, it seems a periodic schedued task is need to check for read-only mulit-instance object and compare to the pre-existing instances. and I found following desciption in the Quick-Start Guide:

Refreshing Object Instances Changes to object instances are normally signalled using the USP_SIGNAL_ObjectAdded() and USP_SIGNAL_ObjectDeleted() functions. However, for some data model objects, these events can only be determined by periodically polling the object's instances. This is wasteful to perform continuously, as the object instances are only required when forming a USP response. Use USP_REGISTER_Object_RefreshInstances() to register an object instance query function which is called on demand.

According to the description, it looks lik the USP_SIGNAL_ObjectAdded and USP_SIGNAL_ObjectDeleted can be avoided through the USP_REGISTER_Object_RefreshInstances , but it seems to me the USP_REGISTER_Object_RefreshInstances doesn't send any event.

Much appriciated if you can help clarify!

Thanks!

holme-r commented 1 year ago

Firstly for any event to be sent, the USP Controller must have setup a subscription for that event in Device.LocalAgent.Subscription. This is the most common cause of not getting an event.

USP_REGISTER_Object_RefreshInstances() can be used to register a callback that is called when the instance cache needs to be refreshed for the object. It can only be used for a top level object (ie one immediately below Device.). The callback must call USP_DM_RefreshInstance() once for each instance in the top level object and any child objects. If a subscription has been set up for object added/deleted, then the callback will be called periodically, and if the set of instances registered by calling USP_DM_RefreshInstance() have changed, then OBUSPA will detect this, and send an event.

wildmeng commented 1 year ago

ah, understood! so, if USP_DM_RefreshInstance is called in callback for USP_REGISTER_Object_RefreshInstances, then the events would be sent later by the obuspa.

but this brings up another issue: the event can not be sent in time, for example, I noticed that the ValueChange event is processed in a periodic timer every 30 seconds by default, our customer complained that it's too long.

wouldn't be better to provide the APIs to send the ValueChanged event by the upper application module itself?

holme-r commented 1 year ago

Call USP_SIGNAL_ObjectAdded() and USP_SIGNAL_ObjectDeleted() if you want the event to be sent immediately. But if you can only generate these events by polling the instances then it doesn't make sense to poll too frequently as it uses too much CPU. If you still want to poll more frequently, then VALUE_CHANGE_POLL_PERIOD in vendor_defs.h can be made smaller.

wildmeng commented 1 year ago

thanks for your answer: still two questions: 1, if the USP_SIGNAL_ObjectAdded is also called, would a duplicated event sent later by the poll process? 2, Is there API to send the ValueChange event immediately?

holme-r commented 1 year ago
  1. You can use either USP_SIGNAL_ObjectAdded or the refresh instances mechanism. You can't use both. If you do, I suspect that a duplicate event would be sent.
  2. The USP_SIGNAL_ObjectAdded() call sends the ObjectCreation notification almost immediately. It posts a message onto the data model thread's queue which after processing, results in the notification being sent.
wildmeng commented 1 year ago

no way to send ValueChange event immediately ? maybe the poll machasim is mainly for read-only parameters, however, for writable parameters, it's possible to send event immediately when it's set?

holme-r commented 1 year ago

Unfortunately OBUSPA does not yet support a subscribe/notify mechanism for value change notifications. This would be mainly useful for parameters stored in a database or, as you say, parameters that have been written by a controller via OBUSPA.

holme-r commented 1 year ago

Closing this issue, as queries have been answered and there has been no further activity on this ticket for a month. Please re-open if there are any continuation queries.