From: Gregg L. <gr...@li...> - 2008-07-12 04:33:29
|
Jim Duda wrote: > 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? Well, first off, the xAP_Items lib also uses a pre_add_hook to check for pertinent UDP traffic and then set_now on pertinent objects. You're not guaranteed order of hook modules; so, that alone could explain it. ... not to be dismissive; but, I don't understand why you would want to use such a coding pattern for this anyway. There's not a single xAP-enabled module that does so. The only reason to ever use a pre_add_hook is for "conduits" (i.e., code that attaches to specific sources of data such as a socket or serial connection) to acquire and parse (usually, semi-raw) data. The xAP_Item lib already does that. So, trying to intercept or do something different is pretty pointless. Perhaps, you could shed light on what you're really trying to do? > 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. Yes--because it is much more correct. > 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 > > > > ------------------------------------------------------------------------- > Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! > Studies have shown that voting for your favorite open source project, > along with a healthy diet, reduces your potential for chronic lameness > and boredom. Vote Now at http://www.sourceforge.net/community/cca08 > ________________________________________________________ > To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365 > |