Disable network at compile time (option) (#307)

This commit is contained in:
carlo-bramini 2017-12-17 10:25:54 +01:00 committed by Tom M
parent 8ebb2495c5
commit 8025f788d3
7 changed files with 105 additions and 82 deletions

View file

@ -69,6 +69,7 @@ option ( enable-dbus "compile DBUS support (if it is available)" on )
option ( BUILD_SHARED_LIBS "Build a shared object or DLL" on )
option ( enable-ladspa "enable LADSPA effect units" on )
option ( enable-ipv6 "enable ipv6 support " on )
option ( enable-network "enable network support (requires BSD sockets) " on )
# Platform specific options
if ( CMAKE_SYSTEM MATCHES "Linux" )
@ -81,6 +82,7 @@ if ( CMAKE_SYSTEM MATCHES "Darwin" )
option ( enable-coreaudio "compile CoreAudio support (if it is available)" on )
option ( enable-coremidi "compile CoreMIDI support (if it is available)" on )
option ( enable-framework "create a Mac OSX style FluidSynth.framework" on )
set ( enable-network off )
endif ( CMAKE_SYSTEM MATCHES "Darwin" )
if ( CMAKE_SYSTEM MATCHES "OS2" )
@ -250,6 +252,11 @@ if ( enable-ipv6 )
endif ( HAVE_INETNTOP )
endif ( enable-ipv6 )
unset ( NETWORK_SUPPORT )
if ( enable-network )
set ( NETWORK_SUPPORT 1 )
endif ( enable-network )
unset ( WITH_FLOAT CACHE )
if ( enable-floats )
set ( WITH_FLOAT 1 )

View file

@ -97,6 +97,12 @@ else ( AUFILE_SUPPORT )
message ( "Audio to file driver: no" )
endif ( AUFILE_SUPPORT )
if ( NETWORK_SUPPORT )
message ( "NETWORK Support : yes" )
else ( NETWORK_SUPPORT )
message ( "NETWORK Support : no" )
endif ( NETWORK_SUPPORT )
if ( IPV6_SUPPORT )
message ( "IPV6 Support : yes" )
else ( IPV6_SUPPORT )

View file

@ -2347,8 +2347,7 @@ fluid_cmd_handler_handle(void* data, int ac, char** av, fluid_ostream_t out)
}
#if !defined(WITHOUT_SERVER)
#ifdef NETWORK_SUPPORT
struct _fluid_server_t {
fluid_server_socket_t* socket;
@ -2359,65 +2358,6 @@ struct _fluid_server_t {
fluid_mutex_t mutex;
};
static int fluid_server_handle_connection(fluid_server_t* server,
fluid_socket_t client_socket,
char* addr);
static void fluid_server_close(fluid_server_t* server);
/**
* Create a new TCP/IP command shell server.
* @param settings Settings instance to use for the shell
* @param synth If not NULL, the synth instance for the command handler to be used by the client
* @param router If not NULL, the midi_router instance for the command handler to be used by the client
* @return New shell server instance or NULL on error
*/
fluid_server_t*
new_fluid_server(fluid_settings_t* settings,
fluid_synth_t* synth, fluid_midi_router_t* router)
{
fluid_server_t* server;
int port;
server = FLUID_NEW(fluid_server_t);
if (server == NULL) {
FLUID_LOG(FLUID_ERR, "Out of memory");
return NULL;
}
server->settings = settings;
server->clients = NULL;
server->synth = synth;
server->router = router;
fluid_mutex_init(server->mutex);
fluid_settings_getint(settings, "shell.port", &port);
server->socket = new_fluid_server_socket(port,
(fluid_server_func_t) fluid_server_handle_connection,
server);
if (server->socket == NULL) {
FLUID_FREE(server);
return NULL;
}
return server;
}
/**
* Delete a TCP/IP shell server.
* @param server Shell server instance
*/
void
delete_fluid_server(fluid_server_t* server)
{
fluid_return_if_fail(server != NULL);
fluid_server_close(server);
FLUID_FREE(server);
}
static void fluid_server_close(fluid_server_t* server)
{
fluid_list_t* list;
@ -2475,17 +2415,6 @@ void fluid_server_remove_client(fluid_server_t* server, fluid_client_t* client)
fluid_mutex_unlock(server->mutex);
}
/**
* Join a shell server thread (wait until it quits).
* @param server Shell server instance
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
*/
int fluid_server_join(fluid_server_t* server)
{
return fluid_server_socket_join(server->socket);
}
struct _fluid_client_t {
fluid_server_t* server;
fluid_settings_t* settings;
@ -2564,5 +2493,82 @@ void delete_fluid_client(fluid_client_t* client)
FLUID_FREE(client);
}
#endif /* NETWORK_SUPPORT */
#endif /* WITHOUT_SERVER */
/**
* Create a new TCP/IP command shell server.
* @param settings Settings instance to use for the shell
* @param synth If not NULL, the synth instance for the command handler to be used by the client
* @param router If not NULL, the midi_router instance for the command handler to be used by the client
* @return New shell server instance or NULL on error
*/
fluid_server_t*
new_fluid_server(fluid_settings_t* settings,
fluid_synth_t* synth, fluid_midi_router_t* router)
{
#ifdef NETWORK_SUPPORT
fluid_server_t* server;
int port;
server = FLUID_NEW(fluid_server_t);
if (server == NULL) {
FLUID_LOG(FLUID_ERR, "Out of memory");
return NULL;
}
server->settings = settings;
server->clients = NULL;
server->synth = synth;
server->router = router;
fluid_mutex_init(server->mutex);
fluid_settings_getint(settings, "shell.port", &port);
server->socket = new_fluid_server_socket(port,
(fluid_server_func_t) fluid_server_handle_connection,
server);
if (server->socket == NULL) {
FLUID_FREE(server);
return NULL;
}
return server;
#else
FLUID_LOG(FLUID_WARN, "Network support disabled on this platform.");
return NULL;
#endif
}
/**
* Delete a TCP/IP shell server.
* @param server Shell server instance
*/
void
delete_fluid_server(fluid_server_t* server)
{
#ifdef NETWORK_SUPPORT
fluid_return_if_fail(server != NULL);
fluid_server_close(server);
FLUID_FREE(server);
#else
FLUID_LOG(FLUID_WARN, "Network support disabled on this platform.");
#endif
}
/**
* Join a shell server thread (wait until it quits).
* @param server Shell server instance
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
*/
int fluid_server_join(fluid_server_t* server)
{
#ifdef NETWORK_SUPPORT
return fluid_server_socket_join(server->socket);
#else
FLUID_LOG(FLUID_WARN, "Network support disabled on this platform.");
return FLUID_OK;
#endif
}

View file

@ -142,6 +142,9 @@
/* Define to enable IPV6 support */
#cmakedefine IPV6_SUPPORT @IPV6_SUPPORT@
/* Define to enable network support */
#cmakedefine NETWORK_SUPPORT @NETWORK_SUPPORT@
/* libsndfile has ogg vorbis support */
#cmakedefine LIBSNDFILE_HASVORBIS @LIBSNDFILE_HASVORBIS@

View file

@ -261,7 +261,7 @@ int main(int argc, char** argv)
fluid_midi_driver_t* mdriver = NULL;
fluid_audio_driver_t* adriver = NULL;
fluid_synth_t* synth = NULL;
#if !defined(MACINTOSH)
#ifdef NETWORK_SUPPORT
fluid_server_t* server = NULL;
#endif
char* config_file = NULL;
@ -270,11 +270,9 @@ int main(int argc, char** argv)
int with_server = 0;
int dump = 0;
int fast_render = 0;
static const char optchars[] = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:R:r:sT:Vvz:";
#ifdef LASH_ENABLED
int connect_lash = 1;
#endif
char *optchars = "a:C:c:dE:f:F:G:g:hijK:L:lm:nO:o:p:R:r:sT:Vvz:";
#ifdef LASH_ENABLED
int enabled_lash = 0; /* set to TRUE if lash gets enabled */
fluid_lash_args_t *lash_args;
@ -691,7 +689,7 @@ int main(int argc, char** argv)
}
/* run the server, if requested */
#if !defined(MACINTOSH)
#ifdef NETWORK_SUPPORT
if (with_server) {
server = new_fluid_server(settings, synth, router);
if (server == NULL) {
@ -736,7 +734,7 @@ int main(int argc, char** argv)
cleanup:
#if !defined(MACINTOSH)
#ifdef NETWORK_SUPPORT
if (server != NULL) {
/* if the user typed 'quit' in the shell, kill the server */
if (!interactive) {

View file

@ -940,6 +940,8 @@ fluid_ostream_printf (fluid_ostream_t out, char* format, ...)
#endif
}
#ifdef NETWORK_SUPPORT
int fluid_server_socket_join(fluid_server_socket_t *server_socket)
{
return fluid_thread_join (server_socket->thread);
@ -1171,3 +1173,5 @@ void delete_fluid_server_socket(fluid_server_socket_t *server_socket)
// Should be called the same number of times as fluid_socket_init()
fluid_socket_cleanup();
}
#endif // NETWORK_SUPPORT

View file

@ -148,9 +148,8 @@ typedef guint64 uint64_t;
/* Darwin special defines (taken from config_macosx.h) */
#ifdef DARWIN
#define MACINTOSH
#define __Types__
#define WITHOUT_SERVER 1
# define MACINTOSH
# define __Types__
#endif