ext/wdm/rb_monitor.c in wdm-0.0.3 vs ext/wdm/rb_monitor.c in wdm-0.1.0

- old
+ new

@@ -58,11 +58,12 @@ static VALUE rb_monitor_stop(VALUE); // ---------------------------------------------------------- static void -monitor_mark(LPVOID param) { +monitor_mark(LPVOID param) +{ WDM_PMonitor monitor; WDM_PEntry entry; monitor = (WDM_PMonitor)param; entry = monitor->head; @@ -72,11 +73,12 @@ entry = entry->next; } } static void -monitor_free(LPVOID param) { +monitor_free(LPVOID param) +{ WDM_PMonitor monitor; WDM_PEntry entry; WDM_DEBUG("Freeing a monitor object!"); @@ -96,23 +98,25 @@ wdm_monitor_free(monitor); } static VALUE -rb_monitor_alloc(VALUE self) { +rb_monitor_alloc(VALUE self) +{ WDM_DEBUG("--------------------------------"); WDM_DEBUG("Allocating a new monitor object!"); WDM_DEBUG("--------------------------------"); return Data_Wrap_Struct(self, monitor_mark, monitor_free, wdm_monitor_new()); } static DWORD -id_to_flag(ID id) { +id_to_flag(ID id) +{ if ( id == wdm_rb_sym_default ) return WDM_MONITOR_FLAGS_DEFAULT; - // TODO: Maybe reorder the if's in the frequentie of use for better performance? + // TODO: Maybe reorder the if's in the frequency of use for better performance? if ( id == wdm_rb_sym_files ) return FILE_NOTIFY_CHANGE_FILE_NAME; if ( id == wdm_rb_sym_directories ) return FILE_NOTIFY_CHANGE_DIR_NAME; if ( id == wdm_rb_sym_attributes ) return FILE_NOTIFY_CHANGE_ATTRIBUTES; if ( id == wdm_rb_sym_size ) return FILE_NOTIFY_CHANGE_SIZE; if ( id == wdm_rb_sym_last_write ) return FILE_NOTIFY_CHANGE_LAST_WRITE; @@ -122,11 +126,12 @@ rb_raise(eWDM_UnknownFlagError, "Unknown watch flag: ':%s'", rb_id2name(id)); } static DWORD -extract_flags_from_rb_array(VALUE flags_array) { +extract_flags_from_rb_array(VALUE flags_array) +{ VALUE flag_symbol; DWORD flags; flags = 0; @@ -138,11 +143,12 @@ return flags; } static VALUE -combined_watch(BOOL recursively, int argc, VALUE *argv, VALUE self) { +combined_watch(BOOL recursively, int argc, VALUE *argv, VALUE self) +{ WDM_PMonitor monitor; WDM_PEntry entry; int directory_letters_count; VALUE directory, flags, os_encoded_directory; BOOL running; @@ -235,16 +241,18 @@ return Qnil; } static VALUE -rb_monitor_watch(int argc, VALUE *argv, VALUE self) { +rb_monitor_watch(int argc, VALUE *argv, VALUE self) +{ return combined_watch(FALSE, argc, argv, self); } static VALUE -rb_monitor_watch_recursively(int argc, VALUE *argv, VALUE self) { +rb_monitor_watch_recursively(int argc, VALUE *argv, VALUE self) +{ return combined_watch(TRUE, argc, argv, self); } static void CALLBACK handle_entry_change( @@ -254,11 +262,11 @@ ) { WDM_PMonitorCallbackParam param; WDM_PQueueItem data_to_process; if ( err_code == ERROR_OPERATION_ABORTED ) { - // Async operation was canceld. This shouldn't happen. + // Async operation was canceled. This shouldn't happen. // TODO: // 1. Maybe add a union in the queue for errors? // 2. What's the best action when this happens? WDM_DEBUG("Dir handler closed in the process callback!"); return; @@ -291,11 +299,12 @@ SetEvent(param->monitor->process_event); } } static BOOL -register_monitoring_entry(WDM_PEntry entry) { +register_monitoring_entry(WDM_PEntry entry) +{ BOOL success; DWORD bytes; bytes = 0; // Not used because the process callback gets passed the written bytes success = ReadDirectoryChangesW( @@ -316,11 +325,12 @@ return TRUE; } static DWORD WINAPI -start_monitoring(LPVOID param) { +start_monitoring(LPVOID param) +{ WDM_PMonitor monitor; WDM_PEntry curr_entry; monitor = (WDM_PMonitor)param; curr_entry = monitor->head; @@ -359,20 +369,22 @@ return 0; } static VALUE -wait_for_changes(LPVOID param) { +wait_for_changes(LPVOID param) +{ HANDLE process_event; process_event = (HANDLE)param; return WaitForSingleObject(process_event, INFINITE) == WAIT_OBJECT_0 ? Qtrue : Qfalse; } static void -process_changes(WDM_PQueue changes) { +process_changes(WDM_PQueue changes) +{ WDM_PQueueItem item; LPBYTE current_info_entry_offset; PFILE_NOTIFY_INFORMATION info; VALUE event; @@ -410,11 +422,12 @@ wdm_queue_item_free(item); } } static void -stop_monitoring(LPVOID param) { +stop_monitoring(LPVOID param) +{ BOOL already_stopped; WDM_PMonitor monitor; WDM_PEntry entry; monitor = (WDM_PMonitor)param; @@ -447,12 +460,12 @@ SetEvent(monitor->process_event); // The process code checks after the wait for an exit signal WaitForSingleObject(monitor->monitoring_thread, 10000); } static VALUE -rb_monitor_run_bang(VALUE self) { - DWORD thread_id; +rb_monitor_run_bang(VALUE self) +{ BOOL already_running, waiting_succeeded; WDM_PMonitor monitor; WDM_DEBUG("Running the monitor!"); @@ -482,11 +495,11 @@ NULL, // default security attributes 0, // use default stack size start_monitoring, // thread function name monitor, // argument to thread function 0, // use default creation flags - &thread_id // returns the thread identifier + NULL // Ignore thread identifier ); if ( monitor->monitoring_thread == NULL ) { rb_raise(eWDM_Error, "Can't create a thread for the monitor!"); } @@ -512,11 +525,12 @@ return Qnil; } static VALUE -rb_monitor_stop(VALUE self) { +rb_monitor_stop(VALUE self) +{ WDM_PMonitor monitor; Data_Get_Struct(self, WDM_Monitor, monitor); stop_monitoring(monitor); @@ -525,10 +539,11 @@ return Qnil; } void -wdm_rb_monitor_init() { +wdm_rb_monitor_init() +{ WDM_DEBUG("Registering WDM::Monitor with Ruby!"); wdm_rb_sym_call = rb_intern("call"); wdm_rb_sym_files = rb_intern("files"); wdm_rb_sym_directories = rb_intern("directories"); \ No newline at end of file