/** * Request to write an <b>Object Instance</b> using the TLV content format. * * @param mode the mode of the request : replace or update. * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resources the list of resources to write. */ public WriteRequest(Mode mode, int objectId, int objectInstanceId, LwM2mResource... resources) { this(mode, ContentFormat.TLV, new LwM2mPath(objectId, objectInstanceId), new LwM2mObjectInstance(objectId, resources)); }
/** * Request to write an <b>Object Instance</b> using the TLV content format. * * @param mode the mode of the request : replace or update. * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resources the list of resources to write. */ public WriteRequest(Mode mode, int objectId, int objectInstanceId, Collection<LwM2mResource> resources) { this(mode, ContentFormat.TLV, new LwM2mPath(objectId, objectInstanceId), new LwM2mObjectInstance(objectId, resources)); }
/** * Request to write an <b>Object Instance</b>. * * @param mode the mode of the request : replace or update. * @param contentFormat Format of the payload (TLV or JSON). * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resources the list of resources to write. * @exception InvalidRequestException if bad @{link ContentFormat} format was used. */ public WriteRequest(Mode mode, ContentFormat contentFormat, int objectId, int objectInstanceId, LwM2mResource... resources) throws InvalidRequestException { this(mode, contentFormat, new LwM2mPath(objectId, objectInstanceId), new LwM2mObjectInstance(objectId, resources)); }
/** * Request to write an <b>Object Instance</b>. * * @param mode the mode of the request : replace or update. * @param contentFormat Format of the payload (TLV or JSON). * @param objectId the id of the object to write. * @param objectInstanceId the id of the object instance to write. * @param resources the list of resources to write. * @exception InvalidRequestException if bad @{link ContentFormat} format was used. */ public WriteRequest(Mode mode, ContentFormat contentFormat, int objectId, int objectInstanceId, Collection<LwM2mResource> resources) throws InvalidRequestException { this(mode, contentFormat, new LwM2mPath(objectId, objectInstanceId), new LwM2mObjectInstance(objectId, resources)); }
private LwM2mObjectInstance convertToServerInstance(int instanceId, ServerConfig serverConfig) { Collection<LwM2mResource> resources = new ArrayList<>(); resources.add(LwM2mSingleResource.newIntegerResource(0, serverConfig.shortId)); resources.add(LwM2mSingleResource.newIntegerResource(1, serverConfig.lifetime)); if (serverConfig.defaultMinPeriod != null) resources.add(LwM2mSingleResource.newIntegerResource(2, serverConfig.defaultMinPeriod)); if (serverConfig.defaultMaxPeriod != null) resources.add(LwM2mSingleResource.newIntegerResource(3, serverConfig.defaultMaxPeriod)); if (serverConfig.disableTimeout != null) resources.add(LwM2mSingleResource.newIntegerResource(5, serverConfig.disableTimeout)); resources.add(LwM2mSingleResource.newBooleanResource(6, serverConfig.notifIfDisabled)); if (serverConfig.binding != null) resources.add(LwM2mSingleResource.newStringResource(7, serverConfig.binding.name())); return new LwM2mObjectInstance(instanceId, resources); } }
resources[i] = context.deserialize(array.get(i), LwM2mNode.class); node = new LwM2mObjectInstance(id, resources);
private static LwM2mObjectInstance parseObjectInstanceTlv(Tlv[] rscTlvs, int objectId, int instanceId, LwM2mModel model) throws CodecException { // read resources Map<Integer, LwM2mResource> resources = new HashMap<>(rscTlvs.length); for (Tlv rscTlv : rscTlvs) { LwM2mPath resourcePath = new LwM2mPath(objectId, instanceId, rscTlv.getIdentifier()); LwM2mResource resource = parseResourceTlv(rscTlv, resourcePath, model); LwM2mResource previousResource = resources.put(resource.getId(), resource); if (previousResource != null) { throw new CodecException("2 RESOURCE nodes (%s,%s) with the same identifier %d for path %s", previousResource, resource, resource.getId(), resourcePath); } } return new LwM2mObjectInstance(instanceId, resources.values()); }
baseName, model); instances.add(new LwM2mObjectInstance(entryByInstanceId.getKey(), resourcesMap.values())); node = new LwM2mObjectInstance(instanceEntry.getKey(), resourcesMap.values()); } else if (nodeClass == LwM2mResource.class) {
private LwM2mObjectInstance convertToSecurityInstance(int instanceId, ServerSecurity securityConfig) { Collection<LwM2mResource> resources = new ArrayList<>(); if (securityConfig.uri != null) resources.add(LwM2mSingleResource.newStringResource(0, securityConfig.uri)); resources.add(LwM2mSingleResource.newBooleanResource(1, securityConfig.bootstrapServer)); if (securityConfig.securityMode != null) resources.add(LwM2mSingleResource.newIntegerResource(2, securityConfig.securityMode.code)); if (securityConfig.publicKeyOrId != null) resources.add(LwM2mSingleResource.newBinaryResource(3, securityConfig.publicKeyOrId)); if (securityConfig.serverPublicKey != null) resources.add(LwM2mSingleResource.newBinaryResource(4, securityConfig.serverPublicKey)); if (securityConfig.secretKey != null) resources.add(LwM2mSingleResource.newBinaryResource(5, securityConfig.secretKey)); if (securityConfig.smsSecurityMode != null) resources.add(LwM2mSingleResource.newIntegerResource(6, securityConfig.smsSecurityMode.code)); if (securityConfig.smsBindingKeyParam != null) resources.add(LwM2mSingleResource.newBinaryResource(7, securityConfig.smsBindingKeyParam)); if (securityConfig.smsBindingKeySecret != null) resources.add(LwM2mSingleResource.newBinaryResource(8, securityConfig.smsBindingKeySecret)); if (securityConfig.serverSmsNumber != null) resources.add(LwM2mSingleResource.newStringResource(9, securityConfig.serverSmsNumber)); if (securityConfig.serverId != null) resources.add(LwM2mSingleResource.newIntegerResource(10, securityConfig.serverId)); if (securityConfig.clientOldOffTime != null) resources.add(LwM2mSingleResource.newIntegerResource(11, securityConfig.clientOldOffTime)); if (securityConfig.bootstrapServerAccountTimeout != null) resources.add(LwM2mSingleResource.newIntegerResource(12, securityConfig.bootstrapServerAccountTimeout)); return new LwM2mObjectInstance(instanceId, resources); }
LwM2mObjectInstance getLwM2mObjectInstance(int instanceid, LwM2mInstanceEnabler instance, ServerIdentity identity, boolean observe) { List<LwM2mResource> resources = new ArrayList<>(); for (ResourceModel resourceModel : getObjectModel().resources.values()) { // check, if internal request (SYSTEM) or readable if (identity.isSystem() || resourceModel.operations.isReadable()) { if (observe) { ObserveResponse response = instance.observe(resourceModel.id); if (response.getCode() == ResponseCode.CONTENT && response.getContent() instanceof LwM2mResource) resources.add((LwM2mResource) response.getContent()); } else { ReadResponse response = instance.read(resourceModel.id); if (response.getCode() == ResponseCode.CONTENT && response.getContent() instanceof LwM2mResource) resources.add((LwM2mResource) response.getContent()); } } } return new LwM2mObjectInstance(instanceid, resources); }
resources.add(resource); return new LwM2mObjectInstance(id, resources);
resources.add(resource); return new LwM2mObjectInstance(id, resources);
if (instanceEnabler == null) { doCreate(new CreateRequest(path.getObjectId(), new LwM2mObjectInstance(path.getObjectInstanceId(), resource))); } else { instanceEnabler.write(path.getResourceId(), resource);
@Override public void visit(CreateRequest request) { coapRequest = Request.newPost(); coapRequest.getOptions().setContentFormat(request.getContentFormat().getCode()); // if no instance id, the client will assign it. int instanceId = request.getInstanceId() != null ? request.getInstanceId() : LwM2mObjectInstance.UNDEFINED; coapRequest.setPayload(encoder.encode(new LwM2mObjectInstance(instanceId, request.getResources()), request.getContentFormat(), request.getPath(), model)); setTarget(coapRequest, request.getPath()); }
new LwM2mObjectInstance(instanceId, resources));
new LwM2mObjectInstance(instanceId, resources));