| 1 |
namespace Xmpp.Xep.Jingle { |
| 2 |
|
| 3 |
public abstract class ComponentConnection : Object { |
| 4 |
public uint8 component_id { get; set; default = 0; } |
| 5 |
public ulong bytes_sent { get; protected set; default=0; } |
| 6 |
public ulong bytes_received { get; protected set; default=0; } |
| 7 |
public abstract async void terminate(bool we_terminated, string? reason_name = null, string? reason_text = null); |
| 8 |
public signal void connection_closed(); |
| 9 |
public signal void connection_error(IOError e); |
| 10 |
} |
| 11 |
|
| 12 |
public abstract class DatagramConnection : ComponentConnection { |
| 13 |
public bool ready { get; set; default = false; } |
| 14 |
private string? terminate_reason_name = null; |
| 15 |
private string? terminate_reason_text = null; |
| 16 |
private bool terminated = false; |
| 17 |
|
| 18 |
public override async void terminate(bool we_terminated, string? reason_string = null, string? reason_text = null) { |
| 19 |
if (!terminated) { |
| 20 |
terminated = true; |
| 21 |
terminate_reason_name = reason_string; |
| 22 |
terminate_reason_text = reason_text; |
| 23 |
connection_closed(); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public signal void datagram_received(Bytes datagram); |
| 28 |
public abstract void send_datagram(Bytes datagram); |
| 29 |
} |
| 30 |
|
| 31 |
public class StreamingConnection : ComponentConnection { |
| 32 |
public Gee.Future<IOStream> stream { get { return promise.future; } } |
| 33 |
protected Gee.Promise<IOStream> promise = new Gee.Promise<IOStream>(); |
| 34 |
private string? terminated = null; |
| 35 |
|
| 36 |
public async void set_stream(IOStream? stream) { |
| 37 |
if (stream == null) { |
| 38 |
promise.set_exception(new IOError.FAILED("Jingle connection failed")); |
| 39 |
return; |
| 40 |
} |
| 41 |
assert(!this.stream.ready); |
| 42 |
promise.set_value(stream); |
| 43 |
if (terminated != null) { |
| 44 |
yield stream.close_async(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
public void set_error(GLib.Error? e) { |
| 49 |
promise.set_exception(e); |
| 50 |
} |
| 51 |
|
| 52 |
public override async void terminate(bool we_terminated, string? reason_name = null, string? reason_text = null) { |
| 53 |
if (terminated == null) { |
| 54 |
terminated = (reason_name ?? "") + " - " + (reason_text ?? "") + @"we terminated? $we_terminated"; |
| 55 |
if (stream.ready) { |
| 56 |
yield stream.value.close_async(); |
| 57 |
} else { |
| 58 |
promise.set_exception(new IOError.FAILED("Jingle connection failed")); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|