server.h
Go to the documentation of this file.
// server.h
//
/****************************************************************************
liblscp - LinuxSampler Control Protocol API
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#ifndef __LSCP_SERVER_H
#define __LSCP_SERVER_H
#include "lscp/socket.h"
#include "lscp/event.h"
#if defined(__cplusplus)
extern "C" {
#endif
//-------------------------------------------------------------------------
// Server socket modes.
typedef enum _lscp_server_mode_t
{
LSCP_SERVER_THREAD = 0,
LSCP_SERVER_SELECT = 1
} lscp_server_mode_t;
typedef enum _lscp_connect_mode_t
{
LSCP_CONNECT_OPEN = 0,
LSCP_CONNECT_CLOSE = 1
} lscp_connect_mode_t;
//-------------------------------------------------------------------------
// Server socket structures.
struct _lscp_server_t;
typedef struct _lscp_connect_t
{
struct _lscp_server_t *server;
lscp_socket_agent_t client;
lscp_event_t events;
struct _lscp_connect_t *prev;
struct _lscp_connect_t *next;
} lscp_connect_t;
typedef struct _lscp_connect_list_t
{
lscp_connect_t *first;
lscp_connect_t *last;
unsigned int count;
lscp_mutex_t mutex;
} lscp_connect_list_t;
typedef lscp_status_t (*lscp_server_proc_t)
(
lscp_connect_t *pConnect,
const char *pchBuffer,
int cchBuffer,
void *pvData
);
typedef struct _lscp_server_t
{
lscp_server_mode_t mode;
lscp_connect_list_t connects;
lscp_server_proc_t pfnCallback;
void *pvData;
lscp_socket_agent_t agent;
} lscp_server_t;
//-------------------------------------------------------------------------
// Server versioning teller fuunctions.
const char * lscp_server_package (void);
const char * lscp_server_version (void);
const char * lscp_server_build (void);
//-------------------------------------------------------------------------
// Server socket functions.
lscp_server_t * lscp_server_create (int iPort, lscp_server_proc_t pfnCallback, void *pvData);
lscp_server_t * lscp_server_create_ex (int iPort, lscp_server_proc_t pfnCallback, void *pvData, lscp_server_mode_t mode);
lscp_status_t lscp_server_join (lscp_server_t *pServer);
lscp_status_t lscp_server_destroy (lscp_server_t *pServer);
lscp_status_t lscp_server_broadcast (lscp_server_t *pServer, lscp_event_t event, const char *pchData, int cchData);
lscp_status_t lscp_server_result (lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer);
lscp_status_t lscp_server_subscribe (lscp_connect_t *pConnect, lscp_event_t event);
lscp_status_t lscp_server_unsubscribe (lscp_connect_t *pConnect, lscp_event_t event);
#if defined(__cplusplus)
}
#endif
#endif // __LSCP_SERVER_H
// end of server.h
_lscp_connect_list_t::mutex
lscp_mutex_t mutex
Definition: server.h:76
lscp_connect_t
struct _lscp_connect_t lscp_connect_t
lscp_server_join
lscp_status_t lscp_server_join(lscp_server_t *pServer)
Definition: server.c:558
lscp_server_subscribe
lscp_status_t lscp_server_subscribe(lscp_connect_t *pConnect, lscp_event_t event)
Definition: server.c:684
lscp_server_mode_t
enum _lscp_server_mode_t lscp_server_mode_t
lscp_server_package
const char * lscp_server_package(void)
Definition: server.c:403
lscp_connect_list_t
struct _lscp_connect_list_t lscp_connect_list_t
lscp_server_build
const char * lscp_server_build(void)
Definition: server.c:409
lscp_connect_mode_t
enum _lscp_connect_mode_t lscp_connect_mode_t
_lscp_server_t::agent
lscp_socket_agent_t agent
Definition: server.h:96
lscp_server_destroy
lscp_status_t lscp_server_destroy(lscp_server_t *pServer)
Definition: server.c:578
lscp_status_t
enum _lscp_status_t lscp_status_t
lscp_server_create
lscp_server_t * lscp_server_create(int iPort, lscp_server_proc_t pfnCallback, void *pvData)
Definition: server.c:428
_lscp_socket_agent_t
Definition: socket.h:68
_lscp_connect_list_t
Definition: server.h:71
_lscp_connect_list_t::first
lscp_connect_t * first
Definition: server.h:73
lscp_mutex_t
pthread_mutex_t lscp_mutex_t
Definition: thread.h:72
LSCP_CONNECT_OPEN
Definition: server.h:48
_lscp_server_t::pfnCallback
lscp_server_proc_t pfnCallback
Definition: server.h:94
_lscp_connect_t::client
lscp_socket_agent_t client
Definition: server.h:63
lscp_server_version
const char * lscp_server_version(void)
Definition: server.c:406
_lscp_connect_mode_t
_lscp_connect_mode_t
Definition: server.h:46
_lscp_connect_t
Definition: server.h:60
_lscp_connect_list_t::count
unsigned int count
Definition: server.h:75
LSCP_CONNECT_CLOSE
Definition: server.h:49
_lscp_server_mode_t
_lscp_server_mode_t
Definition: server.h:37
lscp_server_result
lscp_status_t lscp_server_result(lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer)
Definition: server.c:658
LSCP_SERVER_THREAD
Definition: server.h:39
_lscp_server_t
Definition: server.h:90
lscp_event_t
enum _lscp_event_t lscp_event_t
lscp_server_t
struct _lscp_server_t lscp_server_t
lscp_server_broadcast
lscp_status_t lscp_server_broadcast(lscp_server_t *pServer, lscp_event_t event, const char *pchData, int cchData)
Definition: server.c:606
lscp_server_unsubscribe
lscp_status_t lscp_server_unsubscribe(lscp_connect_t *pConnect, lscp_event_t event)
Definition: server.c:705
event.h
_lscp_server_t::mode
lscp_server_mode_t mode
Definition: server.h:92
_lscp_connect_t::next
struct _lscp_connect_t * next
Definition: server.h:66
_lscp_server_t::connects
lscp_connect_list_t connects
Definition: server.h:93
_lscp_connect_t::prev
struct _lscp_connect_t * prev
Definition: server.h:65
_lscp_server_t::pvData
void * pvData
Definition: server.h:95
_lscp_connect_list_t::last
lscp_connect_t * last
Definition: server.h:74
socket.h
_lscp_connect_t::events
lscp_event_t events
Definition: server.h:64
_lscp_connect_t::server
struct _lscp_server_t * server
Definition: server.h:62
LSCP_SERVER_SELECT
Definition: server.h:40
lscp_server_create_ex
lscp_server_t * lscp_server_create_ex(int iPort, lscp_server_proc_t pfnCallback, void *pvData, lscp_server_mode_t mode)
Definition: server.c:453
lscp_server_proc_t
lscp_status_t(* lscp_server_proc_t)(lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer, void *pvData)
Definition: server.h:82