ruby-changes:1850
From: ko1@a...
Date: 4 Sep 2007 20:49:12 +0900
Subject: [ruby-changes:1850] suke - Ruby:r13341 (trunk): * ext/win32ole/win32ole.c: add WIN32OLE_EVENT#unadvise.
suke 2007-09-04 20:48:53 +0900 (Tue, 04 Sep 2007) New Revision: 13341 Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/test/win32ole/test_win32ole_event.rb trunk/version.h Log: * ext/win32ole/win32ole.c: add WIN32OLE_EVENT#unadvise. * test/win32ole/test_win32ole_event.rb: ditto. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=13341&r2=13340 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_win32ole_event.rb?r1=13341&r2=13340 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13341&r2=13340 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/win32ole/win32ole.c?r1=13341&r2=13340 Index: ChangeLog =================================================================== --- ChangeLog (revision 13340) +++ ChangeLog (revision 13341) @@ -1,3 +1,9 @@ +Tue Sep 4 20:43:44 2007 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c: add WIN32OLE_EVENT#unadvise. + + * test/win32ole/test_win32ole_event.rb: ditto. + Mon Sep 3 15:37:09 2007 Nobuyoshi Nakada <nobu@r...> * common.mk (vm.o): depends on st.h too. Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 13340) +++ ext/win32ole/win32ole.c (revision 13341) @@ -116,7 +116,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.0.8" +#define WIN32OLE_VERSION "1.0.9" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -229,6 +229,7 @@ struct oleeventdata { DWORD dwCookie; IConnectionPoint *pConnectionPoint; + long event_id; }; struct oleparam { @@ -494,6 +495,11 @@ static VALUE ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg); static VALUE fev_on_event(int argc, VALUE *argv, VALUE self); static VALUE fev_on_event_with_outargs(int argc, VALUE *argv, VALUE self); +static VALUE fev_unadvise(VALUE self); +static VALUE evs_push(VALUE ev); +static VALUE evs_delete(long i); +static VALUE evs_entry(long i); +static VALUE evs_length(); static void olevariant_free(struct olevariantdata *pvar); static VALUE folevariant_s_allocate(VALUE klass); static VALUE folevariant_s_array(VALUE klass, VALUE dims, VALUE vvt); @@ -7071,8 +7077,7 @@ PIEVENTSINKOBJ pEV = (PIEVENTSINKOBJ)pEventSink; pTypeInfo = pEV->pTypeInfo; - - obj = rb_ary_entry(ary_ole_event, pEV->m_event_id); + obj = evs_entry(pEV->m_event_id); if (!rb_obj_is_kind_of(obj, cWIN32OLE_EVENT)) { return NOERROR; } @@ -7370,6 +7375,7 @@ obj = Data_Make_Struct(klass,struct oleeventdata,0,ole_event_free,poleev); poleev->dwCookie = 0; poleev->pConnectionPoint = NULL; + poleev->event_id = 0; return obj; } @@ -7444,10 +7450,11 @@ Data_Get_Struct(self, struct oleeventdata, poleev); pIEV->m_event_id - = NUM2INT(rb_funcall(ary_ole_event, rb_intern("length"), 0)); + = NUM2INT(evs_length()); pIEV->pTypeInfo = pTypeInfo; poleev->dwCookie = dwCookie; poleev->pConnectionPoint = pConnectionPoint; + poleev->event_id = pIEV->m_event_id; return self; } @@ -7466,7 +7473,7 @@ fev_initialize(int argc, VALUE *argv, VALUE self) { ev_advise(argc, argv, self); - rb_ary_push(ary_ole_event, self); + evs_push(self); rb_ivar_set(self, id_events, rb_ary_new()); return self; } @@ -7504,7 +7511,12 @@ static VALUE ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg) { + struct oleeventdata *poleev; VALUE event, args, data; + Data_Get_Struct(self, struct oleeventdata, poleev); + if (poleev->pConnectionPoint == NULL) { + rb_raise(eWIN32OLERuntimeError, "IConnectionPoint not found. You must call advise at first."); + } rb_scan_args(argc, argv, "01*", &event, &args); if(!NIL_P(event)) { Check_SafeStr(event); @@ -7544,6 +7556,48 @@ return ev_on_event(argc, argv, self, Qtrue); } +static VALUE +fev_unadvise(VALUE self) +{ + struct oleeventdata *poleev; + Data_Get_Struct(self, struct oleeventdata, poleev); + if (poleev->pConnectionPoint) { + poleev->pConnectionPoint->lpVtbl->Unadvise(poleev->pConnectionPoint, poleev->dwCookie); + OLE_RELEASE(poleev->pConnectionPoint); + poleev->pConnectionPoint = NULL; + + rb_ivar_set(self, id_events, rb_ary_new()); + evs_delete(poleev->event_id); + ole_msg_loop(); + } + return Qnil; +} + +static VALUE +evs_push(VALUE ev) +{ + return rb_ary_push(ary_ole_event, ev); +} + +static VALUE +evs_delete(long i) +{ + rb_ary_store(ary_ole_event, i, Qnil); + return Qnil; +} + +static VALUE +evs_entry(long i) +{ + return rb_ary_entry(ary_ole_event, i); +} + +static VALUE +evs_length() +{ + return rb_funcall(ary_ole_event, rb_intern("length"), 0); +} + static void olevariant_free(struct olevariantdata *pvar) { @@ -8153,6 +8207,7 @@ rb_define_method(cWIN32OLE_EVENT, "initialize", fev_initialize, -1); rb_define_method(cWIN32OLE_EVENT, "on_event", fev_on_event, -1); rb_define_method(cWIN32OLE_EVENT, "on_event_with_outargs", fev_on_event_with_outargs, -1); + rb_define_method(cWIN32OLE_EVENT, "unadvise", fev_unadvise, 0); cWIN32OLE_VARIANT = rb_define_class("WIN32OLE_VARIANT", rb_cObject); rb_define_alloc_func(cWIN32OLE_VARIANT, folevariant_s_allocate); Index: version.h =================================================================== --- version.h (revision 13340) +++ version.h (revision 13341) @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-09-03" +#define RUBY_RELEASE_DATE "2007-09-04" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20070903 +#define RUBY_RELEASE_CODE 20070904 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 3 +#define RUBY_RELEASE_DAY 4 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: test/win32ole/test_win32ole_event.rb =================================================================== --- test/win32ole/test_win32ole_event.rb (revision 13340) +++ test/win32ole/test_win32ole_event.rb (revision 13341) @@ -89,6 +89,26 @@ assert(@event!="") end + def test_unadvise + ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') + ev.on_event {|*args| default_handler(*args)} + @ie.navigate("file:///#{@f}") + while @ie.busy + sleep 0.1 + end + assert_match(/BeforeNavigate/, @event) + ev.unadvise + @event = "" + @ie.navigate("file:///#{@f}") + while @ie.busy + sleep 0.1 + end + assert_equal("", @event); + assert_raise(WIN32OLERuntimeError) { + ev.on_event {|*args| default_handler(*args)} + } + end + def handler1 @event2 = "handler1" end @@ -102,9 +122,9 @@ end def teardown - File.unlink(@f) @ie.quit @ie = nil + File.unlink(@f) GC.start end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml