summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 12:04:48 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-07-11 12:04:48 +0200
commit80ea35c67df70b6fd4f444c6f932b355ee245396 (patch)
tree8fc5719912fedf7b6cfdef3b02520a12eb2dce51 /src/core
parentad56d57251f67ac416ff7ad71a76f30836d2ccb3 (diff)
downloadephraim-80ea35c67df70b6fd4f444c6f932b355ee245396.tar
ephraim-80ea35c67df70b6fd4f444c6f932b355ee245396.zip
Migrated from erl_interface to Eva
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/ephraim.erl6
-rw-r--r--src/core/ephraim_gui.erl28
3 files changed, 33 insertions, 2 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index c49763c..9321f40 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -3,6 +3,7 @@ erl_target(ephraim-core
ephraim_conn.erl
ephraim_conv.erl
ephraim_event.erl
+ ephraim_gui.erl
ephraim_roster.erl
ephraim_util.erl
OPTIONS
diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl
index c0ab7ae..b32e1d7 100644
--- a/src/core/ephraim.erl
+++ b/src/core/ephraim.erl
@@ -5,6 +5,7 @@
conn :: pid(),
roster :: pid(),
event :: pid(),
+ gui :: pid(),
convs :: dict(),
uis :: set()
}).
@@ -22,12 +23,12 @@ stop() ->
-spec init() -> ok.
init() ->
register(ephraim, self()),
- open_port({spawn_executable, "ephraim-gtk"}, [stream, use_stdio, out]),
+ GUI = spawn(ephraim_gui, init, []),
Conn = spawn(ephraim_conn, init, []),
Roster = spawn(ephraim_roster, init, []),
Event = spawn(ephraim_event, init, []),
- loop(#state{conn=Conn,roster=Roster,event=Event,convs=dict:new(),uis=sets:new()}),
+ loop(#state{conn=Conn,roster=Roster,event=Event,gui=GUI,convs=dict:new(),uis=sets:new()}),
init:stop().
-spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()|undefined}.
@@ -59,6 +60,7 @@ loop(State) ->
State#state.conn ! stop,
State#state.roster ! stop,
State#state.event ! stop,
+ State#state.gui ! stop,
ok;
{register_ui, Pid} ->
diff --git a/src/core/ephraim_gui.erl b/src/core/ephraim_gui.erl
new file mode 100644
index 0000000..79433e0
--- /dev/null
+++ b/src/core/ephraim_gui.erl
@@ -0,0 +1,28 @@
+-module(ephraim_gui).
+-compile([debug_info, export_all]).
+
+-spec init() -> ok.
+init() ->
+ Port = open_port({spawn_executable, "ephraim-gtk"}, [binary, nouse_stdio, {packet, 4}]),
+ ephraim ! {register_ui, self()},
+ loop(Port),
+ ephraim ! {unregister_ui, self()}.
+
+-spec loop(port()) -> ok.
+loop(Port) ->
+ receive
+ stop ->
+ ok;
+ {Port, {data, Data}} ->
+ Msg = binary_to_term(Data),
+ case Msg of
+ stop ->
+ ok;
+ _ ->
+ ephraim ! Msg,
+ loop(Port)
+ end;
+ Msg ->
+ Port ! {self(), {command, term_to_binary(Msg)}},
+ loop(Port)
+ end.