cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/doc/p7_sinit.3.txt

145 lines
3.3 KiB
Plaintext

P7_SINIT(3)
===========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_sinit - initialize libp7 with a custom stream
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
#include <libp7/stream.h>
int p7_sinit(p7_handle_t **h, unsigned int flags,
const char *name, p7_stream_t dstream);
p7_handle_t *handle;
int err = p7_sinit(&handle, 1, 1, NULL, (p7_stream_t){
.cookie = cookie,
.read = cookie_read,
.write = cookie_write,
.close = cookie_close,
});
if (err)
printf("Couldn't initialize libp7/communication: %s\n", p7_strerror(err));
/* make miracles */
p7_exit(handle, 1);
----
WARNING
-------
Before sending a pointer to the handle, if you want libp7 to allocate it,
it must be *NULL*! Otherwise, it will try to use the existing one!
DESCRIPTION
-----------
This function is a more advanced version of the functions defined *p7_init*(3):
where these functions use the built-in streams, `p7_sinit` let you define your
own stream, which means *it's up to you to make the connexion between the
external device and the library*.
The stream structure is the following:
[source,c]
----
typedef struct {
void *cookie;
int (*read)();
int (*write)();
int (*setcomm)();
int (*close)();
} p7_stream_t;
----
The callbacks return the libp7 error, or 0 if no error has occured. They are
as follows:
_*read_::
This function implements read operations for the stream. When called,
it receives four arguments:
[source,c]
----
int read(void *cookie, unsigned char *dest, size_t size,
unsigned int timeout);
----
::
The *buf* and *size* arguments are, respectively, a buffer into which
input data can be placed and the size of that buffer. The *timeout*
argument is the timeout in milliseconds.
::
If **read* is a null pointer, then reads from the stream always return
*p7_error_noread*.
_*write_::
This function implements write operations for the stream. When called,
it receives three arguments:
[source,c]
----
int write(void *cookie, const unsigned char *data, size_t size);
----
::
The *buf* and *size* arguments are, respectively, a buffer of data to be
output to the stream and the size of that buffer.
::
If **write* is a null pointer, then outputs to the stream always return
*p7_error_nowrite*.
_*setcomm_::
This function sets communication settings. When called, it receives
four arguments:
[source,c]
----
int setcomm(void *cookie, int speed, int parity, int stopbits);
----
::
The *speed* argument is the speed of the communication in bauds per seconds.
It can be one of: *P7_B9600*, *P7_B19200*.
::
The *parity* argument is the parity of the communication.
It can be one of: *P7_PARITY_NONE*, *P7_PARITY_ODD*, *P7_PARITY_EVEN*.
::
The *stopbits* is the number of stop bits.
It can be one of: *P7_ONESTOPBIT*, *P7_TWOSTOPBITS*.
::
If **setcomm* is a null pointer, or returns an error, it will generally
just be ignored.
_*close_::
This function closes the stream. When called, it receives one argument:
[source,c]
----
int close(void *cookie);
----
::
It should not be a null pointer, and always return 0.
For the flags, see *p7_init*(3).
RETURN VALUE
------------
This function returns zero if everything went well, and the error code
otherwise.
ERRORS
------
See *p7_error*(3).
SEE ALSO
--------
*libp7*(3),
*p7_init*(3),
*p7_error*(3)