summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2010-06-15 09:44:39 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2010-06-15 09:44:39 +0200
commitc3354ad1fd4f843d80ebdd290c8dbaf81919ca38 (patch)
treeadcdb5c3e2484fcd3df66e7eba4446e4908484ec
parent3fe9171137838ede69a3a3e56dbc4b10049d9693 (diff)
downloadephraim-c3354ad1fd4f843d80ebdd290c8dbaf81919ca38.tar
ephraim-c3354ad1fd4f843d80ebdd290c8dbaf81919ca38.zip
Added type specs
-rw-r--r--ephraim.erl29
-rw-r--r--ephraim_conn.erl3
-rw-r--r--ephraim_conv.erl4
3 files changed, 30 insertions, 6 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},
diff --git a/ephraim_conn.erl b/ephraim_conn.erl
index 211db4d..18edd6a 100644
--- a/ephraim_conn.erl
+++ b/ephraim_conn.erl
@@ -7,6 +7,7 @@
roster :: any()
}).
+-spec init() -> ok.
init() ->
application:start(exmpp),
Session = exmpp_session:start(),
@@ -15,11 +16,13 @@ init() ->
exmpp_session:connect_TCP(Session, "jabber.ccc.de", 5222),
session(#conn_state{session=Session}).
+-spec session(#conn_state{}) -> ok.
session(State) ->
exmpp_session:login(State#conn_state.session),
exmpp_session:send_packet(State#conn_state.session, exmpp_presence:set_status(exmpp_presence:available(), "Foo/Test\\Bar")),
loop(State).
+-spec loop(#conn_state{}) -> ok.
loop(State) ->
receive
stop ->
diff --git a/ephraim_conv.erl b/ephraim_conv.erl
index d28cef8..99c7668 100644
--- a/ephraim_conv.erl
+++ b/ephraim_conv.erl
@@ -2,12 +2,14 @@
-compile([debug_info, export_all]).
-record(conv_state, {
- jid :: binary()
+ jid :: exmpp_jid:jid()
}).
+-spec init(exmpp_jid:jid()) -> ok.
init(JID) ->
loop(#conv_state{jid=JID}).
+-spec loop(#conv_state{}) -> ok.
loop(State) ->
receive
stop ->