Class: Winevt::EventLog::Subscribe
- Inherits:
-
Object
- Object
- Winevt::EventLog::Subscribe
- Defined in:
- lib/winevt/subscribe.rb,
ext/winevt/winevt.c,
ext/winevt/winevt_subscribe.c
Instance Method Summary collapse
- #bookmark ⇒ Object
- #each ⇒ Object
- #each_raw ⇒ Object
- #initialize ⇒ Object constructor
- #message ⇒ Object
- #next ⇒ Object
- #render ⇒ Object
- #string_inserts ⇒ Object
- #subscribe(*args) ⇒ Object
- #tail=(rb_tailing_p) ⇒ Object
- #tail?(rb_flag) ⇒ Boolean
Constructor Details
#initialize ⇒ Object
43 44 45 46 47 |
# File 'ext/winevt/winevt_subscribe.c', line 43
static VALUE
rb_winevt_subscribe_initialize(VALUE self)
{
return Qnil;
}
|
Instance Method Details
#bookmark ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'ext/winevt/winevt_subscribe.c', line 205
static VALUE
rb_winevt_subscribe_get_bookmark(VALUE self)
{
char* result;
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
result = render_event(winevtSubscribe->bookmark, EvtRenderBookmark);
return rb_str_new2(result);
}
|
#each ⇒ Object
186 187 188 189 190 191 192 |
# File 'ext/winevt/winevt_subscribe.c', line 186 def each each_raw do |xml, , string_inserts| = .gsub(/(%\d+)/, '\1$s') = sprintf(, *string_inserts) rescue .gsub(/(%\d+)/, "?") yield(xml, , string_inserts) end end |
#each_raw ⇒ Object
4 |
# File 'lib/winevt/subscribe.rb', line 4 alias_method :each_raw, :each |
#message ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'ext/winevt/winevt_subscribe.c', line 165
static VALUE
rb_winevt_subscribe_message(VALUE self)
{
char* result;
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
result = get_description(winevtSubscribe->event);
return rb_utf8_str_new_cstr(result);
}
|
#next ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/winevt/winevt_subscribe.c', line 134
static VALUE
rb_winevt_subscribe_next(VALUE self)
{
EVT_HANDLE event;
ULONG count;
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
if (EvtNext(winevtSubscribe->subscription, 1, &event, INFINITE, 0, &count) != FALSE) {
winevtSubscribe->event = event;
EvtUpdateBookmark(winevtSubscribe->bookmark, winevtSubscribe->event);
return Qtrue;
}
return Qfalse;
}
|
#render ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'ext/winevt/winevt_subscribe.c', line 153
static VALUE
rb_winevt_subscribe_render(VALUE self)
{
char* result;
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
result = render_event(winevtSubscribe->event, EvtRenderEventXml);
return rb_utf8_str_new_cstr(result);
}
|
#string_inserts ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'ext/winevt/winevt_subscribe.c', line 177
static VALUE
rb_winevt_subscribe_string_inserts(VALUE self)
{
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return get_values(winevtSubscribe->event);
}
|
#subscribe(*args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ext/winevt/winevt_subscribe.c', line 71
static VALUE
rb_winevt_subscribe_subscribe(int argc, VALUE *argv, VALUE self)
{
VALUE rb_path, rb_query, rb_bookmark;
EVT_HANDLE hSubscription = NULL, hBookmark = NULL;
HANDLE hSignalEvent;
DWORD len, flags;
VALUE wpathBuf, wqueryBuf;
PWSTR path, query;
DWORD status = ERROR_SUCCESS;
struct WinevtBookmark *winevtBookmark;
struct WinevtSubscribe *winevtSubscribe;
hSignalEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
rb_scan_args(argc, argv, "21", &rb_path, &rb_query, &rb_bookmark);
Check_Type(rb_path, T_STRING);
Check_Type(rb_query, T_STRING);
if (rb_obj_is_kind_of(rb_bookmark, rb_cBookmark)) {
hBookmark = EventBookMark(rb_bookmark)->bookmark;
}
// path : To wide char
len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_path), RSTRING_LEN(rb_path), NULL, 0);
path = ALLOCV_N(WCHAR, wpathBuf, len+1);
MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_path), RSTRING_LEN(rb_path), path, len);
path[len] = L'\0';
// query : To wide char
len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_query), RSTRING_LEN(rb_query), NULL, 0);
query = ALLOCV_N(WCHAR, wqueryBuf, len+1);
MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_query), RSTRING_LEN(rb_query), query, len);
query[len] = L'\0';
if (hBookmark){
flags |= EvtSubscribeStartAfterBookmark;
} else if (winevtSubscribe->tailing) {
flags |= EvtSubscribeToFutureEvents;
} else {
flags |= EvtSubscribeStartAtOldestRecord;
}
hSubscription = EvtSubscribe(NULL, hSignalEvent, path, query, hBookmark, NULL, NULL, flags);
winevtSubscribe->signalEvent = hSignalEvent;
winevtSubscribe->subscription = hSubscription;
if (hBookmark) {
winevtSubscribe->bookmark = hBookmark;
} else {
winevtSubscribe->bookmark = EvtCreateBookmark(NULL);
}
status = GetLastError();
if (status == ERROR_SUCCESS)
return Qtrue;
return Qfalse;
}
|
#tail=(rb_tailing_p) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/winevt/winevt_subscribe.c', line 49
static VALUE
rb_winevt_subscribe_set_tail(VALUE self, VALUE rb_tailing_p)
{
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->tailing = RTEST(rb_tailing_p);
return Qnil;
}
|
#tail?(rb_flag) ⇒ Boolean
61 62 63 64 65 66 67 68 69 |
# File 'ext/winevt/winevt_subscribe.c', line 61
static VALUE
rb_winevt_subscribe_tail_p(VALUE self, VALUE rb_flag)
{
struct WinevtSubscribe *winevtSubscribe;
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return winevtSubscribe->tailing ? Qtrue : Qfalse;
}
|