summaryrefslogtreecommitdiffstats
path: root/src/core/ephraim.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ephraim.erl')
-rw-r--r--src/core/ephraim.erl30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl
index 6a68de0..7be93d2 100644
--- a/src/core/ephraim.erl
+++ b/src/core/ephraim.erl
@@ -4,7 +4,7 @@
-record(state, {
conn :: pid(),
convs :: dict(),
- guis :: set()
+ uis :: set()
}).
-spec start() -> ok.
@@ -13,7 +13,8 @@ start() ->
case register(ephraim, Pid) of
true ->
ok
- end.
+ end,
+ open_port({spawn_executable, "ephraim-gtk"}, [stream, use_stdio, out]).
-spec stop() -> ok.
stop() ->
@@ -23,11 +24,12 @@ stop() ->
-spec init() -> ok.
init() ->
Conn = spawn(ephraim_conn, init, []),
- loop(#state{conn=Conn,convs=dict:new(),guis=sets:new()}).
+ loop(#state{conn=Conn,convs=dict:new(),uis=sets:new()}),
+ init:stop().
-spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()}.
get_conv(State, JID) ->
- Key = exmpp_jid:to_lower(exmpp_jid:bare(JID)),
+ Key = exmpp_jid:to_lower(JID),
case dict:find(Key, State#state.convs) of
{ok, Conv} ->
{State, Conv};
@@ -44,13 +46,21 @@ loop(State) ->
dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs),
State#state.conn ! stop,
ok;
- {register_gui, Pid} ->
- GUIs = State#state.guis,
- State2 = State#state{guis=sets:add_element(Pid,GUIs)},
+ {register_ui, Pid} ->
+ io:format("Registered UI ~p~n", [Pid]),
+ UIs = State#state.uis,
+ State2 = State#state{uis=sets:add_element(Pid,UIs)},
loop(State2);
- {unregister_gui, Pid} ->
- GUIs = State#state.guis,
- State2 = State#state{guis=sets:del_element(Pid,GUIs)},
+ {unregister_ui, Pid} ->
+ io:format("Unregistered UI ~p~n", [Pid]),
+ UIs = State#state.uis,
+ State2 = State#state{uis=sets:del_element(Pid,UIs)},
+ Size = sets:size(State2#state.uis),
+ if Size =:= 0 ->
+ self() ! stop;
+ true ->
+ ok
+ end,
loop(State2);
{receive_message, From, Packet} ->
{State2, Conv} = get_conv(State, From),