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

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 int sock_write_t (int fd, const void *buff, int count, unsigned int timeout)
 Writes data to socket. More...
 
MG_EXPORT int sock_read_t (int fd, void *buff, int count, unsigned int 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) {
...
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

#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 1389 of file minigui.h.

#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 1381 of file minigui.h.

Function Documentation

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
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
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.
int sock_read_t ( int  fd,
void *  buff,
int  count,
unsigned int  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
int sock_write_t ( int  fd,
const void *  buff,
int  count,
unsigned int  timeout 
)

Writes data to socket.

This function writes the data block pointed to by buff which is count bytes long to the socket fd.

Parameters
fdThe file descriptor of the socket.
buffThe buffer contains the data.
countThe length in bytes of the buffer.
timeoutAn upper bound on the amount of time elapsed before sock_write_t returns. When it is zero, sock_write_t can block indefinitely. The timeout value is in tick count, 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_read_t