summaryrefslogtreecommitdiffstats
path: root/src/gui/CoreConnector.vala
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-06-17 13:07:17 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-06-17 13:07:17 +0200
commitbdaae5b6704e29919ec7f284b9e3abe54f96f2f8 (patch)
tree75b3860a2cea86ec7e55d978730b13e41c8015da /src/gui/CoreConnector.vala
parentca7a0bfa5dd63fc45df0a46800a76d7048e70f2b (diff)
downloadephraim-bdaae5b6704e29919ec7f284b9e3abe54f96f2f8.tar
ephraim-bdaae5b6704e29919ec7f284b9e3abe54f96f2f8.zip
Added CMake build system
Diffstat (limited to 'src/gui/CoreConnector.vala')
-rw-r--r--src/gui/CoreConnector.vala73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala
new file mode 100644
index 0000000..08ed43f
--- /dev/null
+++ b/src/gui/CoreConnector.vala
@@ -0,0 +1,73 @@
+public class CoreConnector {
+ unowned Thread thread;
+ bool running;
+
+ private class TermStore {
+ public Erl.Term term;
+ }
+
+ static construct {
+ Erl.init();
+ }
+
+ public CoreConnector() {
+ running = false;
+ }
+
+ public bool start() {
+ if(running)
+ return true;
+
+ running = true;
+
+ try {
+ thread = Thread.create(receive, true);
+ return true;
+ } catch(ThreadError e) {
+ return false;
+ }
+ }
+
+ public void stop() {
+ if(!running)
+ return;
+
+ running = false;
+ thread.join();
+ }
+
+ private void* receive() {
+ Erl.Node node = Erl.Node("ephraim-gtk", "magiccookie", 0);
+ Erl.Connection con = node.connect("ephraim-core@avalon.local");
+
+ con.reg_send("ephraim", Erl.mk_self_pid(node));
+
+ while(running) {
+ TermStore response = new TermStore();
+ Erl.ReceiveType ret = con.receive(out response.term, 1000);
+
+ switch(ret) {
+ case Erl.ReceiveType.ERROR:
+ if(Erl.errno == Erl.Error.TIMEDOUT)
+ break;
+
+ running = false;
+ break;
+ case Erl.ReceiveType.TICK:
+ // Do nothing
+ break;
+ case Erl.ReceiveType.MSG:
+ Idle.add(() => {handleTerm(response); return false;});
+ break;
+ }
+ }
+
+ return null;
+ }
+
+ private void handleTerm(TermStore store) {
+ unowned Erl.Term term = store.term;
+ Erl.print_term(stdout, term);
+ stdout.printf("\n");
+ }
+}