JackServerAPI.cpp

00001 /*
00002 Copyright (C) 2001-2003 Paul Davis
00003 Copyright (C) 2004-2006 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   This program is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU General Public License for more details.
00014 
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifdef WIN32 
00022 #pragma warning (disable : 4786)
00023 #endif
00024 
00025 #include "JackInternalClient.h"
00026 #include "JackGraphManager.h"
00027 #include "JackServer.h"
00028 #include "JackDebugClient.h"
00029 #include "JackServerGlobals.h"
00030 #include "JackError.h"
00031 #include "varargs.h"
00032 
00033 /*
00034 TODO: 
00035  
00036 - implement the "jack_client_new", "jack_client_open", "jack_client_close" API so that we can provide a libjackdmp shared library
00037 to be used by clients for direct access.
00038  
00039 - automatic launch of the jack server with the first client open, automatic close when the last client exit. Use of a jackd.rsc configuration file.
00040  
00041 */
00042 
00043 #ifdef WIN32
00044         #define EXPORT __declspec(dllexport)
00045 #else
00046         #define EXPORT
00047 #endif
00048 
00049 #ifdef __cplusplus
00050 extern "C"
00051 {
00052 #endif
00053 
00054     EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name);
00055     EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
00056 
00057     EXPORT jack_client_t * jack_client_open (const char *client_name,
00058             jack_options_t options,
00059             jack_status_t *status, ...);
00060     EXPORT jack_client_t * jack_client_new (const char *client_name);
00061     EXPORT int jack_client_close (jack_client_t *client);
00062 
00063 #ifdef __cplusplus
00064 }
00065 #endif
00066 
00067 using namespace Jack;
00068 
00069 EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name)
00070 {
00071     JackLog("jack_internal_client_new %s", client_name);
00072     if (client_name == NULL) {
00073         jack_error("jack_internal_client_new called with a NULL client_name");
00074         return NULL;
00075     }
00076 #ifdef __CLIENTDEBUG__
00077     JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
00078 #else
00079     JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
00080 #endif
00081 
00082     int res = client->Open(client_name);
00083     if (res < 0) {
00084         delete client;
00085         return NULL;
00086     } else {
00087         return (jack_client_t*)client;
00088     }
00089 }
00090 
00091 EXPORT void my_jack_internal_client_close(jack_client_t* ext_client)
00092 {
00093     JackLog("jack_internal_client_close");
00094     JackClient* client = (JackClient*)ext_client;
00095     if (client == NULL) {
00096         jack_error("jack_internal_client_close called with a NULL client");
00097     } else {
00098         int res = client->Deactivate();
00099         JackLog("jack_internal_client_close Deactivate %ld", res);
00100         res = client->Close();
00101         delete client;
00102         JackLog("jack_internal_client_close OK");
00103     }
00104 }
00105 
00106 EXPORT jack_client_t* jack_client_new(const char* client_name)
00107 {
00108     int options = JackUseExactName;
00109     if (getenv("JACK_START_SERVER") == NULL)
00110         options |= JackNoStartServer;
00111 
00112     return jack_client_open(client_name, (jack_options_t)options, NULL);
00113 }
00114 
00115 // TO BE IMPLEMENTED PROPERLY
00116 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00117 {
00118     va_list ap;                         /* variable argument pointer */
00119     jack_varargs_t va;          /* variable arguments */
00120     jack_status_t my_status;
00121 
00122     if (status == NULL)                 /* no status from caller? */
00123         status = &my_status;    /* use local status word */
00124     *status = (jack_status_t)0;
00125 
00126     /* validate parameters */
00127     if ((options & ~JackOpenOptions)) {
00128         int my_status1 = *status | (JackFailure | JackInvalidOption);
00129         *status = (jack_status_t)my_status1;
00130         return NULL;
00131     }
00132 
00133     /* parse variable arguments */
00134     va_start(ap, status);
00135     jack_varargs_parse(options, ap, &va);
00136     va_end(ap);
00137 
00138     JackLog("jack_client_open %s\n", client_name);
00139     if (client_name == NULL) {
00140         jack_error("jack_client_new called with a NULL client_name");
00141         return NULL;
00142     }
00143 
00144     JackServerGlobals::Init(); // jack server initialisation
00145 
00146 #ifdef __CLIENTDEBUG__
00147     JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
00148 #else
00149     JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
00150 #endif
00151 
00152     int res = client->Open(client_name);
00153     if (res < 0) {
00154         delete client;
00155         JackServerGlobals::Destroy(); // jack server destruction
00156         return NULL;
00157     } else {
00158         *status = (jack_status_t)0;
00159         return (jack_client_t*)client;
00160     }
00161     return NULL;
00162 }
00163 
00164 EXPORT int jack_client_close(jack_client_t* ext_client)
00165 {
00166     JackLog("jack_client_close\n");
00167     JackClient* client = (JackClient*)ext_client;
00168     if (client == NULL) {
00169         jack_error("jack_client_close called with a NULL client");
00170         return -1;
00171     }
00172     int res = client->Close();
00173     delete client;
00174     JackLog("jack_client_close OK\n");
00175     JackServerGlobals::Destroy(); // jack library destruction
00176     return res;
00177 }
00178 

Generated on Wed Jan 10 11:42:46 2007 for Jackdmp by  doxygen 1.4.5