On Thu, 19 Jun 2003 01:37:09 -0700 (PDT), [EMAIL PROTECTED] (Ben Crane)
wrote:

>Beau,
>
>Thanx, I hunting the info down now, seems quite
>complex. I'm wondering whether it might not be better
>to have a crack at this in C? Have you found perlXS to
>be difficult to implement?

Inline::C and Swig  are easier to do than XS. I hav'nt been able
to get Swig to work with 5.8 though.  

Here is a simple program to mess with the cdrom tray.
USING Swig:
Run these commands in succession:

swig -perl5 cdrom.i gcc -fpic -c cdrom.c cdrom_wrap.c 
          -Dbool=char -I/usr/lib/perl5/5.6.0/i586-linux/CORE
gcc -shared cdrom_wrap.o cdrom.o -o Cdrom.so

then in the script
use Cdrom;


USING Inline::C:

#!/usr/bin/perl -w
use warnings;
use Inline C;
use strict;

my $cd = '/dev/cdrom';

cdlock($cd,0); #unlocks cdrom
cdeject($cd);  #ejects cdrom
cdclose($cd);  #closes cdrom
cdlock($cd,1); #locks cdrom 

exit;
__END__
__C__
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

#define CDROM "/dev/cdrom" 
/* In all functions 'device' means name of CD-ROM device,
* for example /dev/cdrom
*/

/* Close CD-ROM tray */
int cdclose(char *device)
{
int fd = open(device, O_RDONLY|O_NONBLOCK);
if (fd == -1)
return -1;
if (ioctl(fd, CDROMCLOSETRAY) == -1)
return -1;
close(fd);
return 0;
}

/* Eject CD-ROM tray */
int cdeject(char *device)
{
int fd = open(device, O_RDONLY|O_NONBLOCK);
if (fd == -1)
return -1;
if (ioctl(fd, CDROMEJECT) == -1)
return -1;
close(fd);
return 0;
}

/* Lock (if lock==1) or unlock (if lock==0) CD-ROM tray */
int cdlock(char *device, int lock)
{
int fd;
fd = open(device, O_RDONLY|O_NONBLOCK);
if (fd == -1)
return -1;
if (ioctl(fd, CDROM_LOCKDOOR, lock) == -1)
return -1;
close(fd);
return 0;
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to