use of org.thingsboard.server.transport.coap.callback.CoapOkCallback in project thingsboard by thingsboard.
the class DefaultCoapClientContext method cancelRpcSubscription.
private void cancelRpcSubscription(TbCoapClientState state) {
if (state.getRpc() != null) {
clientsByToken.remove(state.getRpc().getToken());
CoapExchange exchange = state.getRpc().getExchange();
state.setRpc(null);
transportService.process(state.getSession(), TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(), new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
if (state.getAttrs() == null) {
closeAndCleanup(state);
}
}
}
use of org.thingsboard.server.transport.coap.callback.CoapOkCallback in project thingsboard by thingsboard.
the class DefaultCoapClientContext method registerFeatureObservation.
private boolean registerFeatureObservation(TbCoapClientState state, String token, CoapExchange exchange, FeatureType featureType) {
state.lock();
try {
boolean newObservation;
if (FeatureType.ATTRIBUTES.equals(featureType)) {
if (state.getAttrs() == null) {
newObservation = true;
state.setAttrs(new TbCoapObservationState(exchange, token));
} else {
newObservation = !state.getAttrs().getToken().equals(token);
if (newObservation) {
TbCoapObservationState old = state.getAttrs();
state.setAttrs(new TbCoapObservationState(exchange, token));
old.getExchange().respond(CoAP.ResponseCode.DELETED);
}
}
} else {
if (state.getRpc() == null) {
newObservation = true;
state.setRpc(new TbCoapObservationState(exchange, token));
} else {
newObservation = !state.getRpc().getToken().equals(token);
if (newObservation) {
TbCoapObservationState old = state.getRpc();
state.setRpc(new TbCoapObservationState(exchange, token));
old.getExchange().respond(CoAP.ResponseCode.DELETED);
}
}
}
if (newObservation) {
clientsByToken.put(token, state);
if (state.getSession() == null) {
TransportProtos.SessionInfoProto session = SessionInfoCreator.create(state.getCredentials(), transportContext, UUID.randomUUID());
state.setSession(session);
CoapSessionListener listener = new CoapSessionListener(state);
state.setListener(listener);
transportService.registerAsyncSession(session, state.getListener());
transportService.process(session, getSessionEventMsg(TransportProtos.SessionEvent.OPEN), null);
}
if (FeatureType.ATTRIBUTES.equals(featureType)) {
transportService.process(state.getSession(), TransportProtos.SubscribeToAttributeUpdatesMsg.getDefaultInstance(), new CoapNoOpCallback(exchange));
transportService.process(state.getSession(), TransportProtos.GetAttributeRequestMsg.newBuilder().setOnlyShared(true).build(), new CoapNoOpCallback(exchange));
} else {
transportService.process(state.getSession(), TransportProtos.SubscribeToRPCMsg.getDefaultInstance(), new CoapOkCallback(exchange, CoAP.ResponseCode.VALID, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
}
}
return newObservation;
} finally {
state.unlock();
}
}
use of org.thingsboard.server.transport.coap.callback.CoapOkCallback in project thingsboard by thingsboard.
the class CoapTransportResource method handlePostAttributesRequest.
private void handlePostAttributesRequest(TbCoapClientState clientState, CoapExchange exchange, Request request) throws AdaptorException {
TransportProtos.SessionInfoProto sessionInfo = clients.getNewSyncSession(clientState);
UUID sessionId = toSessionId(sessionInfo);
transportService.process(sessionInfo, clientState.getAdaptor().convertToPostAttributes(sessionId, request, clientState.getConfiguration().getAttributesMsgDescriptor()), new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
}
use of org.thingsboard.server.transport.coap.callback.CoapOkCallback in project thingsboard by thingsboard.
the class CoapTransportResource method handlePostTelemetryRequest.
private void handlePostTelemetryRequest(TbCoapClientState clientState, CoapExchange exchange, Request request) throws AdaptorException {
TransportProtos.SessionInfoProto sessionInfo = clients.getNewSyncSession(clientState);
UUID sessionId = toSessionId(sessionInfo);
transportService.process(sessionInfo, clientState.getAdaptor().convertToPostTelemetry(sessionId, request, clientState.getConfiguration().getTelemetryMsgDescriptor()), new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
}
use of org.thingsboard.server.transport.coap.callback.CoapOkCallback in project thingsboard by thingsboard.
the class CoapTransportResource method handleClaimRequest.
private void handleClaimRequest(TbCoapClientState clientState, CoapExchange exchange, Request request) throws AdaptorException {
TransportProtos.SessionInfoProto sessionInfo = clients.getNewSyncSession(clientState);
UUID sessionId = toSessionId(sessionInfo);
transportService.process(sessionInfo, clientState.getAdaptor().convertToClaimDevice(sessionId, request, sessionInfo), new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
}
Aggregations