ExCEP.Gateway.SubscriptionManager (ex_cep v0.1.1)

Copy Markdown

Data Subscription rule engine per CSG CEP TS2.2 Section 8.7 & 8.8.

Implements the exact precedence rules:

  1. Model-level subscription (AllDev == "1"): applies to all devices of that model (both existing and newly onboarded), overwriting prior subscriptions for that {model, service_id}.
  2. Device-level subscription (AllDev == "0"): applies only to the listed DeviceList, overwriting prior subscriptions for each {model, service_id, device_id}.

Summary

Functions

Applies a DataSubs Subs list and returns {updated_manager, resp_subs_list}.

Handles GetDataSubs queries and returns the Subs array for GetDataSubsResp.

Resolves the effective subscription rule for {model, service_id, device_id}.

Returns true if a spontaneous change for data_refer should be uploaded.

Types

rule()

@type rule() :: %{
  model: String.t(),
  service_id: String.t(),
  spont?: boolean(),
  period_sec: non_neg_integer(),
  all_data?: boolean(),
  data_list: [String.t()]
}

t()

@type t() :: %ExCEP.Gateway.SubscriptionManager{
  device_rules: %{required({String.t(), String.t(), String.t()}) => rule()},
  model_rules: %{required({String.t(), String.t()}) => rule()}
}

Functions

apply_subscriptions(mgr, subs_list)

@spec apply_subscriptions(t(), term()) :: {t(), [map()]}

Applies a DataSubs Subs list and returns {updated_manager, resp_subs_list}.

new()

@spec new() :: t()

query_subscriptions(mgr, query_subs)

@spec query_subscriptions(t(), [map()]) :: [map()]

Handles GetDataSubs queries and returns the Subs array for GetDataSubsResp.

resolve(mgr, model, service_id, device_id)

@spec resolve(t(), String.t(), String.t(), String.t()) :: rule() | nil

Resolves the effective subscription rule for {model, service_id, device_id}.

should_report_spont?(mgr, model, service_id, device_id, data_refer)

@spec should_report_spont?(t(), String.t(), String.t(), String.t(), String.t()) ::
  boolean()

Returns true if a spontaneous change for data_refer should be uploaded.