Changed default directories, and no more screen types, only open mode/capabilities!

This commit is contained in:
Thomas Touhey 2017-06-30 14:38:41 +02:00
parent c2bad868e6
commit 04c7cbd9d7
13 changed files with 54 additions and 74 deletions

4
configure vendored
View File

@ -30,9 +30,9 @@ loglevel=none # none, info, warn, error, fatal
# Installation directories
root=''
prefix='${root}/usr'
prefix='${root}/opt/p7-project'
prefix_set=
hprefix='${root}/usr'
hprefix='${root}/opt/p7-project'
bindir='${prefix}/bin'
hbindir='${hprefix}/bin'
libdir='${prefix}/lib'"$platform"

View File

@ -51,22 +51,18 @@ typedef struct casio_scsi_s casio_scsi_t;
* written, but not all of it), you shall return an error, because there is
* no partial success.
*
* Here are the stream types. The callbacks that will be taken in `casio_open`
* is directly linked to the stream type you pass to it. */
typedef unsigned int casio_streamtype_t;
# define casio_streamtype_virtual 0x0000
# define casio_streamtype_serial 0x0001
# define casio_streamtype_scsi 0x0002
# define casio_streamtype_usb 0x0004
/* Here are the open modes: */
* An open mode represents the type of operations you will be able to
* make with a stream.
* Here are the open modes: */
typedef unsigned int casio_openmode_t;
# define CASIO_OPENMODE_READ 0x0001 /* the stream is readable. */
# define CASIO_OPENMODE_WRITE 0x0002 /* the stream is writable. */
# define CASIO_OPENMODE_READ 0x0001 /* the stream is readable. */
# define CASIO_OPENMODE_WRITE 0x0002 /* the stream is writable. */
# define CASIO_OPENMODE_SEEK 0x0004 /* the stream is seekable. */
# define CASIO_OPENMODE_SERIAL 0x0008 /* the stream has serial ops. */
# define CASIO_OPENMODE_SCSI 0x0010 /* the stream has SCSI ops. */
# define CASIO_OPENMODE_USB 0x0020 /* the stream has USB ops. */
/* Here is the offset type, to move within a stream: */
@ -94,16 +90,16 @@ typedef int casio_stream_scsi_t OF((void*, casio_scsi_t*));
struct casio_streamfuncs_s {
/* main callbacks */
casio_stream_close_t *casio_streamfuncs_close;
/* settings callbacks */
casio_stream_setattrs_t *casio_streamfuncs_setattrs;
casio_stream_settm_t *casio_streamfuncs_settm;
/* serial callbacks */
/* read & write callbacks */
casio_stream_read_t *casio_streamfuncs_read;
casio_stream_write_t *casio_streamfuncs_write;
casio_stream_seek_t *casio_streamfuncs_seek;
/* serial callbacks */
casio_stream_setattrs_t *casio_streamfuncs_setattrs;
/* SCSI callbacks */
casio_stream_scsi_t *casio_streamfuncs_scsi;
};
@ -113,17 +109,18 @@ struct casio_streamfuncs_s {
# define casio_stream_callbacks_for_serial(CASIO__CLOSE, CASIO__SETCOMM, \
CASIO__SETTM, CASIO__READ, CASIO__WRITE) \
{(casio_stream_close_t*)(CASIO__CLOSE), \
(casio_stream_setattrs_t*)(CASIO__SETCOMM), \
(casio_stream_settm_t*)(CASIO__SETTM), \
(casio_stream_read_t*)(CASIO__READ), \
(casio_stream_write_t*)(CASIO__WRITE), NULL, NULL}
(casio_stream_write_t*)(CASIO__WRITE), NULL, \
(casio_stream_setattrs_t*)(CASIO__SETCOMM), \
NULL}
# define casio_stream_callbacks_for_virtual(CASIO__CLOSE, \
CASIO__READ, CASIO__WRITE, CASIO__SEEK) \
{(casio_stream_close_t*)(CASIO__CLOSE), NULL, NULL, \
{(casio_stream_close_t*)(CASIO__CLOSE), NULL, \
(casio_stream_read_t*)(CASIO__READ), \
(casio_stream_write_t*)(CASIO__WRITE), \
(casio_stream_seek_t*)(CASIO__SEEK), NULL}
(casio_stream_seek_t*)(CASIO__SEEK), NULL, NULL}
/* ************************************************************************* */
/* Stream settings values and flags */
/* ************************************************************************* */
@ -283,8 +280,7 @@ CASIO_EXTERN int CASIO_EXPORT casio_comlist
CASIO_EXTERN int CASIO_EXPORT casio_open
OF((casio_stream_t **casio__stream, casio_openmode_t mode,
casio_streamtype_t casio__type, void *casio__cookie,
const casio_streamfuncs_t *casio__callbacks));
void *casio__cookie, const casio_streamfuncs_t *casio__callbacks));
CASIO_EXTERN int CASIO_EXPORT casio_close
OF((casio_stream_t *casio__stream));
@ -300,13 +296,14 @@ CASIO_EXTERN int CASIO_EXPORT casio_iswritable
# define casio_iswritable(CASIO__STREAM) \
(casio_get_openmode(CASIO__STREAM) & CASIO_OPENMODE_WRITE)
CASIO_EXTERN casio_streamtype_t CASIO_EXPORT casio_get_type
CASIO_EXTERN casio_openmode_t CASIO_EXPORT casio_get_openmode
OF((casio_stream_t *casio__stream));
CASIO_EXTERN casio_openmode_t CASIO_EXPORT casio_get_openmode
CASIO_EXTERN const casio_streamfuncs_t* CASIO_EXPORT casio_get_streamfuncs
OF((casio_stream_t *casio__stream));
CASIO_EXTERN void* CASIO_EXPORT casio_get_cookie
OF((casio_stream_t *casio__stream));
CASIO_EXTERN int CASIO_EXPORT casio_get_lasterr
CASIO_EXTERN int CASIO_EXPORT casio_get_lasterr
OF((casio_stream_t *casio__stream));
/* Read and write data from and to a stream. */

View File

@ -194,7 +194,7 @@ int CASIO_EXPORT casio_seven_send_cmdsys_setlink(casio_link_t *handle,
char sbaud[10], sparity[10], sstopbits[2];
/* check if is a serial connexion */
if (~casio_get_type(handle->casio_link_stream) & casio_streamtype_serial)
if (~casio_get_openmode(handle->casio_link_stream) & CASIO_OPENMODE_SERIAL)
return (casio_error_op);
/* make arguments */

View File

@ -348,6 +348,5 @@ int CASIO_EXPORT casio_seven_open_data_stream(casio_stream_t **stream,
}
/* initialize the stream */
return (casio_open(stream, mode, 0, cookie,
&seven_data_callbacks));
return (casio_open(stream, mode, cookie, &seven_data_callbacks));
}

View File

@ -85,6 +85,7 @@ int CASIO_EXPORT casio_open_csum32(casio_stream_t **stream,
casio_stream_t *original, casio_uint32_t *csum)
{
struct thecookie *cookie = NULL;
casio_openmode_t openmode;
/* FIXME: check original stream */
/* allocate the cookie */
@ -96,6 +97,6 @@ int CASIO_EXPORT casio_open_csum32(casio_stream_t **stream,
cookie->_checksum = csum;
/* Initialize da stream. */
return (casio_open(stream, casio_get_openmode(original),
casio_get_type(original), cookie, &csum32_callbacks));
openmode = casio_get_openmode(original) & CASIO_OPENMODE_READ;
return (casio_open(stream, openmode, cookie, &csum32_callbacks));
}

View File

@ -244,7 +244,7 @@ int CASIO_EXPORT casio_open_stream_file(casio_stream_t **stream,
cookie->_wstream = wstream;
/* initialize the stream */
return (casio_open(stream, mode, 0, cookie, &casio_file_callbacks));
return (casio_open(stream, mode, cookie, &casio_file_callbacks));
fail:
if (rstream && rstream_cl) fclose(rstream);
if (wstream != rstream && wstream_cl) fclose(wstream);

View File

@ -194,10 +194,8 @@ CASIO_LOCAL int casio_libusb_write(void *vcookie,
/* libusb callbacks. */
CASIO_LOCAL const casio_streamfuncs_t casio_libusb_callbacks = {
casio_libusb_close,
NULL, casio_libusb_settm,
casio_libusb_read,
casio_libusb_write,
casio_libusb_close, casio_libusb_settm,
casio_libusb_read, casio_libusb_write, NULL,
NULL, NULL
};
@ -216,8 +214,8 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
libusb_context *context = NULL;
libusb_device *calc = NULL, **device_list = NULL;
libusb_device_handle *dhandle = NULL;
casio_streamtype_t type = casio_streamtype_usb;
libusb_cookie_t *cookie = NULL;
casio_openmode_t openmode = CASIO_OPENMODE_USB;
/* open up context */
if (libusb_init(&context)) {
@ -244,6 +242,7 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
/* check if is a CASIO Protocol 7.00 device */
if (descriptor.idVendor == 0x07cf
&& descriptor.idProduct == 0x6101) {
openmode |= CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE;
calc = device_list[id];
break;
}
@ -251,8 +250,8 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
/* check if is a CASIO SCSI device */
if (descriptor.idVendor == 0x07cf
&& descriptor.idProduct == 0x6102) {
openmode |= CASIO_OPENMODE_SCSI;
calc = device_list[id];
type |= casio_streamtype_scsi;
break;
}
}
@ -343,8 +342,8 @@ int CASIO_EXPORT casio_openusb_libusb(casio_stream_t **stream)
cookie->_end = -1;
/* final call. */
return (casio_open(stream, CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE,
casio_streamtype_usb, cookie, &casio_libusb_callbacks));
return (casio_open(stream, openmode,
cookie, &casio_libusb_callbacks));
fail:
if (cookie) casio_free(cookie);
if (dhandle) libusb_close(dhandle);

View File

@ -102,8 +102,9 @@ int CASIO_EXPORT casio_open_limited(casio_stream_t **stream,
cookie->_left = size;
/* initialize da stream */
return (casio_open(stream, casio_get_openmode(original),
casio_get_type(original), cookie, &casio_limited_callbacks));
return (casio_open(stream,
casio_get_openmode(original) & CASIO_OPENMODE_READ,
cookie, &casio_limited_callbacks));
}
/**

View File

@ -163,6 +163,6 @@ int CASIO_EXPORT casio_open_memory(casio_stream_t **stream,
cookie->_offset = 0;
/* initialize da stream */
return (casio_open(stream, CASIO_OPENMODE_READ, 0, cookie,
return (casio_open(stream, CASIO_OPENMODE_READ, cookie,
&casio_memory_callbacks));
}

View File

@ -477,7 +477,8 @@ int CASIO_EXPORT casio_open_stream_fd(casio_stream_t **stream,
int readfd, int writefd, int closeread, int closewrite)
{
int err; streams_cookie_t *cookie = NULL;
casio_openmode_t mode = CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE;
casio_openmode_t mode =
CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE | CASIO_OPENMODE_SERIAL;
/* check if the devices are valid. */
if ( readfd < 0 || read(readfd, NULL, 0) < 0)
@ -503,7 +504,7 @@ int CASIO_EXPORT casio_open_stream_fd(casio_stream_t **stream,
readfd, writefd));
/* final call */
return (casio_open(stream, mode, casio_streamtype_serial, cookie,
return (casio_open(stream, mode, cookie,
&casio_streams_callbacks));
fail:
if (readfd >= 0 && closeread)

View File

@ -20,20 +20,6 @@
#undef casio_isreadable
#undef casio_iswritable
/**
* casio_get_type:
* Get the stream type.
*
* @arg stream the stream.
* @return the type.
*/
casio_streamtype_t CASIO_EXPORT casio_get_type(casio_stream_t *stream)
{
if (!stream) return (0);
return (stream->casio_stream_type);
}
/**
* casio_get_openmode:
* Get the open mode.

View File

@ -26,15 +26,13 @@
*
* @arg pstream the stream to open.
* @arg mode the open mode.
* @arg type the stream type.
* @arg cookie the stream cookie.
* @arg callbacks the stream callbacks.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_open(casio_stream_t **pstream, casio_openmode_t mode,
casio_streamtype_t type, void *cookie,
const casio_streamfuncs_t *callbacks)
void *cookie, const casio_streamfuncs_t *callbacks)
{
int err; casio_stream_t *stream = NULL;
casio_streamfuncs_t *c;
@ -49,19 +47,18 @@ int CASIO_EXPORT casio_open(casio_stream_t **pstream, casio_openmode_t mode,
memset(c, 0, sizeof(casio_streamfuncs_t));
c->casio_streamfuncs_close = callbacks->casio_streamfuncs_close;
c->casio_streamfuncs_settm = callbacks->casio_streamfuncs_settm;
if (!type
|| (type & (casio_streamtype_usb | casio_streamtype_serial)
&& ~type & casio_streamtype_scsi)) {
c->casio_streamfuncs_read = callbacks->casio_streamfuncs_read;
c->casio_streamfuncs_write = callbacks->casio_streamfuncs_write;
c->casio_streamfuncs_seek = callbacks->casio_streamfuncs_seek; }
if (type & casio_streamtype_serial)
if (mode & CASIO_OPENMODE_READ)
c->casio_streamfuncs_read = callbacks->casio_streamfuncs_read;
if (mode & CASIO_OPENMODE_WRITE)
c->casio_streamfuncs_write = callbacks->casio_streamfuncs_write;
if (mode & (CASIO_OPENMODE_READ | CASIO_OPENMODE_WRITE))
c->casio_streamfuncs_seek = callbacks->casio_streamfuncs_seek;
if (mode & CASIO_OPENMODE_SERIAL)
c->casio_streamfuncs_setattrs = callbacks->casio_streamfuncs_setattrs;
if (type & casio_streamtype_scsi)
if (mode & CASIO_OPENMODE_SCSI)
c->casio_streamfuncs_scsi = callbacks->casio_streamfuncs_scsi;
/* initialize the stream properties */
stream->casio_stream_type = type;
stream->casio_stream_mode = mode;
stream->casio_stream_cookie = cookie;
stream->casio_stream_offset = 0;

View File

@ -27,7 +27,6 @@
struct casio_stream_s {
/* stream information */
casio_streamtype_t casio_stream_type;
casio_openmode_t casio_stream_mode;
void *casio_stream_cookie;
int casio_stream_lasterr;