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 "JackLibGlobals.h"
00025 #include "JackGlobals.h"
00026 #include "JackServerLaunch.h"
00027 
00028 using namespace Jack;
00029 
00030 #ifdef WIN32
00031         #define EXPORT __declspec(dllexport)
00032 #else
00033         #define EXPORT
00034 #endif
00035 
00036 #ifdef __cplusplus
00037 extern "C"
00038 {
00039 #endif
00040 
00041     EXPORT jack_client_t * jack_client_open (const char *client_name,
00042             jack_options_t options,
00043             jack_status_t *status, ...);
00044     EXPORT jack_client_t * jack_client_new (const char *client_name);
00045     EXPORT int jack_client_close (jack_client_t *client);
00046 
00047 #ifdef __cplusplus
00048 }
00049 #endif
00050 
00051 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00052 long JackLibGlobals::fClientCount = 0;
00053 
00054 static inline bool CheckPort(jack_port_id_t port_index)
00055 {
00056     return (port_index < PORT_NUM);
00057 }
00058 
00059 static jack_client_t* jack_client_open_aux(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00060 {
00061     va_list ap;                         /* variable argument pointer */
00062     jack_varargs_t va;          /* variable arguments */
00063     jack_status_t my_status;
00064 
00065     if (status == NULL)                 /* no status from caller? */
00066         status = &my_status;    /* use local status word */
00067     *status = (jack_status_t)0;
00068 
00069     /* validate parameters */
00070     if ((options & ~JackOpenOptions)) {
00071         int my_status1 = *status | (JackFailure | JackInvalidOption);
00072         *status = (jack_status_t)my_status1;
00073         return NULL;
00074     }
00075 
00076     /* parse variable arguments */
00077     va_start(ap, status);
00078     jack_varargs_parse(options, ap, &va);
00079     va_end(ap);
00080 
00081     JackLog("jack_client_open %s\n", client_name);
00082     if (client_name == NULL) {
00083         jack_error("jack_client_new called with a NULL client_name");
00084         return NULL;
00085     }
00086 
00087     JackLibGlobals::Init(); // jack library initialisation
00088         
00089 #ifndef WIN32
00090         if (try_start_server(&va, options, status)) {
00091                 jack_error("jack server is not running or cannot be started");
00092                 JackLibGlobals::Destroy(); // jack library destruction
00093                 return 0;
00094         }
00095 #endif  
00096 
00097 #ifdef __CLIENTDEBUG__
00098     JackClient* client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
00099 #else
00100     JackClient* client = new JackLibClient(GetSynchroTable());
00101 #endif
00102 
00103     int res = client->Open(client_name, options, status);
00104     if (res < 0) {
00105         delete client;
00106         JackLibGlobals::Destroy(); // jack library destruction
00107                 int my_status1 = (JackFailure|JackServerError);
00108         *status = (jack_status_t)my_status1;
00109         return NULL;
00110     } else {
00111         return (jack_client_t*)client;
00112     }
00113 }
00114 
00115 EXPORT jack_client_t* jack_client_new(const char* client_name)
00116 {
00117     int options = JackUseExactName;
00118     if (getenv("JACK_START_SERVER") == NULL)
00119         options |= JackNoStartServer;
00120 
00121     return jack_client_open_aux(client_name, (jack_options_t)options, NULL);
00122 }
00123 
00124 EXPORT jack_client_t* jack_client_open(const char* client_name, jack_options_t options, jack_status_t* status, ...)
00125 {
00126     va_list ap;
00127         va_start(ap, status);
00128         jack_client_t* res = jack_client_open_aux(client_name, options, status, ap);
00129         va_end(ap);
00130         return res;
00131 }
00132 
00133 EXPORT int jack_client_close(jack_client_t* ext_client)
00134 {
00135     JackLog("jack_client_close\n");
00136     JackClient* client = (JackClient*)ext_client;
00137     if (client == NULL) {
00138         jack_error("jack_client_close called with a NULL client");
00139         return -1;
00140     } else {
00141                 int res = client->Close();
00142                 delete client;
00143                 JackLog("jack_client_close OK\n");
00144                 JackLibGlobals::Destroy(); // jack library destruction
00145                 return res;
00146         }
00147 }
00148 
00149 

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