ext/winevt/winevt_subscribe.c in winevt_c-0.7.4 vs ext/winevt/winevt_subscribe.c in winevt_c-0.8.0

- old
+ new

@@ -88,10 +88,11 @@ winevtSubscribe->lastTime = 0; winevtSubscribe->currentRate = 0; winevtSubscribe->renderAsXML = TRUE; winevtSubscribe->readExistingEvents = TRUE; winevtSubscribe->preserveQualifiers = FALSE; + winevtSubscribe->localeInfo = &default_locale; return Qnil; } /* @@ -343,16 +344,16 @@ return render_system_event(event, winevtSubscribe->preserveQualifiers); } } static VALUE -rb_winevt_subscribe_message(EVT_HANDLE event) +rb_winevt_subscribe_message(EVT_HANDLE event, LocaleInfo* localeInfo) { WCHAR* wResult; VALUE utf8str; - wResult = get_description(event); + wResult = get_description(event, localeInfo->langID); utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1); free(wResult); return utf8str; } @@ -391,11 +392,11 @@ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe); for (int i = 0; i < winevtSubscribe->count; i++) { rb_yield_values(3, rb_winevt_subscribe_render(self, winevtSubscribe->hEvents[i]), - rb_winevt_subscribe_message(winevtSubscribe->hEvents[i]), + rb_winevt_subscribe_message(winevtSubscribe->hEvents[i], winevtSubscribe->localeInfo), rb_winevt_subscribe_string_inserts(winevtSubscribe->hEvents[i])); } return Qnil; } @@ -552,10 +553,52 @@ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe); return winevtSubscribe->preserveQualifiers ? Qtrue : Qfalse; } +/* + * This method specifies locale with [String]. + * + * @since 0.8.0 + * @param rb_locale_str [String] + */ +static VALUE +rb_winevt_subscribe_set_locale(VALUE self, VALUE rb_locale_str) +{ + struct WinevtSubscribe* winevtSubscribe; + LocaleInfo* locale_info = &default_locale; + + TypedData_Get_Struct( + self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe); + + locale_info = get_locale_from_rb_str(rb_locale_str); + + winevtSubscribe->localeInfo = locale_info; + + return Qnil; +} + +/* + * This method obtains specified locale with [String]. + * + * @since 0.8.0 + */ +static VALUE +rb_winevt_subscribe_get_locale(VALUE self) +{ + struct WinevtSubscribe* winevtSubscribe; + + TypedData_Get_Struct( + self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe); + + if (winevtSubscribe->localeInfo->langCode) { + return rb_str_new2(winevtSubscribe->localeInfo->langCode); + } else { + return rb_str_new2(default_locale.langCode); + } +} + void Init_winevt_subscribe(VALUE rb_cEventLog) { rb_cSubscribe = rb_define_class_under(rb_cEventLog, "Subscribe", rb_cObject); @@ -594,6 +637,16 @@ /* * @since 0.7.3 */ rb_define_method( rb_cSubscribe, "preserve_qualifiers=", rb_winevt_subscribe_set_preserve_qualifiers, 1); + /* + * @since 0.8.0 + */ + rb_define_method( + rb_cSubscribe, "locale", rb_winevt_subscribe_get_locale, 0); + /* + * @since 0.8.0 + */ + rb_define_method( + rb_cSubscribe, "locale=", rb_winevt_subscribe_set_locale, 1); }