JackLibAPI.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 Lesser General Public License as published by
00007 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public License
00016 along with this program; if not, write to the Free Software 
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 
00019 */
00020 
00021 #include "JackDebugClient.h"
00022 #include "JackLibClient.h"
00023 #include "JackChannel.h"
00024 #include "JackGraphManager.h"
00025 #include "JackLibGlobals.h"
00026 #include "JackGlobals.h"
00027 #include "varargs.h"
00028 
00029 using namespace Jack;
00030 
00031 #ifdef WIN32
00032         #define EXPORT __declspec(dllexport)
00033 #else
00034         #define EXPORT
00035 #endif
00036 
00037 #ifdef __cplusplus
00038 extern "C"
00039 {
00040 #endif
00041 
00042     EXPORT jack_client_t * jack_client_open (const char *client_name,
00043             jack_options_t options,
00044             jack_status_t *status, ...);
00045     EXPORT jack_client_t * jack_client_new (const char *client_name);
00046     EXPORT int jack_client_close (jack_client_t *client);
00047 
00048 #ifdef __cplusplus
00049 }
00050 #endif
00051 
00052 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00053 long JackLibGlobals::fClientCount = 0;
00054 
00055 static inline bool CheckPort(jack_port_id_t port_index)
00056 {
00057     return (port_index < PORT_NUM);
00058 }
00059 
00060 static jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00061 {
00062     va_list ap;                         /* variable argument pointer */
00063     jack_varargs_t va;          /* variable arguments */
00064     jack_status_t my_status;
00065 
00066     if (status == NULL)                 /* no status from caller? */
00067         status = &my_status;    /* use local status word */
00068     *status = (jack_status_t)0;
00069 
00070     /* validate parameters */
00071     if ((options & ~JackOpenOptions)) {
00072         int my_status1 = *status | (JackFailure | JackInvalidOption);
00073         *status = (jack_status_t)my_status1;
00074         return NULL;
00075     }
00076 
00077     /* parse variable arguments */
00078     va_start(ap, status);
00079     jack_varargs_parse(options, ap, &va);
00080     va_end(ap);
00081 
00082     JackLog("jack_client_open %s\n", client_name);
00083     if (client_name == NULL) {
00084         jack_error("jack_client_new called with a NULL client_name");
00085         return NULL;
00086     }
00087 
00088     JackLibGlobals::Init(); // jack library initialisation
00089 
00090 #ifdef __CLIENTDEBUG__
00091     JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
00092 #else
00093     JackClient* client = new JackLibClient(GetSynchroTable());
00094 #endif
00095 
00096     int res = client->Open(client_name);
00097     if (res < 0) {
00098         delete client;
00099         JackLibGlobals::Destroy(); // jack library destruction
00100         return NULL;
00101     } else {
00102         *status = (jack_status_t)0;
00103         return (jack_client_t*)client;
00104     }
00105     return NULL;
00106 }
00107 
00108 EXPORT jack_client_t* jack_client_new(const char* client_name)
00109 {
00110     int options = JackUseExactName;
00111     if (getenv("JACK_START_SERVER") == NULL)
00112         options |= JackNoStartServer;
00113 
00114     return jack_client_open_aux(client_name, (jack_options_t)options, NULL);
00115 }
00116 
00117 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00118 {
00119     va_list ap;
00120         va_start(ap, status);
00121         jack_client_t* res = jack_client_open_aux(client_name, options, status, ap);
00122         va_end(ap);
00123         return res;
00124 }
00125 
00126 EXPORT int jack_client_close(jack_client_t* ext_client)
00127 {
00128     JackLog("jack_client_close\n");
00129     JackClient* client = (JackClient*)ext_client;
00130     if (client == NULL) {
00131         jack_error("jack_client_close called with a NULL client");
00132         return -1;
00133     }
00134     int res = client->Close();
00135     delete client;
00136     JackLog("jack_client_close OK\n");
00137     JackLibGlobals::Destroy(); // jack library destruction
00138     return res;
00139 }
00140 
00141 

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