From: Jim D. <ji...@du...> - 2008-07-12 01:43:27
|
I'm finally getting around with playing with xAP, and having fun! I'm trying to get a xAP_Item to work inside a library module. Can anyone help me understand why this doesn't work? The following code is in a library module. I get the xAP_data startup messages in the log file. I also get the check_for_xAP_data check: messages. However, $check is always empty, so, I'm not getting anything from the xAP_ref. If I use similiar code in a normal code module, all works fine. I've been struggling with this for a few days. Stumped. use strict; package TEST; use xAP_Items; my $xAP_ref = undef; sub startup { &::MainLoop_pre_add_hook( \&TEST::check_for_xAP_data, 1 ); if (not defined $xAP_ref) { &main::print_log ("TEST::check_for_xAP_data startup"); $xAP_ref = new xAP_Item('xap-hbeat.alive'); my $friendly_name = "xAP_test"; &main::store_object_data($xAP_ref, 'xAP_Item', $friendly_name, $friendly_name); } } sub check_for_xAP_data { # First, check the xAP channel for messages # my $check = $xAP_ref->state_now( ); # &main::print_log ("TEST::check_for_xAP_data check: $check"); if ($xAP_ref->state_now) { # dump some debugging information foreach my $key (keys %{$xAP_ref->{'xap-hbeat'}}) { &main::print_log ("TEST::xAP_ref:: receive key: $key data: $xAP_ref->{'xap-hbeat'}{$key}") if $main::Debug{xap_echo}; } } } 1; This code module works fine, I get the hbeat debug messages in the loop. use strict; use TEST; use xAP_Items; # noloop=start &TEST::startup( ); # noloop=stop $xAP_ref = new xAP_Item('xap-hbeat.alive'); #my $check = $xAP_ref->state_now( ); #print_log ("test.pl::check_for_xAP_data check: $check"); if ($xAP_ref->state_now) { # dump some debugging information foreach my $key (keys %{$xAP_ref->{'xap-hbeat'}}) { print_log ("test.pl::xAP_ref:: receive key: $key data: $xAP_ref->{'xap-hbeat'}{$key}"); } } 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: hop data: 1 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: uid data: ffe90000 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: v data: 12 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: interval data: 60 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: port data: 49152 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: pid data: 6816 07/11/08 09:39:02 PM test.pl::xAP_ref:: receive key: class data: xap-hbeat.alive Thanks, Jim |