2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-03 19:49:02 +00:00
fhem-mirror/fhem/FHEM/GPUtils.pm
ntruchsess fbf43ce944 OWX_ASYNC: cleanup and refactor interface to busmaster-classes (do all nested protothreads)
Merge branch 'owx_protothreads'

git-svn-id: https://svn.fhem.de/fhem/trunk@6259 2b470e98-0d58-463d-a4d8-8e2adae1ed80
2014-07-15 16:44:35 +00:00

50 lines
1.1 KiB
Perl

##############################################
# $Id$
##############################################
package GPUtils;
use Exporter qw( import );
use strict;
use warnings;
our %EXPORT_TAGS = (all => [qw(GP_Define GP_Catch GP_ForallClients)]);
Exporter::export_ok_tags('all');
sub GP_Define($$) {
my ($hash, $def) = @_;
my @a = split("[ \t]+", $def);
my $module = $main::modules{$hash->{TYPE}};
return $module->{NumArgs}." arguments expected" if ((defined $module->{NumArgs}) and ($module->{NumArgs} ne scalar(@a)-2));
$hash->{STATE} = 'defined';
if ($main::init_done) {
eval { &{$module->{InitFn}}( $hash, [ @a[ 2 .. scalar(@a) - 1 ] ] ); };
return GP_Catch($@) if $@;
}
return undef;
}
sub GP_Catch($) {
my $exception = shift;
if ($exception) {
$exception =~ /^(.*)( at.*FHEM.*)$/;
return $1;
}
return undef;
}
sub GP_ForallClients($$@)
{
my ($hash,$fn,@args) = @_;
foreach my $d ( sort keys %main::defs ) {
if ( defined( $main::defs{$d} )
&& defined( $main::defs{$d}{IODev} )
&& $main::defs{$d}{IODev} == $hash ) {
&$fn($main::defs{$d},@args);
}
}
return undef;
}
1;