JackServerAPI.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 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 "JackGraphManager.h"
00026 #include "JackInternalClient.h"
00027 #include "JackServer.h"
00028 #include "JackDebugClient.h"
00029 #include "JackServerGlobals.h"
00030 #include "JackError.h"
00031 #include "JackServerLaunch.h"
00032 #include "JackTools.h"
00033 
00034 #ifdef WIN32
00035         #define EXPORT __declspec(dllexport)
00036 #else
00037         #define EXPORT
00038 #endif
00039 
00040 #ifdef __cplusplus
00041 extern "C"
00042 {
00043 #endif
00044 
00045     EXPORT jack_client_t * jack_client_open (const char *client_name,
00046             jack_options_t options,
00047             jack_status_t *status, ...);
00048     EXPORT int jack_client_close (jack_client_t *client);
00049 
00050 #ifdef __cplusplus
00051 }
00052 #endif
00053 
00054 using namespace Jack;
00055 
00056 EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
00057 {
00058     va_list ap;                         /* variable argument pointer */
00059     jack_varargs_t va;          /* variable arguments */
00060     jack_status_t my_status;
00061         JackClient* client;
00062         char client_name[JACK_CLIENT_NAME_SIZE];
00063         
00064         JackTools::RewriteName(ext_client_name, client_name); 
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     if (!JackServerGlobals::Init()) { // jack server initialisation
00089                 int my_status1 = (JackFailure | JackServerError);
00090         *status = (jack_status_t)my_status1;
00091                 return NULL;
00092         }
00093 
00094 #ifndef WIN32
00095         char* jack_debug = getenv("JACK_CLIENT_DEBUG");
00096         if (jack_debug && strcmp(jack_debug, "on") == 0)
00097                 client = new JackDebugClient(new JackInternalClient(JackServer::fInstance, GetSynchroTable())); // Debug mode
00098         else
00099                 client = new JackInternalClient(JackServer::fInstance, GetSynchroTable()); 
00100 #else
00101         client = new JackInternalClient(JackServer::fInstance, GetSynchroTable());
00102 #endif 
00103 
00104     int res = client->Open(va.server_name, client_name, options, status);
00105     if (res < 0) {
00106         delete client;
00107         JackServerGlobals::Destroy(); // jack server destruction
00108                 int my_status1 = (JackFailure | JackServerError);
00109         *status = (jack_status_t)my_status1;
00110         return NULL;
00111     } else {
00112         return (jack_client_t*)client;
00113     }
00114 }
00115 
00116 EXPORT int jack_client_close(jack_client_t* ext_client)
00117 {
00118     JackLog("jack_client_close\n");
00119     JackClient* client = (JackClient*)ext_client;
00120     if (client == NULL) {
00121         jack_error("jack_client_close called with a NULL client");
00122         return -1;
00123     } else {
00124                 int res = client->Close();
00125                 delete client;
00126                 JackLog("jack_client_close OK\n");
00127                 JackServerGlobals::Destroy();   // jack server destruction
00128                 return res;
00129         }
00130 }
00131 

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