Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.eclipse.leshan.server.endpoint.EffectiveEndpointUriProvider;
import org.eclipse.leshan.server.observation.LwM2mNotificationReceiver;
import org.eclipse.leshan.server.profile.ClientProfile;
import org.eclipse.leshan.server.registration.DeviceRegistration;
import org.eclipse.leshan.server.registration.Registration;
import org.eclipse.leshan.server.registration.RegistrationStore;
import org.eclipse.leshan.transport.californium.ObserveUtil;
Expand Down Expand Up @@ -185,7 +186,7 @@ public void remove_observation() {
}

private void givenASimpleRegistration(Long lifetime) {
Registration.Builder builder = new Registration.Builder(registrationId, ep,
DeviceRegistration.Builder builder = new DeviceRegistration.Builder(registrationId, ep,
new IpPeer(new InetSocketAddress(address, port)), uriHandler.createUri("coap://localhost:5683"));

registration = builder.lifeTimeInSec(lifetime).smsNumber(sms).bindingMode(binding).objectLinks(objectLinks)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright (c) 2026 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.link;

import java.util.Arrays;

import org.eclipse.leshan.core.util.StringUtils;

public final class LinkUtil {

Check warning on line 22 in leshan-lwm2m-core/src/main/java/org/eclipse/leshan/core/link/LinkUtil.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=eclipse-leshan_leshan&issues=AZ3-RdwBU26C77mOPDy1&open=AZ3-RdwBU26C77mOPDy1&pullRequest=1750

@SuppressWarnings({ "java:S3776", "java:S1168" })
public static Link[] sort(Link[] linksToSort) {
// sort the list of objects
if (linksToSort == null) {
return null;
}

Link[] res = Arrays.copyOf(linksToSort, linksToSort.length);

Arrays.sort(res, (o1, o2) -> {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return 1;
// by URL
String[] url1 = o1.getUriReference().split("/");
String[] url2 = o2.getUriReference().split("/");

for (int i = 0; i < url1.length && i < url2.length; i++) {
// is it two numbers?
if (isNumber(url1[i]) && isNumber(url2[i])) {
int cmp = Integer.parseInt(url1[i]) - Integer.parseInt(url2[i]);
if (cmp != 0) {
return cmp;
}
} else {

int v = url1[i].compareTo(url2[i]);

if (v != 0) {
return v;
}
}
}

return url1.length - url2.length;
});

return res;
}

private static boolean isNumber(String s) {
return !StringUtils.isEmpty(s) && StringUtils.isNumeric(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.request.BindingMode;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.server.registration.DeviceRegistration;
import org.eclipse.leshan.server.registration.Registration;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -180,8 +181,8 @@ public Registration deserialize(JsonNode jObj) {
jObj.get("epUri").asText(), jObj.get("regId").asText(), jObj.get("ep").asText()));
}

Registration.Builder b = new Registration.Builder(jObj.get("regId").asText(), jObj.get("ep").asText(),
peerSerDes.deserialize(jObj.get("transportdata")), endpointUri);
DeviceRegistration.Builder b = new DeviceRegistration.Builder(jObj.get("regId").asText(),
jObj.get("ep").asText(), peerSerDes.deserialize(jObj.get("transportdata")), endpointUri);

b.bindingMode(BindingMode.parse(jObj.get("bnd").asText()));
if (jObj.get("qm") != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.leshan.core.peer.IpPeer;
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.server.registration.DefaultRegistrationDataExtractor;
import org.eclipse.leshan.server.registration.DeviceRegistration;
import org.eclipse.leshan.server.registration.Registration;
import org.eclipse.leshan.server.registration.RegistrationDataExtractor.RegistrationData;
import org.junit.jupiter.api.Test;
Expand All @@ -56,7 +57,7 @@ void ser_and_des_are_equals() {
objs[0] = new Link("/0/1024/2", attrs);
objs[1] = new Link("/0/2");

Registration.Builder builder = new Registration.Builder("registrationId", "endpoint",
DeviceRegistration.Builder builder = new DeviceRegistration.Builder("registrationId", "endpoint",
new IpPeer(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 1)),
uriHandler.createUri("coap://localhost:5683")).objectLinks(objs).rootPath("/")
.supportedContentFormats(ContentFormat.TLV, ContentFormat.TEXT);
Expand Down Expand Up @@ -94,7 +95,7 @@ void ser_and_des_are_equals_with_app_data() {
appData.put("string", "string test");
appData.put("null", null);

Registration.Builder builder = new Registration.Builder("registrationId", "endpoint",
DeviceRegistration.Builder builder = new DeviceRegistration.Builder("registrationId", "endpoint",
new IpPeer(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 1)),
uriHandler.createUri("coap://localhost:5683")).objectLinks(objs).rootPath("/")
.supportedContentFormats(ContentFormat.TLV, ContentFormat.TEXT).customRegistrationData(appData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.eclipse.leshan.core.observation.Observation;

Expand All @@ -25,16 +26,28 @@
*
* @see RegistrationStore
*/
public class Deregistration {
final Registration registration;
final Collection<Observation> observations;
public class Deregistration implements RegistrationModification {
private final Registration registration;
private final Collection<Observation> observations;
private final List<Deregistration> childrenDeregistration;

public Deregistration(Registration registration, Collection<Observation> observations) {
this(registration, observations, null);
}

public Deregistration(Registration registration, Collection<Observation> observations,
List<Deregistration> childrenDeregistration) {
this.registration = registration;
if (observations == null)
if (observations == null) {
this.observations = Collections.emptyList();
else
} else {
this.observations = observations;
}
if (childrenDeregistration == null) {
this.childrenDeregistration = Collections.emptyList();
} else {
this.childrenDeregistration = childrenDeregistration;
}
}

public Registration getRegistration() {
Expand All @@ -44,4 +57,11 @@ public Registration getRegistration() {
public Collection<Observation> getObservations() {
return observations;
}

/**
* if {@link #getRegistration()} is a gateway then return all de-registration about its children.
*/
public List<Deregistration> getChildrenDeRegistration() {
return childrenDeregistration;
}
}
Loading
Loading