sub read { my ($device) = shift; &debugLock ("Locking $device",2); &lock_directory(); my $file = "$ENV{LOCKS_LOCKING_DIR}/$device"; # if we failed to open the file that was there if (!open(LFILE, "<$file")) { $::DEVICES{byname}{$device}{LOCKS}{LAST_MESSAGE} = "Couldn't open lock file $file"; &debugLock ("Unlocking $device",2); &unlock_directory(); return 0; } my @output; @output = ; close (LFILE); my $tempIndex; for (my $index =0; $index <= $#output; $index++) { next if ($output[$index] !~ /^\(\).*\+/); chomp ($output[$index]); my ($data, $variable_name) = split /\+/, $output[$index]; my ($msg, $variable_value) = split /:/, $data; if ($variable_name =~ /SCRIPT/) { my %tempHash; for ($tempIndex = $index+1;$output[$tempIndex] !~ /^\(\)/ && $output[$tempIndex] !~ /^\*/; $tempIndex++) { $output[$tempIndex] =~ s/^\s+//; my ($data1,$variable) = split (/\+/, $output[$tempIndex]); my ($msg1,$param) = split (/:/, $data1); $tempHash{$msg1}=$param; } $::DEVICES{byname}{$device}{LOCKS}{SCRIPT}{$variable_value}= \%tempHash; $index = --$tempIndex; } else { $::DEVICES{byname}{$device}{LOCKS}{$variable_name}= $variable_value; } } &unlock_directory(); return 1; } sub write { my $device = shift; &debugLock ("Locking $device",2); &lock_directory (); my $file = "$ENV{LOCKS_LOCKING_DIR}/$device"; if (!open(LFILE, ">$file")) { $::DEVICES{byname}{$device}{LOCKS}{LAST_MESSAGE} = "Couldn't write to lock file $file"; &debugLock ("Unlocking $device",2); &unlock_directory(); return 0; } print LFILE < 1) { delete $::DEVICES{byname}{$device}{LOCKS}{SCRIPT}->{$scriptName}; } elsif ($userFlag == 0) { return (1, "The Lock File didnt find the values for the script"); } else { (update required hash value) $::DEVICES{byname}{$device}{LOCKS}{USER} = $userString; delete $::DEVICES{byname}{$device}{LOCKS}{SCRIPT}->{$scriptName}; } $numScripts--; if ($numScripts) { $::DEVICES{byname}{$device}{LOCKS}{LAST_MESSAGE} = "Successfully free'd port lock on $device for $portsRemove"; my $status = &write_port_data($device); return ($status, "Successfully free'd the hash"); } else { # if there are no scripts in the device, i.e., no one is using the device # I want to unlock the device completely. my $success =&unlock($args{DEVICE}, $args{FLAGS}, $args{USER}); return ($success, $::DEVICES{byname}{$args{DEVICE}}{LOCKS}{LAST_MESSAGE}); } } } sub createPort { (create tempHash) my %tempHash; $tempHash{A}=z; $tempHash{B}=y; $tempHash{C}=x; --- --- my $scriptName = "script1"; $::DEVICES{byname}{$device}{LOCKS}{SCRIPT}{$scriptName} = \%tempHash; my $status = &write_port_data ($device); return $status; }