diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ephraim.erl | 30 | ||||
-rw-r--r-- | src/core/ephraim_conv.erl | 4 | ||||
-rwxr-xr-x | src/ephraim | 3 | ||||
-rw-r--r-- | src/gui/CoreConnector.vala | 6 |
4 files changed, 31 insertions, 12 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) -> diff --git a/src/ephraim b/src/ephraim new file mode 100755 index 0000000..5a6b8b8 --- /dev/null +++ b/src/ephraim @@ -0,0 +1,3 @@ +#!/bin/sh + +erl -pa core -name ephraim-core@avalon.local -setcookie magiccookie -run ephraim diff --git a/src/gui/CoreConnector.vala b/src/gui/CoreConnector.vala index 08ed43f..9edbc7d 100644 --- a/src/gui/CoreConnector.vala +++ b/src/gui/CoreConnector.vala @@ -40,7 +40,9 @@ public class CoreConnector { 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)); + Erl.Term self = Erl.mk_self_pid(node); + + con.reg_send("ephraim", Erl.format("{register_ui,~w}", self)); while(running) { TermStore response = new TermStore(); @@ -62,6 +64,8 @@ public class CoreConnector { } } + con.reg_send("ephraim", Erl.format("{unregister_ui,~w}", self)); + return null; } |