From db57a973534f099af2b150f1a1307d1948553d9f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sun, 19 Mar 2017 12:55:36 +0100 Subject: Add typed identity to manager modules and stream flags --- libdino/src/service/stream_interactor.vala | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'libdino/src/service/stream_interactor.vala') diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index f42eb41b..bdc1ac96 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -13,7 +13,7 @@ public class StreamInteractor { public ModuleManager module_manager; public ConnectionManager connection_manager; - private ArrayList interaction_modules = new ArrayList(); + private ArrayList modules = new ArrayList(); public StreamInteractor(Database db) { module_manager = new ModuleManager(db); @@ -46,14 +46,13 @@ public class StreamInteractor { } public void add_module(StreamInteractionModule module) { - interaction_modules.add(module); + modules.add(module); } - public StreamInteractionModule? get_module(string id) { - foreach (StreamInteractionModule module in interaction_modules) { - if (module.get_id() == id) { - return module; - } + public T? get_module(ModuleIdentity? identity) { + if (identity == null) return null; + foreach (StreamInteractionModule module in modules) { + if (identity.matches(module)) return identity.cast(module); } return null; } @@ -65,8 +64,24 @@ public class StreamInteractor { } } +public class ModuleIdentity : Object { + public string id { get; private set; } + + public ModuleIdentity(string id) { + this.id = id; + } + + public T? cast(StreamInteractionModule module) { + return (T?) module; + } + + public bool matches(StreamInteractionModule module) { + return module.id== id; + } +} + public interface StreamInteractionModule : Object { - public abstract string get_id(); + public abstract string id { get; } } } \ No newline at end of file -- cgit v1.2.3-54-g00ecf