| 1 | # Copyright (c) 2015 Timm Murray | ||||||||||||
| 2 | # All rights reserved. | ||||||||||||
| 3 | # | ||||||||||||
| 4 | # Redistribution and use in source and binary forms, with or without | ||||||||||||
| 5 | # modification, are permitted provided that the following conditions are met: | ||||||||||||
| 6 | # | ||||||||||||
| 7 | # * Redistributions of source code must retain the above copyright notice, | ||||||||||||
| 8 | # this list of conditions and the following disclaimer. | ||||||||||||
| 9 | # * Redistributions in binary form must reproduce the above copyright | ||||||||||||
| 10 | # notice, this list of conditions and the following disclaimer in the | ||||||||||||
| 11 | # documentation and/or other materials provided with the distribution. | ||||||||||||
| 12 | # | ||||||||||||
| 13 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||||||||||
| 14 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||||||||||
| 15 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||||||||||
| 16 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||||||||||||
| 17 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||||||||||
| 18 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||||||||||
| 19 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||||||||||
| 20 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||||||||||
| 21 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||||||||||
| 22 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||||||||||
| 23 | # POSSIBILITY OF SUCH DAMAGE. | ||||||||||||
| 24 | package UAV::Pilot::ARDrone::Video::Fileno; | ||||||||||||
| 25 | 2 | $UAV::Pilot::ARDrone::Video::Fileno::VERSION = '1.0'; | |||||||||||
| 26 | 2 | ▶ | use v5.14; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 2 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 2 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 2 | ▶ | use Fcntl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | 2 | extends 'UAV::Pilot::ARDrone::Video'; | |||||||||||
| 33 | |||||||||||||
| 34 | |||||||||||||
| 35 | sub BUILDARGS | ||||||||||||
| 36 | { | ||||||||||||
| 37 | 1 | ▶ | my ($class, $args) = @_; | ||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 38 | 1 | my $io = $class->_build_io( $args ); | |||||||||||
| 39 | |||||||||||||
| 40 | 1 | $$args{'_io'} = $io; | |||||||||||
| 41 | 1 | delete $$args{'host'}; | |||||||||||
| 42 | 1 | delete $$args{'port'}; | |||||||||||
| 43 | 1 | return $args; | |||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | sub fileno | ||||||||||||
| 47 | { | ||||||||||||
| 48 | 1 | ▶ | my ($self, $do_clear_close_on_exec) = @_; | ||||||||||
|
Subroutine
fileno: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||
| 49 | 1 | ▶ | $do_clear_close_on_exec //= 1; | ||||||||||
|
Condition50%1/2
$do_clear_close_on_exec //= 1
MC/DC0%0/1
$do_clear_close_on_exec //= 1
$do_clear_close_on_exec
Truth table50%1/2
A
A= $do_clear_close_on_exec
| |||||||||||||
| 50 | |||||||||||||
| 51 | 1 | my $in = $self->_io; | |||||||||||
| 52 | 1 | ▶ | my $fd = 'MSWin32' eq $^O | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | ? $self->_get_fd_win32( $in, $do_clear_close_on_exec ) | ||||||||||||
| 54 | : $self->_get_fd_unixy( $in, $do_clear_close_on_exec ); | ||||||||||||
| 55 | |||||||||||||
| 56 | 1 | return $fd; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | sub init_event_loop | ||||||||||||
| 60 | ▶ | { | |||||||||||
|
Subroutine
init_event_loop: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 61 | # Do nothing, successfully | ||||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | |||||||||||||
| 65 | sub _get_fd_unixy | ||||||||||||
| 66 | { | ||||||||||||
| 67 | 1 | ▶ | my ($self, $in, $do_clear_close_on_exec) = @_; | ||||||||||
|
Subroutine
_get_fd_unixy: called CC=3 SCAR=11.1
| |||||||||||||
| 68 | |||||||||||||
| 69 | 1 | ▶ | if( $do_clear_close_on_exec ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | # This code may not compile on Windows, so wrap it in an eval(STRING) | ||||||||||||
| 71 | 1 | ▶ | eval <<'END_EVAL'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 72 | use Fcntl; | ||||||||||||
| 73 | my $flags = fcntl( $in, F_GETFD, 0 ) | ||||||||||||
| 74 | or die "fcntl F_GETFD: $!"; | ||||||||||||
| 75 | fcntl( $in, F_SETFD, $flags & ~FD_CLOEXEC ) | ||||||||||||
| 76 | or die "fcntl F_SETFD: $!"; | ||||||||||||
| 77 | END_EVAL | ||||||||||||
| 78 | 1 | ▶ | die "Could not set close-on-exec flag: $@\n" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 1 | return CORE::fileno( $in ); | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | sub _get_fd_win32 | ||||||||||||
| 85 | { | ||||||||||||
| 86 | 0 | ▶ | my ($self, $in, $do_clear_close_on_exec) = @_; | ||||||||||
|
Subroutine
_get_fd_win32: not called CC=2 SCAR=17.9
| |||||||||||||
| 87 | # No close-on-exec flag for Windows, so ignore it | ||||||||||||
| 88 | |||||||||||||
| 89 | # This code won't compile on anything but Windows, so wrap it in | ||||||||||||
| 90 | # an eval(STRING) | ||||||||||||
| 91 | 0 | my $fd = eval <<'END_EVAL'; | |||||||||||
| 92 | use Win32::File 'FdGetOsFHandle'; | ||||||||||||
| 93 | FdGetOsFHandle( fileno( $in ) ); | ||||||||||||
| 94 | END_EVAL | ||||||||||||
| 95 | 0 | ▶ | die "Could not get raw FD: $@\n" if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | |||||||||||||
| 97 | 0 | return $fd; | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | |||||||||||||
| 101 | 2 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 102 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 103 | 2 | 1; | |||||||||||
| 104 | __END__ | ||||||||||||
| 105 | |||||||||||||
| 106 | |||||||||||||
| 107 | =head1 NAME | ||||||||||||
| 108 | |||||||||||||
| 109 | UAV::Pilot::ARDrone::Video::Fileno | ||||||||||||
| 110 | |||||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||||
| 112 | |||||||||||||
| 113 | A version of C<UAV::Pilot::ARDrone::Video> that launches an external process | ||||||||||||
| 114 | and hands it a raw filehandle with C<fileno()>. This is done in a | ||||||||||||
| 115 | cross-platform way. Note that on Windows, this requires C<Win32::File> to be | ||||||||||||
| 116 | installed. | ||||||||||||
| 117 | |||||||||||||
| 118 | Since no reading of the video stream is actual done, C<init_event_loop()> is | ||||||||||||
| 119 | a NOP. | ||||||||||||
| 120 | |||||||||||||
| 121 | =cut | ||||||||||||