#!/usr/bin/perl # 2003/03/15, 2003/04/02 crenz@web42.com # display icon indicating whether zaurus is alive # only works due to weird Win32::GUI behaviour -- a notifyicon # will be deleted if another one with the same text and id is # created use strict; use warnings; use vars qw(*Timer_Timer *DeadIcon_Click *DeadIcon_RightClick *AliveIcon_Click *AliveIcon_RightClick); use Win32::GUI; use Net::Ping; # or use Win32::PingICMP my $hostname = $ARGV[0] || 'zaurus'; # or use '192.168.3.2' my $timer_itvl = 1000; my $off = Win32::GUI::Icon->new("zaurus_off.ico"); my $on = Win32::GUI::Icon->new("zaurus_on.ico"); my $frame; my $isAlive = 0; my $iconID = 0; # low timeout, since we're in "local network" (USB connection) my $p = Net::Ping->new("icmp", .2); sub isAliveOrDead { $p->ping($hostname); # for testing: -r 'c:\projects\z.txt'; } sub sayDead { $frame->AddNotifyIcon( -icon => $off, -id => $iconID, -name => 'DeadIcon', -tip => "$hostname Is Dead"); $isAlive = 0; } sub sayAlive { $frame->AddNotifyIcon( -icon => $on, -id => $iconID, -name => 'AliveIcon', -tip => "$hostname Is Alive"); $isAlive = 1; } sub toggle { if ($isAlive) { sayAlive; $iconID++; sayDead; } else { sayDead; $iconID++; sayAlive; } } sub check { toggle if $isAlive != isAliveOrDead; } sub quit { -1; } $frame = Win32::GUI::Window->new( -name => 'Main', -title => 'ZaurusAlive', -width => 100, -height => 100); sayDead; check; $frame->AddTimer("Timer", $timer_itvl); *Timer_Timer = \✓ # force check on click; alternatively set to \&toggle for debugging *DeadIcon_Click = \✓ *AliveIcon_Click = \✓ *DeadIcon_RightClick = \&quit; *AliveIcon_RightClick = \&quit; # note that the frame is never shown -- we only want the icon Win32::GUI::Dialog;