Search in sources :

Example 1 with AppLayerMessage

use of sugar.free.sightparser.applayer.messages.AppLayerMessage in project SightRemote by TebbeUbben.

the class StatusActivity method onClick.

@Override
public void onClick(View v) {
    if (StatusActivity.this.taskRunner != null)
        StatusActivity.this.taskRunner.cancel();
    handler.removeCallbacks(taskRunnerRunnable);
    AppLayerMessage message = null;
    if (v == tbrCancel) {
        tbrCancel.setVisibility(View.GONE);
        message = new CancelTBRMessage();
        Answers.getInstance().logCustom(new CustomEvent("TBR Cancelled"));
    } else if (v == bolus1Cancel) {
        bolus1Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus1().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    } else if (v == bolus2Cancel) {
        bolus2Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus2().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    } else if (v == bolus3Cancel) {
        bolus3Cancel.setVisibility(View.INVISIBLE);
        CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
        cancelBolusMessage.setBolusId(statusResult.getActiveBolusesMessage().getBolus3().getBolusID());
        message = cancelBolusMessage;
        Answers.getInstance().logCustom(new CustomEvent("Bolus Cancelled"));
    }
    SingleMessageTaskRunner taskRunner = new SingleMessageTaskRunner(getServiceConnector(), message);
    taskRunner.fetch(errorToastResultCallback);
    handler.postDelayed(taskRunnerRunnable, 500);
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) CancelTBRMessage(sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage) CancelBolusMessage(sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage) SingleMessageTaskRunner(sugar.free.sightparser.handling.SingleMessageTaskRunner)

Example 2 with AppLayerMessage

use of sugar.free.sightparser.applayer.messages.AppLayerMessage in project SightRemote by TebbeUbben.

the class AppLayerProcessor method onOutboundMessage.

@Override
public void onOutboundMessage(Object message, Pipeline pipeline) throws Exception {
    if (!(message instanceof AppLayerMessage))
        return;
    Log.d("SightService", "SEND: " + message.getClass());
    DataMessage dataMessage = new DataMessage();
    dataMessage.setData(((AppLayerMessage) message).serialize());
    pipeline.send(dataMessage);
    Answers.getInstance().logCustom(new CustomEvent("Sent Application Layer Message").putCustomAttribute("Message", message.getClass().getSimpleName()));
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) DataMessage(sugar.free.sightparser.authlayer.DataMessage)

Example 3 with AppLayerMessage

use of sugar.free.sightparser.applayer.messages.AppLayerMessage in project SightRemote by TebbeUbben.

the class AppLayerProcessor method onInboundMessage.

@Override
public void onInboundMessage(Object message, Pipeline pipeline) throws Exception {
    if (!(message instanceof DataMessage))
        return;
    DataMessage dataMessage = (DataMessage) message;
    ByteBuf byteBuf = new ByteBuf(dataMessage.getData().length);
    byteBuf.putBytes(dataMessage.getData());
    AppLayerMessage appLayerMessage = AppLayerMessage.deserialize(byteBuf);
    Log.d("SightService", "RECEIVE: " + appLayerMessage.getClass());
    pipeline.receive(appLayerMessage);
    Answers.getInstance().logCustom(new CustomEvent("Received Application Layer Message").putCustomAttribute("Message", appLayerMessage.getClass().getSimpleName()));
}
Also used : CustomEvent(com.crashlytics.android.answers.CustomEvent) AppLayerMessage(sugar.free.sightparser.applayer.messages.AppLayerMessage) DataMessage(sugar.free.sightparser.authlayer.DataMessage) ByteBuf(sugar.free.sightparser.pipeline.ByteBuf)

Example 4 with AppLayerMessage

use of sugar.free.sightparser.applayer.messages.AppLayerMessage 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

AppLayerMessage (sugar.free.sightparser.applayer.messages.AppLayerMessage)4 CustomEvent (com.crashlytics.android.answers.CustomEvent)3 DataMessage (sugar.free.sightparser.authlayer.DataMessage)2 ArrayList (java.util.ArrayList)1 Service (sugar.free.sightparser.applayer.descriptors.Service)1 ActivateServiceMessage (sugar.free.sightparser.applayer.messages.connection.ActivateServiceMessage)1 ServiceChallengeMessage (sugar.free.sightparser.applayer.messages.connection.ServiceChallengeMessage)1 CancelBolusMessage (sugar.free.sightparser.applayer.messages.remote_control.CancelBolusMessage)1 CancelTBRMessage (sugar.free.sightparser.applayer.messages.remote_control.CancelTBRMessage)1 DisconnectedError (sugar.free.sightparser.error.DisconnectedError)1 MessageRequest (sugar.free.sightparser.handling.MessageRequest)1 SingleMessageTaskRunner (sugar.free.sightparser.handling.SingleMessageTaskRunner)1 ByteBuf (sugar.free.sightparser.pipeline.ByteBuf)1