Experts, I have been racking my brain over this one for the past two days. It should be simple but for the life of me I cannot figure it out. I want to convert the following structure into a class:
Code:
#define SIOC_SERIAL _IOR('S', 254, struct scsi_serial)
struct scsi_serial{
ubit8 device_type; // SCSI Device Type.
ubit8 page_code; // SCSI Page Code.
ubit8 reserved; // SCSI Reserved.
ubit8 page_length; // SCSI Page Length.
ubit8 serial[252]; // SCSI Serial Number.
};
The above mentioned structure is from the HPUX 11i scsi.h and scsi_ctl.h files.
The closest that I have been able to come is as follows:
Code:
/**************************************************
**
** Filename: cdskinfo2.h
**
** Purpose:
**
**************************************************/
#ifndef _CDSKINFO2_H_
#define _CDSKINFO2_H_
#include <string>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#define SIOC_SERIAL _IOR('S', 254, struct scsi_serial)
struct scsi_serial{
ubit8 device_type; // SCSI Device Type.
ubit8 page_code; // SCSI Page Code.
ubit8 reserved; // SCSI Reserved.
ubit8 page_length; // SCSI Page Length.
ubit8 serial[252]; // SCSI Serial Number.
};
class CdskInfo{
public:
/* Data Members */
char device_name[256]; // SCSI Device Name.
struct scsi_serial sn;
// Constructor
CdskInfo( char *s );
/* Public Methods */
void print_device_name();
void dump();
int open_device();
};
#endif
Code:
/**************************************************
**
** Filename: cdskinfo2.c
**
** Purpose:
**
**************************************************/
#include "cdskinfo2.h"
CdskInfo::CdskInfo( char *s ){
int fd, ret;
strcpy( device_name, s );
open_device();
}
void CdskInfo::print_device_name(){
printf ( "SCSI_DEVICE_NAME=%s\n", device_name );
}
void CdskInfo::dump(){
printf ( "SCSI_DEVICE_NAME=%s\n", device_name );
printf ( "SCSI_SERIAL_NUMBER=%s\n", sn.serial );
}
int CdskInfo::open_device ( ){
int fd, ret;
if ( ( fd = open( device_name, O_RDONLY | O_NDELAY ) ) <= 0 ){
perror( "Open Error" );
return ( -1 );
}
if ( ( ret = ioctl( fd, SIOC_SERIAL, &sn ) ) != 0 ){
perror( "SIOC_SERIAL Error" );
return ( -1 );
}
return ( ret );
}
Code:
/**************************************************
**
** Filename: cdskinfo_main.cc
**
** Purpose:
**
**************************************************/
#include <iostream.h>
#include <cstdlib>
#include "cdskinfo2.h"
int main ( int argc, char *argv[] ) {
CdskInfo sserial( argv[1] );
sserial.print_device_name();
sserial.dump();
exit( 0 );
}
The above source compiles and runs fine but it is not quite what I am trying to accomplish. My main desire is to eliminate the need to physically define the scsi_serial structure all to gether and just have a "pure" class based on this structure. One of the biggest hurdles I have had in this conversion is with the ioctl statement.
Can anyone help me in solving this problem.
Thanks in advance,
DeadPoet