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 "JackServerLaunch.h"
00032 
00033 #ifdef WIN32
00034         #define EXPORT __declspec(dllexport)
00035 #else
00036         #define EXPORT
00037 #endif
00038 
00039 #ifdef __cplusplus
00040 extern "C"
00041 {
00042 #endif
00043 
00044     EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name, const char* dll_name, const char* object_data);
00045     EXPORT void my_jack_internal_client_close(jack_client_t* ext_client);
00046 
00047     EXPORT jack_client_t * jack_client_open (const char *client_name,
00048             jack_options_t options,
00049             jack_status_t *status, ...);
00050     EXPORT jack_client_t * jack_client_new (const char *client_name);
00051     EXPORT int jack_client_close (jack_client_t *client);
00052 
00053 #ifdef __cplusplus
00054 }
00055 #endif
00056 
00057 using namespace Jack;
00058 
00059 EXPORT jack_client_t* my_jack_internal_client_new(const char* client_name, const char* dll_name, const char* object_data)
00060 {
00061         jack_status_t my_status = (jack_status_t)0;
00062 
00063     JackLog("jack_internal_client_new %s", client_name);
00064     if (client_name == NULL) {
00065         jack_error("jack_internal_client_new called with a NULL client_name");
00066         return NULL;
00067     }
00068         
00069         JackClient* client;
00070         
00071         try {
00072         #ifdef __CLIENTDEBUG__
00073                 client = new JackDebugClient(new JackLoadableInternalClient(JackServer::fInstance, GetSynchroTable(), dll_name, object_data)); // Debug mode
00074         #else
00075                 client = new JackLoadableInternalClient(JackServer::fInstance, GetSynchroTable(), dll_name, object_data); // To improve...
00076         #endif
00077         } catch (...) {  // Allocation or dynamic code loading failure
00078                 return NULL;
00079         }
00080 
00081     jack_options_t options = JackUseExactName;
00082     int res = client->Open(client_name, options, &my_status);
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                 client->Close();
00099         delete client;
00100         JackLog("jack_internal_client_close OK");
00101     }
00102 }
00103 
00104 EXPORT jack_client_t* jack_client_new(const char* client_name)
00105 {
00106     int options = JackUseExactName;
00107     if (getenv("JACK_START_SERVER") == NULL)
00108         options |= JackNoStartServer;
00109 
00110     return jack_client_open(client_name, (jack_options_t)options, NULL);
00111 }
00112 
00113 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00114 {
00115     va_list ap;                         /* variable argument pointer */
00116     jack_varargs_t va;          /* variable arguments */
00117     jack_status_t my_status;
00118 
00119     if (status == NULL)                 /* no status from caller? */
00120         status = &my_status;    /* use local status word */
00121     *status = (jack_status_t)0;
00122 
00123     /* validate parameters */
00124     if ((options & ~JackOpenOptions)) {
00125         int my_status1 = *status | (JackFailure | JackInvalidOption);
00126         *status = (jack_status_t)my_status1;
00127         return NULL;
00128     }
00129 
00130     /* parse variable arguments */
00131     va_start(ap, status);
00132     jack_varargs_parse(options, ap, &va);
00133     va_end(ap);
00134 
00135     JackLog("jack_client_open %s\n", client_name);
00136     if (client_name == NULL) {
00137         jack_error("jack_client_new called with a NULL client_name");
00138         return NULL;
00139     }
00140 
00141     if (!JackServerGlobals::Init()) { // jack server initialisation
00142                 int my_status1 = (JackFailure | JackServerError);
00143         *status = (jack_status_t)my_status1;
00144                 return NULL;
00145         }
00146                   
00147 #ifdef __CLIENTDEBUG__
00148     JackClient* client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
00149 #else
00150     JackClient* client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); // To improve...
00151 #endif
00152 
00153     int res = client->Open(client_name, options, status);
00154     if (res < 0) {
00155         delete client;
00156         JackServerGlobals::Destroy(); // jack server destruction
00157                 int my_status1 = (JackFailure | JackServerError);
00158         *status = (jack_status_t)my_status1;
00159         return NULL;
00160     } else {
00161         return (jack_client_t*)client;
00162     }
00163 }
00164 
00165 EXPORT int jack_client_close(jack_client_t* ext_client)
00166 {
00167     JackLog("jack_client_close\n");
00168     JackClient* client = (JackClient*)ext_client;
00169     if (client == NULL) {
00170         jack_error("jack_client_close called with a NULL client");
00171         return -1;
00172     } else {
00173                 int res = client->Close();
00174                 delete client;
00175                 JackLog("jack_client_close OK\n");
00176                 JackServerGlobals::Destroy();   // jack server destruction
00177                 return res;
00178         }
00179 }
00180 

Generated on Mon Oct 15 17:11:14 2007 for Jackdmp by  doxygen 1.5.1