src.dualinventive.com/mtinfo/tcpserver/include/client-list.h

94 lines
2.4 KiB
C

/*
************************************************************************
**
** Copyright (c) 2010..2012 by
** Core|Vision B.V.
** Cereslaan 10b
** 5384 VT Heesch
** The Netherlands
**
** All Rights Reserved
**
************************************************************************
*/
/*
************************************************************************
**
** Project name: Dual Inventive: TCP Server
** Filename: client-list.h
** Author: Jack Weeland
** Date: February 12, 2010
** File version: $Revision: 1.5 $
** $Date: 2013/04/15 15:31:46 $
**
************************************************************************
*/
/*
************************************************************************
**
** TCP-server; communication with the ZKL3000
** Client list, which provides token parsing in the upstream (back-end
** to front-end) communication
**
************************************************************************
*/
#ifndef _CLIENT_LIST_H
#define _CLIENT_LIST_H
#include <di-util/cp3000.h>
#include <di-util/list.h>
#include <stdarg.h>
#include <sys/select.h> // for 'fd_set'
/*
** Constants
*/
// maximum number of clients, limited by the size of a 'fd_set';
// 32 entries are reserver for "the system" (this number is
// arbitrary...)
#define MAX_CLIENTS ((FD_SETSIZE) - 32)
/*
** Definitions
*/
// the client list
typedef struct CLIENT_LIST *clientlst_t;
/*
** Exported functions
*/
// accept and add a new client
int clist_add_client(clientlst_t, cp3000_device_t client);
// direct access to the client array
int clist_count(clientlst_t);
cp3000_device_t clist_get_client_by_index(clientlst_t, int index);
// find a client by its unique ID
cp3000_device_t clist_get_client_by_id(clientlst_t, client_t client_id);
// forward status or arbitray token to all clients or a single client
int clist_forward_token(clientlst_t, token_info_t);
int clist_forward_status(clientlst_t, int flags, const char *status_str);
int clist_forward_status_single(clientlst_t, client_t client_id, int flags, const char *status_str);
// process data from the clients; 'p_devices' is the list with devices,
// returned by 'cp3000_select()', with devices that have data available
// (post check by the callback for the list iterator)
int clist_process_data(
clientlst_t,
const cp3000_device_t *p_device,
int n_devices
);
// create and destroy client list
clientlst_t clist_init(cp3000_device_t);
void clist_destroy(clientlst_t);
#endif /* _CLIENT_LIST_H */