Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_gui_network.c File Reference
#include <getopt.h>
#include <sys/time.h>
#include <sys/types.h>
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include "nilorea/n_str.h"
#include "nilorea/n_time.h"
#include "nilorea/n_network.h"
#include "nilorea/n_network_msg.h"
#include "nilorea/n_gui.h"
+ Include dependency graph for ex_gui_network.c:

Go to the source code of this file.

Macros

#define ALLEGRO_UNSTABLE   1
 
#define HEIGHT   600
 
#define NETMSG_CHAT   100
 
#define WIDTH   800
 

Functions

N_STRbuild_chat_msg (const char *text)
 build a chat network message
 
void chat_log_add (const char *text)
 add a line to the chat log listbox
 
int decode_chat_msg (N_STR *str, char **out_text)
 decode a received chat message
 
int main (int argc, char **argv)
 
void on_send_click (int widget_id, void *user_data)
 send button callback
 
void poll_network_msgs (NETWORK *netw, const char *prefix)
 process incoming messages on a single network connection
 
void refresh_clients_list (void)
 refresh the connected clients listbox (server only)
 
void usage (void)
 

Variables

static int btn_send = -1
 
ALLEGRO_DISPLAY * display = NULL
 
static int DONE = 0
 
static N_GUI_CTXgui = NULL
 
static int lbl_clients_header = -1
 
static int lbl_status = -1
 
static int listbox_clients = -1
 
static int listbox_log = -1
 
static int mode = -1
 
static NETWORKnetw_client = NULL
 
static NETWORKnetw_server = NULL
 
static NETWORK_POOLpool = NULL
 
static char * port_str = NULL
 
static char * server_addr = NULL
 
static int textarea_input = -1
 
static int win_chat = -1
 
static int win_clients = -1
 

Macro Definition Documentation

◆ ALLEGRO_UNSTABLE

#define ALLEGRO_UNSTABLE   1

Definition at line 45 of file ex_gui_network.c.

◆ HEIGHT

#define HEIGHT   600

Definition at line 43 of file ex_gui_network.c.

◆ NETMSG_CHAT

#define NETMSG_CHAT   100
Examples
ex_gui_network.c.

Definition at line 60 of file ex_gui_network.c.

◆ WIDTH

#define WIDTH   800

Definition at line 42 of file ex_gui_network.c.

Function Documentation

◆ build_chat_msg()

N_STR * build_chat_msg ( const char *  text)

build a chat network message

Parameters
textthe chat text
Returns
serialized N_STR ready to send, or NULL on error
Examples
ex_gui_network.c.

Definition at line 130 of file ex_gui_network.c.

References add_int_to_msg(), add_strdup_to_msg(), create_msg(), delete_msg(), make_str_from_msg(), and NETMSG_CHAT.

Referenced by on_send_click(), and poll_network_msgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ chat_log_add()

void chat_log_add ( const char *  text)

add a line to the chat log listbox

Parameters
textthe text to add
Examples
ex_gui_network.c.

Definition at line 92 of file ex_gui_network.c.

References gui, listbox_log, and n_gui_listbox_add_item().

Referenced by main(), on_send_click(), and poll_network_msgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_chat_msg()

int decode_chat_msg ( N_STR str,
char **  out_text 
)

decode a received chat message

Parameters
strthe serialized message
out_textoutput: allocated chat text (caller must Free)
Returns
TRUE on success, FALSE on error
Examples
ex_gui_network.c.

Definition at line 149 of file ex_gui_network.c.

References delete_msg(), get_int_from_msg(), get_str_from_msg(), make_msg_from_str(), and NETMSG_CHAT.

Referenced by poll_network_msgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

◆ on_send_click()

void on_send_click ( int  widget_id,
void *  user_data 
)

send button callback

Parameters
widget_idthe button widget id
user_dataunused
Examples
ex_gui_network.c.

Definition at line 187 of file ex_gui_network.c.

References build_chat_msg(), chat_log_add(), free_nstr, gui, mode, n_gui_textarea_get_text(), n_gui_textarea_set_text(), netw_add_msg(), netw_client, netw_pool_broadcast(), nstrdup(), pool, and textarea_input.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ poll_network_msgs()

void poll_network_msgs ( NETWORK netw,
const char *  prefix 
)

process incoming messages on a single network connection

Parameters
netwthe network to poll
prefixlabel prefix for log display
Examples
ex_gui_network.c.

Definition at line 222 of file ex_gui_network.c.

References build_chat_msg(), chat_log_add(), decode_chat_msg(), Free, free_nstr, mode, netw, netw_get_msg(), netw_pool_broadcast(), and pool.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ refresh_clients_list()

void refresh_clients_list ( void  )

refresh the connected clients listbox (server only)

Examples
ex_gui_network.c.

Definition at line 101 of file ex_gui_network.c.

References gui, HT_FOREACH, listbox_clients, n_gui_listbox_clear(), pool, and NETWORK_POOL::pool.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ usage()

void usage ( void  )

Definition at line 246 of file ex_gui_network.c.

Variable Documentation

◆ btn_send

int btn_send = -1
static
Examples
ex_gui_network.c.

Definition at line 79 of file ex_gui_network.c.

Referenced by main().

◆ display

ALLEGRO_DISPLAY* display = NULL

Definition at line 62 of file ex_gui_network.c.

◆ DONE

int DONE = 0
static

Definition at line 64 of file ex_gui_network.c.

◆ gui

◆ lbl_clients_header

int lbl_clients_header = -1
static
Examples
ex_gui_network.c.

Definition at line 83 of file ex_gui_network.c.

Referenced by main().

◆ lbl_status

int lbl_status = -1
static

Definition at line 76 of file ex_gui_network.c.

◆ listbox_clients

int listbox_clients = -1
static
Examples
ex_gui_network.c.

Definition at line 84 of file ex_gui_network.c.

Referenced by main(), and refresh_clients_list().

◆ listbox_log

int listbox_log = -1
static
Examples
ex_gui_network.c.

Definition at line 77 of file ex_gui_network.c.

Referenced by chat_log_add(), and main().

◆ mode

◆ netw_client

NETWORK* netw_client = NULL
static
Examples
ex_gui_network.c.

Definition at line 71 of file ex_gui_network.c.

Referenced by main(), and on_send_click().

◆ netw_server

NETWORK* netw_server = NULL
static
Examples
ex_gui_network.c, and ex_network.c.

Definition at line 70 of file ex_gui_network.c.

Referenced by main().

◆ pool

◆ port_str

char* port_str = NULL
static
Examples
ex_gui_network.c, and ex_network_mock.c.

Definition at line 67 of file ex_gui_network.c.

Referenced by _proxy_tcp_connect(), main(), main(), and n_mock_server_start().

◆ server_addr

char* server_addr = NULL
static
Examples
ex_gui_network.c.

Definition at line 66 of file ex_gui_network.c.

Referenced by main().

◆ textarea_input

int textarea_input = -1
static
Examples
ex_gui_network.c.

Definition at line 78 of file ex_gui_network.c.

Referenced by main(), and on_send_click().

◆ win_chat

int win_chat = -1
static
Examples
ex_gui_network.c.

Definition at line 75 of file ex_gui_network.c.

Referenced by main().

◆ win_clients

int win_clients = -1
static
Examples
ex_gui_network.c.

Definition at line 82 of file ex_gui_network.c.

Referenced by main().