1 |
capela |
62 |
// server.h |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
|
|
liblscp - LinuxSampler Control Protocol API |
5 |
|
|
Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public |
9 |
|
|
License as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
|
12 |
|
|
This library is distributed in the hope that it will be useful, |
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
Lesser General Public License for more details. |
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU Lesser General Public |
18 |
|
|
License along with this library; if not, write to the Free Software |
19 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
|
21 |
|
|
*****************************************************************************/ |
22 |
|
|
|
23 |
|
|
#ifndef __LSCP_SERVER_H |
24 |
|
|
#define __LSCP_SERVER_H |
25 |
|
|
|
26 |
|
|
#include "lscp/socket.h" |
27 |
|
|
|
28 |
|
|
#if defined(__cplusplus) |
29 |
|
|
extern "C" { |
30 |
|
|
#endif |
31 |
|
|
|
32 |
|
|
//------------------------------------------------------------------------- |
33 |
|
|
// Server socket modes. |
34 |
|
|
|
35 |
|
|
/** Server thread model. */ |
36 |
|
|
typedef enum _lscp_server_mode_t |
37 |
|
|
{ |
38 |
|
|
LSCP_SERVER_THREAD = 0, |
39 |
|
|
LSCP_SERVER_SELECT = 1 |
40 |
|
|
|
41 |
|
|
} lscp_server_mode_t; |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
/** Connection mode notification. */ |
45 |
|
|
typedef enum _lscp_connect_mode_t |
46 |
|
|
{ |
47 |
|
|
LSCP_CONNECT_OPEN = 0, |
48 |
|
|
LSCP_CONNECT_CLOSE = 1 |
49 |
|
|
|
50 |
|
|
} lscp_connect_mode_t; |
51 |
|
|
|
52 |
|
|
|
53 |
|
|
//------------------------------------------------------------------------- |
54 |
|
|
// Server socket structures. |
55 |
|
|
|
56 |
|
|
struct _lscp_server_t; |
57 |
|
|
|
58 |
|
|
/** Client connection descriptor struct. */ |
59 |
|
|
typedef struct _lscp_connect_t |
60 |
|
|
{ |
61 |
|
|
struct _lscp_server_t *server; |
62 |
|
|
lscp_socket_agent_t client; |
63 |
|
|
int port; |
64 |
|
|
int ping; |
65 |
|
|
char * sessid; |
66 |
|
|
struct _lscp_connect_t *prev; |
67 |
|
|
struct _lscp_connect_t *next; |
68 |
|
|
|
69 |
|
|
} lscp_connect_t; |
70 |
|
|
|
71 |
|
|
/** Client connection list struct. */ |
72 |
|
|
typedef struct _lscp_connect_list_t |
73 |
|
|
{ |
74 |
|
|
lscp_connect_t *first; |
75 |
|
|
lscp_connect_t *last; |
76 |
|
|
unsigned int count; |
77 |
|
|
lscp_mutex_t mutex; |
78 |
|
|
|
79 |
|
|
} lscp_connect_list_t; |
80 |
|
|
|
81 |
|
|
/** Server callback procedure prototype. */ |
82 |
|
|
typedef lscp_status_t (*lscp_server_proc_t) |
83 |
|
|
( |
84 |
|
|
lscp_connect_t *pConnect, |
85 |
|
|
const char *pchBuffer, |
86 |
|
|
int cchBuffer, |
87 |
|
|
void *pvData |
88 |
|
|
); |
89 |
|
|
|
90 |
|
|
/** Server descriptor struct. */ |
91 |
|
|
typedef struct _lscp_server_t |
92 |
|
|
{ |
93 |
|
|
lscp_server_mode_t mode; |
94 |
|
|
lscp_connect_list_t connects; |
95 |
|
|
lscp_server_proc_t pfnCallback; |
96 |
|
|
void *pvData; |
97 |
capela |
132 |
lscp_socket_agent_t cmd; |
98 |
|
|
lscp_socket_agent_t evt; |
99 |
capela |
62 |
lscp_thread_t *pWatchdog; |
100 |
|
|
int iWatchdog; |
101 |
|
|
int iSleep; |
102 |
|
|
|
103 |
|
|
} lscp_server_t; |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
//------------------------------------------------------------------------- |
107 |
|
|
// Server versioning teller fuunctions. |
108 |
|
|
|
109 |
|
|
const char * lscp_server_package (void); |
110 |
|
|
const char * lscp_server_version (void); |
111 |
|
|
const char * lscp_server_build (void); |
112 |
|
|
|
113 |
|
|
|
114 |
|
|
//------------------------------------------------------------------------- |
115 |
|
|
// Server socket functions. |
116 |
|
|
|
117 |
|
|
lscp_server_t * lscp_server_create (int iPort, lscp_server_proc_t pfnCallback, void *pvData); |
118 |
|
|
lscp_server_t * lscp_server_create_ex (int iPort, lscp_server_proc_t pfnCallback, void *pvData, lscp_server_mode_t mode); |
119 |
|
|
lscp_status_t lscp_server_join (lscp_server_t *pServer); |
120 |
|
|
lscp_status_t lscp_server_destroy (lscp_server_t *pServer); |
121 |
|
|
|
122 |
|
|
lscp_status_t lscp_server_broadcast (lscp_server_t *pServer, const char *pchBuffer, int cchBuffer); |
123 |
|
|
|
124 |
|
|
lscp_status_t lscp_server_result (lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer); |
125 |
|
|
|
126 |
|
|
lscp_status_t lscp_server_subscribe (lscp_connect_t *pConnect, int iPort); |
127 |
|
|
lscp_status_t lscp_server_unsubscribe (lscp_connect_t *pConnect, const char *pszSessID); |
128 |
|
|
|
129 |
|
|
|
130 |
|
|
#if defined(__cplusplus) |
131 |
|
|
} |
132 |
|
|
#endif |
133 |
|
|
|
134 |
|
|
#endif // __LSCP_SERVER_H |
135 |
|
|
|
136 |
|
|
// end of server.h |