Skip to content

Commit

Permalink
revisao final, e adicao da janela lateral
Browse files Browse the repository at this point in the history
  • Loading branch information
thadeurc committed Oct 23, 2009
1 parent 948789c commit 832ee09
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 70 deletions.
49 changes: 49 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MAC5765 - T�picos em Sistemas de Computa��o - Segundo Semestre de 2009
Programa��o Funcional Contempor�nea

EP1 - Exerc�cio-Programa 1: Melhorias no IRC Lite do Armstrong

Alunos: Sergio Lopes e Thadeu de Russo e Carmo

Instru��es
----------
Para compilar os arquivos fontes erlang, basta chamar no diret�rio ep1-sergio-thadeu o comando make. Uma vez que este comando tenha sido executado,
os arquivos *.beam ser�o criados. Al�m disso, o arquivo lib_chan.conf ser� copiado para ${HOME}/.erlang.config.

Para iniciar a execu��o do servidor de chat, basta executar o comando make chat_server.

Para iniciar a execu��o dos clientes do chat, existem 3 alternativas diferentes:

1) make chat_client. Esta chamada ir� criar 6 clientes divididos em 2 groups (general, e general2);
2) No diret�rio do ep, executar erl para iniciar a execu��o do erlang, e logo em seguida chamar chat_client:start(). Isso ir� executar
um cliente com o nome joe, no grupo general;
3) No diret�rio do ep, executar erl para iniciar a execu��o do erlang, e logo em seguida chamar chat_client:start(Grupo, Usuario), onde
Grupo � o grupo que se deseja entrar, e Usuario, o nome do usu�rio. E.g.: chat_client:start("esportes", "Pedro").

Segue abaixo as intru��es espec�ficas para cada um dos itens solicitados:

1- "Improve the graphics widged, adding a side panel to list the names of the people in the current group."
Basta entrar na aplica��o que o painel ser� mostrado ao lado direito da janela de conversa. O painel � atualiado automaticamente para novos usu�rios
que fa�am login no grupo, ou deixem o mesmo.

2- "Add code to show the names of all people in a group."
Na caixa de escrita para envio de mensagem, basta digitar o comando : show_group_members:<grupo>, onde <grupo> � o nome do grupo que se deseja ver os
integrantes. E.g.: jow> show_group_members:general. O resultado � listado na janela de conversa.

3- "Add code to list all the groups."
Na caixa de escrita para envio de mensagem, basta digitar o comando : show_groups E.g.: jow> show_groups. O resultado � listado na janela de conversa.

4- "Add person to person conversations".
Na caixa de escrita para envio de mensagem, basta digitar o comando : to:<pessoa> ! <mensagem>, onde <pessoa> � uma <pessoa> no grupo corrente e <mensagem>
� a pr�pria mensagem. E.g.: to:joe ! ola, como vai? O resultado � mostrado na janela de quem recebeu e enviou a mensagem.

5- "Add code so that the server machine does not run the group controller but so that this functionality is provided by the first user to join the system in a
particular group."
** Este item nao foi implementado.


Coment�rios gerais:
-------------------

Os arquivos da biblioteca de comunica��o (lib_*), n�o sofreram nenhum tipo de altera��o. Estas se concentram nos arquivos io_widget.erl, chat_server.erl,
chat_client.erl, chat_group_controller.erl. Basicamente novas mensagens foram adicionadas, e seu tratamento.
39 changes: 6 additions & 33 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,17 @@
.erl.beam:
erlc -W $<

## to test lib_chan
## make server in one window
## make client in the other window

MODS = any_apply \
chat_client chat_group chat_server\
io_widget kvs\
lib_chan lib_chan_mm lib_chan_cs lib_chan_test\
lib_chan_auth \
mod_echo mod_math mod_chat_controller mod_name_server\
test1 test_name_server mod_srpc
MODS = chat_client chat_group chat_server\
io_widget \
lib_chan lib_chan_mm lib_chan_cs\
lib_chan_auth lib_md5\
mod_echo mod_math mod_chat_controller mod_name_server


ERL = erl -boot start_clean

all: compile
@echo "To run the chat test program"
@echo " 1) start two xterms"
@echo " 2) in xterm one type -- make chat_server"
@echo " 3) in xterm two type -- make chat_client"
@echo " Note: remember to type make in the directory above this"
@echo " before running make in this directory"
@echo "To run the lib_chan test program"
@echo " 1) start two xterms"
@echo " 2) in xterm one type -- make server"
@echo " 3) in xterm two type -- make client"
@echo " Ignore any output in the server window"
@echo " The results of the test are printed in the client window"


compile: ${MODS:%=%.beam}
mkdir -p ${HOME}/.erlang_config/
cp conf ${HOME}/.erlang_config/lib_chan.conf
Expand All @@ -40,17 +22,8 @@ compile: ${MODS:%=%.beam}
chat_client: compile
erl -pa ../ -s chat_client test

test: compile
erl -s chat_tests start

chat_server: compile
erl -pa ../ -s chat_server start

server: compile
erl -pa ../ -boot start_clean -pa '.' -s lib_chan_test start_server

client: compile
erl -pa ../ -boot start_clean -pa '.' -s lib_chan_test start_client

clean:
rm -rf *.beam erl_crash.dump
18 changes: 14 additions & 4 deletions src/chat_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@

-import(io_widget,
[get_state/1, insert_str/2, set_prompt/2, set_state/2,
set_title/2, set_handler/2, update_state/3]).

-export([start/0, test/0, connect/5]).
set_title/2, set_handler/2, update_state/3, update_list/2]).

-export([start/0, start/2, test/0, connect/5]).

start() ->
connect("localhost", 2223, "AsDT67aQ", "general", "joe").

start(Group, User) ->
connect("localhost", 2223, "AsDT67aQ", Group, User).




test() ->
connect("localhost", 2223, "AsDT67aQ", "general", "joe"),
connect("localhost", 2223, "AsDT67aQ", "general2", "jane"),
connect("localhost", 2223, "AsDT67aQ", "general2", "jim"),
connect("localhost", 2223, "AsDT67aQ", "general", "john"),
connect("localhost", 2223, "AsDT67aQ", "general2", "peter"),
connect("localhost", 2223, "AsDT67aQ", "general", "sue").


Expand All @@ -36,7 +42,7 @@ handler(Host, Port, HostPsw, Group, Nick) ->
set_state(Widget, Nick),
set_prompt(Widget, [Nick, " > "]),
set_handler(Widget, fun parse_command/1),
start_connector(Host, Port, HostPsw),
start_connector(Host, Port, HostPsw),
disconnected(Widget, Group, Nick).


Expand Down Expand Up @@ -89,6 +95,10 @@ active(Widget, MM, Group) ->
T = [names(X) || X <- L],
insert_str(Widget, ["(",Group, ") members: " ++ T, "\n"]),
active(Widget, MM, Group);
{chan, MM, {new_list, L}} ->
T = [names(X) || X <- L],
update_list(Widget, T),
active(Widget, MM, Group);
{chan, MM, {list_groups_reply, L}} ->
T = [groups(X) || X <- L],
insert_str(Widget, ["Groups: " ++ T, "\n"]),
Expand Down
5 changes: 4 additions & 1 deletion src/chat_group.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ group_controller(ServerPid, L) ->
controller(C, self()),
send(C, ack),
self() ! {chan, C, {relay, Nick, "I'm joining the group"}},
group_controller(ServerPid, [{C,Nick}|L]);
L1 = [{C,Nick}|L],
foreach(fun({Pid,_}) -> send(Pid, {new_list,L1}) end, L1),
group_controller(ServerPid, L1);
{chan_closed, C} ->
{Nick, L1} = delete(C, L, []),
self() ! {chan, C, {relay, Nick, "I'm leaving the group"}},
foreach(fun({Pid,_}) -> send(Pid, {new_list,L1}) end, L1),
group_controller(ServerPid, L1);
{chan, C, {list_all, Group}} ->
lib_chan_mm:send(ServerPid, {self(), C, list_all, Group}),
Expand Down
2 changes: 1 addition & 1 deletion src/chat_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

start() ->
start_server(),
lib_chan:start_server("/Users/thadeurc/Erlang-Chat/src/chat.conf").
lib_chan:start_server("chat.conf").

start_server() ->
register(chat_server,
Expand Down
42 changes: 12 additions & 30 deletions src/io_widget.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
-module(io_widget).

-export([get_state/1,
start/1, test/0,
start/1,
set_handler/2,
set_prompt/2,
set_state/2,
set_title/2, insert_str/2, update_state/3]).
set_title/2, insert_str/2, update_state/3, update_list/2]).

start(Pid) ->
gs:start(),
Expand All @@ -25,6 +25,7 @@ set_handler(Pid, Fun) -> Pid ! {handler, Fun}.
set_prompt(Pid, Str) -> Pid ! {prompt, Str}.
set_state(Pid, State) -> Pid ! {state, State}.
insert_str(Pid, Str) -> Pid ! {insert, Str}.
update_list(Pid, L) -> Pid ! {update_list, L}.
update_state(Pid, N, X) -> Pid ! {updateState, N, X}.

rpc(Pid, Q) ->
Expand All @@ -35,14 +36,14 @@ rpc(Pid, Q) ->
end.

widget(Pid) ->
Size = [{width,500},{height,200}],
Size = [{width,600},{height,200}],
Win = gs:window(gs:start(),
[{map,true},{configure,true},{title,"window"}|Size]),
gs:frame(packer, Win,[{packer_x, [{stretch,1,500}]},
{packer_y, [{stretch,10,120,100},
{stretch,1,15,15}]}]),
gs:frame(packer, Win,[{packer_x, [{stretch,70},{stretch,30}]},
{packer_y, [{stretch,90},{stretch,10}]}]),
gs:create(editor,editor,packer, [{pack_x,1},{pack_y,1},{vscroll,right}]),
gs:create(entry, entry, packer, [{pack_x,1},{pack_y,2},{keypress,true}]),
gs:create(listbox, listbox, packer, [{pack_x, 2},{pack_y,{1, 2}}, {vscroll,right},{hscroll,bottom}, {click,false},{doubleclick,false}]),
gs:config(packer, Size),
Prompt = " > ",
State = nil,
Expand All @@ -57,8 +58,6 @@ loop(Win, Pid, Prompt, State, Parse) ->
{handler, Fun} ->
loop(Win, Pid, Prompt, State, Fun);
{prompt, Str} ->
%% this clobbers the line being input ...
%% this could be fixed - hint
gs:config(entry, {delete,{0,last}}),
gs:config(entry, {insert,{0,Str}}),
loop(Win, Pid, Str, State, Parse);
Expand All @@ -71,6 +70,9 @@ loop(Win, Pid, Prompt, State, Parse) ->
gs:config(editor, {insert,{'end',Str}}),
scroll_to_show_last_line(),
loop(Win, Pid, Prompt, State, Parse);
{update_list, L} ->
gs:config(listbox, {items,L}),
loop(Win, Pid, Prompt, State, Parse);
{updateState, N, X} ->
io:format("setelemtn N=~p X=~p Satte=~p~n",[N,X,State]),
State1 = setelement(N, State, X),
Expand All @@ -79,8 +81,7 @@ loop(Win, Pid, Prompt, State, Parse) ->
io:format("Destroyed~n",[]),
exit(windowDestroyed);
{gs, entry,keypress,_,['Return'|_]} ->
Text = gs:read(entry, text),
%% io:format("Read:~p~n",[Text]),
Text = gs:read(entry, text),
gs:config(entry, {delete,{0,last}}),
gs:config(entry, {insert,{0,Prompt}}),
try Parse(Text) of
Expand Down Expand Up @@ -110,26 +111,7 @@ scroll_to_show_last_line() ->
true -> gs:config(editor, {vscrollpos, 0})
end.

test() ->
spawn(fun() -> test1() end).

test1() ->
W = io_widget:start(self()),
io_widget:set_title(W, "Test window"),
loop(W).

loop(W) ->
receive
{W, {str, Str}} ->
Str1 = Str ++ "\n",
io_widget:insert_str(W, Str1),
loop(W)
end.

parse(Str) ->
{str, Str}.






2 changes: 1 addition & 1 deletion src/lib_chan_mm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trace_with_tag(Pid, Tag) ->
end}).

loop(Socket, Pid) ->
trace_with_tag(self(), trace),
%trace_with_tag(self(), trace),
process_flag(trap_exit, true),
loop1(Socket, Pid, false).

Expand Down

0 comments on commit 832ee09

Please sign in to comment.