summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 19:19:18 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 19:19:18 +0200
commit6a93cb6f2c014e4092f1ada75d2f37ac082f763b (patch)
treeaba37d426fbd15566604f419ffda494358d4cf3c /src
parente7850780ac1abd5d4f74b7c36edebdebc40bb4fc (diff)
downloadephraim-6a93cb6f2c014e4092f1ada75d2f37ac082f763b.tar
ephraim-6a93cb6f2c014e4092f1ada75d2f37ac082f763b.zip
Some optimizations
Diffstat (limited to 'src')
-rw-r--r--src/gui/CoreConnector.vala107
1 files changed, 46 insertions, 61 deletions
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 5191c9e..445f097 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -1,10 +1,20 @@
public class CoreConnector {
- //unowned Thread thread;
- //bool running;
+ static Eva.Term match_roster_update;
+ static Eva.Term match_resource_entry;
+ static Eva.Term match_avatar;
+ static Eva.Term match_new_conversation;
+ static Eva.Term match_receive_message;
+ static Eva.Term match_sent_message;
+
+ static construct {
+ match_roster_update = Eva.parse("{roster_update,JID,Name,Subscription,Groups,Resources,Avatar}");
+ match_resource_entry = Eva.parse("{Name,{resource_entry,Priority,Show,Status}}");
+ match_avatar = Eva.parse("{avatar,Data}");
+ match_new_conversation = Eva.parse("{new_conversation,JID}");
+ match_receive_message = Eva.parse("{receive_message,JID,Type,Body}");
+ match_sent_message = Eva.parse("{sent_message,JID,Type,Body}");
+ }
- //Erl.Node node;
- //Erl.Connection con;
- //Erl.Term self;
Eva.PacketHandler con;
public signal void update_contact(Contact contact);
@@ -12,46 +22,13 @@ public class CoreConnector {
public signal void receive_message(string jid, string type, string message);
public signal void sent_message(string jid, string type, string message);
- /*private class TermStore {
- public Erl.Term term;
- }*/
-
- /*static construct {
- Erl.init();
- }*/
-
- public CoreConnector() {
- //running = false;
- }
-
public void start() {
- /*node = Erl.Node("ephraim-gtk", "magiccookie", 0);
- con = node.connect("ephraim-core@avalon.local");
-
- self = Erl.mk_self_pid(node);
-
- con.reg_send("ephraim", Erl.format("{register_ui,~w}", self));
-
- try {
- thread = Thread.create(receive, true);
- return true;
- } catch(ThreadError e) {
- return false;
- }*/
-
con = new Eva.PacketHandler(new UnixInputStream(3, true), new UnixOutputStream(4, true), 4);
con.received_term.connect(handle_term);
con.start();
}
public void stop() {
- /*if(!running)
- return;
-
- running = false;
- receive.end();*/
-
- //con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self));
con.send(new Eva.Atom("stop"));
}
@@ -64,11 +41,12 @@ public class CoreConnector {
private void handle_term(Eva.Term term) {
Gee.Map<string, Eva.Term> match;
- if((match = term.match(Eva.parse("{roster_update,JID,Name,Subscription,Groups,Resources,Avatar}"))) != null) {
+ if((match = term.match(match_roster_update)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null)
- // TODO Debug output
+ if(jid_term == null) {
+ warn_if_reached();
return;
+ }
string jid = from_utf8(jid_term);
Eva.Binary name_term = match["Name"] as Eva.Binary;
@@ -96,7 +74,7 @@ public class CoreConnector {
while(resources != null) {
Gee.Map<string, Eva.Term> r;
- if((r = resources.head.match(Eva.parse("{Name,{resource_entry,Priority,Show,Status}}"))) != null) {
+ if((r = resources.head.match(match_resource_entry)) != null) {
Eva.Binary rname_term = r["Name"] as Eva.Binary;
Eva.Numeric prio_term = r["Priority"] as Eva.Numeric;
Eva.Atom show_term = r["Show"] as Eva.Atom;
@@ -136,7 +114,7 @@ public class CoreConnector {
resources = resources.tail as Eva.Cons;
}
- Gee.Map<string, Eva.Term> avatar = match["Avatar"].match(Eva.parse("{avatar,Data}"));
+ Gee.Map<string, Eva.Term> avatar = match["Avatar"].match(match_avatar);
if(avatar != null) {
Eva.Binary avatarData = avatar["Data"] as Eva.Binary;
@@ -146,59 +124,66 @@ public class CoreConnector {
contact.avatar = new Gdk.Pixbuf.from_stream_at_scale(avatarStream, 32, 32, true, null);
avatarStream.close(null);
} catch(Error e) {
- // TODO Debug output
+ warn_if_reached();
}
}
}
update_contact(contact);
}
- else if((match = term.match(Eva.parse("{new_conversation,JID}"))) != null) {
+ else if((match = term.match(match_new_conversation)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null)
- // TODO Debug output
+ if(jid_term == null) {
+ warn_if_reached();
return;
+ }
string jid = from_utf8(jid_term);
new_conversation(jid);
}
- else if((match = term.match(Eva.parse("{receive_message,JID,Type,Body}"))) != null) {
+ else if((match = term.match(match_receive_message)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null)
- // TODO Debug output
+ if(jid_term == null) {
+ warn_if_reached();
return;
+ }
string jid = from_utf8(jid_term);
Eva.Atom type_term = match["Type"] as Eva.Atom;
- if(type_term == null)
- // TODO Debug output
+ if(type_term == null) {
+ warn_if_reached();
return;
+ }
string type = type_term.value;
Eva.Binary body_term = match["Body"] as Eva.Binary;
- if(body_term == null)
- // TODO Debug output
+ if(body_term == null) {
+ warn_if_reached();
return;
+ }
string body = from_utf8(body_term);
receive_message(jid, type, body);
}
- else if((match = term.match(Eva.parse("{sent_message,JID,Type,Body}"))) != null) {
+ else if((match = term.match(match_sent_message)) != null) {
Eva.Binary jid_term = match["JID"] as Eva.Binary;
- if(jid_term == null)
- // TODO Debug output
+ if(jid_term == null) {
+ warn_if_reached();
return;
+ }
string jid = from_utf8(jid_term);
Eva.Atom type_term = match["Type"] as Eva.Atom;
- if(type_term == null)
- // TODO Debug output
+ if(type_term == null) {
+ warn_if_reached();
return;
+ }
string type = type_term.value;
Eva.Binary body_term = match["Body"] as Eva.Binary;
- if(body_term == null)
- // TODO Debug output
+ if(body_term == null) {
+ warn_if_reached();
return;
+ }
string body = from_utf8(body_term);
sent_message(jid, type, body);