2016-02-02 15:40:09 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
Copyright (c) 2015-2016 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _STIO_PRO_H_
|
|
|
|
#define _STIO_PRO_H_
|
|
|
|
|
|
|
|
#include <stio.h>
|
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
enum stio_dev_pro_sid_t
|
2016-02-02 15:40:09 +00:00
|
|
|
{
|
2016-04-16 16:05:57 +00:00
|
|
|
STIO_DEV_PRO_MASTER = -1,
|
|
|
|
STIO_DEV_PRO_IN = 0,
|
|
|
|
STIO_DEV_PRO_OUT = 1,
|
|
|
|
STIO_DEV_PRO_ERR = 2
|
2016-02-02 15:40:09 +00:00
|
|
|
};
|
2016-04-16 16:05:57 +00:00
|
|
|
typedef enum stio_dev_pro_sid_t stio_dev_pro_sid_t;
|
2016-02-02 15:40:09 +00:00
|
|
|
|
|
|
|
typedef struct stio_dev_pro_t stio_dev_pro_t;
|
2016-04-12 13:56:59 +00:00
|
|
|
typedef struct stio_dev_pro_slave_t stio_dev_pro_slave_t;
|
2016-02-02 15:40:09 +00:00
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
typedef int (*stio_dev_pro_on_read_t) (stio_dev_pro_t* dev, const void* data, stio_iolen_t len, stio_dev_pro_sid_t sid);
|
2016-04-12 13:56:59 +00:00
|
|
|
typedef int (*stio_dev_pro_on_write_t) (stio_dev_pro_t* dev, stio_iolen_t wrlen, void* wrctx);
|
2016-04-16 16:05:57 +00:00
|
|
|
typedef void (*stio_dev_pro_on_close_t) (stio_dev_pro_t* dev, stio_dev_pro_sid_t sid);
|
2016-02-02 15:40:09 +00:00
|
|
|
|
|
|
|
struct stio_dev_pro_t
|
|
|
|
{
|
|
|
|
STIO_DEV_HEADERS;
|
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
int flags;
|
2016-04-06 13:49:47 +00:00
|
|
|
stio_intptr_t child_pid;
|
2016-04-12 13:56:59 +00:00
|
|
|
stio_dev_pro_slave_t* slave[3];
|
2016-04-16 16:05:57 +00:00
|
|
|
int slave_count;
|
2016-02-02 15:40:09 +00:00
|
|
|
|
|
|
|
stio_dev_pro_on_read_t on_read;
|
|
|
|
stio_dev_pro_on_write_t on_write;
|
2016-04-16 16:05:57 +00:00
|
|
|
stio_dev_pro_on_close_t on_close;
|
2016-02-02 15:40:09 +00:00
|
|
|
|
2016-04-12 13:56:59 +00:00
|
|
|
stio_mchar_t* mcmd;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stio_dev_pro_slave_t
|
|
|
|
{
|
|
|
|
STIO_DEV_HEADERS;
|
2016-04-16 16:05:57 +00:00
|
|
|
stio_dev_pro_sid_t id;
|
2016-04-12 13:56:59 +00:00
|
|
|
stio_syshnd_t pfd;
|
|
|
|
stio_dev_pro_t* master; /* parent device */
|
2016-02-02 15:40:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum stio_dev_pro_make_flag_t
|
|
|
|
{
|
|
|
|
STIO_DEV_PRO_WRITEIN = (1 << 0),
|
|
|
|
STIO_DEV_PRO_READOUT = (1 << 1),
|
|
|
|
STIO_DEV_PRO_READERR = (1 << 2),
|
2016-04-06 13:49:47 +00:00
|
|
|
|
|
|
|
STIO_DEV_PRO_ERRTOOUT = (1 << 3),
|
|
|
|
STIO_DEV_PRO_OUTTOERR = (1 << 4),
|
|
|
|
|
|
|
|
STIO_DEV_PRO_INTONUL = (1 << 5),
|
|
|
|
STIO_DEV_PRO_OUTTONUL = (1 << 6),
|
|
|
|
STIO_DEV_PRO_ERRTONUL = (1 << 7),
|
|
|
|
|
|
|
|
STUO_DEV_PRO_DROPIN = (1 << 8),
|
|
|
|
STUO_DEV_PRO_DROPOUT = (1 << 9),
|
2016-04-12 13:56:59 +00:00
|
|
|
STUO_DEV_PRO_DROPERR = (1 << 10),
|
|
|
|
|
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
STIO_DEV_PRO_SHELL = (1 << 13),
|
|
|
|
|
|
|
|
/* perform no waitpid() on a child process upon device destruction.
|
|
|
|
* you should set this flag if your application has automatic child
|
|
|
|
* process reaping enabled. for instance, SIGCHLD is set to SIG_IGN
|
|
|
|
* on POSIX.1-2001 compliant systems */
|
|
|
|
STIO_DEV_PRO_FORGET_CHILD = (1 << 14),
|
|
|
|
|
|
|
|
|
|
|
|
STIO_DEV_PRO_FORGET_DIEHARD_CHILD = (1 << 15)
|
2016-02-02 15:40:09 +00:00
|
|
|
};
|
|
|
|
typedef enum stio_dev_pro_make_flag_t stio_dev_pro_make_flag_t;
|
|
|
|
|
|
|
|
typedef struct stio_dev_pro_make_t stio_dev_pro_make_t;
|
|
|
|
struct stio_dev_pro_make_t
|
|
|
|
{
|
|
|
|
int flags; /**< bitwise-ORed of stio_dev_pro_make_flag_t enumerators */
|
|
|
|
const void* cmd;
|
2016-04-16 16:05:57 +00:00
|
|
|
stio_dev_pro_on_write_t on_write; /* mandatory */
|
|
|
|
stio_dev_pro_on_read_t on_read; /* mandatory */
|
|
|
|
stio_dev_pro_on_close_t on_close; /* optional */
|
2016-02-02 15:40:09 +00:00
|
|
|
};
|
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
|
|
|
|
enum stio_dev_pro_ioctl_cmd_t
|
|
|
|
{
|
2016-04-17 17:00:58 +00:00
|
|
|
STIO_DEV_PRO_CLOSE,
|
|
|
|
STIO_DEV_PRO_KILL_CHILD
|
2016-04-16 16:05:57 +00:00
|
|
|
};
|
|
|
|
typedef enum stio_dev_pro_ioctl_cmd_t stio_dev_pro_ioctl_cmd_t;
|
|
|
|
|
2016-02-02 15:40:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STIO_EXPORT stio_dev_pro_t* stio_dev_pro_make (
|
|
|
|
stio_t* stio,
|
|
|
|
stio_size_t xtnsize,
|
|
|
|
const stio_dev_pro_make_t* data
|
|
|
|
);
|
|
|
|
|
|
|
|
STIO_EXPORT void stio_dev_pro_kill (
|
|
|
|
stio_dev_pro_t* pro
|
|
|
|
);
|
|
|
|
|
|
|
|
STIO_EXPORT int stio_dev_pro_write (
|
2016-04-12 13:56:59 +00:00
|
|
|
stio_dev_pro_t* pro,
|
|
|
|
const void* data,
|
|
|
|
stio_iolen_t len,
|
|
|
|
void* wrctx
|
|
|
|
);
|
|
|
|
|
|
|
|
STIO_EXPORT int stio_dev_pro_timedwrite (
|
|
|
|
stio_dev_pro_t* pro,
|
|
|
|
const void* data,
|
|
|
|
stio_iolen_t len,
|
|
|
|
const stio_ntime_t* tmout,
|
|
|
|
void* wrctx
|
2016-02-02 15:40:09 +00:00
|
|
|
);
|
|
|
|
|
2016-04-16 16:05:57 +00:00
|
|
|
STIO_EXPORT int stio_dev_pro_close (
|
|
|
|
stio_dev_pro_t* pro,
|
|
|
|
stio_dev_pro_sid_t sid
|
|
|
|
);
|
|
|
|
|
2016-04-17 17:00:58 +00:00
|
|
|
|
|
|
|
STIO_EXPORT int stio_dev_pro_killchild (
|
|
|
|
stio_dev_pro_t* pro
|
|
|
|
);
|
|
|
|
|
2016-02-02 15:40:09 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|