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);
}
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()));
}
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()));
}
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);
}
}
}
Aggregations