From 01a7b041fd6b510ab5f24d84d063ebeca641dc0a Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Sat, 17 Jan 2015 16:03:50 +0100 Subject: [PATCH] devicechannel: packet_received signal --- src/device.vala | 6 ++++++ src/devicechannel.vala | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/device.vala b/src/device.vala index a833323..e8f7f3e 100644 --- a/src/device.vala +++ b/src/device.vala @@ -112,6 +112,9 @@ class Device : Object { _channel.connected.connect((c) => { this.greet(); }); + _channel.packet_received.connect((c, pkt) => { + this.packet_received(pkt); + }); _channel.open(); debug("open finished"); } @@ -120,4 +123,7 @@ class Device : Object { } + private void packet_received(Packet pkt) { + debug("got packet"); + } } \ No newline at end of file diff --git a/src/devicechannel.vala b/src/devicechannel.vala index 00a7e0f..2016626 100644 --- a/src/devicechannel.vala +++ b/src/devicechannel.vala @@ -26,6 +26,7 @@ class DeviceChannel : Object { public signal void connected(); + public signal void packet_received(Packet pkt); private InetSocketAddress _isa = null; private SocketConnection _conn = null; @@ -106,6 +107,12 @@ class DeviceChannel : Object { _din.read_byte(); pkt = Packet.new_from_data(data); + if (pkt == null) { + critical("failed to build packet from data"); + return; + } + + handle_packet(pkt); } private async void _io_ready() { @@ -119,4 +126,18 @@ class DeviceChannel : Object { critical("error occurred: %d: %s", e.code, e.message); } } + + private void handle_packet(Packet pkt) { + debug("handle packet of type: %s", pkt.pkt_type); + if (pkt.pkt_type == Packet.ENCRYPTED) { + handle_encrypted_packet(pkt); + } else { + // signal that we got a packet + packet_received(pkt); + } + } + + private void handle_encrypted_packet(Packet pkt) { + + } } \ No newline at end of file