diff options
author | Marvin W <git@larma.de> | 2017-04-18 17:53:25 +0200 |
---|---|---|
committer | Marvin W <git@larma.de> | 2017-04-18 20:20:41 +0200 |
commit | f95b4f4e0949eefaed871c267626e3ff84ce5ca6 (patch) | |
tree | e60469776bcf062d2db15e9968bf6dbd37fa1630 /libdino/src/service | |
parent | 765c2605cd0abf2b4431051142f09e2676584222 (diff) | |
download | dino-f95b4f4e0949eefaed871c267626e3ff84ce5ca6.tar.gz dino-f95b4f4e0949eefaed871c267626e3ff84ce5ca6.zip |
xmpp-vala/core+libdino: concurrency + nullity improvements
Diffstat (limited to 'libdino/src/service')
-rw-r--r-- | libdino/src/service/avatar_manager.vala | 60 | ||||
-rw-r--r-- | libdino/src/service/muc_manager.vala | 5 | ||||
-rw-r--r-- | libdino/src/service/stream_interactor.vala | 4 |
3 files changed, 42 insertions, 27 deletions
diff --git a/libdino/src/service/avatar_manager.vala b/libdino/src/service/avatar_manager.vala index de3d86fb..42a08168 100644 --- a/libdino/src/service/avatar_manager.vala +++ b/libdino/src/service/avatar_manager.vala @@ -47,12 +47,16 @@ public class AvatarManager : StreamInteractionModule, Object { } private Pixbuf? get_avatar_by_hash(string hash) { - if (cached_pixbuf.has_key(hash)) { - return cached_pixbuf[hash]; + lock (cached_pixbuf) { + if (cached_pixbuf.has_key(hash)) { + return cached_pixbuf[hash]; + } } Pixbuf? image = avatar_storage.get_image(hash); if (image != null) { - cached_pixbuf[hash] = image; + lock (cached_pixbuf) { + cached_pixbuf[hash] = image; + } } return image; } @@ -62,13 +66,17 @@ public class AvatarManager : StreamInteractionModule, Object { if (!stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { jid_ = jid.bare_jid; } - string? user_avatars_id = user_avatars[jid_]; - if (user_avatars_id != null) { - return get_avatar_by_hash(user_avatars_id); + lock(user_avatars) { + string? user_avatars_id = user_avatars[jid_]; + if (user_avatars_id != null) { + return get_avatar_by_hash(user_avatars_id); + } } - string? vcard_avatars_id = vcard_avatars[jid_]; - if (vcard_avatars_id != null) { - return get_avatar_by_hash(vcard_avatars_id); + lock(vcard_avatars) { + string? vcard_avatars_id = vcard_avatars[jid_]; + if (vcard_avatars_id != null) { + return get_avatar_by_hash(vcard_avatars_id); + } } return null; } @@ -103,20 +111,26 @@ public class AvatarManager : StreamInteractionModule, Object { on_vcard_avatar_received(account, new Jid(jid), id) ); - user_avatars = db.get_avatar_hashes(Source.USER_AVATARS); - foreach (Jid jid in user_avatars.keys) { - on_user_avatar_received(account, jid, user_avatars[jid]); + lock (user_avatars) { + user_avatars = db.get_avatar_hashes(Source.USER_AVATARS); + foreach (Jid jid in user_avatars.keys) { + on_user_avatar_received(account, jid, user_avatars[jid]); + } } - vcard_avatars = db.get_avatar_hashes(Source.VCARD); - foreach (Jid jid in vcard_avatars.keys) { - on_vcard_avatar_received(account, jid, vcard_avatars[jid]); + lock (vcard_avatars) { + vcard_avatars = db.get_avatar_hashes(Source.VCARD); + foreach (Jid jid in vcard_avatars.keys) { + on_vcard_avatar_received(account, jid, vcard_avatars[jid]); + } } } private void on_user_avatar_received(Account account, Jid jid, string id) { - if (!user_avatars.has_key(jid) || user_avatars[jid] != id) { - user_avatars[jid] = id; - db.set_avatar_hash(jid, id, Source.USER_AVATARS); + lock (user_avatars) { + if (!user_avatars.has_key(jid) || user_avatars[jid] != id) { + user_avatars[jid] = id; + db.set_avatar_hash(jid, id, Source.USER_AVATARS); + } } Pixbuf? avatar = avatar_storage.get_image(id); if (avatar != null) { @@ -125,10 +139,12 @@ public class AvatarManager : StreamInteractionModule, Object { } private void on_vcard_avatar_received(Account account, Jid jid, string id) { - if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) { - vcard_avatars[jid] = id; - if (!jid.is_full()) { // don't save muc avatars - db.set_avatar_hash(jid, id, Source.VCARD); + lock (vcard_avatars) { + if (!vcard_avatars.has_key(jid) || vcard_avatars[jid] != id) { + vcard_avatars[jid] = id; + if (!jid.is_full()) { // don't save muc avatars + db.set_avatar_hash(jid, id, Source.VCARD); + } } } Pixbuf? avatar = avatar_storage.get_image(id); diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index a0d6dbe5..3c855c0e 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -161,9 +161,8 @@ public class MucManager : StreamInteractionModule, Object { }); } - private void on_stream_negotiated(Account account) { - Core.XmppStream stream = stream_interactor.get_stream(account); - if (stream != null) stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => { + private void on_stream_negotiated(Account account, Core.XmppStream stream) { + stream.get_module(Xep.Bookmarks.Module.IDENTITY).get_conferences(stream, (stream, conferences, o) => { Tuple<MucManager, Account> tuple = o as Tuple<MucManager, Account>; MucManager outer_ = tuple.a; Account account_ = tuple.b; diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index 81ddfebd..028d031b 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -9,7 +9,7 @@ public class StreamInteractor { public signal void account_added(Account account); public signal void account_removed(Account account); - public signal void stream_negotiated(Account account); + public signal void stream_negotiated(Account account, Core.XmppStream stream); public ModuleManager module_manager; public ConnectionManager connection_manager; @@ -59,7 +59,7 @@ public class StreamInteractor { private void on_stream_opened(Account account, Core.XmppStream stream) { stream.stream_negotiated.connect( (stream) => { - stream_negotiated(account); + stream_negotiated(account, stream); }); } } |