MiniGUI API Reference (MiniGUI-Processes)  v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Macros | Functions

MiniGUI-Processes uses UNIX domain socket to build the communication between the server and the clients. More...

Macros

#define sock_write(fd, buff, count)   sock_write_t(fd, buff, count, 0)
 The blocking version of sock_write_t function. More...
 
#define sock_read(fd, buff, count)   sock_read_t(fd, buff, count, 0)
 The blocking version of sock_read_t function. More...
 

Functions

MG_EXPORT int serv_listen (const char *name)
 Creates a listen socket. More...
 
MG_EXPORT int serv_accept (int listenfd, pid_t *pidptr, uid_t *uidptr)
 Waits for a client connection to arrive, and accept it. More...
 
MG_EXPORT int cli_conn (const char *name, char project)
 Used by clients to connect to a server. More...
 
MG_EXPORT ssize_t sock_read_t (int fd, void *buff, size_t count, DWORD timeout)
 Reads data from socket. More...
 

Detailed Description

MiniGUI-Processes uses UNIX domain socket to build the communication between the server and the clients.

You can also use the underlay interfaces which MiniGUI uses to create your own UNIX domain socket.

Example:

#define LISTEN_SOCKET "/var/tmp/mysocket"
static int listen_fd;
BOOL listen_socket (HWND hwnd)
{
if ((listen_fd = serv_listen (LISTEN_SOCKET)) < 0)
return FALSE;
return RegisterListenFD (fd, POLL_IN, hwnd, NULL);
}
/*
* When the server receives the request to connect from a client,
* the window hwnd will receive a MSG_FDEVENT message.
* Now the server can accept the request.
*/
LRESULT MyWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
...
case MSG_FDEVENT:
if (LOWORD (wParam) == listen_fd) {
/* This message comes from the listen socket fd. */
pid_t pid;
uid_t uid;
int conn_fd;
conn_fd = serv_accept (listen_fd, &pid, &uid);
if (conn_fd >= 0) {
RegisterListenFD (conn_fd, POLL_IN, hwnd, NULL);
}
}
else {
/* Client send a request. */
int fd = LOWORD(wParam);
/* Handle the request from client. */
sock_read_t (fd, ...);
sock_write_t (fd, ....);
}
break;
...
}
}
/*
* Clients can use the following code to connect itself to the server.
*/
int conn_fd;
if ((conn_fd = cli_conn (LISTEN_SOCKET, 'b')) >= 0) {
/* Send a request to the server. */
sock_write_t (fd, ....);
/* Get the reply from the server. */
sock_read_t (fd, ....);
}

Macro Definition Documentation

◆ sock_read

#define sock_read (   fd,
  buff,
  count 
)    sock_read_t(fd, buff, count, 0)

The blocking version of sock_read_t function.

See also
sock_read_t

Definition at line 2444 of file minigui.h.

◆ sock_write

#define sock_write (   fd,
  buff,
  count 
)    sock_write_t(fd, buff, count, 0)

The blocking version of sock_write_t function.

See also
sock_write_t

Definition at line 2436 of file minigui.h.

Function Documentation

◆ cli_conn()

int cli_conn ( const char *  name,
char  project 
)

Used by clients to connect to a server.

This function is used by clients to connect to a server.

The created socket will be located at the directory '/var/tmp', and with name of '/var/tmp/xxxxx-c', where 'xxxxx' is the pid of client. and 'c' is a character to distinguish different projects.

Note that MiniGUI itself uses 'a' as the project character to create socket between 'mginit' and clients.

Parameters
nameThe name of the well-known listen socket (created by server).
projectA character to distinguish different projects (Do NOT use 'a').
Returns
The new connected fd if all OK, < 0 on error.
See also
serv_listen, serv_accept

◆ serv_accept()

int serv_accept ( int  listenfd,
pid_t *  pidptr,
uid_t *  uidptr 
)

Waits for a client connection to arrive, and accept it.

This function is used by the server to wait a connection and accept it.

After creating a listening socket by calling serv_listen, you can call this function to create a connection with a client. We also obtain the client's PID and UID from the pathname that it must bind before calling us.

Parameters
listenfdThe fd of listen socket.
pidptrThe client PID will be saved to this buffer when this function returns.
uidptrThe client UID will be saved to this buffer when this function returns.
Returns
The new connected fd if all OK, < 0 on error.
See also
serv_listen, cli_conn

◆ serv_listen()

int serv_listen ( const char *  name)

Creates a listen socket.

This function is used by the server to create a listening socket. Any MiniGUI-Processes application can call this function to create a listening socket. The server, i.e. mginit, of MiniGUI-Processes uses this function to create its listening socket, and named the socket to '/var/tmp/minigui'.

Parameters
nameThe path name of the listening socket.
Returns
The file discriptor of the listening socket created, -1 on error.
Note
As a convention, you should located the socket in '/var/tmp/' directory.

◆ sock_read_t()

ssize_t sock_read_t ( int  fd,
void *  buff,
size_t  count,
DWORD  timeout 
)

Reads data from socket.

This function reads data which is count bytes long to the buffer buff from the socket fd.

Parameters
fdThe file descriptor of the socket.
buffThe buffer used to save the data.
countThe length in bytes of the buffer.
timeoutAn upper bound on the amount of time elapsed before sock_read_t returns. When it is zero, sock_read_t can block indefinitely. The timeout value is in the tick count of MiniGUI, and tick count of MiniGUI is in unit of 10 milliseconds.
Returns
SOCKERR_OK if all OK, < 0 on error.
Return values
SOCKERR_OKRead data successfully.
SOCKERR_IOThere are some I/O errors occurred.
SOCKERR_CLOSEDThe socket has been closed by the peer.
SOCKERR_INVARGYou passed invalid arguments.
SOCKERR_TIMEOUTTimeout.
Note
The timeout only goes into effect when this function called by the server of MiniGUI-Processes, i.e. mginit.
See also
sock_write_t
serv_accept
MG_EXPORT int serv_accept(int listenfd, pid_t *pidptr, uid_t *uidptr)
Waits for a client connection to arrive, and accept it.
NULL
#define NULL
A value indicates null pointer.
Definition: common.h:369
HWND
GHANDLE HWND
Handle to main window or control.
Definition: common.h:407
WPARAM
UINT_PTR WPARAM
A type definition for the first message paramter.
Definition: common.h:706
LRESULT
LONG_PTR LRESULT
Signed result of message processing.
Definition: common.h:583
UINT
unsigned int UINT
A type definition for unsigned integer.
Definition: common.h:664
FALSE
#define FALSE
FALSE value, defined as 0 by MiniGUI.
Definition: common.h:351
serv_listen
MG_EXPORT int serv_listen(const char *name)
Creates a listen socket.
BOOL
int BOOL
A type definition for boolean value.
Definition: common.h:343
sock_read_t
MG_EXPORT ssize_t sock_read_t(int fd, void *buff, size_t count, DWORD timeout)
Reads data from socket.
cli_conn
MG_EXPORT int cli_conn(const char *name, char project)
Used by clients to connect to a server.
LOWORD
#define LOWORD(l)
Returns the low word of the double word l.
Definition: common.h:814
LPARAM
UINT_PTR LPARAM
A type definition for the second message paramter.
Definition: common.h:712