Search in sources :

Example 6 with DisconnectedError

use of sugar.free.sightparser.error.DisconnectedError in project SightRemote by TebbeUbben.

the class RequestWorker method onInboundMessage.

@Override
public void onInboundMessage(final Object message, Pipeline pipeline) throws Exception {
    synchronized (messageRequests) {
        if (messageRequests.size() == 0)
            return;
        if (message instanceof DisconnectedError) {
            for (MessageRequest messageRequest : new ArrayList<>(messageRequests)) {
                sendError(messageRequest, (Exception) message);
                messageRequests.remove(messageRequest);
            }
            return;
        }
        MessageRequest messageRequest = messageRequests.get(0);
        if (message instanceof Exception) {
            sendError(messageRequest, (Exception) message);
            messageRequests.remove(messageRequest);
            requestNext(pipeline);
            return;
        }
        if (messageRequest.getMessageStatus() == MessageStatus.ACTIVATING_SERVICE) {
            Service service = messageRequest.getAppLayerMessage().getService();
            if (message instanceof ServiceChallengeMessage) {
                byte[] password = Cryptograph.getServicePasswordHash(service.getServicePassword(), ((ServiceChallengeMessage) message).getRandomData());
                ActivateServiceMessage activateService = new ActivateServiceMessage();
                activateService.setServicePassword(password);
                activateService.setServiceID(service.getServiceID());
                activateService.setVersion(service.getVersion());
                pipeline.send(activateService);
            } else if (message instanceof ActivateServiceMessage) {
                pipeline.getActivatedServices().add(service);
                requestNext(pipeline);
            }
        } else if (messageRequest.getMessageStatus() == MessageStatus.PENDING && message instanceof AppLayerMessage) {
            sendMessage(messageRequest, (AppLayerMessage) message);
            messageRequests.remove(messageRequest);
            requestNext(pipeline);
        }
    }
}
Also used : ActivateServiceMessage(sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) MessageRequest(sugar.free.sightparser.handling.MessageRequest) ServiceChallengeMessage(sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage) ArrayList(java.util.ArrayList) Service(sugar.free.sightparser.applayer.descriptors.Service) DisconnectedError(sugar.free.sightparser.error.DisconnectedError)

Aggregations

DisconnectedError (sugar.free.sightparser.error.DisconnectedError)6 CustomEvent (com.crashlytics.android.answers.CustomEvent)2 IOException (java.io.IOException)2 MessageRequest (sugar.free.sightparser.handling.MessageRequest)2 Snackbar (android.support.design.widget.Snackbar)1 ArrayList (java.util.ArrayList)1 TimerTask (java.util.TimerTask)1 Service (sugar.free.sightparser.applayer.descriptors.Service)1 AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)1 ActivateServiceMessage (sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage)1 BindMessage (sugar.free.sightparser.applayer.messages.connection.BindMessage)1 ServiceChallengeMessage (sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage)1 ConnectionResponse (sugar.free.sightparser.authlayer.ConnectionResponse)1 KeyRequest (sugar.free.sightparser.authlayer.KeyRequest)1 KeyResponse (sugar.free.sightparser.authlayer.KeyResponse)1 PairingStatus (sugar.free.sightparser.authlayer.PairingStatus)1 VerifyConfirmRequest (sugar.free.sightparser.authlayer.VerifyConfirmRequest)1 VerifyConfirmResponse (sugar.free.sightparser.authlayer.VerifyConfirmResponse)1 VerifyDisplayRequest (sugar.free.sightparser.authlayer.VerifyDisplayRequest)1 VerifyDisplayResponse (sugar.free.sightparser.authlayer.VerifyDisplayResponse)1