From b9145a8161071bee25c6c1c026fbc2381bdfa0bb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 21 Jun 2010 23:12:44 +0200 Subject: Show roster --- src/core/ephraim.erl | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'src/core/ephraim.erl') diff --git a/src/core/ephraim.erl b/src/core/ephraim.erl index 7be93d2..dc8382d 100644 --- a/src/core/ephraim.erl +++ b/src/core/ephraim.erl @@ -2,19 +2,15 @@ -compile([debug_info, export_all]). -record(state, { - conn :: pid(), - convs :: dict(), - uis :: set() + conn :: pid(), + roster :: pid(), + convs :: dict(), + uis :: set() }). -spec start() -> ok. start() -> - Pid = spawn(?MODULE, init, []), - case register(ephraim, Pid) of - true -> - ok - end, - open_port({spawn_executable, "ephraim-gtk"}, [stream, use_stdio, out]). + spawn(?MODULE, init, []). -spec stop() -> ok. stop() -> @@ -23,8 +19,12 @@ stop() -> -spec init() -> ok. init() -> + register(ephraim, self()), + open_port({spawn_executable, "ephraim-gtk"}, [stream, use_stdio, out]), + Conn = spawn(ephraim_conn, init, []), - loop(#state{conn=Conn,convs=dict:new(),uis=sets:new()}), + Roster = spawn(ephraim_roster, init, []), + loop(#state{conn=Conn,roster=Roster,convs=dict:new(),uis=sets:new()}), init:stop(). -spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()}. @@ -43,14 +43,18 @@ get_conv(State, JID) -> loop(State) -> receive stop -> - dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs), + %dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs), + ephraim_util:send_all_values(State#state.convs, stop), State#state.conn ! stop, + State#state.roster ! stop, ok; + {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_ui, Pid} -> io:format("Unregistered UI ~p~n", [Pid]), UIs = State#state.uis, @@ -62,10 +66,29 @@ loop(State) -> ok end, loop(State2); + + {ui_update, Msg} -> + ephraim_util:send_all(sets:to_list(State#state.uis), Msg), + loop(State); + + {roster, Packet} -> + State#state.roster ! Packet, + loop(State); + {receive_message, From, Packet} -> {State2, Conv} = get_conv(State, From), Conv ! {receive_message, Packet}, loop(State2); + + {receive_iq, IQ} -> + case IQ of + {iq, response, result, _, 'jabber:iq:roster', Payload, _, _, 'jabber:client'} -> + State#state.roster ! {roster_iq, Payload}; + _ -> + io:format("ephraim: IQ: ~p~n", [IQ]) + end, + loop(State); + Msg -> io:format("ephraim: ~p~n", [Msg]), loop(State) -- cgit v1.2.3