Skip to content
Snippets Groups Projects
Commit df538060 authored by Tumbul, Erwin's avatar Tumbul, Erwin
Browse files

Update BroadcastReceiver to use new protocol definition.

parent 7bdbe960
No related branches found
No related tags found
No related merge requests found
...@@ -7,27 +7,28 @@ import android.util.Log; ...@@ -7,27 +7,28 @@ import android.util.Log;
import io.grpc.ManagedChannel; import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder; import io.grpc.ManagedChannelBuilder;
import io.grpc.notifier.Message;
import io.grpc.notifier.Nothing; import io.grpc.notifier.Nothing;
import io.grpc.notifier.NotifierComGrpc; import io.grpc.notifier.NotifierCommunicationGrpc;
import io.grpc.notifier.SendMessageRequest;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
public class NotificationBroadcastReceiver extends BroadcastReceiver { public class NotificationBroadcastReceiver extends BroadcastReceiver {
private ManagedChannel channel; private ManagedChannel channel;
private final NotifierComGrpc.NotifierComStub asyncStub; private final NotifierCommunicationGrpc.NotifierCommunicationStub asyncStub;
public NotificationBroadcastReceiver() { public NotificationBroadcastReceiver() {
channel = ManagedChannelBuilder.forAddress("192.168.0.127", 8080).usePlaintext().build(); channel = ManagedChannelBuilder.forAddress("192.168.0.127", 8080).usePlaintext().build();
Log.i("NOTIFIER[NotificationBroadcastReceiver]", String.format("ConnectivityState: %s", channel.getState(true).name())); Log.i("NOTIFIER[NotificationBroadcastReceiver]", String.format("ConnectivityState: %s", channel.getState(true).name()));
asyncStub = NotifierComGrpc.newStub(channel); asyncStub = NotifierCommunicationGrpc.newStub(channel);
} }
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Log.i("NOTIFIER[onReceive]", "Received notification."); Log.i("NOTIFIER[onReceive]", "Received notification.");
Notification notification = (Notification) intent.getSerializableExtra("Notification"); Notification notification = (Notification) intent.getSerializableExtra("Notification");
SendMessageRequest message = SendMessageRequest.newBuilder().setMessage(notification.toString()).build(); Message message = Message.newBuilder().setCommId(1).setContent(notification.toString()).build();
asyncStub.sendMessage(message, new StreamObserver<Nothing>() { asyncStub.sendMessage(message, new StreamObserver<Nothing>() {
@Override @Override
public void onNext(Nothing value) { public void onNext(Nothing value) {
...@@ -46,5 +47,6 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver { ...@@ -46,5 +47,6 @@ public class NotificationBroadcastReceiver extends BroadcastReceiver {
Log.i("NOTIFIER[onReceive]", "Completed sendMessage."); Log.i("NOTIFIER[onReceive]", "Completed sendMessage.");
} }
}); });
} }
} }
...@@ -23,11 +23,10 @@ class NotifierService(NotifierCommunicationServicer): ...@@ -23,11 +23,10 @@ class NotifierService(NotifierCommunicationServicer):
# TODO: read comm_id and wait for messages # TODO: read comm_id and wait for messages
yield Message(comm_id=-1, content="test") yield Message(comm_id=-1, content="test")
def SendMessage(self, request_iterator, context): def SendMessage(self, request, context):
for msg in request_iterator: # TODO: read comm_id and route message
# TODO: read comm_id and route message print(request.comm_id)
print(msg.comm_id) print(request.content)
print(msg.content)
return Nothing() return Nothing()
......
...@@ -10,7 +10,7 @@ package netcode; ...@@ -10,7 +10,7 @@ package netcode;
service NotifierCommunication { service NotifierCommunication {
rpc Open (OpenRequest) returns (CommResponse); rpc Open (OpenRequest) returns (CommResponse);
rpc Answer (AnswerRequest) returns (CommResponse); rpc Answer (AnswerRequest) returns (CommResponse);
rpc SendMessage (stream Message) returns (Nothing); rpc SendMessage (Message) returns (Nothing);
rpc ReceiveMessage (ReceiveRequest) returns (stream Message); rpc ReceiveMessage (ReceiveRequest) returns (stream Message);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment