#========================================================================= 
#          Copyright © 2001-2004 QUALCOMM Incorporated.
#                     All Rights Reserved.
#========================================================================= 
#! /usr/local/bin/perl -w
use strict;

#use lib "$ENV{BREWTOOLSDIR}\\BREW Perl Interface";
use BREWPerlIF;


###################################################################
# Sample perl application to demonstrate device directory 
# enumeration operatoins (GetDeviceFileList and GetDeviceDirList):
#
#        1) Gets list of files present in the specified device 
#           directory (BREW Shared directory), 
#        2) Gets list of sub-directories present in the specified 
#           device directory (BREW Shared directory).
################################################################## 

###################################################################
# Variable Declaration Section
###################################################################

# serial port name to which the device is connected
my $comPort = "COM1";

my $dllName = "$ENV{BTILDIR}\\OEMLayer\\QCOMOEM.dll";

# place holder for device directory path
my $deviceDir = "/shared";

# place holder for storing result
my $resultRef;
my $fileItem;

# index
my $index;

#####################################################################
# Here starts the actual processing
#####################################################################

# connect to the device
printf "Connecting to device\n" ;


if( BREWPerlIF::ConnecttoDevice($comPort, $dllName)) {
	print "Connection to Device successful\n";
} else {
	die "Could not connect to the device on specified port $comPort\n";
}

printf "\nFiles present in device directory $deviceDir:\n";
$resultRef = BREWPerlIF::GetDeviceFileList ($deviceDir);
foreach $fileItem (@{$resultRef}) {
	printf "$fileItem\n";
}

printf "\nSub-directories present in device directory $deviceDir:\n";
$resultRef = BREWPerlIF::GetDeviceDirectoryList ($deviceDir);
for ($index = 0; $index <= $#{$resultRef}; $index++) {
	printf "$resultRef->[$index]\n";
}

printf "\ndisconnecting from device\n" ;
if(BREWPerlIF::ReleaseDevice()) {
	print "disconnect from the device successful\n";
} else {
	die "Could not disconnect from the device\n";
}