rename xxx_create() / xxx_destory() -> xxx_new() / xxx_free()
This commit is contained in:
@@ -5,25 +5,25 @@
|
||||
#include "packet_io_marsio.h"
|
||||
#include "packet_io_dumpfile.h"
|
||||
|
||||
typedef void *on_create(void *config);
|
||||
typedef void on_destroy(void *handle);
|
||||
typedef void *on_stat(void *handle);
|
||||
typedef int on_init(void *handle, uint16_t thread_id);
|
||||
typedef int on_recv(void *handle, uint16_t thread_id, struct packet **pkt);
|
||||
typedef void on_send(void *handle, uint16_t thread_id, struct packet *pkt);
|
||||
typedef void *new_cb(void *config);
|
||||
typedef void free_cb(void *handle);
|
||||
typedef void *stat_cb(void *handle);
|
||||
typedef int init_cb(void *handle, uint16_t thread_id);
|
||||
typedef int recv_cb(void *handle, uint16_t thread_id, struct packet **pkt);
|
||||
typedef void send_cb(void *handle, uint16_t thread_id, struct packet *pkt);
|
||||
|
||||
struct packet_io
|
||||
{
|
||||
void *handle;
|
||||
on_create *create;
|
||||
on_destroy *destroy;
|
||||
on_stat *stat;
|
||||
on_init *init;
|
||||
on_recv *recv;
|
||||
on_send *send;
|
||||
new_cb *on_new;
|
||||
free_cb *on_free;
|
||||
stat_cb *on_stat;
|
||||
init_cb *on_init;
|
||||
recv_cb *on_recv;
|
||||
send_cb *on_send;
|
||||
};
|
||||
|
||||
struct packet_io *packet_io_create(struct packet_io_config *config)
|
||||
struct packet_io *packet_io_new(struct packet_io_config *config)
|
||||
{
|
||||
struct packet_io *handle = (struct packet_io *)calloc(1, sizeof(struct packet_io));
|
||||
if (handle == NULL)
|
||||
@@ -47,25 +47,25 @@ struct packet_io *packet_io_create(struct packet_io_config *config)
|
||||
if (config->mode == PACKET_IO_MARSIO)
|
||||
{
|
||||
_config = &marsio_config;
|
||||
handle->create = (on_create *)packet_io_marsio_create;
|
||||
handle->destroy = (on_destroy *)packet_io_marsio_destory;
|
||||
handle->stat = (on_stat *)packet_io_marsio_stat;
|
||||
handle->init = (on_init *)packet_io_marsio_init;
|
||||
handle->recv = (on_recv *)packet_io_marsio_recv;
|
||||
handle->send = (on_send *)packet_io_marsio_send;
|
||||
handle->on_new = (new_cb *)packet_io_marsio_new;
|
||||
handle->on_free = (free_cb *)packet_io_marsio_free;
|
||||
handle->on_stat = (stat_cb *)packet_io_marsio_stat;
|
||||
handle->on_init = (init_cb *)packet_io_marsio_init;
|
||||
handle->on_recv = (recv_cb *)packet_io_marsio_recv;
|
||||
handle->on_send = (send_cb *)packet_io_marsio_send;
|
||||
}
|
||||
else
|
||||
{
|
||||
_config = &dumpfile_config;
|
||||
handle->create = (on_create *)packet_io_dumpfile_create;
|
||||
handle->destroy = (on_destroy *)packet_io_dumpfile_destory;
|
||||
handle->stat = (on_stat *)packet_io_dumpfile_stat;
|
||||
handle->init = (on_init *)packet_io_dumpfile_init;
|
||||
handle->recv = (on_recv *)packet_io_dumpfile_recv;
|
||||
handle->send = (on_send *)packet_io_dumpfile_send;
|
||||
handle->on_new = (new_cb *)packet_io_dumpfile_new;
|
||||
handle->on_free = (free_cb *)packet_io_dumpfile_free;
|
||||
handle->on_stat = (stat_cb *)packet_io_dumpfile_stat;
|
||||
handle->on_init = (init_cb *)packet_io_dumpfile_init;
|
||||
handle->on_recv = (recv_cb *)packet_io_dumpfile_recv;
|
||||
handle->on_send = (send_cb *)packet_io_dumpfile_send;
|
||||
}
|
||||
|
||||
handle->handle = handle->create(_config);
|
||||
handle->handle = handle->on_new(_config);
|
||||
if (handle->handle == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
@@ -74,15 +74,15 @@ struct packet_io *packet_io_create(struct packet_io_config *config)
|
||||
return handle;
|
||||
|
||||
error_out:
|
||||
packet_io_destroy(handle);
|
||||
packet_io_free(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void packet_io_destroy(struct packet_io *handle)
|
||||
void packet_io_free(struct packet_io *handle)
|
||||
{
|
||||
if (handle)
|
||||
{
|
||||
handle->destroy(handle->handle);
|
||||
handle->on_free(handle->handle);
|
||||
free(handle);
|
||||
handle = NULL;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ void packet_io_destroy(struct packet_io *handle)
|
||||
|
||||
struct packet_io_stat *packet_io_get_stat(struct packet_io *handle)
|
||||
{
|
||||
return (struct packet_io_stat *)handle->stat(handle->handle);
|
||||
return (struct packet_io_stat *)handle->on_stat(handle->handle);
|
||||
}
|
||||
|
||||
void packet_io_print_stat(struct packet_io *handle)
|
||||
@@ -106,15 +106,15 @@ void packet_io_print_stat(struct packet_io *handle)
|
||||
|
||||
int packet_io_init(struct packet_io *handle, uint16_t thread_id)
|
||||
{
|
||||
return handle->init(handle->handle, thread_id);
|
||||
return handle->on_init(handle->handle, thread_id);
|
||||
}
|
||||
|
||||
int packet_io_recv(struct packet_io *handle, uint16_t thread_id, struct packet **pkt)
|
||||
{
|
||||
return handle->recv(handle->handle, thread_id, pkt);
|
||||
return handle->on_recv(handle->handle, thread_id, pkt);
|
||||
}
|
||||
|
||||
void packet_io_send(struct packet_io *handle, uint16_t thread_id, struct packet *pkt)
|
||||
{
|
||||
handle->send(handle->handle, thread_id, pkt);
|
||||
handle->on_send(handle->handle, thread_id, pkt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user