| 1 | # Udev::FFI - Copyright (C) 2017-2019 Ilya Pavlov | ||||||||||||||||||||||||||||
| 2 | # Udev::FFI is licensed under the | ||||||||||||||||||||||||||||
| 3 | # GNU Lesser General Public License v2.1 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Udev::FFI; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Udev::FFI::Functions qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Udev::FFI::Device; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Udev::FFI::Monitor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Udev::FFI::Enumerate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | $Udev::FFI::VERSION = '0.104000'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | *Udev::FFI::udev_version = \&Udev::FFI::Functions::udev_version; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub new { | ||||||||||||||||||||||||||||
| 27 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.6
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | if (0 == Udev::FFI::Functions->init()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | return undef; # error already in $@ | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | my $self = {_context => udev_new()}; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | unless (defined($self->{_context})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $@ = "Can't create udev context: $!"; | |||||||||||||||||||||||||||
| 36 | 0 | return undef; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | bless $self, $class; | |||||||||||||||||||||||||||
| 40 | 2 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub new_device_from_syspath { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_device_from_syspath: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $syspath = shift; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | my $device = udev_device_new_from_syspath($self->{_context}, $syspath); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return defined($device) ?Udev::FFI::Device->new($device, $self) :undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | sub new_device_from_devnum { | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_device_from_devnum: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 59 | 0 | my $devnum = shift; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $device = udev_device_new_from_devnum($self->{_context}, ord($type), $devnum); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return defined($device) ?Udev::FFI::Device->new($device, $self) :undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub new_device_from_subsystem_sysname { | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_device_from_subsystem_sysname: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my $subsystem = shift; | |||||||||||||||||||||||||||
| 71 | 0 | my $sysname = shift; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $device = udev_device_new_from_subsystem_sysname($self->{_context}, $subsystem, $sysname); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return defined($device) ?Udev::FFI::Device->new($device, $self) :undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub new_device_from_device_id { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_device_from_device_id: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $id = shift; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $device = udev_device_new_from_device_id($self->{_context}, $id); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return defined($device) ?Udev::FFI::Device->new($device, $self) :undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub new_device_from_environment { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_device_from_environment: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $device = udev_device_new_from_environment($self->{_context}); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return defined($device) ?Udev::FFI::Device->new($device, $self) :undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | sub new_monitor { | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_monitor: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $source = shift || 'udev'; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'udev'
MC/DC0%0/1
shift() || 'udev'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | croak('Valid sources identifiers are "udev" and "kernel"') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$source ne "udev" and $source ne "kernel"
MC/DC0%0/2
$source ne "udev" and $source ne "kernel"
$source ne "udev"
$source ne "kernel"
Truth table0%0/3
A and B
A= $source ne "udev"B= $source ne "kernel"
| |||||||||||||||||||||||||||||
| 106 | if $source ne 'udev' && $source ne 'kernel'; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | my $monitor = udev_monitor_new_from_netlink($self->{_context}, $source); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | unless (defined($monitor)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $@ = $! || "Can't create udev monitor from netlink"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$! || q[Can't create udev monitor from netlink]
MC/DC0%0/1
$! || q[Can't create udev monitor from netlink]
$!
Truth table0%0/2
A
A= $!
| |||||||||||||||||||||||||||||
| 111 | 0 | return undef; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return Udev::FFI::Monitor->new($monitor, $self); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | sub new_enumerate { | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new_enumerate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my $enumerate = udev_enumerate_new($self->{_context}); | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | unless (defined($enumerate)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $@ = $! || "Can't create enumerate context"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$! || q[Can't create enumerate context]
MC/DC0%0/1
$! || q[Can't create enumerate context]
$!
Truth table0%0/2
A
A= $!
| |||||||||||||||||||||||||||||
| 125 | 0 | return undef; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | return Udev::FFI::Enumerate->new($enumerate, $self); | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub DESTROY { | ||||||||||||||||||||||||||||
| 134 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | udev_unref( $self->{_context} ); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 3 | 1; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||