Skip to content

Commit

Permalink
add ServerIdentity to read/write/execute/observe/create for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Feb 4, 2019
1 parent 1b1d9f7 commit 953ccd5
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.TimeZone;

import org.eclipse.leshan.client.request.ServerIdentity;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
import org.eclipse.leshan.client.resource.LwM2mInstanceEnabler;
import org.eclipse.leshan.core.model.ObjectModel;
Expand Down Expand Up @@ -56,7 +57,7 @@ public Device(String manufacturer, String modelNumber, String serialNumber, Stri
}

@Override
public ReadResponse read(int resourceid) {
public ReadResponse read(ServerIdentity identity, int resourceid) {

switch (resourceid) {
case 0: // manufacturer
Expand All @@ -81,12 +82,12 @@ public ReadResponse read(int resourceid) {
return ReadResponse.success(resourceid, supportedBinding);

default:
return super.read(resourceid);
return super.read(identity, resourceid);
}
}

@Override
public WriteResponse write(int resourceid, LwM2mResource value) {
public WriteResponse write(ServerIdentity identity, int resourceid, LwM2mResource value) {

switch (resourceid) {

Expand All @@ -101,17 +102,17 @@ public WriteResponse write(int resourceid, LwM2mResource value) {
return WriteResponse.success();

default:
return super.write(resourceid, value);
return super.write(identity, resourceid, value);
}
}

@Override
public ExecuteResponse execute(int resourceid, String params) {
public ExecuteResponse execute(ServerIdentity identity, int resourceid, String params) {

if (resourceid == 4) { // reboot
return ExecuteResponse.internalServerError("not implemented");
} else {
return super.execute(resourceid, params);
return super.execute(identity, resourceid, params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import org.eclipse.leshan.SecurityMode;
import org.eclipse.leshan.client.request.ServerIdentity;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
import org.eclipse.leshan.client.resource.LwM2mInstanceEnabler;
import org.eclipse.leshan.core.model.ObjectModel;
Expand Down Expand Up @@ -135,7 +136,7 @@ public static Security x509(String serverUri, int shortServerId, byte[] clientCe
}

@Override
public WriteResponse write(int resourceId, LwM2mResource value) {
public WriteResponse write(ServerIdentity identity, int resourceId, LwM2mResource value) {
LOG.debug("Write on resource {}: {}", resourceId, value);

// restricted to BS server?
Expand Down Expand Up @@ -189,13 +190,13 @@ public WriteResponse write(int resourceId, LwM2mResource value) {
return WriteResponse.success();

default:
return super.write(resourceId, value);
return super.write(identity, resourceId, value);
}

}

@Override
public ReadResponse read(int resourceid) {
public ReadResponse read(ServerIdentity identity, int resourceid) {
// only accessible for internal read?

switch (resourceid) {
Expand All @@ -221,13 +222,13 @@ public ReadResponse read(int resourceid) {
return ReadResponse.success(resourceid, shortServerId);

default:
return super.read(resourceid);
return super.read(identity, resourceid);
}
}

@Override
public ExecuteResponse execute(int resourceid, String params) {
return super.execute(resourceid, params);
public ExecuteResponse execute(ServerIdentity identity, int resourceid, String params) {
return super.execute(identity, resourceid, params);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.List;

import org.eclipse.leshan.client.request.ServerIdentity;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
import org.eclipse.leshan.client.resource.LwM2mInstanceEnabler;
import org.eclipse.leshan.core.model.ObjectModel;
Expand Down Expand Up @@ -56,7 +57,7 @@ public Server(int shortServerId, long lifetime, BindingMode binding, boolean not
}

@Override
public ReadResponse read(int resourceid) {
public ReadResponse read(ServerIdentity identity, int resourceid) {

switch (resourceid) {
case 0: // short server ID
Expand All @@ -82,12 +83,12 @@ public ReadResponse read(int resourceid) {
return ReadResponse.success(resourceid, binding.toString());

default:
return super.read(resourceid);
return super.read(identity, resourceid);
}
}

@Override
public WriteResponse write(int resourceid, LwM2mResource value) {
public WriteResponse write(ServerIdentity identity, int resourceid, LwM2mResource value) {

switch (resourceid) {

Expand Down Expand Up @@ -138,18 +139,18 @@ public WriteResponse write(int resourceid, LwM2mResource value) {
}

default:
return super.write(resourceid, value);
return super.write(identity, resourceid, value);
}
}

@Override
public ExecuteResponse execute(int resourceid, String params) {
public ExecuteResponse execute(ServerIdentity identity, int resourceid, String params) {

if (resourceid == 8) { // registration update trigger
// TODO implement registration update trigger executable resource
return ExecuteResponse.internalServerError("not implemented");
} else {
return super.execute(resourceid, params);
return super.execute(identity, resourceid, params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;

import org.eclipse.leshan.client.request.ServerIdentity;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.response.ExecuteResponse;
Expand Down Expand Up @@ -67,24 +68,24 @@ public void fireResourcesChange(int... resourceIds) {
}

@Override
public ReadResponse read(int resourceid) {
public ReadResponse read(ServerIdentity identity, int resourceid) {
return ReadResponse.notFound();
}

@Override
public WriteResponse write(int resourceid, LwM2mResource value) {
public WriteResponse write(ServerIdentity identity, int resourceid, LwM2mResource value) {
return WriteResponse.notFound();
}

@Override
public ExecuteResponse execute(int resourceid, String params) {
public ExecuteResponse execute(ServerIdentity identity, int resourceid, String params) {
return ExecuteResponse.notFound();
}

@Override
public ObserveResponse observe(int resourceid) {
public ObserveResponse observe(ServerIdentity identity, int resourceid) {
// Perform a read by default
ReadResponse readResponse = this.read(resourceid);
ReadResponse readResponse = this.read(identity, resourceid);
return new ObserveResponse(readResponse.getCode(), readResponse.getContent(), null, null,
readResponse.getErrorMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public synchronized CreateResponse create(ServerIdentity identity, CreateRequest
return CreateResponse.notFound();
}
}
return doCreate(request);
return doCreate(identity, request);
}

protected CreateResponse doCreate(CreateRequest request) {
protected CreateResponse doCreate(ServerIdentity identity, CreateRequest request) {
// This should be a not implemented error, but this is not defined in the spec.
return CreateResponse.internalServerError("not implemented");
}
Expand Down Expand Up @@ -230,10 +230,10 @@ public synchronized DeleteResponse delete(ServerIdentity identity, DeleteRequest
}
}

return doDelete(request);
return doDelete(identity, request);
}

protected DeleteResponse doDelete(DeleteRequest request) {
protected DeleteResponse doDelete(ServerIdentity identity, DeleteRequest request) {
// This should be a not implemented error, but this is not defined in the spec.
return DeleteResponse.internalServerError("not implemented");
}
Expand All @@ -245,10 +245,10 @@ public synchronized BootstrapDeleteResponse delete(ServerIdentity identity, Boot
return BootstrapDeleteResponse.badRequest("Device object instance is not deletable");
}
}
return doDelete(request);
return doDelete(identity, request);
}

public BootstrapDeleteResponse doDelete(BootstrapDeleteRequest request) {
public BootstrapDeleteResponse doDelete(ServerIdentity identity, BootstrapDeleteRequest request) {
// This should be a not implemented error, but this is not defined in the spec.
return BootstrapDeleteResponse.internalServerError("not implemented");
}
Expand Down Expand Up @@ -278,10 +278,10 @@ public synchronized ExecuteResponse execute(ServerIdentity identity, ExecuteRequ
return ExecuteResponse.methodNotAllowed();
}

return doExecute(request);
return doExecute(identity, request);
}

protected ExecuteResponse doExecute(ExecuteRequest request) {
protected ExecuteResponse doExecute(ServerIdentity identity, ExecuteRequest request) {
// This should be a not implemented error, but this is not defined in the spec.
return ExecuteResponse.internalServerError("not implemented");
}
Expand All @@ -305,11 +305,11 @@ public synchronized DiscoverResponse discover(ServerIdentity identity, DiscoverR
if (id == LwM2mId.SECURITY) {
return DiscoverResponse.notFound();
}
return doDiscover(request);
return doDiscover(identity, request);

}

protected DiscoverResponse doDiscover(DiscoverRequest request) {
protected DiscoverResponse doDiscover(ServerIdentity identity, DiscoverRequest request) {

LwM2mPath path = request.getPath();
if (path.isObject()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;

import org.eclipse.leshan.client.request.ServerIdentity;
import org.eclipse.leshan.core.model.ObjectModel;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.response.ExecuteResponse;
Expand Down Expand Up @@ -77,41 +78,49 @@ public interface LwM2mInstanceEnabler {
/**
* Gets the current value of one of this LWM2M object instance's resources.
*
* @param identity the identity of the requester. This could be an internal call in this case
* <code> identity == ServerIdentity.SYSTEM</code>.
* @param resourceId the ID of the resource to get the value of
* @return the response object representing the outcome of the operation. An implementation should set the result's
* {@link ReadResponse#getCode() response code} to either reflect the success or reason for failure to
* retrieve the value.
*/
ReadResponse read(int resourceId);
ReadResponse read(ServerIdentity identity, int resourceId);

/**
* Sets the value of one of this LWM2M object instance's resources.
*
* @param identity the identity of the requester. This could be an internal call in this case
* <code> identity == ServerIdentity.SYSTEM</code>.
* @param resourceid the ID of the resource to set the value for
* @param value the value to set the resource to
* @return the response object representing the outcome of the operation. An implementation should set the result's
* {@link WriteResponse#getCode() response code} to either reflect the success or reason for failure to set
* the value.
*/
WriteResponse write(int resourceid, LwM2mResource value);
WriteResponse write(ServerIdentity identity, int resourceid, LwM2mResource value);

/**
* Executes the operation represented by one of this LWM2M object instance's resources.
*
* @param identity the identity of the requester. This could be an internal call in this case
* <code> identity == ServerIdentity.SYSTEM</code>.
* @param resourceid the ID of the resource to set the value for
* @param params the input parameters of the operation
* @return the response object representing the outcome of the operation. An implementation should set the result's
* {@link ExecuteResponse#getCode() response code} to either reflect the success or reason for failure to
* execute the operation.
*/
ExecuteResponse execute(int resourceid, String params);
ExecuteResponse execute(ServerIdentity identity, int resourceid, String params);

/**
* Performs an observe register on one of this LWM2M object instance's resources.
*
*
* @param identity the identity of the requester. This could be an internal call in this case
* <code> identity == ServerIdentity.SYSTEM</code>.
* @param resourceid the ID of the resource to set the value for
*/
ObserveResponse observe(int resourceid);
ObserveResponse observe(ServerIdentity identity, int resourceid);

/**
* @param objectModel the model of this instance
Expand Down
Loading

0 comments on commit 953ccd5

Please sign in to comment.