2020-06-14 16:09:17 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
Copyright (c) 2016-2020 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 PIPEVIDED 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, PIPECUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PIPEFITS; 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 _MIO_MAR_H_
|
|
|
|
#define _MIO_MAR_H_
|
|
|
|
|
|
|
|
#include <mio.h>
|
|
|
|
|
|
|
|
typedef struct mio_dev_mar_t mio_dev_mar_t;
|
|
|
|
|
2020-06-24 03:00:46 +00:00
|
|
|
enum mio_dev_mar_progress_t
|
2020-06-14 16:09:17 +00:00
|
|
|
{
|
2020-06-24 03:00:46 +00:00
|
|
|
MIO_DEV_MAR_INITIAL,
|
|
|
|
MIO_DEV_MAR_CONNECTING,
|
|
|
|
MIO_DEV_MAR_CONNECTED,
|
|
|
|
MIO_DEV_MAR_QUERY_STARTING,
|
|
|
|
MIO_DEV_MAR_QUERY_STARTED,
|
|
|
|
MIO_DEV_MAR_ROW_FETCHING,
|
|
|
|
MIO_DEV_MAR_ROW_FETCHED
|
2020-06-14 16:09:17 +00:00
|
|
|
};
|
2020-06-24 03:00:46 +00:00
|
|
|
typedef enum mio_dev_mar_progress_t mio_dev_mar_progress_t;
|
2020-06-14 16:09:17 +00:00
|
|
|
|
2020-06-24 03:00:46 +00:00
|
|
|
#define MIO_DEV_MAR_SET_PROGRESS(dev,value) ((dev)->progress = (value))
|
|
|
|
#define MIO_DEV_MAR_GET_PROGRESS(dev) ((dev)->progress)
|
2020-06-14 16:09:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef int (*mio_dev_mar_on_read_t) (
|
|
|
|
mio_dev_mar_t* dev,
|
2020-06-21 08:42:36 +00:00
|
|
|
const void* data,
|
|
|
|
mio_iolen_t len
|
2020-06-14 16:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
typedef int (*mio_dev_mar_on_write_t) (
|
|
|
|
mio_dev_mar_t* dev,
|
2020-06-21 08:42:36 +00:00
|
|
|
mio_iolen_t wrlen,
|
|
|
|
void* wrctx
|
2020-06-14 16:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
typedef void (*mio_dev_mar_on_connect_t) (
|
|
|
|
mio_dev_mar_t* dev
|
|
|
|
);
|
|
|
|
|
|
|
|
typedef void (*mio_dev_mar_on_disconnect_t) (
|
|
|
|
mio_dev_mar_t* dev
|
|
|
|
);
|
|
|
|
|
|
|
|
typedef void (*mio_dev_mar_on_query_started_t) (
|
|
|
|
mio_dev_mar_t* dev,
|
2020-06-21 08:42:36 +00:00
|
|
|
int mar_ret,
|
|
|
|
const mio_bch_t* mar_errmsg
|
2020-06-14 16:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
typedef void (*mio_dev_mar_on_row_fetched_t) (
|
|
|
|
mio_dev_mar_t* dev,
|
2020-06-21 08:42:36 +00:00
|
|
|
void* row_data
|
2020-06-14 16:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
struct mio_dev_mar_t
|
|
|
|
{
|
|
|
|
MIO_DEV_HEADER;
|
|
|
|
|
|
|
|
void* hnd;
|
|
|
|
void* res;
|
2020-06-24 03:00:46 +00:00
|
|
|
mio_dev_mar_progress_t progress;
|
2020-06-14 16:09:17 +00:00
|
|
|
|
2020-06-24 03:00:46 +00:00
|
|
|
unsigned int connected: 1;
|
|
|
|
unsigned int connected_deferred: 1;
|
|
|
|
unsigned int query_started_deferred: 1;
|
2020-06-24 07:37:11 +00:00
|
|
|
/*unsigned int query_started: 1;*/
|
|
|
|
unsigned int row_fetched_deferred: 1;
|
2020-06-24 03:00:46 +00:00
|
|
|
unsigned int broken: 1;
|
|
|
|
mio_syshnd_t broken_syshnd;
|
2020-06-14 16:09:17 +00:00
|
|
|
|
|
|
|
int row_wstatus;
|
|
|
|
void* row;
|
|
|
|
|
|
|
|
mio_dev_mar_on_read_t on_read;
|
|
|
|
mio_dev_mar_on_write_t on_write;
|
|
|
|
mio_dev_mar_on_connect_t on_connect;
|
|
|
|
mio_dev_mar_on_disconnect_t on_disconnect;
|
|
|
|
mio_dev_mar_on_query_started_t on_query_started;
|
|
|
|
mio_dev_mar_on_row_fetched_t on_row_fetched;
|
|
|
|
};
|
|
|
|
|
2020-06-24 03:00:46 +00:00
|
|
|
enum mio_dev_mar_make_flag_t
|
|
|
|
{
|
2020-06-24 07:37:11 +00:00
|
|
|
MIO_DEV_MAR_USE_TMOUT = (1 << 0)
|
2020-06-24 03:00:46 +00:00
|
|
|
};
|
|
|
|
typedef enum mio_dev_mar_make_flag_t mio_dev_mar_make_flag_t;
|
|
|
|
|
2020-06-24 07:37:11 +00:00
|
|
|
|
|
|
|
typedef struct mio_dev_mar_tmout_t mio_dev_mar_tmout_t;
|
|
|
|
struct mio_dev_mar_tmout_t
|
|
|
|
{
|
|
|
|
mio_ntime_t c;
|
|
|
|
mio_ntime_t r;
|
|
|
|
mio_ntime_t w;
|
|
|
|
};
|
|
|
|
|
2020-06-14 16:09:17 +00:00
|
|
|
typedef struct mio_dev_mar_make_t mio_dev_mar_make_t;
|
|
|
|
struct mio_dev_mar_make_t
|
|
|
|
{
|
2020-06-24 03:00:46 +00:00
|
|
|
int flags;
|
2020-06-24 07:37:11 +00:00
|
|
|
mio_dev_mar_tmout_t tmout;
|
2020-06-14 16:09:17 +00:00
|
|
|
mio_dev_mar_on_write_t on_write; /* mandatory */
|
|
|
|
mio_dev_mar_on_read_t on_read; /* mandatory */
|
|
|
|
mio_dev_mar_on_connect_t on_connect; /* optional */
|
|
|
|
mio_dev_mar_on_disconnect_t on_disconnect; /* optional */
|
|
|
|
mio_dev_mar_on_query_started_t on_query_started;
|
|
|
|
mio_dev_mar_on_row_fetched_t on_row_fetched;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mio_dev_mar_connect_t mio_dev_mar_connect_t;
|
|
|
|
struct mio_dev_mar_connect_t
|
|
|
|
{
|
|
|
|
const mio_bch_t* host;
|
|
|
|
const mio_bch_t* username;
|
|
|
|
const mio_bch_t* password;
|
|
|
|
const mio_bch_t* dbname;
|
|
|
|
mio_uint16_t port;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum mio_dev_mar_ioctl_cmd_t
|
|
|
|
{
|
|
|
|
MIO_DEV_MAR_CONNECT,
|
|
|
|
MIO_DEV_MAR_QUERY_WITH_BCS,
|
|
|
|
MIO_DEV_MAR_FETCH_ROW
|
|
|
|
};
|
|
|
|
typedef enum mio_dev_mar_ioctl_cmd_t mio_dev_mar_ioctl_cmd_t;
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
typedef struct mio_svc_marc_t mio_svc_marc_t;
|
2020-06-19 09:17:42 +00:00
|
|
|
typedef mio_dev_mar_connect_t mio_svc_marc_connect_t;
|
2020-06-24 07:37:11 +00:00
|
|
|
typedef mio_dev_mar_tmout_t mio_svc_marc_tmout_t;
|
2020-06-19 09:17:42 +00:00
|
|
|
|
2020-06-21 08:42:36 +00:00
|
|
|
enum mio_svc_marc_qtype_t
|
|
|
|
{
|
|
|
|
MIO_SVC_MARC_QTYPE_SELECT, /* SELECT, SHOW, ... */
|
|
|
|
MIO_SVC_MARC_QTYPE_ACTION /* UPDATE, INSERT, DELETE, ALTER ... */
|
|
|
|
};
|
|
|
|
typedef enum mio_svc_marc_qtype_t mio_svc_marc_qtype_t;
|
|
|
|
|
|
|
|
enum mio_svc_marc_rcode_t
|
|
|
|
{
|
|
|
|
MIO_SVC_MARC_RCODE_ROW, /* has row *- data is MYSQL_ROW */
|
|
|
|
MIO_SVC_MARC_RCODE_DONE, /* completed or no more row - data is NULL */
|
2020-06-21 15:30:44 +00:00
|
|
|
MIO_SVC_MARC_RCODE_ERROR /* query error - data is mio_sv_marc_dev_error_t* */
|
2020-06-21 08:42:36 +00:00
|
|
|
};
|
|
|
|
typedef enum mio_svc_marc_rcode_t mio_svc_marc_rcode_t;
|
|
|
|
|
2020-06-21 15:30:44 +00:00
|
|
|
struct mio_svc_marc_dev_error_t
|
|
|
|
{
|
|
|
|
int mar_errcode;
|
|
|
|
const mio_bch_t* mar_errmsg;
|
|
|
|
};
|
|
|
|
typedef struct mio_svc_marc_dev_error_t mio_svc_marc_dev_error_t;
|
|
|
|
|
2020-06-21 08:42:36 +00:00
|
|
|
typedef void (*mio_svc_marc_on_result_t) (
|
|
|
|
mio_svc_marc_t* marc,
|
|
|
|
mio_oow_t sid,
|
|
|
|
mio_svc_marc_rcode_t rcode,
|
|
|
|
void* data,
|
|
|
|
void* qctx
|
2020-06-19 09:17:42 +00:00
|
|
|
);
|
|
|
|
|
2020-06-24 07:37:11 +00:00
|
|
|
|
2020-06-19 09:17:42 +00:00
|
|
|
/* -------------------------------------------------------------- */
|
2020-06-14 16:09:17 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MIO_EXPORT mio_dev_mar_t* mio_dev_mar_make (
|
|
|
|
mio_t* mio,
|
|
|
|
mio_oow_t xtnsize,
|
|
|
|
const mio_dev_mar_make_t* data
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(MIO_HAVE_INLINE)
|
|
|
|
static MIO_INLINE mio_t* mio_dev_mar_getmio (mio_dev_mar_t* mar) { return mio_dev_getmio((mio_dev_t*)mar); }
|
|
|
|
#else
|
|
|
|
# define mio_dev_mar_getmio(mar) mio_dev_getmio(mar)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MIO_HAVE_INLINE)
|
|
|
|
static MIO_INLINE void* mio_dev_mar_getxtn (mio_dev_mar_t* mar) { return (void*)(mar + 1); }
|
|
|
|
#else
|
|
|
|
# define mio_dev_mar_getxtn(mar) ((void*)(((mio_dev_mar_t*)mar) + 1))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
MIO_EXPORT int mio_dev_mar_connect (
|
|
|
|
mio_dev_mar_t* mar,
|
|
|
|
mio_dev_mar_connect_t* ci
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT int mio_dev_mar_querywithbchars (
|
|
|
|
mio_dev_mar_t* mar,
|
|
|
|
const mio_bch_t* qstr,
|
|
|
|
mio_oow_t qlen
|
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT int mio_dev_mar_fetchrows (
|
|
|
|
mio_dev_mar_t* mar
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(MIO_HAVE_INLINE)
|
|
|
|
static MIO_INLINE void mio_dev_mar_kill (mio_dev_mar_t* mar) { mio_dev_kill ((mio_dev_t*)mar); }
|
|
|
|
static MIO_INLINE void mio_dev_mar_halt (mio_dev_mar_t* mar) { mio_dev_halt ((mio_dev_t*)mar); }
|
|
|
|
#else
|
|
|
|
# define mio_dev_mar_kill(mar) mio_dev_kill((mio_dev_t*)mar)
|
|
|
|
# define mio_dev_mar_halt(mar) mio_dev_halt((mio_dev_t*)mar)
|
|
|
|
#endif
|
|
|
|
|
2020-06-24 09:09:56 +00:00
|
|
|
MIO_EXPORT mio_oow_t mio_dev_mar_escapebchars (
|
|
|
|
mio_dev_mar_t* dev,
|
|
|
|
const mio_bch_t* qstr,
|
|
|
|
mio_oow_t qlen,
|
|
|
|
mio_bch_t* buf
|
|
|
|
);
|
2020-06-14 16:09:17 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* MARDB CLIENT SERVICE */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
MIO_EXPORT mio_svc_marc_t* mio_svc_marc_start (
|
2020-06-19 09:17:42 +00:00
|
|
|
mio_t* mio,
|
2020-06-24 07:37:11 +00:00
|
|
|
const mio_svc_marc_connect_t* ci,
|
|
|
|
const mio_svc_marc_tmout_t* tmout
|
2020-06-14 16:09:17 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
MIO_EXPORT void mio_svc_marc_stop (
|
|
|
|
mio_svc_marc_t* marc
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(MIO_HAVE_INLINE)
|
|
|
|
static MIO_INLINE mio_t* mio_svc_marc_getmio(mio_svc_marc_t* svc) { return mio_svc_getmio((mio_svc_t*)svc); }
|
|
|
|
#else
|
|
|
|
# define mio_svc_marc_getmio(svc) mio_svc_getmio(svc)
|
|
|
|
#endif
|
|
|
|
|
2020-06-24 09:09:56 +00:00
|
|
|
MIO_EXPORT int mio_svc_marc_querywithbchars (
|
2020-06-21 15:30:44 +00:00
|
|
|
mio_svc_marc_t* marc,
|
|
|
|
mio_oow_t sid,
|
|
|
|
mio_svc_marc_qtype_t qtype,
|
|
|
|
const mio_bch_t* qptr,
|
|
|
|
mio_oow_t qlen,
|
|
|
|
mio_svc_marc_on_result_t on_result,
|
|
|
|
void* qctx
|
2020-06-19 09:17:42 +00:00
|
|
|
);
|
|
|
|
|
2020-06-24 09:09:56 +00:00
|
|
|
MIO_EXPORT mio_oow_t mio_svc_marc_escapebchars (
|
|
|
|
mio_svc_marc_t* marc,
|
|
|
|
const mio_bch_t* qstr,
|
|
|
|
mio_oow_t qlen,
|
|
|
|
mio_bch_t* buf
|
2020-06-24 07:37:11 +00:00
|
|
|
);
|
|
|
|
|
2020-06-14 16:09:17 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|