10 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
sub addstring
{
# add a string to a screen
my $screenname=shift;
my $widgetname=shift;
my $sock=getsocket();
debug ("widget_add \"$screenname\" \"$widgetname\" string");
print $sock "widget_add \"$screenname\" \"$widgetname\" string\n";
my $answer=suck($sock);
if ( $answer ne "1" ) { die "error while creating widget \"$widgetname\" in screen \"$screenname\". Server said: $answer";}
return 1;
}
sub setstring
{
# modify a string-type widget
my $screenname=shift;
my $widgetname=shift;
my $x=shift;
my $y=shift;
my $value=shift;
my $sock=getsocket();
debug ("widget_set \"$screenname\" \"$widgetname\" $x $y \"$value\"");
print $sock "widget_set \"$screenname\" \"$widgetname\" $x $y \"$value\"\n";
my $answer=suck($sock);
if ( $answer ne "1" ) { die "error while modifying widget \"$widgetname\" in screen \"screenname\". Server said: $answer";}
return 1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sub suck
{
# read any message from the LCDd,
# discard listen / ignore messages and return
# value indicating a successful or failed operation
my $sock=shift;
my $message="";
my $answer="";
SUCKLOOP:
# We need a point to jump back when we recieve a listen/ignore message
recv ( $sock,$message,512,0); # 512 Bytes enough?
chomp ($message);
if ( index($message,"listen") >=0 ) { debug ("Discarded listen message ($message)");goto SUCKLOOP;}
if ( index($message,"ignore") >=0 ) { debug ("Discarded ignore message ($message)");goto SUCKLOOP;}
if ( index($message,"connect") >=0 ) { debug ("successfully registered as a client ($message)");return 1;}
if ( index($message,"huh?") >=0 ) { debug("error ($message)");return $message;}
if ( index($message,"success") >=0 ) { debug("success");return 1;}
return 1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
sub suck {
# read any message from the LCDd,
# discard listen / ignore messages and return
# value indicating a successful or failed operation
my $sock=shift;
my $answer="";
my $sucking = 1;
my $retval;
while($sucking) {
my $message = $sock->getline();
chomp ($message);
if ( index($message,"listen") >=0 ) { debug ("Discarded listen message ($message)");}
elsif ( index($message,"ignore") >=0 ) { debug ("Discarded ignore message ($message)");}
elsif ( index($message,"connect") >=0 ) { debug ("successfully registered as a client ($message)"); $retval = 1; $sucking = 0;}
elsif ( index($message,"huh?") >=0 ) { debug("error ($message)"); $retval = $message; $sucking = 0;}
elsif ( index($message,"success") >=0 ) { debug("success"); $retval = 1; $sucking = 0;}
}
return $retval
}
1
2
3
4
5
6
7
sub foo {
if($noerror) {
return (1, "");
} else {
return (0, "Es ist ein Fehler aufgetreten!");
}
}
1
2
3
4
5
6
7
8
$starttime=time();
...
...
...
$enddtime=time();
$difftime=$endtime-$starttime;
$sleeptime=1-$difftime;
sleep ($sleeptime);
suck(...) or die;
1
2
3
print "Modul $modulname hat versucht ein nicht existierendes $typ widget mit dem Namen $widgetname zu verändern\n";
Oder halt :
print "Modul $modulname hat versucht das widget $widgetname mit dem Typ $typ zu erzeugen. Dieses widget existiert bereits"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Sucker;
sub new {
...
}
sub suck(...) {
my $self = shift;
#
# auswertungen
#
unless(error) return 1;
else {
$self->{lasterror} = $message;
return 0;
}
}
sub getlasterror {
return shift->{lasterror};
}
1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
sub addstring
{
...
...
...
my $answer=suck($socket);
if ( $answer == 1 ) { return 1;}
if ( $answer == 2 ) {print "Modul $modul hat versucht auf widget $widgetname zuzugreifen, dieses Widget existiert nicht";return 0; }
if ( $answer == 3 ) { print "Es wurde durch Modul $modulname ein falscher Parameter für widget $widgetname übergeben";return 0; }
...
...
...
}
sub suck
{
...
...
...
if ( index($message,"listen") >=0 ) { debug ("Discarded listen message ($message)");goto SUCKLOOP;}
if ( index($message,"ignore") >=0 ) { debug ("Discarded ignore message ($message)");goto SUCKLOOP;}
if ( index($message,"connect") >=0 ) { debug ("successfully registered as a client ($message)");return 1;}
if ( index($message,"huh?") >=0 )
{
debug("error ($message)");
if ( $message = "huh? unknown widget id" ){return 2;}
if ( $message = "huh? incorrect parameter" ){return 3;}
....
....
}
if ( index($message,"success") >=0 ) { debug("success");return 1;}
}
QuoteBe aware that the optimizer might have optimized call frames
away before "caller" had a chance to get the information. That
means that caller(N) might not return information about the
call frame you expect it do, for "N > 1". In particular,
@DB::args might have information from the previous time
"caller" was called.
10 Einträge, 1 Seite |