Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KWH40
fml40-reference-implementation
Commits
50cfaf48
Commit
50cfaf48
authored
Oct 26, 2020
by
Jiahang Chen
Browse files
fix bug due to access to expiring
parent
f6e29bc2
Pipeline
#348701
passed with stage
in 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ml/thing.py
View file @
50cfaf48
...
...
@@ -125,23 +125,29 @@ def add_user_def(func):
def
__dir_syn
(
self
):
while
True
:
time
.
sleep
(
0.1
)
old_dir_json
=
self
.
dir_json
self
.
to_dir_json
()
if
self
.
dir_json
==
old_dir_json
:
try
:
time
.
sleep
(
0.1
)
old_dir_json
=
self
.
dir_json
self
.
to_dir_json
()
if
self
.
dir_json
==
old_dir_json
:
continue
else
:
self
.
dir
.
updateThingIDBased
(
thingID
=
self
.
thing_id
,
payload
=
self
.
dir_json
)
except
:
continue
else
:
self
.
dir
.
updateThingIDBased
(
thingID
=
self
.
thing_id
,
payload
=
self
.
dir_json
)
def
__repo_syn
(
self
):
while
self
.
__is_repo
:
time
.
sleep
(
0.1
)
old_repo_json
=
self
.
repo_json
self
.
to_repo_json
()
if
self
.
repo_json
==
old_repo_json
:
try
:
time
.
sleep
(
0.1
)
old_repo_json
=
self
.
repo_json
self
.
to_repo_json
()
if
self
.
repo_json
==
old_repo_json
:
continue
else
:
self
.
repo
.
updateThingIDBased
(
thingID
=
self
.
thing_id
,
payload
=
self
.
repo_json
)
except
:
continue
else
:
self
.
repo
.
updateThingIDBased
(
thingID
=
self
.
thing_id
,
payload
=
self
.
repo_json
)
def
__connect_with_idp
(
self
):
print
(
BColors
.
OKBLUE
+
"[S³I][IdP]"
+
BColors
.
ENDC
+
": Connect with S3I-IdentityProvider"
)
...
...
@@ -165,7 +171,6 @@ def __on_token(self, token):
if
self
.
__is_broker
:
self
.
__connect_with_broker
()
def
__connect_with_dir
(
self
):
print
(
BColors
.
OKBLUE
...
...
@@ -223,7 +228,7 @@ def __on_websocket_connection_closed(self):
)
def
sync_with_repo
(
self
,
path
,
topic
):
#TODO
#
TODO
if
not
self
.
__ws_connected
:
return
None
msg
=
{
"topic"
:
topic
,
"path"
:
path
,
"value"
:
self
.
repo_json
[
path
]}
...
...
@@ -237,12 +242,17 @@ def __connect_with_broker(self):
def
receive
():
while
True
:
msg_str
=
self
.
broker
.
receive_once
(
self
.
__endpoint
)
if
msg_str
==
""
:
try
:
time
.
sleep
(
0.1
)
msg_str
=
self
.
broker
.
receive_once
(
self
.
__endpoint
)
if
msg_str
==
""
:
continue
else
:
self
.
__on_broker_callback
(
ch
=
None
,
method
=
None
,
properties
=
None
,
body
=
json
.
loads
(
msg_str
))
except
:
continue
else
:
self
.
__on_broker_callback
(
ch
=
None
,
method
=
None
,
properties
=
None
,
body
=
json
.
loads
(
msg_str
))
threading
.
Thread
(
target
=
receive
).
start
()
...
...
@@ -423,11 +433,8 @@ def on_service_request(self, body_json):
replyingToUUID
=
body_json
.
get
(
"identifier"
,
None
),
msgUUID
=
"s3i:{}"
.
format
(
uuid
.
uuid4
())
)
receiver_eps
=
list
()
for
r
in
service_reply
.
msg
.
get
(
"receivers"
,
None
):
receiver_ep
=
find_broker_endpoint
(
self
.
dir
,
r
)
receiver_eps
.
append
(
receiver_ep
)
self
.
broker
.
send
(
receiver_endpoints
=
receiver_eps
,
msg
=
json
.
dumps
(
service_reply
.
msg
))
self
.
broker
.
send
(
receiver_endpoints
=
[
body_json
.
get
(
"replyToEndpoint"
,
None
)],
msg
=
json
.
dumps
(
service_reply
.
msg
))
def
on_get_value_reply
(
self
,
msg
):
print
(
...
...
@@ -454,7 +461,7 @@ def to_dir_json(self):
if
self
.
policy_id
is
not
None
:
self
.
dir_json
[
"policyId"
]
=
self
.
policy_id
self
.
dir_json
[
"attributes"
][
"class"
]
=
"ml40::Thing"
self
.
dir_json
[
"attributes"
][
"name"
]
=
self
.
name
if
self
.
roles
:
self
.
dir_json
[
"attributes"
][
"roles"
]
=
list
()
...
...
@@ -500,5 +507,3 @@ def to_subthing_json(self):
for
key
in
self
.
features
.
keys
():
json_out
[
"features"
].
append
(
self
.
features
[
key
].
to_json
())
return
json_out
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment