diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-06-15 09:44:39 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-06-15 09:44:39 +0200 |
commit | c3354ad1fd4f843d80ebdd290c8dbaf81919ca38 (patch) | |
tree | adcdb5c3e2484fcd3df66e7eba4446e4908484ec /ephraim.erl | |
parent | 3fe9171137838ede69a3a3e56dbc4b10049d9693 (diff) | |
download | ephraim-c3354ad1fd4f843d80ebdd290c8dbaf81919ca38.tar ephraim-c3354ad1fd4f843d80ebdd290c8dbaf81919ca38.zip |
Added type specs
Diffstat (limited to 'ephraim.erl')
-rw-r--r-- | ephraim.erl | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ephraim.erl b/ephraim.erl index 11ef8a8..60902da 100644 --- a/ephraim.erl +++ b/ephraim.erl @@ -3,20 +3,29 @@ -record(state, { conn :: pid(), - convs :: dict:dictionary() + convs :: dict(), + guis :: set() }). +-spec start() -> ok. start() -> Pid = spawn(?MODULE, init, []), - register(ephraim, Pid). + case register(ephraim, Pid) of + true -> + ok + end. +-spec stop() -> ok. stop() -> - ephraim ! stop. + ephraim ! stop, + ok. +-spec init() -> ok. init() -> Conn = spawn(ephraim_conn, init, []), - loop(#state{conn=Conn,convs=dict:new()}). + loop(#state{conn=Conn,convs=dict:new(),guis=sets:new()}). +-spec get_conv(#state{},exmpp_jid:jid()) -> {#state{},pid()}. get_conv(State, JID) -> case dict:find(JID, State#state.convs) of {ok, Conv} -> @@ -27,11 +36,21 @@ get_conv(State, JID) -> {State#state{convs=Dict}, Conv} end. +-spec loop(#state{}) -> ok. loop(State) -> receive stop -> dict:fold(fun(_,Conv,Msg) -> Conv ! Msg end, stop, State#state.convs), - State#state.conn ! stop; + State#state.conn ! stop, + ok; + {register_gui, Pid} -> + GUIs = State#state.guis, + State2 = State#state{guis=sets:add_element(Pid,GUIs)}, + loop(State2); + {unregister_gui, Pid} -> + GUIs = State#state.guis, + State2 = State#state{guis=sets:del_element(Pid,GUIs)}, + loop(State2); {receive_message, From, Packet} -> {State2, Conv} = get_conv(State, From), Conv ! {receive_message, Packet}, |