JackLibAPI.cpp

00001 /*
00002 Copyright (C) 2001-2003 Paul Davis
00003 Copyright (C) 2004-2008 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 #include "JackTools.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 int jack_client_close (jack_client_t *client);
00046 
00047 #ifdef __cplusplus
00048 }
00049 #endif
00050 
00051 JackLibGlobals* JackLibGlobals::fGlobals = NULL;
00052 int JackLibGlobals::fClientCount = 0;
00053 
00054 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00055 {
00056     va_list ap;                         /* variable argument pointer */
00057     jack_varargs_t va;          /* variable arguments */
00058     jack_status_t my_status;
00059         JackClient* client;
00060         char client_name[JACK_CLIENT_NAME_SIZE];
00061         
00062         JackTools::RewriteName(ext_client_name, client_name); 
00063 
00064     if (status == NULL)                 /* no status from caller? */
00065         status = &my_status;    /* use local status word */
00066     *status = (jack_status_t)0;
00067 
00068     /* validate parameters */
00069     if ((options & ~JackOpenOptions)) {
00070         int my_status1 = *status | (JackFailure | JackInvalidOption);
00071         *status = (jack_status_t)my_status1;
00072         return NULL;
00073     }
00074 
00075     /* parse variable arguments */
00076     va_start(ap, status);
00077     jack_varargs_parse(options, ap, &va);
00078     va_end(ap);
00079         
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 #ifndef WIN32
00098         char* jack_debug = getenv("JACK_CLIENT_DEBUG");
00099         if (jack_debug && strcmp(jack_debug, "on") == 0)
00100                 client = new JackDebugClient(new JackLibClient(GetSynchroTable())); // Debug mode
00101         else
00102                 client = new JackLibClient(GetSynchroTable()); 
00103 #else
00104         client = new JackLibClient(GetSynchroTable());
00105 #endif 
00106 
00107     int res = client->Open(va.server_name, client_name, options, status);
00108     if (res < 0) {
00109         delete client;
00110         JackLibGlobals::Destroy(); // jack library destruction
00111                 int my_status1 = (JackFailure|JackServerError);
00112         *status = (jack_status_t)my_status1;
00113         return NULL;
00114     } else {
00115         return (jack_client_t*)client;
00116     }
00117 }
00118 
00119 EXPORT int jack_client_close(jack_client_t* ext_client)
00120 {
00121     JackLog("jack_client_close\n");
00122     JackClient* client = (JackClient*)ext_client;
00123     if (client == NULL) {
00124         jack_error("jack_client_close called with a NULL client");
00125         return -1;
00126     } else {
00127                 int res = client->Close();
00128                 delete client;
00129                 JackLog("jack_client_close OK\n");
00130                 JackLibGlobals::Destroy(); // jack library destruction
00131                 return res;
00132         }
00133 }
00134 
00135 

Generated on Thu Feb 14 11:16:02 2008 for Jackdmp by  doxygen 1.5.1