ext/winevt/winevt_subscribe.c in winevt_c-0.4.7.rc2 vs ext/winevt/winevt_subscribe.c in winevt_c-0.5.0
- old
+ new
@@ -112,10 +112,13 @@
flags |= EvtSubscribeStartAtOldestRecord;
}
hSubscription = EvtSubscribe(NULL, hSignalEvent, path, query, hBookmark, NULL, NULL, flags);
+ ALLOCV_END(wpathBuf);
+ ALLOCV_END(wqueryBuf);
+
winevtSubscribe->signalEvent = hSignalEvent;
winevtSubscribe->subscription = hSubscription;
if (hBookmark) {
winevtSubscribe->bookmark = hBookmark;
} else {
@@ -191,23 +194,51 @@
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return get_values(winevtSubscribe->event);
}
static VALUE
+rb_winevt_subscribe_close_handle(VALUE self)
+{
+ struct WinevtSubscribe *winevtSubscribe;
+
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
+
+ if (winevtSubscribe->event != NULL) {
+ EvtClose(winevtSubscribe->event);
+ }
+
+ return Qnil;
+}
+
+static VALUE
+rb_winevt_subscribe_each_yield(VALUE self)
+{
+ struct WinevtSubscribe *winevtSubscribe;
+
+ RETURN_ENUMERATOR(self, 0, 0);
+
+ TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
+
+ rb_yield_values(3,
+ rb_winevt_subscribe_render(self),
+ rb_winevt_subscribe_message(self),
+ rb_winevt_subscribe_string_inserts(self));
+
+ return Qnil;
+}
+
+static VALUE
rb_winevt_subscribe_each(VALUE self)
{
struct WinevtSubscribe *winevtSubscribe;
RETURN_ENUMERATOR(self, 0, 0);
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
while (rb_winevt_subscribe_next(self)) {
- rb_yield_values(3,
- rb_winevt_subscribe_render(self),
- rb_winevt_subscribe_message(self),
- rb_winevt_subscribe_string_inserts(self));
+ rb_ensure(rb_winevt_subscribe_each_yield, self, rb_winevt_subscribe_close_handle, self);
}
return Qnil;
}
@@ -236,9 +267,10 @@
rb_define_method(rb_cSubscribe, "next", rb_winevt_subscribe_next, 0);
rb_define_method(rb_cSubscribe, "render", rb_winevt_subscribe_render, 0);
rb_define_method(rb_cSubscribe, "message", rb_winevt_subscribe_message, 0);
rb_define_method(rb_cSubscribe, "string_inserts", rb_winevt_subscribe_string_inserts, 0);
rb_define_method(rb_cSubscribe, "each", rb_winevt_subscribe_each, 0);
+ rb_define_method(rb_cSubscribe, "close_handle", rb_winevt_subscribe_close_handle, 0);
rb_define_method(rb_cSubscribe, "bookmark", rb_winevt_subscribe_get_bookmark, 0);
rb_define_method(rb_cSubscribe, "tail?", rb_winevt_subscribe_tail_p, 0);
rb_define_method(rb_cSubscribe, "tail=", rb_winevt_subscribe_set_tail, 1);
}