Browse Source

devicechannel: packet_received signal

bboozzoo/device-cache
Maciek Borzecki 10 years ago
parent
commit
01a7b041fd
2 changed files with 27 additions and 0 deletions
  1. +6
    -0
      src/device.vala
  2. +21
    -0
      src/devicechannel.vala

+ 6
- 0
src/device.vala View File

@ -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");
}
}

+ 21
- 0
src/devicechannel.vala View File

@ -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) {
}
}

Loading…
Cancel
Save