class Coolio::StatWatcher
Public Class Methods
Create a new Coolio::StatWatcher
for the given path. This will monitor the 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 Coolio_StatWatcher_initialize(int argc, VALUE *argv, VALUE self) { VALUE path, interval; struct Coolio_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 Coolio_Watcher, watcher_data); watcher_data->dispatch_callback = Coolio_StatWatcher_dispatch_callback; ev_stat_init( &watcher_data->event_types.ev_stat, Coolio_StatWatcher_libev_callback, RSTRING_PTR(path), interval == Qnil ? 0 : NUM2DBL(interval) ); watcher_data->event_types.ev_stat.data = (void *)self; return Qnil; }
Public Instance Methods
Attach the stat watcher to the given Coolio::Loop
. If the watcher is already attached to a loop, detach it from the old one and attach it to the new one.
static VALUE Coolio_StatWatcher_attach(VALUE self, VALUE loop) { ev_tstamp interval, timeout; struct Coolio_Loop *loop_data; struct Coolio_Watcher *watcher_data; if(!rb_obj_is_kind_of(loop, cCoolio_Loop)) rb_raise(rb_eArgError, "expected loop to be an instance of Coolio::Loop, not %s", RSTRING_PTR(rb_inspect(loop))); Data_Get_Struct(loop, struct Coolio_Loop, loop_data); Data_Get_Struct(self, struct Coolio_Watcher, watcher_data); if(watcher_data->loop != Qnil) Coolio_StatWatcher_detach(self); watcher_data->loop = loop; ev_stat_start(loop_data->ev_loop, &watcher_data->event_types.ev_stat); rb_call_super(1, &loop); return self; }
Detach the stat watcher from its current Coolio::Loop
.
static VALUE Coolio_StatWatcher_detach(VALUE self) { Watcher_Detach(stat, self); return self; }
Temporarily disable a stat watcher which is attached to a loop. This is useful if you wish to toggle event monitoring on and off.
static VALUE Coolio_StatWatcher_disable(VALUE self) { Watcher_Disable(stat, self); return self; }
Re-enable a stat watcher which has been temporarily disabled. See the disable method for a more thorough explanation.
static VALUE Coolio_StatWatcher_enable(VALUE self) { Watcher_Enable(stat, self); return self; }
Called whenever the status of the given path changes
static VALUE Coolio_StatWatcher_on_change(VALUE self, VALUE previous, VALUE current) { return Qnil; }
Retrieve the path associated with this StatWatcher
static VALUE Coolio_StatWatcher_path(VALUE self) { return rb_iv_get(self, "@path"); }