Class: Winevt::EventLog::Subscribe
- Inherits:
-
Object
- Object
- Winevt::EventLog::Subscribe
- Defined in:
- ext/winevt/winevt_subscribe.c,
lib/winevt/subscribe.rb,
ext/winevt/winevt.c,
ext/winevt/winevt_subscribe.c
Overview
Subscribe Windows EventLog channel.
Defined Under Namespace
Classes: RemoteHandlerError, SubscribeHandlerError
Constant Summary collapse
- RATE_INFINITE =
For Subscribe#rate_limit=. It represents unspecified rate limit.
SUBSCRIBE_RATE_INFINITE
Instance Method Summary collapse
- #bookmark ⇒ Object
-
#cancel ⇒ Boolean
This method cancels channel subscription.
-
#close ⇒ Object
This method closes channel handles forcibly.
- #each ⇒ Object
- #initialize ⇒ Object constructor
-
#locale ⇒ Object
This method obtains specified locale with [String].
-
#locale=(rb_locale_str) ⇒ Object
This method specifies locale with [String].
- #next ⇒ Object
-
#preserve_qualifiers=(rb_preserve_qualifiers) ⇒ Object
This method specifies whether preserving qualifiers key or not.
-
#preserve_qualifiers? ⇒ Integer
This method returns whether preserving qualifiers or not.
-
#preserve_sid=(rb_preserve_sid_p) ⇒ Object
This method specifies whether preserving SID or not.
-
#preserve_sid? ⇒ Boolean
This method returns whether preserving SID or not.
- #rate_limit ⇒ Object
- #rate_limit=(rb_rate_limit) ⇒ Object
-
#read_existing_events=(rb_read_existing_events_p) ⇒ Object
This method specifies whether read existing events or not.
-
#read_existing_events? ⇒ Boolean
This method returns whether read existing events or not.
- #render_as_xml=(rb_render_as_xml) ⇒ Object
- #render_as_xml? ⇒ Object
- #subscribe(*args) ⇒ Object
- #subscribe_raw ⇒ Object
- #unresolved_message_count ⇒ Object
Constructor Details
#initialize ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'ext/winevt/winevt_subscribe.c', line 98
static VALUE
rb_winevt_subscribe_initialize(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->rateLimit = SUBSCRIBE_RATE_INFINITE;
winevtSubscribe->lastTime = 0;
winevtSubscribe->currentRate = 0;
winevtSubscribe->renderAsXML = TRUE;
winevtSubscribe->readExistingEvents = TRUE;
winevtSubscribe->preserveQualifiers = FALSE;
winevtSubscribe->localeInfo = &default_locale;
winevtSubscribe->preserveSID = TRUE;
winevtSubscribe->unresolvedMessageCount = 0;
return Qnil;
}
|
Instance Method Details
#bookmark ⇒ Object
531 532 533 534 535 536 537 538 539 540 |
# File 'ext/winevt/winevt_subscribe.c', line 531
static VALUE
rb_winevt_subscribe_get_bookmark(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return render_to_rb_str(winevtSubscribe->bookmark, EvtRenderBookmark);
}
|
#cancel ⇒ Boolean
This method cancels channel subscription.
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 |
# File 'ext/winevt/winevt_subscribe.c', line 760
static VALUE
rb_winevt_subscribe_cancel(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
BOOL result = FALSE;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
if (winevtSubscribe->subscription) {
result = EvtCancel(winevtSubscribe->subscription);
}
if (result) {
return Qtrue;
} else {
return Qfalse;
}
}
|
#close ⇒ Object
This method closes channel handles forcibly.
785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'ext/winevt/winevt_subscribe.c', line 785
static VALUE
rb_winevt_subscribe_close(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
close_handles(winevtSubscribe);
return Qnil;
}
|
#each ⇒ Object
513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'ext/winevt/winevt_subscribe.c', line 513
static VALUE
rb_winevt_subscribe_each(VALUE self)
{
RETURN_ENUMERATOR(self, 0, 0);
while (rb_winevt_subscribe_next(self)) {
rb_ensure(
rb_winevt_subscribe_each_yield, self, rb_winevt_subscribe_close_handle, self);
}
return Qnil;
}
|
#locale ⇒ Object
This method obtains specified locale with [String].
684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'ext/winevt/winevt_subscribe.c', line 684
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);
}
}
|
#locale=(rb_locale_str) ⇒ Object
This method specifies locale with [String].
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'ext/winevt/winevt_subscribe.c', line 663
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_info_from_rb_str(rb_locale_str);
winevtSubscribe->localeInfo = locale_info;
return Qnil;
}
|
#next ⇒ Object
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'ext/winevt/winevt_subscribe.c', line 344
static VALUE
rb_winevt_subscribe_next(VALUE self)
{
EVT_HANDLE hEvents[SUBSCRIBE_ARRAY_SIZE];
ULONG count = 0;
DWORD status = ERROR_SUCCESS;
DWORD dwWait = 0;
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
if (is_rate_limit_exceeded(winevtSubscribe)) {
return Qfalse;
}
/* If subscription handle is NULL, it should return false. */
if (!winevtSubscribe->subscription) {
return Qfalse;
}
/* If a signalEvent notifies whether a state of processed event(s)
* is existing or not.
* For checking for a result of WaitForSingleObject,
* we need to raise SubscribeHandlerError exception when
* WAIT_FAILED is detected for further investigations.
* Note that we don't need to wait explicitly here.
* Because this function is inside of each enumerator.
* So, WaitForSingleObject should return immediately and should be
* processed with the latter each loops if there is no more items.
* Just intended to check that there is no errors here. */
dwWait = WaitForSingleObject(winevtSubscribe->signalEvent, 0);
if (dwWait == WAIT_FAILED) {
raise_system_error(rb_eSubscribeHandlerError, GetLastError());
} else if (dwWait != WAIT_OBJECT_0) {
return Qfalse;
}
if (!EvtNext(winevtSubscribe->subscription,
SUBSCRIBE_ARRAY_SIZE,
hEvents,
INFINITE,
0,
&count)) {
status = GetLastError();
if (ERROR_CANCELLED == status) {
return Qfalse;
}
if (ERROR_NO_MORE_ITEMS != status) {
return Qfalse;
}
ResetEvent(winevtSubscribe->signalEvent);
}
if (status == ERROR_SUCCESS) {
// #each frees each batch in its ensure block; this covers calling #next
// directly in a loop.
for (DWORD i = 0; i < winevtSubscribe->count; i++) {
if (winevtSubscribe->hEvents[i]) {
EvtClose(winevtSubscribe->hEvents[i]);
winevtSubscribe->hEvents[i] = NULL;
}
}
winevtSubscribe->count = count;
for (ULONG i = 0; i < count; i++) {
winevtSubscribe->hEvents[i] = hEvents[i];
EvtUpdateBookmark(winevtSubscribe->bookmark, winevtSubscribe->hEvents[i]);
}
update_to_reflect_rate_limit_state(winevtSubscribe, count);
return Qtrue;
}
return Qfalse;
}
|
#preserve_qualifiers=(rb_preserve_qualifiers) ⇒ Object
This method specifies whether preserving qualifiers key or not.
627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'ext/winevt/winevt_subscribe.c', line 627
static VALUE
rb_winevt_subscribe_set_preserve_qualifiers(VALUE self, VALUE rb_preserve_qualifiers)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->preserveQualifiers = RTEST(rb_preserve_qualifiers);
return Qnil;
}
|
#preserve_qualifiers? ⇒ Integer
This method returns whether preserving qualifiers or not.
646 647 648 649 650 651 652 653 654 655 |
# File 'ext/winevt/winevt_subscribe.c', line 646
static VALUE
rb_winevt_subscribe_get_preserve_qualifiers_p(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return winevtSubscribe->preserveQualifiers ? Qtrue : Qfalse;
}
|
#preserve_sid=(rb_preserve_sid_p) ⇒ Object
This method specifies whether preserving SID or not.
704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'ext/winevt/winevt_subscribe.c', line 704
static VALUE
rb_winevt_subscribe_set_preserve_sid(VALUE self, VALUE rb_preserve_sid_p)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->preserveSID = RTEST(rb_preserve_sid_p);
return Qnil;
}
|
#preserve_sid? ⇒ Boolean
This method returns whether preserving SID or not.
722 723 724 725 726 727 728 729 730 731 |
# File 'ext/winevt/winevt_subscribe.c', line 722
static VALUE
rb_winevt_subscribe_preserve_sid_p(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return winevtSubscribe->preserveSID ? Qtrue : Qfalse;
}
|
#rate_limit ⇒ Object
548 549 550 551 552 553 554 555 556 557 |
# File 'ext/winevt/winevt_subscribe.c', line 548
static VALUE
rb_winevt_subscribe_get_rate_limit(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return INT2NUM(winevtSubscribe->rateLimit);
}
|
#rate_limit=(rb_rate_limit) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'ext/winevt/winevt_subscribe.c', line 565
static VALUE
rb_winevt_subscribe_set_rate_limit(VALUE self, VALUE rb_rate_limit)
{
struct WinevtSubscribe* winevtSubscribe;
DWORD rateLimit;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
rateLimit = NUM2LONG(rb_rate_limit);
if ((rateLimit != (DWORD)SUBSCRIBE_RATE_INFINITE) && (rateLimit < 10 || rateLimit % 10)) {
rb_raise(rb_eArgError, "Specify a multiples of 10 or RATE_INFINITE constant");
} else {
winevtSubscribe->rateLimit = rateLimit;
}
return Qnil;
}
|
#read_existing_events=(rb_read_existing_events_p) ⇒ Object
This method specifies whether read existing events or not.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'ext/winevt/winevt_subscribe.c', line 124
static VALUE
rb_winevt_subscribe_set_read_existing_events(VALUE self, VALUE rb_read_existing_events_p)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->readExistingEvents = RTEST(rb_read_existing_events_p);
return Qnil;
}
|
#read_existing_events? ⇒ Boolean
This method returns whether read existing events or not.
142 143 144 145 146 147 148 149 150 151 |
# File 'ext/winevt/winevt_subscribe.c', line 142
static VALUE
rb_winevt_subscribe_read_existing_events_p(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return winevtSubscribe->readExistingEvents ? Qtrue : Qfalse;
}
|
#render_as_xml=(rb_render_as_xml) ⇒ Object
608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'ext/winevt/winevt_subscribe.c', line 608
static VALUE
rb_winevt_subscribe_set_render_as_xml(VALUE self, VALUE rb_render_as_xml)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
winevtSubscribe->renderAsXML = RTEST(rb_render_as_xml);
return Qnil;
}
|
#render_as_xml? ⇒ Object
591 592 593 594 595 596 597 598 599 600 |
# File 'ext/winevt/winevt_subscribe.c', line 591
static VALUE
rb_winevt_subscribe_render_as_xml_p(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return winevtSubscribe->renderAsXML ? Qtrue : Qfalse;
}
|
#subscribe(*args) ⇒ Object
164 165 166 167 168 169 170 171 172 173 |
# File 'ext/winevt/winevt_subscribe.c', line 164 def subscribe(path, query, bookmark = nil, session = nil) if bookmark.is_a?(Winevt::EventLog::Bookmark) && session.is_a?(Winevt::EventLog::Session) subscribe_raw(path, query, bookmark.render, session) elsif bookmark.is_a?(Winevt::EventLog::Bookmark) subscribe_raw(path, query, bookmark.render) else subscribe_raw(path, query) end end |
#subscribe_raw ⇒ Object
4 |
# File 'lib/winevt/subscribe.rb', line 4 alias_method :subscribe_raw, :subscribe |
#unresolved_message_count ⇒ Object
743 744 745 746 747 748 749 750 751 752 |
# File 'ext/winevt/winevt_subscribe.c', line 743
static VALUE
rb_winevt_subscribe_get_unresolved_message_count(VALUE self)
{
struct WinevtSubscribe* winevtSubscribe;
TypedData_Get_Struct(
self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
return ULL2NUM(winevtSubscribe->unresolvedMessageCount);
}
|