Re: Re: Gtk::input_add() for a popen() filehandle?
| From: | Andrei Zmievski | Date: | Tue, 09 Apr 2002 17:28:20 +0000 |
| Subject: | Re: Re: Gtk::input_add() for a popen() filehandle? | ||
| References: | 1 2 3 4 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-1766@lists.php.net to get a copy of this message | ||
Try this one. It works, but for some reason keeps calling the callback
function even after the data has ended. I will investigate:
On Tue, 09 Apr 2002, Alan Knowles wrote:
> I'm not getting anywhere with this :) - and it's getting late. (this is
> using php-gtk CVS and php4.2Rc2)
> - simple proof of concept: press the button, and the program is supposed
> to do a fopen or popen, and add a callback.
>
>
> Am I missing something here....
> regards
> alan
>
>
> <?
> error_reporting(E_ALL);
> dl('php_gtk.'.(strstr(PHP_OS, 'WIN') ? 'dll' : 'so'));
>
> class MyClass {
>
> var $window;
> var $pixmap;
> var $mask;
> var $w;
>
> function build() {
> $this->window = &new GtkWindow();
> $this->window->set_position(GTK_WIN_POS_CENTER);
> $this->window->set_name('my_window');
> $this->window->connect_object('destroy', array('gtk',
> 'main_quit'));
> $this->box = &new GtkVbox();
> $this->window->add($this->box);
>
> $this->gtktext = &new GtkText();
> $this->box->add($this->gtktext);
>
> $this->button = &new GtkButton("press me");
> $this->button->connect("pressed",array(&$this,"pressed"));
> $this->box->add($this->button);
>
> $this->window->show_all();
> }
> function pressed() {
> echo "starting something";
> $fp = fopen("/home/alan/access.log","r");
> Gtk::input_add($fp, GDK_INPUT_READ, array(&$this,"reader"));
>
> }
> function reader($a,$b,$c) {
> echo "got something";
> echo serialize(array($a,$b,$c));
> }
> }
>
> $gui = new MyClass;
> $gui->build();
>
> gtk::main();
> ?>
>
> Andrei Zmievski wrote:
>
> >On Thu, 04 Apr 2002, James Cameron wrote:
> >
> >>On Wed, Apr 03, 2002 at 01:13:02PM -0600, Andrei Zmievski wrote:
> >>
> >>>Okay, the patch I sent out should work for PHP 4.3.0-dev. I tested it.
> >>>By the way, Cameron, are you calling gtk::main() in your sample script?
> >>>
> >>James. Yep, definitely. Without calling that I didn't think anything
> >>would show on screen.
> >>
> >>Thanks for the patch, I will adopt it for my Linux systems, but for
> >>Windows I'll have to wait for a new Win32 binary kit, as I do not have
> >>the build tools mentioned in win32/README.win32.txt .
> >>
> >>I'll probably just ship .BAT files to my customer in the meanwhile,
> >>rather than a GUI.
> >>
> >
> >You can ask if anyone on the list can build it for you.
> >
> >-Andrei
> >* DOS is, quite possibly, the worst text-adventure game ever. *
> >
>
>
-Andrei
* I am a legend in my spare time. *
? Makefile.global ? scan_makefile_in.awk ? test.php ? include ? Makefile.objects ? input.diff ? test/.gdbinit Index: ext/gtk+/gtk.overrides =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtk.overrides,v retrieving revision 1.49 diff -u -2 -b -w -B -r1.49 gtk.overrides --- ext/gtk+/gtk.overrides 3 Apr 2002 19:13:35 -0000 1.49 +++ ext/gtk+/gtk.overrides 9 Apr 2002 17:27:47 -0000 @@ -320,5 +320,5 @@ callback_lineno = zend_get_executed_lineno(TSRMLS_C); extra = php_gtk_func_args_as_hash(ZEND_NUM_ARGS(), 3, ZEND_NUM_ARGS()); - data = php_gtk_build_value("(VNsi)", callback, extra, callback_filename, callback_lineno); + data = php_gtk_build_value("(VVNsi)", callback, source_rsrc, extra, callback_filename, callback_lineno); RETURN_LONG(gtk_input_add_full(source, condition, NULL, (GtkCallbackMarshal)php_gtk_input_marshal, Index: main/php_gtk_object.c =================================================================== RCS file: /repository/php-gtk/main/php_gtk_object.c,v retrieving revision 1.48 diff -u -2 -b -w -B -r1.48 php_gtk_object.c --- main/php_gtk_object.c 12 Jan 2002 00:11:42 -0000 1.48 +++ main/php_gtk_object.c 9 Apr 2002 17:27:47 -0000 @@ -292,4 +292,5 @@ zval *retval = NULL, **callback, **extra = NULL; zval **callback_filename = NULL, **callback_lineno = NULL; + zval **source_rsrc = NULL; zval ***input_args; char *callback_name; @@ -297,7 +298,8 @@ zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&extra); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&callback_filename); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_lineno); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&source_rsrc); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&extra); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_filename); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 4, (void **)&callback_lineno); if (!php_gtk_is_callable(*callback, 0, &callback_name)) { @@ -308,4 +310,9 @@ params = php_gtk_args_as_hash(nargs, args); + /* + * We substitute the first argument with the actual resource zval. + */ + zval_add_ref(source_rsrc); + zend_hash_index_update(Z_ARRVAL_P(params), 0, (void*)source_rsrc, sizeof(zval *), NULL); if (extra) php_array_merge(Z_ARRVAL_P(params), Z_ARRVAL_PP(extra), 0);
? Makefile.global ? scan_makefile_in.awk ? test.php ? include ? Makefile.objects ? input.diff ? test/.gdbinit Index: ext/gtk+/gtk.overrides =================================================================== RCS file: /repository/php-gtk/ext/gtk+/gtk.overrides,v retrieving revision 1.49 diff -u -2 -b -w -B -r1.49 gtk.overrides --- ext/gtk+/gtk.overrides 3 Apr 2002 19:13:35 -0000 1.49 +++ ext/gtk+/gtk.overrides 9 Apr 2002 17:27:47 -0000 @@ -320,5 +320,5 @@ callback_lineno = zend_get_executed_lineno(TSRMLS_C); extra = php_gtk_func_args_as_hash(ZEND_NUM_ARGS(), 3, ZEND_NUM_ARGS()); - data = php_gtk_build_value("(VNsi)", callback, extra, callback_filename, callback_lineno); + data = php_gtk_build_value("(VVNsi)", callback, source_rsrc, extra, callback_filename, callback_lineno); RETURN_LONG(gtk_input_add_full(source, condition, NULL, (GtkCallbackMarshal)php_gtk_input_marshal, Index: main/php_gtk_object.c =================================================================== RCS file: /repository/php-gtk/main/php_gtk_object.c,v retrieving revision 1.48 diff -u -2 -b -w -B -r1.48 php_gtk_object.c --- main/php_gtk_object.c 12 Jan 2002 00:11:42 -0000 1.48 +++ main/php_gtk_object.c 9 Apr 2002 17:27:47 -0000 @@ -292,4 +292,5 @@ zval *retval = NULL, **callback, **extra = NULL; zval **callback_filename = NULL, **callback_lineno = NULL; + zval **source_rsrc = NULL; zval ***input_args; char *callback_name; @@ -297,7 +298,8 @@ zend_hash_index_find(Z_ARRVAL_P(callback_data), 0, (void **)&callback); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&extra); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&callback_filename); - zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_lineno); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 1, (void **)&source_rsrc); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 2, (void **)&extra); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 3, (void **)&callback_filename); + zend_hash_index_find(Z_ARRVAL_P(callback_data), 4, (void **)&callback_lineno); if (!php_gtk_is_callable(*callback, 0, &callback_name)) { @@ -308,4 +310,9 @@ params = php_gtk_args_as_hash(nargs, args); + /* + * We substitute the first argument with the actual resource zval. + */ + zval_add_ref(source_rsrc); + zend_hash_index_update(Z_ARRVAL_P(params), 0, (void*)source_rsrc, sizeof(zval *), NULL); if (extra) php_array_merge(Z_ARRVAL_P(params), Z_ARRVAL_PP(extra), 0);