Commit 0fc33708 authored by Dmitry Frank's avatar Dmitry Frank Committed by Cesanta Bot

First step towards separate userdata argument

PUBLISHED_FROM=93fe1cc2c5e2513509511a81e5919cbd37056b10
parent c416012f
...@@ -4,9 +4,8 @@ decl_name: "mg_connect_ws" ...@@ -4,9 +4,8 @@ decl_name: "mg_connect_ws"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
mg_event_handler_t event_handler, MG_CB(mg_event_handler_t event_handler,
const char *url, const char *protocol, void *user_data);
const char *extra_headers);
--- ---
Helper function that creates an outbound WebSocket connection. Helper function that creates an outbound WebSocket connection.
......
...@@ -3,11 +3,8 @@ title: "mg_connect_ws_opt()" ...@@ -3,11 +3,8 @@ title: "mg_connect_ws_opt()"
decl_name: "mg_connect_ws_opt" decl_name: "mg_connect_ws_opt"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect_ws_opt(struct mg_mgr *mgr, struct mg_connection *mg_connect_ws_opt(
mg_event_handler_t ev_handler, struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
struct mg_connect_opts opts,
const char *url, const char *protocol,
const char *extra_headers);
--- ---
Helper function that creates an outbound WebSocket connection Helper function that creates an outbound WebSocket connection
......
...@@ -3,11 +3,9 @@ title: "mg_connect_http()" ...@@ -3,11 +3,9 @@ title: "mg_connect_http()"
decl_name: "mg_connect_http" decl_name: "mg_connect_http"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect_http(struct mg_mgr *mgr, struct mg_connection *mg_connect_http(
mg_event_handler_t event_handler, struct mg_mgr *mgr,
const char *url, MG_CB(mg_event_handler_t event_handler, void *user_data);
const char *extra_headers,
const char *post_data);
--- ---
Helper function that creates an outbound HTTP connection. Helper function that creates an outbound HTTP connection.
......
...@@ -3,12 +3,8 @@ title: "mg_connect_http_opt()" ...@@ -3,12 +3,8 @@ title: "mg_connect_http_opt()"
decl_name: "mg_connect_http_opt" decl_name: "mg_connect_http_opt"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr, struct mg_connection *mg_connect_http_opt(
mg_event_handler_t ev_handler, struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
struct mg_connect_opts opts,
const char *url,
const char *extra_headers,
const char *post_data);
--- ---
Helper function that creates an outbound HTTP connection. Helper function that creates an outbound HTTP connection.
......
...@@ -4,7 +4,8 @@ decl_name: "mg_file_upload_handler" ...@@ -4,7 +4,8 @@ decl_name: "mg_file_upload_handler"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data, void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
mg_fu_fname_fn local_name_fn); mg_fu_fname_fn local_name_fn
MG_UD_ARG(void *user_data);
--- ---
File upload handler. File upload handler.
......
...@@ -3,7 +3,9 @@ title: "mg_add_sock()" ...@@ -3,7 +3,9 @@ title: "mg_add_sock()"
decl_name: "mg_add_sock" decl_name: "mg_add_sock"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t); struct mg_connection *mg_add_sock(struct mg_mgr *mgr, sock_t sock,
MG_CB(mg_event_handler_t handler,
void *user_data);
--- ---
Creates a connection, associates it with the given socket and event handler Creates a connection, associates it with the given socket and event handler
......
...@@ -3,9 +3,9 @@ title: "mg_add_sock_opt()" ...@@ -3,9 +3,9 @@ title: "mg_add_sock_opt()"
decl_name: "mg_add_sock_opt" decl_name: "mg_add_sock_opt"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_add_sock_opt(struct mg_mgr *, sock_t, struct mg_connection *mg_add_sock_opt(struct mg_mgr *mgr, sock_t sock,
mg_event_handler_t, MG_CB(mg_event_handler_t handler,
struct mg_add_sock_opts); void *user_data);
--- ---
Creates a connection, associates it with the given socket and event handler Creates a connection, associates it with the given socket and event handler
......
...@@ -3,8 +3,9 @@ title: "mg_bind()" ...@@ -3,8 +3,9 @@ title: "mg_bind()"
decl_name: "mg_bind" decl_name: "mg_bind"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_bind(struct mg_mgr *, const char *, struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address,
mg_event_handler_t); MG_CB(mg_event_handler_t handler,
void *user_data);
--- ---
Creates a listening connection. Creates a listening connection.
......
...@@ -4,8 +4,8 @@ decl_name: "mg_bind_opt" ...@@ -4,8 +4,8 @@ decl_name: "mg_bind_opt"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler, MG_CB(mg_event_handler_t handler,
struct mg_bind_opts opts); void *user_data);
--- ---
Creates a listening connection. Creates a listening connection.
......
...@@ -3,7 +3,8 @@ title: "mg_broadcast()" ...@@ -3,7 +3,8 @@ title: "mg_broadcast()"
decl_name: "mg_broadcast" decl_name: "mg_broadcast"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t); void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
size_t len);
--- ---
Passes a message of a given length to all connections. Passes a message of a given length to all connections.
......
...@@ -4,7 +4,8 @@ decl_name: "mg_connect" ...@@ -4,7 +4,8 @@ decl_name: "mg_connect"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler); MG_CB(mg_event_handler_t handler,
void *user_data);
--- ---
Connects to a remote host. Connects to a remote host.
......
...@@ -4,8 +4,8 @@ decl_name: "mg_connect_opt" ...@@ -4,8 +4,8 @@ decl_name: "mg_connect_opt"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler, MG_CB(mg_event_handler_t handler,
struct mg_connect_opts opts); void *user_data);
--- ---
Connects to a remote host. Connects to a remote host.
......
...@@ -4,7 +4,7 @@ decl_name: "mg_event_handler_t" ...@@ -4,7 +4,7 @@ decl_name: "mg_event_handler_t"
symbol_kind: "typedef" symbol_kind: "typedef"
signature: | signature: |
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev, typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
void *ev_data); void *ev_data MG_UD_ARG(void *user_data));
--- ---
Callback function (event handler) prototype. Must be defined by the user. Callback function (event handler) prototype. Must be defined by the user.
......
...@@ -3,7 +3,7 @@ title: "mg_next()" ...@@ -3,7 +3,7 @@ title: "mg_next()"
decl_name: "mg_next" decl_name: "mg_next"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *); struct mg_connection *mg_next(struct mg_mgr *mgr, struct mg_connection *c);
--- ---
Iterates over all active connections. Iterates over all active connections.
......
This diff is collapsed.
...@@ -2963,6 +2963,18 @@ struct { \ ...@@ -2963,6 +2963,18 @@ struct { \
#define MG_ENABLE_EXTRA_ERRORS_DESC 0 #define MG_ENABLE_EXTRA_ERRORS_DESC 0
#endif #endif
#ifndef MG_ENABLE_CALLBACK_USERDATA
#define MG_ENABLE_CALLBACK_USERDATA 0
#endif
#if MG_ENABLE_CALLBACK_USERDATA
#define MG_UD_ARG(ud) , ud
#define MG_CB(cb, ud) cb, ud
#else
#define MG_UD_ARG(ud)
#define MG_CB(cb, ud) cb
#endif
#endif /* CS_MONGOOSE_SRC_FEATURES_H_ */ #endif /* CS_MONGOOSE_SRC_FEATURES_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "mongoose/src/net_if.h" #line 1 "mongoose/src/net_if.h"
...@@ -3229,7 +3241,7 @@ struct mg_connection; ...@@ -3229,7 +3241,7 @@ struct mg_connection;
* Mongoose calls the event handler, passing the events defined below. * Mongoose calls the event handler, passing the events defined below.
*/ */
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev, typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
void *ev_data); void *ev_data MG_UD_ARG(void *user_data));
/* Events. Meaning of event parameter (evp) is given in the comment. */ /* Events. Meaning of event parameter (evp) is given in the comment. */
#define MG_EV_POLL 0 /* Sent to each connection on each mg_mgr_poll() call */ #define MG_EV_POLL 0 /* Sent to each connection on each mg_mgr_poll() call */
...@@ -3392,7 +3404,8 @@ time_t mg_mgr_poll(struct mg_mgr *, int milli); ...@@ -3392,7 +3404,8 @@ time_t mg_mgr_poll(struct mg_mgr *, int milli);
* be passed as the `ev_data` pointer. Maximum message size is capped * be passed as the `ev_data` pointer. Maximum message size is capped
* by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes. * by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
*/ */
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t); void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
size_t len);
#endif #endif
/* /*
...@@ -3408,7 +3421,7 @@ void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t); ...@@ -3408,7 +3421,7 @@ void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
* } * }
* ``` * ```
*/ */
struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *); struct mg_connection *mg_next(struct mg_mgr *mgr, struct mg_connection *c);
/* /*
* Optional parameters to `mg_add_sock_opt()`. * Optional parameters to `mg_add_sock_opt()`.
...@@ -3429,7 +3442,9 @@ struct mg_add_sock_opts { ...@@ -3429,7 +3442,9 @@ struct mg_add_sock_opts {
* *
* For more options see the `mg_add_sock_opt` variant. * For more options see the `mg_add_sock_opt` variant.
*/ */
struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t); struct mg_connection *mg_add_sock(struct mg_mgr *mgr, sock_t sock,
MG_CB(mg_event_handler_t handler,
void *user_data));
/* /*
* Creates a connection, associates it with the given socket and event handler * Creates a connection, associates it with the given socket and event handler
...@@ -3437,9 +3452,10 @@ struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t); ...@@ -3437,9 +3452,10 @@ struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t);
* *
* See the `mg_add_sock_opts` structure for a description of the options. * See the `mg_add_sock_opts` structure for a description of the options.
*/ */
struct mg_connection *mg_add_sock_opt(struct mg_mgr *, sock_t, struct mg_connection *mg_add_sock_opt(struct mg_mgr *mgr, sock_t sock,
mg_event_handler_t, MG_CB(mg_event_handler_t handler,
struct mg_add_sock_opts); void *user_data),
struct mg_add_sock_opts opts);
/* /*
* Optional parameters to `mg_bind_opt()`. * Optional parameters to `mg_bind_opt()`.
...@@ -3485,8 +3501,9 @@ struct mg_bind_opts { ...@@ -3485,8 +3501,9 @@ struct mg_bind_opts {
* *
* See `mg_bind_opt` for full documentation. * See `mg_bind_opt` for full documentation.
*/ */
struct mg_connection *mg_bind(struct mg_mgr *, const char *, struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address,
mg_event_handler_t); MG_CB(mg_event_handler_t handler,
void *user_data));
/* /*
* Creates a listening connection. * Creates a listening connection.
* *
...@@ -3506,7 +3523,8 @@ struct mg_connection *mg_bind(struct mg_mgr *, const char *, ...@@ -3506,7 +3523,8 @@ struct mg_connection *mg_bind(struct mg_mgr *, const char *,
* NOTE: The connection remains owned by the manager, do not free(). * NOTE: The connection remains owned by the manager, do not free().
*/ */
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler, MG_CB(mg_event_handler_t handler,
void *user_data),
struct mg_bind_opts opts); struct mg_bind_opts opts);
/* Optional parameters to `mg_connect_opt()` */ /* Optional parameters to `mg_connect_opt()` */
...@@ -3569,7 +3587,8 @@ struct mg_connect_opts { ...@@ -3569,7 +3587,8 @@ struct mg_connect_opts {
* See `mg_connect_opt()` for full documentation. * See `mg_connect_opt()` for full documentation.
*/ */
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler); MG_CB(mg_event_handler_t handler,
void *user_data));
/* /*
* Connects to a remote host. * Connects to a remote host.
...@@ -3620,7 +3639,8 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address, ...@@ -3620,7 +3639,8 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
* ``` * ```
*/ */
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address, struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
mg_event_handler_t handler, MG_CB(mg_event_handler_t handler,
void *user_data),
struct mg_connect_opts opts); struct mg_connect_opts opts);
#if MG_ENABLE_SSL && MG_NET_IF != MG_NET_IF_SIMPLELINK #if MG_ENABLE_SSL && MG_NET_IF != MG_NET_IF_SIMPLELINK
...@@ -4274,7 +4294,8 @@ void mg_send_websocket_handshake3(struct mg_connection *nc, const char *path, ...@@ -4274,7 +4294,8 @@ void mg_send_websocket_handshake3(struct mg_connection *nc, const char *path,
* ``` * ```
*/ */
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
mg_event_handler_t event_handler, MG_CB(mg_event_handler_t event_handler,
void *user_data),
const char *url, const char *protocol, const char *url, const char *protocol,
const char *extra_headers); const char *extra_headers);
...@@ -4284,10 +4305,9 @@ struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, ...@@ -4284,10 +4305,9 @@ struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
* Mostly identical to `mg_connect_ws`, but allows to provide extra parameters * Mostly identical to `mg_connect_ws`, but allows to provide extra parameters
* (for example, SSL parameters) * (for example, SSL parameters)
*/ */
struct mg_connection *mg_connect_ws_opt(struct mg_mgr *mgr, struct mg_connection *mg_connect_ws_opt(
mg_event_handler_t ev_handler, struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data),
struct mg_connect_opts opts, struct mg_connect_opts opts, const char *url, const char *protocol,
const char *url, const char *protocol,
const char *extra_headers); const char *extra_headers);
/* /*
...@@ -4739,7 +4759,8 @@ typedef struct mg_str (*mg_fu_fname_fn)(struct mg_connection *nc, ...@@ -4739,7 +4759,8 @@ typedef struct mg_str (*mg_fu_fname_fn)(struct mg_connection *nc,
* ``` * ```
*/ */
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data, void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
mg_fu_fname_fn local_name_fn); mg_fu_fname_fn local_name_fn
MG_UD_ARG(void *user_data));
#endif /* MG_ENABLE_HTTP_STREAMING_MULTIPART */ #endif /* MG_ENABLE_HTTP_STREAMING_MULTIPART */
#endif /* MG_ENABLE_FILESYSTEM */ #endif /* MG_ENABLE_FILESYSTEM */
...@@ -4926,11 +4947,10 @@ extern "C" { ...@@ -4926,11 +4947,10 @@ extern "C" {
* "var_1=value_1&var_2=value_2"); * "var_1=value_1&var_2=value_2");
* ``` * ```
*/ */
struct mg_connection *mg_connect_http(struct mg_mgr *mgr, struct mg_connection *mg_connect_http(
mg_event_handler_t event_handler, struct mg_mgr *mgr,
const char *url, MG_CB(mg_event_handler_t event_handler, void *user_data), const char *url,
const char *extra_headers, const char *extra_headers, const char *post_data);
const char *post_data);
/* /*
* Helper function that creates an outbound HTTP connection. * Helper function that creates an outbound HTTP connection.
...@@ -4939,11 +4959,9 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr, ...@@ -4939,11 +4959,9 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
*parameters *parameters
* (for example, SSL parameters) * (for example, SSL parameters)
*/ */
struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr, struct mg_connection *mg_connect_http_opt(
mg_event_handler_t ev_handler, struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data),
struct mg_connect_opts opts, struct mg_connect_opts opts, const char *url, const char *extra_headers,
const char *url,
const char *extra_headers,
const char *post_data); const char *post_data);
/* Creates digest authentication header for a client request. */ /* Creates digest authentication header for a client request. */
...@@ -5837,7 +5855,8 @@ struct mg_sntp_message { ...@@ -5837,7 +5855,8 @@ struct mg_sntp_message {
/* Establishes connection to given sntp server */ /* Establishes connection to given sntp server */
struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr,
mg_event_handler_t event_handler, MG_CB(mg_event_handler_t event_handler,
void *user_data),
const char *sntp_server_name); const char *sntp_server_name);
/* Sends time request to given connection */ /* Sends time request to given connection */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment