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

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

use Socket;

#########################################################
# This sample file provides the user with an example to #
# set the log and message options via perl interface and#
# start the logging. It uses the file only option for   # 
# logging to file only. It sets the filesize limit to   #
# 300KB after which it rollsover to a new file having   #
# the same name with a "_$num" appended. $num = 1 to x  #
# depending upon the number of rollovers the script     #
# wants........In this case, it is 2.                   #
#########################################################

$portName = "COM1";


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

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


printf "Setting message level\n";
if( BREWPerlIF::SetMessageLevel(4)) {
	printf "MsgLevel Setting done \n"; 
} else {
	die "Could not set Message Level\n";
}
print "Setting Log Mask\n";
if(BREWPerlIF::SetLogMask("0x000000000000000000000007FFF8")) {
printf "LogMask Setting successful\n" ; 
} else {
	die "Could not Set LogMask\n";
}

printf "Setting Options\n"; 
$filename = "C:\\BrewPerlIF_".$$; ## Add the process id extension to it.
if (BREWPerlIF::SetOptions_fileOnly($filename) == 0) {  
	die "Could not set options successfully\n";
	}

printf "Setting file size limit\n"; # Limit in Bytes. 
				   # There will be a rollover once the file
				   # exceeds this limit 

BREWPerlIF::SetFileSizeLimit(300000); # Limit: 300K
BREWPerlIF::SetNumOfFilesNeeded(2); # i.e total size: 600K

printf "Starting the logging: Log filename- $filename\n";
if( BREWPerlIF::StartLogger() == 0) {
	die "Could not start the logger\n";
	}


while(BREWPerlIF::GetTotalFilesWritten() < 2)
{
print ".";
sleep(1); # Sleep here does not affect the processing as the threads in the PerlIF are already doing their jobs, we need 
	  # to have sleep just to make sure that this does not take up the entire CPU time.
}
print "\n";
print "logging ended\n";
