Skip to content

Commit

Permalink
version 0.32
Browse files Browse the repository at this point in the history
git-svn-id: https://gtknode.googlecode.com/svn/trunk@45 9999ab98-4a1b-0410-ba6a-d90168ca9a37
  • Loading branch information
massemanet committed Nov 5, 2007
1 parent 6b63060 commit e4a4581
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 128 deletions.
52 changes: 52 additions & 0 deletions ChangeLog
@@ -1,3 +1,55 @@
2006-10-09 Mats Cronqvist <locmacr@mwlx084>

* priv/generator/generator.erl: generation of doc links fixed


2007-02-13 mats cronqvist <mats.cronqvist@gmail.com>
* added support for a GTKNODE_BIN env to point out the c-node binary

2007-01-03 mats.cronqvist <mats.cronqvist@gmail.com>
* fixed a bug in doc link generation

2006-12-07 mats.cronqvist <mats.cronqvist@gmail.com>
* added clipboard handling infrastructure

2006-12-06 mats.cronqvist <mats.cronqvist@gmail.com>
* fixed examples. v0.30

2006-12-06 mats.cronqvist <mats.cronqvist@gmail.com>
* the c-node will chop up reply list in bits of 1,000, to alleviate
timeout problems.

2006-11-27 mats.cronqvist <mats.cronqvist@gmail.com>
* new gtknode:cmd
* added "hello" example

2006-11-27 mats.cronqvist <mats.cronqvist@gmail.com>
* implemented GN_signal_connect! woo hoo.

2006-11-21 mats.cronqvist <mats.cronqvist@gmail.com>
* doc

2006-11-21 mats.cronqvist <mats.cronqvist@gmail.com>
* treeview example finished

2006-11-21 mats.cronqvist <mats.cronqvist@gmail.com>
* spiffy new examples

2006-11-20 mats.cronqvist <mats.cronqvist@gmail.com>
* automake confusion

2006-11-20 mats.cronqvist <mats.cronqvist@gmail.com>
* bad error handling

2006-11-16 mats.cronqvist <mats.cronqvist@gmail.com>
* makefile tweaks

2006-11-02 mats.cronqvist <mats.cronqvist@gmail.com>
* sherk removal

2006-11-02 mats.cronqvist <mats.cronqvist@gmail.com>
* moved sherk to the eper project

2006-10-09 Mats Cronqvist <locmacr@mwlx084> 2006-10-09 Mats Cronqvist <locmacr@mwlx084>


* priv/generator/generator.erl: generation of doc links fixed * priv/generator/generator.erl: generation of doc links fixed
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,4 +1,4 @@
AC_INIT(GTK+ 2 wrapper library for Erlang, 0.30, AC_INIT(GTK+ 2 wrapper library for Erlang, 0.32,
mats.cronqvist@ericsson.com, gtknode) mats.cronqvist@ericsson.com, gtknode)
dnl Require autoconf version >=2.59c. first one with erlang macros dnl Require autoconf version >=2.59c. first one with erlang macros
AC_PREREQ(2.59c) AC_PREREQ(2.59c)
Expand Down
254 changes: 127 additions & 127 deletions src/gtknode.erl
Expand Up @@ -24,79 +24,79 @@
%%% runs in client process %%% runs in client process
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
start(Name) -> start(Name) ->
case whereis(Name) of case whereis(Name) of
undefined -> undefined ->
Self = self(), Self = self(),
Pid = spawn_link(fun() -> init(Self, Name) end), Pid = spawn_link(fun() -> init(Self, Name) end),
receive receive
started -> Pid; started -> Pid;
quit -> ok quit -> ok
end; end;
_ -> _ ->
{already_started,Name} {already_started,Name}
end. end.


stop(Pid) when is_pid(Pid) -> stop(Pid) when is_pid(Pid) ->
case is_process_alive(Pid) of case is_process_alive(Pid) of
true -> Pid ! quit; true -> Pid ! quit;
false -> {not_running,Pid} false -> {not_running,Pid}
end; end;
stop(Name) when is_atom(Name) -> stop(Name) when is_atom(Name) ->
case whereis(Name) of case whereis(Name) of
undefined -> {not_running,Name}; undefined -> {not_running,Name};
Pid -> stop(Pid) Pid -> stop(Pid)
end. end.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% for debugging, run gtknode:debug and start gtknode from a shell thusly; %%% for debugging, run gtknode:debug and start gtknode from a shell thusly;
%%% gtknode <erlnodename> <host> gtknode_dbg <cookie> nod <erl_dist_version> %%% gtknode <erlnodename> <host> gtknode_dbg <cookie> nod <erl_dist_version>
%%% E.g. bin/gtknode foo mwlx084 gtknode_dbg cki nod 11 %%% E.g. bin/gtknode foo mwlx084 gtknode_dbg cki nod 11
%%% send messages to the gtknode with gtknode:debug/2, thusly; %%% send messages to the gtknode with gtknode:debug/2, thusly;
%%% gtknode:dbg('GN_glade_init',["gladefile.glade"]). %%% gtknode:debug('GN_glade_init',["gladefile.glade"]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
debug(Cmd,Args) -> debug([{Cmd,Args}]). debug(Cmd,Args) -> debug([{Cmd,Args}]).
debug(CmdArgs) -> debug(CmdArgs) ->
catch debug(), catch debug(),
gtknode_dbgH ! {cmd, CmdArgs}, gtknode_dbgH ! {cmd, CmdArgs},
ok. ok.
debug() -> debug() ->
case whereis(gtknode_dbg) of case whereis(gtknode_dbg) of
undefined -> spawn(fun initDBG/0); undefined -> spawn(fun initDBG/0);
_ -> erlang:fault({already_started,gtknode_dbg}) _ -> erlang:fault({already_started,gtknode_dbg})
end. end.


initDBG() -> initDBG() ->
process_flag(trap_exit,true), process_flag(trap_exit,true),
register(gtknode_dbg, self()), register(gtknode_dbg, self()),
Handler = spawn_link(fun initDBGH/0), Handler = spawn_link(fun initDBGH/0),
waiting_handshake(#st{handler_pid=Handler, name=gtknode_dbg}). waiting_handshake(#st{handler_pid=Handler, name=gtknode_dbg}).


initDBGH() -> initDBGH() ->
register(gtknode_dbgH, self()), register(gtknode_dbgH, self()),
loopDBGH(). loopDBGH().


loopDBGH() -> loopDBGH() ->
receive receive
{gtknode_dbg, {signal, Sig}} -> {gtknode_dbg, {signal, Sig}} ->
?LOG({signal,Sig}),loopDBGH(); ?LOG({signal,Sig}),loopDBGH();
{gtknode_dbg, {reply, Rep}} -> {gtknode_dbg, {reply, Rep}} ->
?LOG({reply,Rep}),loopDBGH(); ?LOG({reply,Rep}),loopDBGH();
{cmd,quit} -> {cmd,quit} ->
gtknode_dbg ! quit; gtknode_dbg ! quit;
{cmd, Cmd} -> {cmd, Cmd} ->
gtknode_dbg ! {self(),Cmd},loopDBGH() gtknode_dbg ! {self(),Cmd},loopDBGH()
end. end.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cmd(GUI,C,As) -> cmd(GUI,[{C,As}]). cmd(GUI,C,As) -> cmd(GUI,[{C,As}]).


cmd(_GUI,[]) -> cmd(_GUI,[]) ->
{'EXIT',{foobar,St}} = (catch erlang:error(foobar)), ?LOG({empty,St}); {'EXIT',{foobar,St}} = (catch erlang:error(foobar)), ?LOG({empty,St});
cmd(GUI,CAs) -> cmd(GUI,CAs) ->
GUI ! {self(),CAs}, GUI ! {self(),CAs},
receive receive
{GUI,{reply,Reps}} -> filter_reps(Reps,CAs) {GUI,{reply,Reps}} -> filter_reps(Reps,CAs)
end. end.


filter_reps([{ok,Rep}],[_]) -> Rep; filter_reps([{ok,Rep}],[_]) -> Rep;
filter_reps([{ok,_}|Reps],[_|CAs]) -> filter_reps(Reps,CAs); filter_reps([{ok,_}|Reps],[_|CAs]) -> filter_reps(Reps,CAs);
Expand All @@ -118,14 +118,14 @@ filter_reps([{error,R}|_],[CA|_]) -> exit({gtknode_error,{R,CA}}).
%%% atom(quit) | EXIT signals %%% atom(quit) | EXIT signals
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
init(Client, Name) -> init(Client, Name) ->
process_flag(trap_exit,true), process_flag(trap_exit,true),
register(Name, self()), register(Name, self()),
Client ! started, Client ! started,
Port = start_gtknode(Name), Port = start_gtknode(Name),
waiting_handshake(#st{handler_pid=Client, name=Name, gtk_port=Port}). waiting_handshake(#st{handler_pid=Client, name=Name, gtk_port=Port}).


start_gtknode(Name) -> start_gtknode(Name) ->
open_port({spawn,make_cmd(Name)},[stderr_to_stdout,exit_status]). open_port({spawn,make_cmd(Name)},[stderr_to_stdout,exit_status]).


make_cmd(Name) -> make_cmd(Name) ->
[Node,Host] = string:tokens(atom_to_list(node()),"@"), [Node,Host] = string:tokens(atom_to_list(node()),"@"),
Expand All @@ -150,97 +150,97 @@ exe() ->
end. end.


erl_dist_vsn() -> erl_dist_vsn() ->
case string:tokens(erlang:system_info(version),".") of case string:tokens(erlang:system_info(version),".") of
[[X]|_] when X < $5-> throw({ancient_erl_version,[X]}); [[X]|_] when X < $5-> throw({ancient_erl_version,[X]});
["5","0"|_] -> 7; ["5","0"|_] -> 7;
["5","1"|_] -> 7; ["5","1"|_] -> 7;
["5","2"|_] -> 8; ["5","2"|_] -> 8;
["5","3"|_] -> 9; ["5","3"|_] -> 9;
["5","4"|_] ->10; ["5","4"|_] ->10;
["5","5"|_] ->11; ["5","5"|_] ->11;
_ -> 12 _ -> 12
end. end.


string_join([Pref|Toks], Sep) -> string_join([Pref|Toks], Sep) ->
lists:foldl(fun(Tok,O) -> O++Sep++Tok end, Pref, Toks). lists:foldl(fun(Tok,O) -> O++Sep++Tok end, Pref, Toks).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% the states; waiting_handshake, idle, waiting_reply %%% the states; waiting_handshake, idle, waiting_reply
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
waiting_handshake(St = #st{gtk_port=Port}) -> waiting_handshake(St = #st{gtk_port=Port}) ->
receive receive
{{GtkPid,handshake}, []} -> {{GtkPid,handshake}, []} ->
link(GtkPid), link(GtkPid),
idle(St#st{gtk_pid=GtkPid}); idle(St#st{gtk_pid=GtkPid});
{Port,PortData} -> %from the port {Port,PortData} -> %from the port
waiting_handshake(handle_portdata(St, PortData)); waiting_handshake(handle_portdata(St, PortData));
{'EXIT',Port,Reason} -> %port died, us too {'EXIT',Port,Reason} -> %port died, us too
die({port_died,Reason}); die({port_died,Reason});
quit -> quit ->
die(quitting) die(quitting)
after after
?BORED -> waiting_handshake(bored(waiting_handshake,St)) ?BORED -> waiting_handshake(bored(waiting_handshake,St))
end. end.


idle(St = #st{gtk_pid=GtkPid, gtk_port=Port, handler_pid=HandPid}) -> idle(St = #st{gtk_pid=GtkPid, gtk_port=Port, handler_pid=HandPid}) ->
receive receive
{{GtkPid, signal}, Sig} -> {{GtkPid, signal}, Sig} ->
%%from gtknode %%from gtknode
HandPid ! {St#st.name, {signal, Sig}}, HandPid ! {St#st.name, {signal, Sig}},
idle(St); idle(St);
{Pid,CmdArgs} when pid(Pid) -> {Pid,CmdArgs} when pid(Pid) ->
%%from client %%from client
GtkPid ! CmdArgs, GtkPid ! CmdArgs,
waiting(St#st{client_pid = Pid},CmdArgs,[]); waiting(St#st{client_pid = Pid},CmdArgs,[]);
{Port,PortData} -> {Port,PortData} ->
%%from the port %%from the port
idle(handle_portdata(St, PortData)); idle(handle_portdata(St, PortData));
{'EXIT',HandPid,Reason} -> {'EXIT',HandPid,Reason} ->
%%handler died %%handler died
die({handler_died,Reason}); die({handler_died,Reason});
{'EXIT',Port,Reason} -> {'EXIT',Port,Reason} ->
%%port died, us too %%port died, us too
die({port_died,Reason}); die({port_died,Reason});
quit -> quit ->
die(quitting) die(quitting)
end. end.


waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port},CmdArgs,OldReps) -> waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port},CmdArgs,OldReps) ->
receive receive
{{GtkPid,reply}, Ans}-> %from gtknode {{GtkPid,reply}, Ans}-> %from gtknode
case length(Reps=OldReps++Ans)-length(CmdArgs) of case length(Reps=OldReps++Ans)-length(CmdArgs) of
0 -> 0 ->
St#st.client_pid ! {St#st.name, {reply,Reps}}, St#st.client_pid ! {St#st.name, {reply,Reps}},
idle(St#st{client_pid = []}); idle(St#st{client_pid = []});
_ -> _ ->
waiting(St,CmdArgs,Reps) waiting(St,CmdArgs,Reps)
end; end;
{Port,{data,PortData}} -> %from the port {Port,{data,PortData}} -> %from the port
waiting(handle_portdata(St, PortData),CmdArgs,OldReps); waiting(handle_portdata(St, PortData),CmdArgs,OldReps);
{'EXIT',Port,Reason} -> %port died, us too {'EXIT',Port,Reason} -> %port died, us too
die({port_died,{Reason,CmdArgs}}); die({port_died,{Reason,CmdArgs}});
quit -> quit ->
die(quitting) die(quitting)
after after
?BORED -> waiting(bored(waiting,St),CmdArgs,OldReps) ?BORED -> waiting(bored(waiting,St),CmdArgs,OldReps)
end. end.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
handle_portdata(St, PortData) -> handle_portdata(St, PortData) ->
case PortData of case PortData of
{data, Str} -> ?LOG({portdata, Str}); {data, Str} -> ?LOG({portdata, Str});
_ -> ?LOG({portdata,PortData}) _ -> ?LOG({portdata,PortData})
end, end,
St. St.


bored(State,St) -> bored(State,St) ->
?LOG([{bored,State}, {state,St}, {msgs,process_info(self(),messages)}]), ?LOG([{bored,State}, {state,St}, {msgs,process_info(self(),messages)}]),
St. St.


die(quitting) -> ok; die(quitting) -> ok;
die(Reason) -> die(Reason) ->
process_flag(trap_exit,false), process_flag(trap_exit,false),
exit({dying,Reason}). exit({dying,Reason}).


log(ProcInfo,Term) when not is_list(Term) -> log(ProcInfo,[Term]); log(ProcInfo,Term) when not is_list(Term) -> log(ProcInfo,[Term]);
log(ProcInfo,List) -> log(ProcInfo,List) ->
error_logger:info_report([{in,CF}||{current_function,CF}<-ProcInfo]++List). error_logger:info_report([{in,CF}||{current_function,CF}<-ProcInfo]++List).

0 comments on commit e4a4581

Please sign in to comment.