Skip to content

Commit

Permalink
more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jvermillard committed Apr 5, 2023
1 parent 52910a1 commit 38972f4
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions content/english/post/object25.md
Expand Up @@ -72,7 +72,10 @@ So by default, in Leshan, we do nothing. In the user server code, I added a regi
if (response != null && response.isSuccess()) {
LOG.debug("read /25 response: {}", response.getContent());
try {
registerObject25(registration, response, gatewayRegUpdate);
LwM2mObject object25 = (LwM2mObject) response.getContent();
object25.getInstances().forEach((id, objectInstance25) -> {
registerObject25Instance(registration, objectInstance25, gatewayRegUpdate);
});
} catch (RuntimeException e) {
LOG.error("Error while processing object 25 value", e);
}
Expand All @@ -83,20 +86,6 @@ So by default, in Leshan, we do nothing. In the user server code, I added a regi
}
}

private void registerObject25(Registration registration, ReadResponse response, RegistrationUpdate gatewayRegUpdate) {
if (response.getContent() instanceof LwM2mObject) {
LwM2mObject object25 = (LwM2mObject) response.getContent();
object25.getInstances().forEach((id, objectInstance25) -> {
registerObject25Instance(registration, objectInstance25, gatewayRegUpdate);
});
} else if (response.getContent() instanceof LwM2mObjectInstance) {
LwM2mObjectInstance objectInstance25 = (LwM2mObjectInstance) response.getContent();
registerObject25Instance(registration, objectInstance25, gatewayRegUpdate);
} else {
LOG.error("Unknown response content of type: {}", response.getContent().getClass().getName());
}
}

private void registerObject25Instance(Registration registration, LwM2mObjectInstance objectInstance25, RegistrationUpdate gatewayRegUpdate) {
String deviceId = objectInstance25.getResource(0).getValue().toString();
String prefix = objectInstance25.getResource(1).getValue().toString();
Expand Down

0 comments on commit 38972f4

Please sign in to comment.