MiniGUI API Reference (MiniGUI-Processes)
v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
|
You can register a customized request handler to extend your server, i.e. mginit, of MiniGUI-Processes. More...
Data Structures | |
struct | _REQUEST |
Macros | |
#define | MAX_SYS_REQID 0x0023 |
Maximal system reserved request identifier. More... | |
#define | MAX_REQID 0x0030 |
Maximal request identifier. More... | |
Typedefs | |
typedef struct _REQUEST | REQUEST |
typedef REQUEST * | PREQUEST |
typedef int(* | REQ_HANDLER) (int cli, int clifd, void *buff, size_t len) |
The prototype of a request handler (version 0). More... | |
typedef int(* | REQ_HANDLER_V1) (int cli, int clifd, void *buff, size_t len, int fd_received) |
The prototype of an extended request handler (version 1). More... | |
Functions | |
static int GUIAPI | ClientRequestEx (const REQUEST *request, const void *ex_data, int ex_data_len, void *result, int len_rslt) |
Sends a request to the server and wait reply. More... | |
static int | ClientRequest (const REQUEST *request, void *result, int len_rslt) |
Sends a request to the server and wait reply. More... | |
MG_EXPORT int GUIAPI | GetSockFD2Server (void) |
Get the file descriptor of the socket connected to the server. More... | |
MG_EXPORT int GUIAPI | ServerSendReplyEx (int clifd, const void *reply, int len, int fd_to_send) |
Sends a reply to the client. More... | |
static int GUIAPI | ServerSendReply (int clifd, const void *reply, int len) |
Sends the reply to the client. More... | |
MG_EXPORT BOOL GUIAPI | RegisterRequestHandler (int req_id, REQ_HANDLER your_handler) |
Registers a customized request handler of version 0. More... | |
MG_EXPORT BOOL GUIAPI | RegisterRequestHandlerV1 (int req_id, REQ_HANDLER_V1 your_handler_v1) |
Registers a customized extended request handler of version 1. More... | |
MG_EXPORT REQ_HANDLER GUIAPI | GetRequestHandler (int req_id) |
Get the request handler by request identifier. More... | |
MG_EXPORT REQ_HANDLER_V1 GUIAPI | GetRequestHandlerV1 (int req_id) |
Get the extended request handler by a request identifier. More... | |
MG_EXPORT void *GUIAPI | GetRequestHandlerEx (int req_id, int *version) |
Get the request handler and the version by request identifier. More... | |
You can register a customized request handler to extend your server, i.e. mginit, of MiniGUI-Processes.
A request consists of an identifier and the data associated with the request. The identifier is used by MiniGUI to determine which handler should be called when a request arrives. When MiniGUI finds one handler, it will call the handler and pass the socket fd connected to the client, the data associated with the request, and the length of the data. Eventually, the handler will sent the reply to the client.
After register a customized request handler in your server, you can call ClientRequest function in the client to send a request to the server and wait for the reply. On the other hand, the request handler in the server will receive the request and call ServerSendReply to send the reply to the client. In this way, you can create a simple IPC (inter-process conmmunication) mechanism between clients and the server.
Example:
#define MAX_REQID 0x0030 |
Maximal request identifier.
#define MAX_SYS_REQID 0x0023 |
Maximal system reserved request identifier.
typedef int(* REQ_HANDLER)(int cli, int clifd, void *buff, size_t len) |
The prototype of a request handler (version 0).
typedef int(* REQ_HANDLER_V1)(int cli, int clifd, void *buff, size_t len, int fd_received) |
The prototype of an extended request handler (version 1).
Since 5.0.0
|
inlinestatic |
Sends a request to the server and wait reply.
If result is NULL or len_rslt is zero, the function will return immediately after sent the data to the server.
This function is a simplified version of ClientRequestEx, i.e. there is no extra data to be sent.
request | The pointer to REQUEST, which contains the data of the request. |
result | The buffer receives the reply. |
len_rslt | The lenght of the buffer. |
Definition at line 2078 of file minigui.h.
References ClientRequestEx(), and NULL.
|
inlinestatic |
Sends a request to the server and wait reply.
If result is NULL or len_rslt is zero, the function will return immediately after sent the data to the server.
request | The pointer to REQUEST, which contains the data of the request. |
ex_data | The pointer to extra data to be sent to the server. |
ex_data_len | The length of the extra data in bytes. |
result | The buffer receives the reply. |
len_rslt | The lenght of the buffer. |
Definition at line 2045 of file minigui.h.
Referenced by ClientRequest().
REQ_HANDLER GUIAPI GetRequestHandler | ( | int | req_id | ) |
Get the request handler by request identifier.
This function returns the request handler of the specified request identifier req_id.
req_id | The request identifier. |
void *GUIAPI GetRequestHandlerEx | ( | int | req_id, |
int * | version | ||
) |
Get the request handler and the version by request identifier.
This function returns the request handler and the version of the specified request identifier req_id.
req_id | The request identifier. |
version | The pointer to an integer to store the version number of the request handler. |
Since 5.0.0
REQ_HANDLER_V1 GUIAPI GetRequestHandlerV1 | ( | int | req_id | ) |
Get the extended request handler by a request identifier.
This function returns the request handler of the specified request identifier req_id.
req_id | The request identifier. |
int GUIAPI GetSockFD2Server | ( | void | ) |
Get the file descriptor of the socket connected to the server.
This function returns the file descriptor of the socket connected to the server, i.e. mginit.
BOOL GUIAPI RegisterRequestHandler | ( | int | req_id, |
REQ_HANDLER | your_handler | ||
) |
Registers a customized request handler of version 0.
This function registers a request handler (version 0) to the server.
req_id | The identifier of the customized request. |
your_handler | The handler of the request. Being NULL to unregister the request handler. |
BOOL GUIAPI RegisterRequestHandlerV1 | ( | int | req_id, |
REQ_HANDLER_V1 | your_handler_v1 | ||
) |
Registers a customized extended request handler of version 1.
This function registers an extended request handler (version 1) to the server.
req_id | The identifier of the customized request. |
your_handler_v1 | The handler (version 1) of the request. Being NULL to unregister the request handler. |
Since 5.0.0
|
inlinestatic |
Sends the reply to the client.
This function sends a replay pointed to by reply which is len bytes long to the client.
clifd | The fd connected to the client. |
reply | The buffer contains the reply data. |
len | The length of the reply data in bytes. |
int GUIAPI ServerSendReplyEx | ( | int | clifd, |
const void * | reply, | ||
int | len, | ||
int | fd_to_send | ||
) |
Sends a reply to the client.
This function sends a replay pointed to by reply which is len bytes long to the client, as well as the file descriptor will be sent to the client.
clifd | The fd connected to the client. |
reply | The buffer contains the reply data. |
len | The length of the reply data in bytes. |
fd_to_send | The file descriptor which will be sent to the client; it will be ignored if it is less than 0. |
Since 5.0.0