summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-06-17 16:23:15 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-06-17 16:23:15 +0200
commit0671f09eb9c44aae49bb438a19a1de3abd1c0202 (patch)
tree8e081dc433fbeb784ddeef8f46b51ab9a107a0e1 /src/core
parentbdaae5b6704e29919ec7f284b9e3abe54f96f2f8 (diff)
downloadephraim-0671f09eb9c44aae49bb438a19a1de3abd1c0202.tar
ephraim-0671f09eb9c44aae49bb438a19a1de3abd1c0202.zip
Improved interaction between core and GUI
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ephraim.erl30
-rw-r--r--src/core/ephraim_conv.erl4
2 files changed, 23 insertions, 11 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),
diff --git a/src/core/ephraim_conv.erl b/src/core/ephraim_conv.erl
index 99c7668..00b2bc1 100644
--- a/src/core/ephraim_conv.erl
+++ b/src/core/ephraim_conv.erl
@@ -7,7 +7,9 @@
-spec init(exmpp_jid:jid()) -> ok.
init(JID) ->
- loop(#conv_state{jid=JID}).
+ io:format("Starting a conversation with ~p~n", [JID]),
+ loop(#conv_state{jid=JID}),
+ io:format("Stopping a conversation with ~p~n", [JID]).
-spec loop(#conv_state{}) -> ok.
loop(State) ->