liblscp 0.5.6
|
00001 // server.h 00002 // 00003 /**************************************************************************** 00004 liblscp - LinuxSampler Control Protocol API 00005 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License along 00018 with this program; if not, write to the Free Software Foundation, Inc., 00019 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00020 00021 *****************************************************************************/ 00022 00023 #ifndef __LSCP_SERVER_H 00024 #define __LSCP_SERVER_H 00025 00026 #include "lscp/socket.h" 00027 #include "lscp/event.h" 00028 00029 #if defined(__cplusplus) 00030 extern "C" { 00031 #endif 00032 00033 //------------------------------------------------------------------------- 00034 // Server socket modes. 00035 00037 typedef enum _lscp_server_mode_t 00038 { 00039 LSCP_SERVER_THREAD = 0, 00040 LSCP_SERVER_SELECT = 1 00041 00042 } lscp_server_mode_t; 00043 00044 00046 typedef enum _lscp_connect_mode_t 00047 { 00048 LSCP_CONNECT_OPEN = 0, 00049 LSCP_CONNECT_CLOSE = 1 00050 00051 } lscp_connect_mode_t; 00052 00053 00054 //------------------------------------------------------------------------- 00055 // Server socket structures. 00056 00057 struct _lscp_server_t; 00058 00060 typedef struct _lscp_connect_t 00061 { 00062 struct _lscp_server_t *server; 00063 lscp_socket_agent_t client; 00064 lscp_event_t events; 00065 struct _lscp_connect_t *prev; 00066 struct _lscp_connect_t *next; 00067 00068 } lscp_connect_t; 00069 00071 typedef struct _lscp_connect_list_t 00072 { 00073 lscp_connect_t *first; 00074 lscp_connect_t *last; 00075 unsigned int count; 00076 lscp_mutex_t mutex; 00077 00078 } lscp_connect_list_t; 00079 00081 typedef lscp_status_t (*lscp_server_proc_t) 00082 ( 00083 lscp_connect_t *pConnect, 00084 const char *pchBuffer, 00085 int cchBuffer, 00086 void *pvData 00087 ); 00088 00090 typedef struct _lscp_server_t 00091 { 00092 lscp_server_mode_t mode; 00093 lscp_connect_list_t connects; 00094 lscp_server_proc_t pfnCallback; 00095 void *pvData; 00096 lscp_socket_agent_t agent; 00097 00098 } lscp_server_t; 00099 00100 00101 //------------------------------------------------------------------------- 00102 // Server versioning teller fuunctions. 00103 00104 const char * lscp_server_package (void); 00105 const char * lscp_server_version (void); 00106 const char * lscp_server_build (void); 00107 00108 00109 //------------------------------------------------------------------------- 00110 // Server socket functions. 00111 00112 lscp_server_t * lscp_server_create (int iPort, lscp_server_proc_t pfnCallback, void *pvData); 00113 lscp_server_t * lscp_server_create_ex (int iPort, lscp_server_proc_t pfnCallback, void *pvData, lscp_server_mode_t mode); 00114 lscp_status_t lscp_server_join (lscp_server_t *pServer); 00115 lscp_status_t lscp_server_destroy (lscp_server_t *pServer); 00116 00117 lscp_status_t lscp_server_broadcast (lscp_server_t *pServer, lscp_event_t event, const char *pchData, int cchData); 00118 00119 lscp_status_t lscp_server_result (lscp_connect_t *pConnect, const char *pchBuffer, int cchBuffer); 00120 00121 lscp_status_t lscp_server_subscribe (lscp_connect_t *pConnect, lscp_event_t event); 00122 lscp_status_t lscp_server_unsubscribe (lscp_connect_t *pConnect, lscp_event_t event); 00123 00124 00125 #if defined(__cplusplus) 00126 } 00127 #endif 00128 00129 #endif // __LSCP_SERVER_H 00130 00131 // end of server.h