Beispiel #1
0
  @Override
  protected WriteResponse doWrite(WriteRequest request) {
    LwM2mPath path = request.getPath();

    // Manage Instance case
    LwM2mInstanceEnabler instance = instances.get(path.getObjectInstanceId());
    if (instance == null) return WriteResponse.notFound();

    if (path.getResourceId() == null) {
      for (LwM2mResource resource :
          ((LwM2mObjectInstance) request.getNode()).getResources().values()) {
        instance.write(resource.getId(), resource);
      }
      return WriteResponse.success();
    }

    // Manage Resource case
    return instance.write(path.getResourceId(), (LwM2mResource) request.getNode());
  }
Beispiel #2
0
  @Override
  protected synchronized CreateResponse doCreate(CreateRequest request) {
    Integer instanceId = request.getPath().getObjectInstanceId();
    if (instanceId == null) {
      // the client is in charge to generate the id of the new instance
      if (instances.isEmpty()) {
        instanceId = 0;
      } else {
        instanceId = Collections.max(instances.keySet()) + 1;
      }
    }

    LwM2mInstanceEnabler newInstance = instanceFactory.create(getObjectModel());

    for (LwM2mResource resource : request.getResources()) {
      newInstance.write(resource.getId(), resource);
    }
    instances.put(instanceId, newInstance);
    listenInstance(newInstance, instanceId);

    return CreateResponse.success(
        new LwM2mPath(request.getPath().getObjectId(), instanceId).toString());
  }