8 import comm.datalayer.NotifyInfo
9 import comm.datalayer.SubscriptionProperties
13 from ctrlxdatalayer.clib_variant
import C_DLR_VARIANT
17 class NotifyType(enum.Enum):
32 __slots__ = [
'__data',
'__info']
34 def __init__(self, data: C_DLR_VARIANT, info: C_DLR_VARIANT):
36 @param[in] data of the notify item
37 @param[in] containing notify_info.fbs
41 if i.get_type() != VariantType.FLATBUFFERS:
43 b = i.get_flatbuffers()
44 self.
__info__info = comm.datalayer.NotifyInfo.NotifyInfo.GetRootAsNotifyInfo(
49 data of the notify item
61 return self.
__info__info.Node().decode(
"utf-8")
71 def get_timestamp(self) -> int:
73 uint64; // Filetime: Contains a 64-bit value representing the number of
74 100-nanosecond intervals since January 1, 1601 (UTC).
78 return self.
__info__info.Timestamp()
83 EPOCH_AS_FILETIME = 116444736000000000
84 HUNDREDS_OF_NANOSECONDS = 10000000
87 def to_datetime(filetime: int) -> datetime.datetime:
88 """Converts a Microsoft filetime number to a Python datetime. The new
89 datetime object is time zone-naive but is equivalent to tzinfo=utc.
90 >>> filetime_to_dt(116444736000000000)
91 datetime.datetime(1970, 1, 1, 0, 0)
92 >>> filetime_to_dt(128930364000000000)
93 datetime.datetime(2009, 7, 25, 23, 0)
95 return datetime.datetime.fromtimestamp(
96 (filetime - EPOCH_AS_FILETIME) / HUNDREDS_OF_NANOSECONDS, tz=datetime.timezone.utc)
99 ResponseNotifyCallback = typing.Callable[[
100 Result, typing.List[NotifyItem], ctrlxdatalayer.clib.userData_c_void_p],
None]
102 ResponseNotifyCallback
103 This callback delivers a vector with the updated nodes of a subscription.
104 It is usually called in the interval given by the publishInterval
105 which has been set by the creation of the subscription.
106 The callback may not contain all nodes of the subscription.I.e.when a node did not change.
107 The callback may contain a node multiple times.I.e.when the node did
108 change multiple times since the last callback.
109 The sorting order of the items in the vector is undefined.
110 @param[in] status Notify status
111 @param[in] items Notify data
112 @param[in] userdata Same userdata as in create subscription given
113 Result != OK the list of NotifyItem is None
130 notification of the close
135 def create_properties(ident: str, publish_interval: int = 1000,
136 keepalive_interval: int = 60000, error_interval: int = 10000) -> Variant:
139 @returns <Variant> Variant that describe ruleset of subscription
141 builder = flatbuffers.Builder(1024)
143 idl = builder.CreateString(ident)
144 comm.datalayer.SubscriptionProperties.SubscriptionPropertiesStart(
146 comm.datalayer.SubscriptionProperties.SubscriptionPropertiesAddId(
148 comm.datalayer.SubscriptionProperties.SubscriptionPropertiesAddPublishInterval(
149 builder, publish_interval)
150 comm.datalayer.SubscriptionProperties.SubscriptionPropertiesAddKeepaliveInterval(
151 builder, keepalive_interval)
152 comm.datalayer.SubscriptionProperties.SubscriptionPropertiesAddErrorInterval(
153 builder, error_interval)
154 prop = comm.datalayer.SubscriptionProperties.SubscriptionPropertiesEnd(
158 v.set_flatbuffers(builder.Output())
162 def get_id(prop: Variant) -> str:
164 if prop.get_type() != VariantType.FLATBUFFERS:
166 b = prop.get_flatbuffers()
167 p = comm.datalayer.SubscriptionProperties.SubscriptionProperties.GetRootAsSubscriptionProperties(
169 return p.Id().decode(
"utf-8")
str get_address(self)
Node address.
NotifyType get_type(self)
Notify type.
def __init__(self, C_DLR_VARIANT data, C_DLR_VARIANT info)
Variant get_data(self)
data of the notify item
str id(self)
Subscription ID.
def on_close(self)
notification of the close