Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implemented GN_signal_connect! woo hoo.

git-svn-id: https://gtknode.googlecode.com/svn/trunk@25 9999ab98-4a1b-0410-ba6a-d90168ca9a37
  • Loading branch information...
commit 12b280a69f8a3265be1318b661898010570585e1 1 parent 89bd73a
@massemanet authored
View
1  c_src/gtknode.c
@@ -19,6 +19,7 @@ static void start_gtk(int argc, char **argv, int ErlFd){
/* initialise libraries */
gtk_init(&argc, &argv);
+ glade_xml_get_type();
/* watch the erlang distribution file descriptor */
channel = g_io_channel_unix_new(ErlFd);
View
8 c_src/gtknode.h
@@ -11,8 +11,9 @@ int gn_start_cnode(char **argv);
gboolean gn_handle_read(GIOChannel *source,GIOCondition cond,gpointer data);
/* called by all signals */
-void gn_sighandler(GtkWidget *widget);/* , gpointer user_data); */
-void gn_erl(GtkWidget *widget);/* , gpointer user_data); */
+void gn_sighandler(GtkWidget *widget);
+void gn_erl(GtkWidget *widget);
+void erl(GtkWidget *widget);
/* inits libglade */
gboolean gn_glade_init(char *filename);
@@ -64,6 +65,9 @@ gboolean gn_check_struct(ei_x_buff *xbuf,
gchar* struct_name, gchar* struct_type, void** pp);
gboolean gn_check_arity(ei_x_buff *xbuf, int a1, int a2);
+void gn_store_obj(gchar *bf, GObject *w);
+
+
gint gn_get_list(ei_x_buff *xbuf, char *buff, int *index);
gint gn_get_tuple(ei_x_buff *xbuf, char *buff, int *index);
View
18 c_src/gtknode_glade.c
@@ -10,18 +10,26 @@ gboolean gn_glade_init(char *filename) {
return TRUE;
}
-void erl(GtkWidget *widget){
+void erl(GtkWidget *widget) {
const char *widgetname;
+ gchar bf[24];
GSignalInvocationHint *ihint = g_signal_get_invocation_hint(widget);
const gchar *signalname = g_signal_name(ihint->signal_id);
- if ( ! (widgetname = glade_get_widget_name(widget)) )
- widgetname = "UNKNOWN";
- gn_send_signal(widgetname, signalname);
+
+ g_message("g_quark_from_static_string %i",g_quark_from_static_string("GladeXML::name"));
+ if ( (widgetname = glade_get_widget_name(widget)) ) {
+ g_message("gn_send_signal_1");
+ gn_send_signal(widgetname, signalname);
+ } else {
+ gn_store_obj(bf,G_OBJECT (widget));
+ gn_send_signal(bf, signalname);
+ }
+ g_message("erl");
}
void gn_erl(GtkWidget *widget){
- erl(widget);
+ erl(widget);
}
void gn_sighandler(GtkWidget *widget){
erl(widget);
View
16 c_src/gtknode_internal.c
@@ -242,3 +242,19 @@ gboolean GN_widget_get_attr(int ARI, ei_x_buff *XBUF, char *B, int *I) {
}
return TRUE;
}
+
+gboolean GN_signal_connect(int ARI, ei_x_buff *XBUF, char *B, int *I) {
+ gchar signal[MAXATOMLEN+1];
+ GtkWidget* widget;
+
+ if ( ! gn_check_arity(XBUF, 2, ARI) ) return FALSE;
+ if ( ! gn_get_arg_object(XBUF, B, I, GTK_TYPE_WIDGET, (GObject**)&widget) )
+ return FALSE;
+ if ( ! gn_get_arg_gchar_fix(XBUF, B, I, signal) ) return FALSE;
+
+ g_signal_connect (G_OBJECT (widget), signal, G_CALLBACK (erl), NULL);
+
+ gn_put_void(XBUF);
+
+ return TRUE;
+}
View
17 c_src/gtknode_marshal.c
@@ -151,14 +151,21 @@ void gn_put_string(ei_x_buff *xbuf, char *p) {
}
}
+void gn_store_obj(gchar *bf, GObject *w) {
+
+ sprintf(bf,"%d", (long)w);
+ if ( ! hash_lookup(bf) ) {
+ /* ref all objs that are sent to erl to avoid garbing */
+ g_object_ref(w);
+ hash_insert(bf, (void*)w);
+ }
+}
+
void gn_put_object(ei_x_buff *xbuf, GObject *w) {
gchar bf[24];
-
+
if ( G_IS_OBJECT(w) ){
- /* ref all objs that are returned to erl to avoid garbing */
- g_object_ref(w);
- g_assert( (sprintf(bf,"%d", (long)w) < sizeof(bf)) );
- hash_insert(bf, (void*)w);
+ gn_store_obj(bf,w);
} else if ( w == 0 ) {
memcpy(bf,"NULL",5);
} else {
View
63 src/gtknode.erl
@@ -18,6 +18,7 @@
-record(st,{gtk_port=[],client_pid=[],handler_pid=[],gtk_pid=[],name=[]}).
-define(BORED, 5000).
+-define(LOG(T), log(process_info(self()),T)).
%%%-------------------------------------------------------------------
%%% runs in client process
@@ -68,9 +69,9 @@ initDBGH() ->
loopDBGH() ->
receive
{gtknode_dbg, {signal, Sig}} ->
- io:fwrite("signal - ~p~n", [Sig]),loopDBGH();
+ ?LOG({signal,Sig}),loopDBGH();
{gtknode_dbg, {reply, Rep}} ->
- io:fwrite("reply - ~p~n", [Rep]),loopDBGH();
+ ?LOG({reply,Rep}),loopDBGH();
{cmd,quit} ->
gtknode_dbg ! quit;
{cmd, Cmd} ->
@@ -104,10 +105,10 @@ init(Client, Name) ->
process_flag(trap_exit,true),
register(Name, self()),
Client ! started,
- Port = start_gtkNode(Name),
+ Port = start_gtknode(Name),
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]).
make_cmd(Name) ->
@@ -131,7 +132,9 @@ erl_dist_vsn() ->
["5","1"|_] -> 7;
["5","2"|_] -> 8;
["5","3"|_] -> 9;
- _ -> 10
+ ["5","4"|_] ->10;
+ ["5","5"|_] ->11;
+ _ -> 12
end.
string_join([Pref|Toks], Sep) ->
@@ -146,10 +149,10 @@ waiting_handshake(St = #st{gtk_port=Port}) ->
idle(St#st{gtk_pid=GtkPid});
{Port,PortData} -> %from the port
waiting_handshake(handle_portdata(St, PortData));
- {'EXIT',Port,_Reason} -> %port died, us too
- die(St#st{gtk_port=[]});
+ {'EXIT',Port,Reason} -> %port died, us too
+ die({port_died,Reason});
quit ->
- die(St)
+ die(quitting)
after
?BORED -> waiting_handshake(bored(waiting_handshake,St))
end.
@@ -157,55 +160,57 @@ waiting_handshake(St = #st{gtk_port=Port}) ->
idle(St = #st{gtk_pid=GtkPid, gtk_port=Port, handler_pid=HandPid}) ->
receive
{{GtkPid, signal}, Sig} ->
- %%from gtkNode
+ %%from gtknode
HandPid ! {St#st.name, {signal, Sig}},
idle(St);
{Pid,CmdArgs} when pid(Pid) ->
%%from client
GtkPid ! CmdArgs,
- waiting(St#st{client_pid = Pid});
+ waiting(St#st{client_pid = Pid},CmdArgs);
{Port,PortData} ->
%%from the port
idle(handle_portdata(St, PortData));
- {'EXIT',HandPid,_Reason} ->
+ {'EXIT',HandPid,Reason} ->
%%handler died
- die(St#st{handler_pid=[]});
- {'EXIT',Port,_Reason} ->
+ die({handler_died,Reason});
+ {'EXIT',Port,Reason} ->
%%port died, us too
- die(St#st{gtk_port=[]});
+ die({port_died,Reason});
quit ->
- die(St)
+ die(quitting)
end.
-waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port}) ->
+waiting(St = #st{gtk_pid=GtkPid, gtk_port=Port},CmdArgs) ->
receive
- {{GtkPid,reply}, Ans}-> %from gtkNode
+ {{GtkPid,reply}, Ans}-> %from gtknode
St#st.client_pid ! {St#st.name, {reply,Ans}},
idle(St#st{client_pid = []});
{Port,{data,PortData}} -> %from the port
- waiting(handle_portdata(St, PortData));
- {'EXIT',Port,_Reason} -> %port died, us too
- die(St#st{gtk_port=[]});
+ waiting(handle_portdata(St, PortData),CmdArgs);
+ {'EXIT',Port,Reason} -> %port died, us too
+ die({port_died,{Reason,CmdArgs}});
quit ->
- die(St)
+ die(quitting)
after
- ?BORED -> waiting(bored(waiting,St))
+ ?BORED -> waiting(bored(waiting,St),CmdArgs)
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
handle_portdata(St, PortData) ->
case PortData of
- {data, Str} -> io:fwrite("~w - portdata - ~s~n", [?MODULE, Str]);
- _ -> io:fwrite("~w - portdata - ~p~n", [?MODULE, PortData])
+ {data, Str} -> ?LOG({portdata, Str});
+ _ -> ?LOG({portdata,PortData})
end,
St.
bored(State,St) ->
- io:fwrite("~w - bored - ~p~n~p~n~p~n",
- [?MODULE, State, St, process_info(self(),messages)]),
+ ?LOG([{bored,State}, {state,St}, {msgs,process_info(self(),messages)}]),
St.
-die(_St) ->
- io:fwrite("~w - terminating~n", [?MODULE]),
+die(Reason) ->
process_flag(trap_exit,false),
- exit(dying).
+ exit({dying,Reason}).
+
+log(ProcInfo,Term) when not is_list(Term) -> log(ProcInfo,[Term]);
+log(ProcInfo,List) ->
+ error_logger:info_report([{in,CF}||{current_function,CF}<-ProcInfo]++List).
Please sign in to comment.
Something went wrong with that request. Please try again.