File: server.h

package info (click to toggle)
liblscp 0.5.5-0.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,912 kB
  • ctags: 568
  • sloc: sh: 9,074; ansic: 5,461; makefile: 110
file content (131 lines) | stat: -rw-r--r-- 3,761 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// 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.

/** Server thread model. */
typedef enum _lscp_server_mode_t
{
	LSCP_SERVER_THREAD = 0,
	LSCP_SERVER_SELECT = 1

} lscp_server_mode_t;


/** Connection mode notification. */
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;

/** Client connection descriptor struct. */
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;

/** Client connection list struct. */
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;

/** Server callback procedure prototype. */
typedef lscp_status_t (*lscp_server_proc_t)
(
	lscp_connect_t *pConnect,
	const char *pchBuffer,
	int cchBuffer,
	void *pvData
);

/** Server descriptor struct. */
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