netcore.c File Reference

Main Page Modules Alphabetical List Compound List File List Compound Members File Members

# /home/micah/picogui/pg1/client/c/src/netcore.c File Reference

`#include "clientlib.h"`
`#include <ctype.h>`
`#include <stdlib.h>`
`#include <errno.h>`

## Functions
int | _pg_send (void *data, u32 datasize)
int | _pg_recv (void *data, u32 datasize)
int | _pg_recvtimeout (s16 *rsptype)
void * | _pg_malloc (size_t size)
void | _pg_defaulterr (u16 errortype, const char *msg)
void | _pgsig (int sig)
void | _pg_add_request (s16 reqtype, void *data, u32 datasize)
void | _pg_getresponse (int eventwait)
void | _pg_free_memdata (struct pgmemdata memdat)
char * | _pg_dynformat (const char *fmt, va_list ap)
void | _pg_idle (void)
void | pgInit (int argc, char **argv)
| Initialize PicoGUI.
void | pgSetErrorHandler (void(*handler)(u16 errortype, const char *msg))
| Replace the default error handler.
const char * | pgErrortypeString (u16 errortype)
| Convert a numerical errortype to a string.
pgidlehandler | pgSetIdle (s32 t, pgidlehandler handler)
| Set a handler to be called periodically.
void | pgFlushRequests (void)
| Flush all unsent request packets to the server.
void | pgEventLoop (void)
| Event processing and dispatching loop.
void | pgDispatchEvent (struct pgEvent *evt)
| Dispatch an event to registered handlers.
void | pgExitEventLoop (void)
| Exit the current event loop.
pgEvent * | pgGetEvent (void)
| Wait for a single event.
void | pgBind (pghandle widgetkey, s16 eventkey, pgevthandler handler, void *extra)
| Attatch an event handler to a widget and/or event.
void | pgCustomizeSelect (pgselecthandler handler, pgselectbh bottomhalf)
## Variables
int | _pgsockfd
s16 | _pgrequestid
s16 | _pgdefault_rship
pghandle | _pgdefault_widget
unsigned char | _pgeventloop_on
unsigned char | _pgreqbuffer [PG_REQBUFSIZE]
s16 | _pgreqbuffer_size
s16 | _pgreqbuffer_count
s16 | _pgreqbuffer_lasttype
void(* | _pgerrhandler )(u16 errortype, const char *msg)
_pghandlernode * | _pghandlerlist
timeval | _pgidle_period
pgidlehandler | _pgidle_handler
unsigned char | _pgidle_lock
char * | _pg_appname
pgselecthandler | _pgselect_handler
pgselectbh | _pgselect_bottomhalf
_pg_return_type | _pg_return
pghandle | _pg_appletbox

## Function Documentation

void _pg_add_request | ( | s16 | reqtype,
|  | void * | data,
|  | u32 | datasize
| ) |

void _pg_defaulterr | ( | u16 | errortype,
|  | const char * | msg
| ) |

char* _pg_dynformat | ( | const char * | fmt,
|  | va_list | ap
| ) |

void _pg_free_memdata | ( | struct pgmemdata | memdat | ) |

void _pg_getresponse | ( | int | eventwait | ) |

void _pg_idle | ( | void |  | ) |

void* _pg_malloc | ( | size_t | size | ) |

int _pg_recv | ( | void * | data,
|  | u32 | datasize
| ) |

int _pg_recvtimeout | ( | s16 * | rsptype | ) |

int _pg_send | ( | void * | data,
|  | u32 | datasize
| ) |

void _pgsig | ( | int | sig | ) |

void pgBind | ( | pghandle | widgetkey,
|  | s16 | eventkey,
|  | pgevthandler | handler,
|  | void * | extra
| ) |

  | Attatch an event handler to a widget and/or event. Parameters:
  widgetkey | A widget to attach to, or PGBIND_ANY to respond to any widget's events
  eventkey | An event to attach to, or PGBIND_ANY to respond to any event by the selected widget(s).
  handler | A pointer to a PicoGUI event handler
  extra | The value to pass within the pgEvent's `extra` field
When the widgetkey and eventkey both match, the handler is called, and the specified value for extra is passed in its pgEvent structure. The extra value passed depends on the binding that triggered the call, not on the widget or event involved. If widgetkey and eventkey are exactly the same as an existing binding, its handler and extra value are reset to the ones specified here. If handler is NULL the binding is deleted. See also: pgevthandler, pgEvent

void pgCustomizeSelect | ( | pgselecthandler | handler,
|  | pgselectbh | bottomhalf
| ) |

void pgDispatchEvent | ( | struct pgEvent * | evt | ) |

  | Dispatch an event to registered handlers. Parameters:
  evt | Pointer to the event to dispatch. This should not be the same pointer returned by pgGetEvent(), as it is only valid until the next PicoGUI call! See pgGetEvent() for more information.
This function searches all registered event handlers, and dispatches the event to any applicable handlers. It also provides various default handlers, such as closing the program on recieving PG_WE_CLOSE. See also: pgGetEvent, pgCheckEvent, pgEventLoop

const char* pgErrortypeString | ( | u16 | errortype | ) |

  | Convert a numerical errortype to a string. Parameters:
  errortype | A PG_ERRT_* error type constant
Returns: A pointer to the corresponding string constant

void pgEventLoop | ( | void |  | ) |

| Event processing and dispatching loop. pgEventLoop waits for events from the PicoGUI server and dispatches them according to bindings set up with pgBind. The handler set with pgSetIdle is also called if applicable. pgEventLoop can be called more than once throughout the life of the program, but it is not re-entrant. If the app recieves an event while it is not waiting in an EventLoop, the server will queue them until the client is ready. See also: pgGetEvent, pgExitEventLoop, pgBind, pgSetIdle

void pgExitEventLoop | ( | void |  | ) |

| Exit the current event loop. If the client is currently inside an event loop, this function sets a flag to exit it at the next possible opportunity See also: pgEventLoop

void pgFlushRequests | ( | void |  | ) |

| Flush all unsent request packets to the server. Usually this is handled automatically, but it is needed in some situations. For example, a remote input driver that has no real event loop, but needs to send keyboard or mouse events. The events would not actually be sent to the server until pgFlushRequests is called. See also: pgUpdate

struct pgEvent* pgGetEvent | ( | void |  | ) |

| Wait for a single event. Returns: A pgEvent structure This is good for small dialog boxes, or other situations when pgBind and pgEventLoop are overkill. pgGetEvent can be used while an event loop is already in progress, for example in a pgSetIdle or pgBind handler function. You can also use this in combination with pgCheckEvent to passively check for new events while performing some other operation, such as animation. Important! Note that the returned pointer is only valid until the next PicoGUI call! It's usually a good idea to use something like this:
    struct pgEvent evt;

    evt = *pgGetEvent();
If the relevant values from the pgEvent structure will be copied elsewhere before the next PicoGUI call, that is alright too. Thus, the following code is perfectly fine:
    i = pgGetPayload( pgGetEvent()->from );
See also: pgEventLoop, pgBind, pgSetIdle, pgSetPayload, pgGetPayload, pgCheckEvent

void pgInit | ( | int | argc,
|  | char ** | argv
| ) |

| Initialize PicoGUI. See if there are any command line args relevant to PicoGUI (such as for setting the PicoGUI server) and establish a connection to the server. This must be the first PicoGUI call in the client, and it should almost certainly be called before and command line processing. pgInit processes command line arguments beginning with "--pg" and removes them from the argument list and terminates argv[] with a NULL. This is compatible with optarg and probably other argument-processing systems. Currently the following arguments are handled: --pgserver Connects to the PicoGUI server specified in --version Prints the client library version Unrecognized commands beginning with "--pg" display a list of available commands. If it is unable to contact the server, a client error is triggered. The client does not need to explicitly disconnect from the PicoGUI server See also: pgRegisterApp, pgSetErrorHandler

void pgSetErrorHandler | ( | void(* | handler)(u16 errortype, const char *msg) | ) |

  | Replace the default error handler. Parameters:
  handler | A pointer to the new handler function
  errortype | The general type of error, a PG_ERRT_* constant
  msg | A message string with more information
Errors can be triggered by the client (in the case of an IO error or fatal signal) or by the server. (A bug somewhere, out of memory, etc.) The default error handler displays a message dialog allowing the user to optionally terminate the program. If it is unable to display the message dialog, the error is printed to stderr and the program is terminated. See also: pgInit, pgErrortypeString

pgidlehandler pgSetIdle | ( | s32 | t,
|  | pgidlehandler | handler
| ) |

  | Set a handler to be called periodically. Parameters:
  t | Maximum number of milliseconds to wait between calls to handler
  handler | Pointer to a handler function, or NULL to disable
Returns: Pointer to the previous handler function This is based on the pgSetnonblocking code added by Philippe, but this fits the event-driven model better, and most importantly it handles stopping and starting the event loop automatically. Note that it is still possible for PicoGUI to block if the server sends a partial reply packet, but even if the idle handler were called during this time the network connection would be 'jammed' so there wouldn't be much point. See also: pgEventLoop

## Variable Documentation

pghandle _pg_appletbox

char* _pg_appname

struct _pg_return_type _pg_return

s16 _pgdefault_rship

pghandle _pgdefault_widget

void(* _pgerrhandler)(u16 errortype,const char *msg)

unsigned char _pgeventloop_on

struct _pghandlernode* _pghandlerlist

pgidlehandler _pgidle_handler

unsigned char _pgidle_lock

struct timeval _pgidle_period

unsigned char _pgreqbuffer[PG_REQBUFSIZE]

s16 _pgreqbuffer_count

s16 _pgreqbuffer_lasttype

s16 _pgreqbuffer_size

s16 _pgrequestid

pgselectbh _pgselect_bottomhalf

pgselecthandler _pgselect_handler

int _pgsockfd