From 3d963b3d2545162501ba797ea769a58bbcd2aafc Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Wed, 30 Aug 2023 12:23:26 +0800 Subject: [PATCH] Extend JoinLayer() to JoinLayerEx() to return the client identifier; Add a new API GetClientId() --- include/minigui.h | 89 +++++++++++++++++++++++++++++++++++++++++++-- src/client/client.c | 18 +++++++-- src/misc/map.c | 2 +- 3 files changed, 101 insertions(+), 8 deletions(-) diff --git a/include/minigui.h b/include/minigui.h index 5e8bb536..3290b356 100644 --- a/include/minigui.h +++ b/include/minigui.h @@ -456,6 +456,45 @@ MG_EXPORT void GUIAPI MiniGUIPanic (int exitcode); * @{ */ +/** + * \fn GHANDLE GUIAPI JoinLayerEx (const char* layer_name, + const char* client_name, + int max_nr_highers, int max_nr_normals, int *cli_id) + * \brief Joins to a layer and returns the client identifier if success. + * + * This function should be called by clients before calling any other MiniGUI + * functions. You can call \a GetLayerInfo to get the layer information. + * If the layer to be joined does not exist, the server, i.e. \a mginit, will + * try to create a new one. If you passed a NULL pointer or a null string for + * \a layer_name, the client will join to the default layer. + * + * If the client want to create a new layer, you should specify the maximal + * number of z-nodes in the higher level (max_nr_highers) and the maximal + * number of z-nodes in the normal level (max_nr_normals) of the new layer. + * Passing zero to \a max_nr_highers and max_nr_normals will use the default + * values, and the default values are specified by ServerStartup. + * + * Note that the server will create a default layer named "mginit". + * + * \param layer_name The name of the layer. You can use NAME_TOPMOST_LAYER to + * specify the current topmost layer. + * \param client_name The name of the client. + * \param max_nr_highers The maximal number of z-nodes in the higher level of + * the new layer. + * \param max_nr_normals The maximal number of z-nodes in the normal level of + * the new layer. + * \param cli_id The pointer to a buffer of int to return the client identifier. + * + * \return The handle to the layer on success, INV_LAYER_HANDLE on error. + * + * \note Only call this function in clients of MiniGUI-Processes. + * + * \sa GetLayerInfo, ServerStartup, ServerCreateLayer + */ +MG_EXPORT GHANDLE GUIAPI JoinLayerEx (const char* layer_name, + const char* client_name, + int max_nr_highers, int max_nr_normals, int *cli_id); + /** * \fn GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, @@ -490,9 +529,30 @@ MG_EXPORT void GUIAPI MiniGUIPanic (int exitcode); * * \sa GetLayerInfo, ServerStartup, ServerCreateLayer */ -MG_EXPORT GHANDLE GUIAPI JoinLayer (const char* layer_name, +static inline GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, - int max_nr_highers, int max_nr_normals); + int max_nr_highers, int max_nr_normals) +{ + return JoinLayerEx (layer_name, client_name, + max_nr_highers, max_nr_normals, NULL); +} + +/** + * \fn int GUIAPI GetClientId (void) + * \brief Gets the client identifier. + * + * You can get the information of a layer through this function. + * The information will be returned through the pointer arguments + * if the specific pointer is not NULL. + * + * \return Returns the client identifier of the current process. + * Note that the server always returns 0. + * + * \sa JoinLayerEx + * + * Since 5.2.0 + */ +MG_EXPORT int GUIAPI GetClientId (void); /** * \fn GHANDLE GUIAPI GetLayerInfo (const char* layer_name, @@ -2125,7 +2185,7 @@ MG_EXPORT int GUIAPI ServerSendReplyEx (int clifd, * \fn int GUIAPI ServerSendReply (int clifd, const void* reply, int len) * \brief Sends the reply to the client. * - * This function sends a replay pointed to by \a reply which is + * This function sends a reply pointed to by \a reply which is * \a len bytes long to the client. * * \note Only used by the server to send the reply to the client. @@ -2673,6 +2733,26 @@ MG_EXPORT void GUIAPI DesktopUpdateAllWindow (void); #define DUMMY_LAYER_HANDLE (GHANDLE)(-1) +/** + * \fn GHANDLE GUIAPI JoinLayerEx (const char* layer_name, + const char* client_name, + int max_nr_highers, int max_nr_normals, int *cli_fd) + * \brief The dummy replacement of the same function for MiniGUI-Processes. + * + * This function is a replacment of the same function for MiniGUI-Processes + * runtime mode. We provide this function for MiniGUI-Threads and + * MiniGUI-Standalone runtime modes, in order to avoid using the + * conditional compilation instructions in your source code. + * + * \return Always returns DUMMY_LAYER_HANDLE to indicate success. + */ +static inline GHANDLE GUIAPI JoinLayerEx (const char* layer_name, + const char* client_name, + int max_nr_highers, int max_nr_normals, int *cli_fd) +{ + return DUMMY_LAYER_HANDLE; +} + /** * \fn GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, @@ -2687,7 +2767,8 @@ MG_EXPORT void GUIAPI DesktopUpdateAllWindow (void); * \return Always returns DUMMY_LAYER_HANDLE to indicate success. */ static inline GHANDLE GUIAPI JoinLayer (const char* layer_name, - const char* client_name, int max_nr_highers, int max_nr_normals) + const char* client_name, + int max_nr_highers, int max_nr_normals) { return DUMMY_LAYER_HANDLE; } diff --git a/src/client/client.c b/src/client/client.c index a68acaf6..cd1da6b9 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -518,8 +518,8 @@ BOOL client_IdleHandler4Client (PMSGQUEUE msg_queue, BOOL wait) return (n > 0); } -GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, - int max_nr_topmosts, int max_nr_normals) +GHANDLE GUIAPI JoinLayerEx (const char* layer_name, const char* client_name, + int max_nr_topmosts, int max_nr_normals, int *cli_id) { GHANDLE layer_handle = INV_LAYER_HANDLE; REQUEST req; @@ -529,8 +529,12 @@ GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, if (mgIsServer) return layer_handle; - if (__mg_client_id != 0) /* Already joined, return the handle */ + if (__mg_client_id != 0) { + /* Already joined, return the handle */ + if (cli_id) + *cli_id = __mg_client_id; return GetLayerInfo (NAME_SELF_LAYER, NULL, NULL, NULL); + } if (layer_name) { strncpy (info.layer_name, layer_name, LEN_LAYER_NAME); @@ -593,10 +597,18 @@ GHANDLE GUIAPI JoinLayer (const char* layer_name, const char* client_name, __mg_start_client_desktop (); + if (cli_id) + *cli_id = __mg_client_id; + ret: return layer_handle; } +int GUIAPI GetClientId (void) +{ + return __mg_client_id; +} + GHANDLE GUIAPI GetLayerInfo (const char* layer_name, int* nr_clients, BOOL* is_topmost, int* cli_active) { diff --git a/src/misc/map.c b/src/misc/map.c index ffbc0486..ef26b09c 100644 --- a/src/misc/map.c +++ b/src/misc/map.c @@ -307,7 +307,7 @@ map_entry_t* __mg_map_insert_ex2 (map_t* map, const void* key, map_entry_t *parent; if (map == NULL) - return -1; + return NULL; WRLOCK_MAP (map);