Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.o
.openhvf/
build/
local/

# Exploratory testing
explore/
Expand Down
2 changes: 1 addition & 1 deletion lib/FuguLib/Daemon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# %args:
# logfile => $path # Where to redirect stdout/stderr (default: /dev/null)
# on_fork => sub($) # Callback after fork, receives PID in parent
sub daemonize( $class, %args )
sub daemonize ( $class, %args )
{
my $logfile = $args{logfile} // '/dev/null';
my $on_fork = $args{on_fork};
Expand All @@ -47,7 +47,7 @@
}

# Child process
$DB::inhibit_exit = 0;

Check failure on line 50 in lib/FuguLib/Daemon.pm

View workflow job for this annotation

GitHub Actions / Lint

Name "DB::inhibit_exit" used only once: possible typo
setsid() or die "Cannot start new session: $!";

# Redirect standard file descriptors
Expand Down
30 changes: 15 additions & 15 deletions lib/FuguLib/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use constant {
MODE_QUIET => 'quiet',
};

sub new( $class, %args )
sub new ( $class, %args )
{
my $mode = $args{mode} // MODE_STDERR;
my $level = $args{level} // 'info';
Expand Down Expand Up @@ -66,26 +66,26 @@ sub new( $class, %args )
return $self;
}

sub DESTROY($self)
sub DESTROY ($self)
{
if ( $self->{opened} && $self->{mode} eq MODE_SYSLOG ) {
closelog();
}
}

# Logging methods
sub debug( $self, $fmt, @args ) { $self->_log( 'debug', $fmt, @args ); }
sub info( $self, $fmt, @args ) { $self->_log( 'info', $fmt, @args ); }
sub notice( $self, $fmt, @args ) { $self->_log( 'notice', $fmt, @args ); }
sub warning( $self, $fmt, @args ) { $self->_log( 'warning', $fmt, @args ); }
sub warn( $self, $fmt, @args ) { $self->_log( 'warning', $fmt, @args ); }
sub error( $self, $fmt, @args ) { $self->_log( 'error', $fmt, @args ); }
sub err( $self, $fmt, @args ) { $self->_log( 'error', $fmt, @args ); }
sub crit( $self, $fmt, @args ) { $self->_log( 'crit', $fmt, @args ); }
sub debug ( $self, $fmt, @args ) { $self->_log( 'debug', $fmt, @args ); }
sub info ( $self, $fmt, @args ) { $self->_log( 'info', $fmt, @args ); }
sub notice ( $self, $fmt, @args ) { $self->_log( 'notice', $fmt, @args ); }
sub warning ( $self, $fmt, @args ) { $self->_log( 'warning', $fmt, @args ); }
sub warn ( $self, $fmt, @args ) { $self->_log( 'warning', $fmt, @args ); }
sub error ( $self, $fmt, @args ) { $self->_log( 'error', $fmt, @args ); }
sub err ( $self, $fmt, @args ) { $self->_log( 'error', $fmt, @args ); }
sub crit ( $self, $fmt, @args ) { $self->_log( 'crit', $fmt, @args ); }

# $self->_log($level, $fmt, @args):
# Internal logging method
sub _log( $self, $level, $fmt, @args )
sub _log ( $self, $level, $fmt, @args )
{
return if $self->{mode} eq MODE_QUIET;

Expand All @@ -107,7 +107,7 @@ sub _log( $self, $level, $fmt, @args )

# $self->set_level($level):
# Change minimum log level
sub set_level( $self, $level )
sub set_level ( $self, $level )
{
$self->{level} = _parse_level($level);
}
Expand Down Expand Up @@ -146,19 +146,19 @@ my %facility_map = (
local7 => LOG_LOCAL7,
);

sub _parse_level($level)
sub _parse_level ($level)
{
$level = lc($level);
return $level_map{$level} // 1; # Default to info
}

sub _level_to_priority($level)
sub _level_to_priority ($level)
{
$level = lc($level);
return $priority_map{$level} // LOG_INFO;
}

sub _parse_facility($facility)
sub _parse_facility ($facility)
{
$facility = lc($facility);
return $facility_map{$facility} // LOG_DAEMON;
Expand Down
2 changes: 1 addition & 1 deletion lib/FuguLib/Privdrop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use POSIX qw(setuid setgid);
#
# # Now running as _openhap
# $server->run();
sub drop_privileges( $class, %args )
sub drop_privileges ( $class, %args )
{
my $user = $args{user}
or die "user parameter required for drop_privileges";
Expand Down
14 changes: 7 additions & 7 deletions lib/FuguLib/Process.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# on_error => sub($err) # Optional: error callback
# on_success => sub($pid) # Optional: success callback
# check_alive => $seconds # Optional: wait and verify process is alive
sub spawn_command( $class, %args )
sub spawn_command ( $class, %args )
{
my $cmd = $args{cmd}
or return { success => 0, error => 'No command specified' };
Expand Down Expand Up @@ -69,7 +69,7 @@
if ( $pid == 0 ) {

# Child process
$DB::inhibit_exit = 0;

Check failure on line 72 in lib/FuguLib/Process.pm

View workflow job for this annotation

GitHub Actions / Lint

Name "DB::inhibit_exit" used only once: possible typo

if ($daemonize) {

Expand Down Expand Up @@ -141,7 +141,7 @@
# $class->is_alive($pid):
# Check if process is alive (not dead, not zombie)
# Returns 1 if alive, 0 if dead or doesn't exist or zombie
sub is_alive( $class, $pid )
sub is_alive ( $class, $pid )
{
return 0 unless defined $pid;
return 0 unless $pid =~ /^\d+$/;
Expand Down Expand Up @@ -172,7 +172,7 @@
# %args:
# grace_period => $seconds # Time to wait after TERM before KILL (default: 5)
# on_kill => sub() # Called after successful kill
sub terminate( $class, $pid, %args )
sub terminate ( $class, $pid, %args )
{
return 1 unless defined $pid;
return 1 unless $class->is_alive($pid);
Expand Down Expand Up @@ -218,7 +218,7 @@
# $class->reap($pid):
# Attempt to reap a zombie process
# Returns 1 if process was reaped or doesn't exist, 0 if still running
sub reap( $class, $pid )
sub reap ( $class, $pid )
{
return 1 unless defined $pid;
return 1 unless $pid =~ /^\d+$/;
Expand All @@ -234,7 +234,7 @@
# $class->reap_all():
# Reap all zombie children (non-blocking)
# Returns count of children reaped
sub reap_all($class)
sub reap_all ($class)
{
my $count = 0;
while ( waitpid( -1, WNOHANG ) > 0 ) {
Expand All @@ -246,7 +246,7 @@
# $class->wait_exit($pid, $timeout):
# Wait for process to exit
# Returns 1 if process exited, 0 if timeout
sub wait_exit( $class, $pid, $timeout = 30 )
sub wait_exit ( $class, $pid, $timeout = 30 )
{
my $start = time;
while ( time - $start < $timeout ) {
Expand All @@ -273,7 +273,7 @@
# args => [$port, $dir],
# daemonize => 1,
# );
sub spawn_perl( $class, %args )
sub spawn_perl ( $class, %args )
{
my $code = delete $args{code}
or return { success => 0, error => 'No code specified' };
Expand All @@ -298,7 +298,7 @@
my %default_paths;
for my $key (qw(privlib archlib sitelib sitearch vendorlib vendorarch))
{
my $path = $Config::Config{$key};

Check failure on line 301 in lib/FuguLib/Process.pm

View workflow job for this annotation

GitHub Actions / Lint

Name "Config::Config" used only once: possible typo
$default_paths{$path} = 1 if defined $path && length $path;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/FuguLib/Signal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ our $interrupted = 0;
# Stack of cleanup handlers
my @cleanup_handlers;

sub new($class)
sub new ($class)
{
bless {
handlers => {},
Expand All @@ -42,7 +42,7 @@ sub new($class)
# $self->setup_graceful_exit(@signals):
# Setup handlers for graceful exit on specified signals
# Calls all registered cleanup handlers and exits
sub setup_graceful_exit( $self, @signals )
sub setup_graceful_exit ( $self, @signals )
{
for my $sig (@signals) {
$self->{original}{$sig} = $SIG{$sig} // 'DEFAULT';
Expand All @@ -59,7 +59,7 @@ sub setup_graceful_exit( $self, @signals )
# $self->setup_interrupt_flag(@signals):
# Setup handlers that set interrupt flag without exiting
# Allows long-running operations to check and exit cleanly
sub setup_interrupt_flag( $self, @signals )
sub setup_interrupt_flag ( $self, @signals )
{
for my $sig (@signals) {
$self->{original}{$sig} = $SIG{$sig} // 'DEFAULT';
Expand All @@ -72,15 +72,15 @@ sub setup_interrupt_flag( $self, @signals )
# $self->add_cleanup($handler):
# Add cleanup handler to be called on signal
# Handler receives signal name as argument
sub add_cleanup( $self, $handler )
sub add_cleanup ( $self, $handler )
{
push @cleanup_handlers, $handler;
return $self;
}

# $self->restore():
# Restore original signal handlers
sub restore($self)
sub restore ($self)
{
for my $sig ( keys %{ $self->{handlers} } ) {
$SIG{$sig} = $self->{original}{$sig};
Expand All @@ -104,7 +104,7 @@ sub reset_interrupted()
$interrupted = 0;
}

sub _run_cleanup_handlers( $self, $signal )
sub _run_cleanup_handlers ( $self, $signal )
{
for my $handler (@cleanup_handlers) {
eval { $handler->($signal); };
Expand All @@ -113,7 +113,7 @@ sub _run_cleanup_handlers( $self, $signal )
}

# DESTROY runs when object goes out of scope
sub DESTROY($self)
sub DESTROY ($self)
{
$self->restore;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/FuguLib/State.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use FuguLib::Process;
#
# Provides safe PID file reading/writing with locking and stale PID detection.

sub new( $class, $pidfile )
sub new ( $class, $pidfile )
{
return unless defined $pidfile;

Expand All @@ -39,7 +39,7 @@ sub new( $class, $pidfile )
# $self->write_pid($pid):
# Write PID to file with exclusive lock
# Returns 1 on success, 0 on failure
sub write_pid( $self, $pid = $$ )
sub write_pid ( $self, $pid = $$ )
{
my $pidfile = $self->{pidfile};

Expand All @@ -57,7 +57,7 @@ sub write_pid( $self, $pid = $$ )
# $self->read_pid():
# Read PID from file
# Returns PID or undef if not found or invalid
sub read_pid($self)
sub read_pid ($self)
{
my $pidfile = $self->{pidfile};
return unless -f $pidfile;
Expand All @@ -74,7 +74,7 @@ sub read_pid($self)

# $self->remove():
# Remove PID file
sub remove($self)
sub remove ($self)
{
my $pidfile = $self->{pidfile};
return 1 unless -f $pidfile;
Expand All @@ -84,7 +84,7 @@ sub remove($self)
# $self->is_running():
# Check if process from PID file is running
# Returns PID if running, undef otherwise
sub is_running($self)
sub is_running ($self)
{
my $pid = $self->read_pid;
return unless defined $pid;
Expand All @@ -94,7 +94,7 @@ sub is_running($self)

# $self->is_stale():
# Check if PID file is stale (process not running)
sub is_stale($self)
sub is_stale ($self)
{
my $pid = $self->read_pid;
return 0 unless defined $pid;
Expand Down
20 changes: 10 additions & 10 deletions lib/OpenHAP/Accessory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package OpenHAP::Accessory;

sub new( $class, %args )
sub new ( $class, %args )
{
my $self = bless {
aid => $args{aid},
Expand All @@ -21,7 +21,7 @@
return $self;
}

sub _add_accessory_info_service($self)
sub _add_accessory_info_service ($self)
{

require OpenHAP::Service;
Expand Down Expand Up @@ -89,21 +89,21 @@
push @{ $self->{services} }, $info;
}

sub add_service( $self, $service )
sub add_service ( $self, $service )
{
push @{ $self->{services} }, $service;
}

sub get_services($self)
sub get_services ($self)
{
return @{ $self->{services} };
}

sub get_service( $self, $type )
sub get_service ( $self, $type )
{
# Look up the full UUID if a short name is given
require OpenHAP::Service;
my $target_uuid = $OpenHAP::Service::SERVICE_TYPES{$type} // $type;

Check failure on line 106 in lib/OpenHAP/Accessory.pm

View workflow job for this annotation

GitHub Actions / Lint

Name "OpenHAP::Service::SERVICE_TYPES" used only once: possible typo

for my $service ( @{ $self->{services} } ) {
return $service if $service->{type} eq $target_uuid;
Expand All @@ -112,7 +112,7 @@
return;
}

sub get_characteristic( $self, $iid )
sub get_characteristic ( $self, $iid )
{
for my $service ( @{ $self->{services} } ) {
my $char = $service->get_characteristic($iid);
Expand All @@ -122,7 +122,7 @@
return;
}

sub to_json($self)
sub to_json ($self)
{
my @services;
for my $service ( @{ $self->{services} } ) {
Expand All @@ -135,18 +135,18 @@
};
}

sub identify($self)
sub identify ($self)
{
# Override in subclasses to implement identify functionality
# (e.g., blink LED, beep, etc.)
}

sub add_event_callback( $self, $callback )
sub add_event_callback ( $self, $callback )
{
push @{ $self->{event_callbacks} }, $callback;
}

sub notify_change( $self, $iid )
sub notify_change ( $self, $iid )
{
# Notify all registered callbacks about characteristic change
for my $callback ( @{ $self->{event_callbacks} } ) {
Expand Down
Loading
Loading