summaryrefslogtreecommitdiffstats
path: root/src/gui/CoreConnector.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/CoreConnector.vala')
-rw-r--r--src/gui/CoreConnector.vala53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
index 9edbc7d..fdd74ee 100644
--- a/src/gui/CoreConnector.vala
+++ b/src/gui/CoreConnector.vala
@@ -2,6 +2,12 @@ public class CoreConnector {
unowned Thread thread;
bool running;
+ Erl.Node node;
+ Erl.Connection con;
+ Erl.Term self;
+
+ Roster roster;
+
private class TermStore {
public Erl.Term term;
}
@@ -10,8 +16,9 @@ public class CoreConnector {
Erl.init();
}
- public CoreConnector() {
+ public CoreConnector(Roster roster0) {
running = false;
+ roster = roster0;
}
public bool start() {
@@ -20,6 +27,13 @@ public class CoreConnector {
running = true;
+ 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;
@@ -34,16 +48,12 @@ public class CoreConnector {
running = false;
thread.join();
+
+ con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self));
}
+
private void* receive() {
- Erl.Node node = Erl.Node("ephraim-gtk", "magiccookie", 0);
- Erl.Connection con = node.connect("ephraim-core@avalon.local");
-
- Erl.Term self = Erl.mk_self_pid(node);
-
- con.reg_send("ephraim", Erl.format("{register_ui,~w}", self));
-
while(running) {
TermStore response = new TermStore();
Erl.ReceiveType ret = con.receive(out response.term, 1000);
@@ -64,14 +74,31 @@ public class CoreConnector {
}
}
- con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self));
-
return null;
}
+ private Erl.Term? match(string pattern, Erl.Term term) {
+ Erl.Term pattern_term = Erl.format(pattern);
+
+ if(pattern_term.match(term) != 0)
+ return pattern_term;
+ else
+ return null;
+ }
+
private void handleTerm(TermStore store) {
- unowned Erl.Term term = store.term;
- Erl.print_term(stdout, term);
- stdout.printf("\n");
+ unowned Erl.Term term = store.term;
+ Erl.Term match_term;
+
+ if((match_term = match("{roster_update,JID,Resources}", term)) != null) {
+ Erl.Term JID_term = match_term.var_content("JID");
+ string JID = ((string)JID_term.bin_ptr()).ndup(JID_term.bin_size());
+
+ roster.update_contact(new Contact(JID));
+ }
+ else {
+ Erl.print_term(stdout, term);
+ stdout.printf("\n");
+ }
}
}