ext/rev/rev_stat_watcher.c in rev-0.3.0 vs ext/rev/rev_stat_watcher.c in rev-0.3.1

- old
+ new

@@ -14,11 +14,11 @@ static VALUE mRev = Qnil; static VALUE cRev_Watcher = Qnil; static VALUE cRev_StatWatcher = Qnil; static VALUE cRev_Loop = Qnil; -static VALUE Rev_StatWatcher_initialize(VALUE self, VALUE path); +static VALUE Rev_StatWatcher_initialize(int argc, VALUE *argv, VALUE self); static VALUE Rev_StatWatcher_attach(VALUE self, VALUE loop); static VALUE Rev_StatWatcher_detach(VALUE self); static VALUE Rev_StatWatcher_enable(VALUE self); static VALUE Rev_StatWatcher_disable(VALUE self); static VALUE Rev_StatWatcher_on_change(VALUE self); @@ -37,41 +37,51 @@ mRev = rb_define_module("Rev"); cRev_Watcher = rb_define_class_under(mRev, "Watcher", rb_cObject); cRev_StatWatcher = rb_define_class_under(mRev, "StatWatcher", cRev_Watcher); cRev_Loop = rb_define_class_under(mRev, "Loop", rb_cObject); - rb_define_method(cRev_StatWatcher, "initialize", Rev_StatWatcher_initialize, 1); + rb_define_method(cRev_StatWatcher, "initialize", Rev_StatWatcher_initialize, -1); rb_define_method(cRev_StatWatcher, "attach", Rev_StatWatcher_attach, 1); rb_define_method(cRev_StatWatcher, "detach", Rev_StatWatcher_detach, 0); rb_define_method(cRev_StatWatcher, "enable", Rev_StatWatcher_enable, 0); rb_define_method(cRev_StatWatcher, "disable", Rev_StatWatcher_disable, 0); rb_define_method(cRev_StatWatcher, "on_change", Rev_StatWatcher_on_change, 0); rb_define_method(cRev_StatWatcher, "path", Rev_StatWatcher_path, 0); } /** * call-seq: - * Rev::StatWatcher.initialize(path) -> Rev::StatWatcher + * Rev::StatWatcher.initialize(path, interval = 0) -> Rev::StatWatcher * * Create a new Rev::StatWatcher for the given path. This will monitor the - * given path for changes at the filesystem level. + * given path for changes at the filesystem level. The interval argument + * specified how often in seconds the path should be polled for changes. + * Setting interval to zero uses an "automatic" value (typically around 5 + * seconds) which optimizes performance. Otherwise, values less than + * 0.1 are not particularly meaningful. Where available (at present, on Linux) + * high performance file monitoring interfaces will be used instead of polling. */ -static VALUE Rev_StatWatcher_initialize(VALUE self, VALUE path) +static VALUE Rev_StatWatcher_initialize(int argc, VALUE *argv, VALUE self) { + VALUE path, interval; struct Rev_Watcher *watcher_data; + rb_scan_args(argc, argv, "11", &path, &interval); + if(interval != Qnil) + interval = rb_convert_type(interval, T_FLOAT, "Float", "to_f"); + path = rb_String(path); rb_iv_set(self, "@path", path); Data_Get_Struct(self, struct Rev_Watcher, watcher_data); watcher_data->dispatch_callback = Rev_StatWatcher_dispatch_callback; ev_stat_init( &watcher_data->event_types.ev_stat, Rev_StatWatcher_libev_callback, RSTRING_PTR(path), - 0 + interval == Qnil ? 0 : NUM2DBL(interval) ); watcher_data->event_types.ev_stat.data = (void *)self; return Qnil; } @@ -177,6 +187,6 @@ /* Rev::Loop dispatch callback */ static void Rev_StatWatcher_dispatch_callback(VALUE self, int revents) { rb_funcall(self, rb_intern("on_change"), 0, 0); -} \ No newline at end of file +}