Class: Winevt::EventLog::Subscribe
- Inherits:
-
Object
- Object
- Winevt::EventLog::Subscribe
- Defined in:
- ext/winevt/winevt.c
Instance Method Summary collapse
- #bookmark ⇒ Object
- #each ⇒ Object
- #initialize ⇒ Object constructor
- #next ⇒ Object
- #render ⇒ Object
- #subscribe(argv, self) ⇒ Object
- #tail=(rb_tailing_p) ⇒ Object
- #tail?(rb_flag) ⇒ Boolean
Constructor Details
#initialize ⇒ Object
210 211 212 213 214 |
# File 'ext/winevt/winevt.c', line 210
static VALUE
rb_winevt_subscribe_initialize(VALUE self)
{
return Qnil;
}
|
Instance Method Details
#bookmark ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'ext/winevt/winevt.c', line 348
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
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'ext/winevt/winevt.c', line 332
static VALUE
rb_winevt_subscribe_each(VALUE self)
{
struct WinevtSubscribe *winevtSubscribe;
RETURN_ENUMERATOR(self, 0, 0);
TypedData_Get_Struct(self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
while (rb_winevt_subscribe_next(self)) {
rb_yield(rb_winevt_subscribe_render(self));
}
return Qnil;
}
|
#next ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'ext/winevt/winevt.c', line 301
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
320 321 322 323 324 325 326 327 328 329 330 |
# File 'ext/winevt/winevt.c', line 320
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_str_new2(result);
}
|
#subscribe(argv, self) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'ext/winevt/winevt.c', line 238
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
216 217 218 219 220 221 222 223 224 225 226 |
# File 'ext/winevt/winevt.c', line 216
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
228 229 230 231 232 233 234 235 236 |
# File 'ext/winevt/winevt.c', line 228
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;
}
|