aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/stream_interactor.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-10 19:53:24 +0100
committerfiaxh <git@mx.ax.lt>2017-03-10 19:53:24 +0100
commit24b55d83a1f9e21b028c8d5ac9778e75565f417d (patch)
tree195b0f332e32d08e1a18fc3d8a5a6725c5ed11d7 /libdino/src/service/stream_interactor.vala
parent4c48c5c16d5f5b010c2e5dfb1affcb59f937510c (diff)
parent29ca70a6d534e1cd79963718c793ae740318cff1 (diff)
downloaddino-24b55d83a1f9e21b028c8d5ac9778e75565f417d.tar.gz
dino-24b55d83a1f9e21b028c8d5ac9778e75565f417d.zip
Merge branch 'master' of github.com:dino/dino
Diffstat (limited to 'libdino/src/service/stream_interactor.vala')
-rw-r--r--libdino/src/service/stream_interactor.vala70
1 files changed, 70 insertions, 0 deletions
diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala
new file mode 100644
index 00000000..f3859e3b
--- /dev/null
+++ b/libdino/src/service/stream_interactor.vala
@@ -0,0 +1,70 @@
+using Gee;
+
+using Xmpp;
+using Dino.Entities;
+
+namespace Dino {
+
+public class StreamInteractor {
+
+ public signal void account_added(Account account);
+ public signal void stream_negotiated(Account account);
+
+ public ModuleManager module_manager;
+ public ConnectionManager connection_manager;
+ private ArrayList<StreamInteractionModule> interaction_modules = new ArrayList<StreamInteractionModule>();
+
+ public StreamInteractor(Database db) {
+ module_manager = new ModuleManager(db);
+ connection_manager = new ConnectionManager(module_manager);
+
+ connection_manager.stream_opened.connect(on_stream_opened);
+ }
+
+ public void connect(Account account) {
+ module_manager.add_account(account);
+ account_added(account);
+ connection_manager.connect(account);
+ }
+
+ public void disconnect(Account account) {
+ connection_manager.disconnect(account);
+ }
+
+ public ArrayList<Account> get_accounts() {
+ ArrayList<Account> ret = new ArrayList<Account>(Account.equals_func);
+ foreach (Account account in connection_manager.get_managed_accounts()) {
+ ret.add(account);
+ }
+ return ret;
+ }
+
+ public Core.XmppStream? get_stream(Account account) {
+ return connection_manager.get_stream(account);
+ }
+
+ public void add_module(StreamInteractionModule module) {
+ interaction_modules.add(module);
+ }
+
+ public StreamInteractionModule? get_module(string id) {
+ foreach (StreamInteractionModule module in interaction_modules) {
+ if (module.get_id() == id) {
+ return module;
+ }
+ }
+ return null;
+ }
+
+ private void on_stream_opened(Account account, Core.XmppStream stream) {
+ stream.stream_negotiated.connect( (stream) => {
+ stream_negotiated(account);
+ });
+ }
+}
+
+public interface StreamInteractionModule : Object {
+ internal abstract string get_id();
+}
+
+} \ No newline at end of file