Jack2 1.9.7
JackAPI.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 "JackClient.h"
00022 #include "JackError.h"
00023 #include "JackGraphManager.h"
00024 #include "JackEngineControl.h"
00025 #include "JackClientControl.h"
00026 #include "JackGlobals.h"
00027 #include "JackTime.h"
00028 #include "JackCompilerDeps.h"
00029 #include "JackPortType.h"
00030 #include "JackPlatformPlug.h"
00031 #include <math.h>
00032 
00033 #ifdef __CLIENTDEBUG__
00034 #include "JackLibGlobals.h"
00035 #endif
00036 
00037 using namespace Jack;
00038 
00039 #ifdef __cplusplus
00040 extern "C"
00041 {
00042 #endif
00043 
00044     typedef void (*print_function)(const char*);
00045     typedef void *(*thread_routine)(void*);
00046 
00047     EXPORT
00048     void
00049     jack_get_version(
00050         int *major_ptr,
00051         int *minor_ptr,
00052         int *micro_ptr,
00053         int *proto_ptr);
00054 
00055     EXPORT
00056     const char*
00057     jack_get_version_string();
00058 
00059     jack_client_t * jack_client_new_aux(const char* client_name,
00060             jack_options_t options,
00061             jack_status_t *status);
00062     EXPORT jack_client_t * jack_client_open(const char* client_name,
00063             jack_options_t options,
00064             jack_status_t *status, ...);
00065     EXPORT jack_client_t * jack_client_new(const char* client_name);
00066     EXPORT int jack_client_name_size(void);
00067     EXPORT char* jack_get_client_name(jack_client_t *client);
00068     EXPORT int jack_internal_client_new(const char* client_name,
00069                                          const char* load_name,
00070                                          const char* load_init);
00071     EXPORT void jack_internal_client_close(const char* client_name);
00072     EXPORT int jack_is_realtime(jack_client_t *client);
00073     EXPORT void jack_on_shutdown(jack_client_t *client,
00074                                   JackShutdownCallback shutdown_callback, void *arg);
00075     EXPORT void jack_on_info_shutdown(jack_client_t *client,
00076                                   JackInfoShutdownCallback shutdown_callback, void *arg);
00077     EXPORT int jack_set_process_callback(jack_client_t *client,
00078                                           JackProcessCallback process_callback,
00079                                           void *arg);
00080     EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
00081 
00082     // new
00083     EXPORT jack_nframes_t jack_cycle_wait(jack_client_t*);
00084     EXPORT void jack_cycle_signal(jack_client_t*, int status);
00085     EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
00086 
00087     EXPORT int jack_set_thread_init_callback(jack_client_t *client,
00088             JackThreadInitCallback thread_init_callback,
00089             void *arg);
00090     EXPORT int jack_set_freewheel_callback(jack_client_t *client,
00091                                             JackFreewheelCallback freewheel_callback,
00092                                             void *arg);
00093     EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
00094     EXPORT int jack_set_buffer_size(jack_client_t *client, jack_nframes_t nframes);
00095     EXPORT int jack_set_buffer_size_callback(jack_client_t *client,
00096             JackBufferSizeCallback bufsize_callback,
00097             void *arg);
00098     EXPORT int jack_set_sample_rate_callback(jack_client_t *client,
00099             JackSampleRateCallback srate_callback,
00100             void *arg);
00101     EXPORT int jack_set_client_registration_callback(jack_client_t *,
00102             JackClientRegistrationCallback
00103             registration_callback, void *arg);
00104     EXPORT int jack_set_port_registration_callback(jack_client_t *,
00105             JackPortRegistrationCallback
00106             registration_callback, void *arg);
00107     EXPORT int jack_set_port_connect_callback(jack_client_t *,
00108             JackPortConnectCallback
00109             connect_callback, void *arg);
00110     EXPORT int jack_set_port_rename_callback(jack_client_t *,
00111                                     JackPortRenameCallback
00112                                     rename_callback, void *arg);
00113     EXPORT int jack_set_graph_order_callback(jack_client_t *,
00114             JackGraphOrderCallback graph_callback,
00115             void *);
00116     EXPORT int jack_set_xrun_callback(jack_client_t *,
00117                                        JackXRunCallback xrun_callback, void *arg);
00118     EXPORT int jack_set_latency_callback(jack_client_t *client,
00119                                JackLatencyCallback latency_callback, void *arg);
00120 
00121     EXPORT int jack_activate(jack_client_t *client);
00122     EXPORT int jack_deactivate(jack_client_t *client);
00123     EXPORT jack_port_t * jack_port_register(jack_client_t *client,
00124             const char* port_name,
00125             const char* port_type,
00126             unsigned long flags,
00127             unsigned long buffer_size);
00128     EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *);
00129     EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t);
00130     EXPORT const char*  jack_port_name(const jack_port_t *port);
00131     EXPORT const char*  jack_port_short_name(const jack_port_t *port);
00132     EXPORT int jack_port_flags(const jack_port_t *port);
00133     EXPORT const char*  jack_port_type(const jack_port_t *port);
00134     EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port);
00135     EXPORT int jack_port_is_mine(const jack_client_t *, const jack_port_t *port);
00136     EXPORT int jack_port_connected(const jack_port_t *port);
00137     EXPORT int jack_port_connected_to(const jack_port_t *port,
00138                                        const char* port_name);
00139     EXPORT const char* * jack_port_get_connections(const jack_port_t *port);
00140     EXPORT const char* * jack_port_get_all_connections(const jack_client_t *client,
00141             const jack_port_t *port);
00142     EXPORT int jack_port_tie(jack_port_t *src, jack_port_t *dst);
00143     EXPORT int jack_port_untie(jack_port_t *port);
00144 
00145     // Old latency API
00146     EXPORT jack_nframes_t jack_port_get_latency(jack_port_t *port);
00147     EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t *,
00148             jack_port_t *port);
00149     EXPORT void jack_port_set_latency(jack_port_t *, jack_nframes_t);
00150     EXPORT int jack_recompute_total_latency(jack_client_t*, jack_port_t* port);
00151 
00152     // New latency API
00153     EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
00154     EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
00155     EXPORT int jack_recompute_total_latencies(jack_client_t*);
00156 
00157     EXPORT int jack_port_set_name(jack_port_t *port, const char* port_name);
00158     EXPORT int jack_port_set_alias(jack_port_t *port, const char* alias);
00159     EXPORT int jack_port_unset_alias(jack_port_t *port, const char* alias);
00160     EXPORT int jack_port_get_aliases(const jack_port_t *port, char* const aliases[2]);
00161     EXPORT int jack_port_request_monitor(jack_port_t *port, int onoff);
00162     EXPORT int jack_port_request_monitor_by_name(jack_client_t *client,
00163             const char* port_name, int onoff);
00164     EXPORT int jack_port_ensure_monitor(jack_port_t *port, int onoff);
00165     EXPORT int jack_port_monitoring_input(jack_port_t *port);
00166     EXPORT int jack_connect(jack_client_t *,
00167                              const char* source_port,
00168                              const char* destination_port);
00169     EXPORT int jack_disconnect(jack_client_t *,
00170                                 const char* source_port,
00171                                 const char* destination_port);
00172     EXPORT int jack_port_disconnect(jack_client_t *, jack_port_t *);
00173     EXPORT int jack_port_name_size(void);
00174     EXPORT int jack_port_type_size(void);
00175     EXPORT size_t jack_port_type_get_buffer_size(jack_client_t *client, const char* port_type);
00176     EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *);
00177     EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *);
00178     EXPORT const char* * jack_get_ports(jack_client_t *,
00179                                          const char* port_name_pattern,
00180                                          const char* type_name_pattern,
00181                                          unsigned long flags);
00182     EXPORT jack_port_t * jack_port_by_name(jack_client_t *, const char* port_name);
00183     EXPORT jack_port_t * jack_port_by_id(jack_client_t *client,
00184                                           jack_port_id_t port_id);
00185     EXPORT int jack_engine_takeover_timebase(jack_client_t *);
00186     EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t *);
00187     EXPORT jack_time_t jack_get_time();
00188     EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
00189     EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
00190     EXPORT jack_nframes_t jack_frame_time(const jack_client_t *);
00191     EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t *client);
00192     EXPORT float jack_cpu_load(jack_client_t *client);
00193     EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *);
00194     EXPORT void jack_set_error_function(print_function);
00195     EXPORT void jack_set_info_function(print_function);
00196 
00197     EXPORT float jack_get_max_delayed_usecs(jack_client_t *client);
00198     EXPORT float jack_get_xrun_delayed_usecs(jack_client_t *client);
00199     EXPORT void jack_reset_max_delayed_usecs(jack_client_t *client);
00200 
00201     EXPORT int jack_release_timebase(jack_client_t *client);
00202     EXPORT int jack_set_sync_callback(jack_client_t *client,
00203                                        JackSyncCallback sync_callback,
00204                                        void *arg);
00205     EXPORT int jack_set_sync_timeout(jack_client_t *client,
00206                                       jack_time_t timeout);
00207     EXPORT int jack_set_timebase_callback(jack_client_t *client,
00208                                            int conditional,
00209                                            JackTimebaseCallback timebase_callback,
00210                                            void *arg);
00211     EXPORT int jack_transport_locate(jack_client_t *client,
00212                                       jack_nframes_t frame);
00213     EXPORT jack_transport_state_t jack_transport_query(const jack_client_t *client,
00214             jack_position_t *pos);
00215     EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t *client);
00216     EXPORT int jack_transport_reposition(jack_client_t *client,
00217                                           jack_position_t *pos);
00218     EXPORT void jack_transport_start(jack_client_t *client);
00219     EXPORT void jack_transport_stop(jack_client_t *client);
00220     EXPORT void jack_get_transport_info(jack_client_t *client,
00221                                          jack_transport_info_t *tinfo);
00222     EXPORT void jack_set_transport_info(jack_client_t *client,
00223                                          jack_transport_info_t *tinfo);
00224 
00225     EXPORT int jack_client_real_time_priority(jack_client_t*);
00226     EXPORT int jack_client_max_real_time_priority(jack_client_t*);
00227     EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority);
00228     EXPORT int jack_client_create_thread(jack_client_t* client,
00229                                           jack_native_thread_t *thread,
00230                                           int priority,
00231                                           int realtime,         // boolean
00232                                           thread_routine routine,
00233                                           void *arg);
00234     EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread);
00235 
00236     EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread);
00237     EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread);
00238 #ifndef WIN32
00239     EXPORT void jack_set_thread_creator(jack_thread_creator_t jtc);
00240 #endif
00241     EXPORT char * jack_get_internal_client_name(jack_client_t *client,
00242             jack_intclient_t intclient);
00243     EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t *client,
00244             const char* client_name,
00245             jack_status_t *status);
00246     EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client,
00247             const char* client_name,
00248             jack_options_t options,
00249             jack_status_t *status, ...);
00250     EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t *client,
00251             const char* client_name,
00252             jack_options_t options,
00253             jack_status_t *status, va_list ap);
00254 
00255     EXPORT jack_status_t jack_internal_client_unload(jack_client_t *client,
00256             jack_intclient_t intclient);
00257     EXPORT void jack_free(void* ptr);
00258 
00259     EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg);
00260     EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path);
00261     EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event);
00262     EXPORT void jack_session_event_free(jack_session_event_t* ev);
00263     EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name);
00264     EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid);
00265     EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* name, const char* uuid);
00266     EXPORT void jack_session_commands_free(jack_session_command_t *cmds);
00267     EXPORT int jack_client_has_session_callback(jack_client_t *client, const char* client_name);
00268 
00269 #ifdef __cplusplus
00270 }
00271 #endif
00272 
00273 static inline bool CheckPort(jack_port_id_t port_index)
00274 {
00275     return (port_index > 0 && port_index < PORT_NUM_MAX);
00276 }
00277 
00278 static inline bool CheckBufferSize(jack_nframes_t buffer_size)
00279 {
00280     return (buffer_size >= 1 && buffer_size <= BUFFER_SIZE_MAX);
00281 }
00282 
00283 static inline void WaitGraphChange()
00284 {
00285     /*
00286     TLS key that is set only in RT thread, so never waits for pending
00287     graph change in RT context (just read the current graph state).
00288     */
00289 
00290     if (jack_tls_get(JackGlobals::fRealTime) == NULL) {
00291         JackGraphManager* manager = GetGraphManager();
00292         JackEngineControl* control = GetEngineControl();
00293         assert(manager);
00294         assert(control);
00295         if (manager->IsPendingChange()) {
00296             jack_log("WaitGraphChange...");
00297             JackSleep(int(control->fPeriodUsecs * 1.1f));
00298         }
00299     }
00300 }
00301 
00302 EXPORT void jack_set_error_function(print_function func)
00303 {
00304     jack_error_callback = (func == NULL) ? &default_jack_error_callback : func;
00305 }
00306 
00307 EXPORT void jack_set_info_function(print_function func)
00308 {
00309     jack_info_callback = (func == NULL) ? &default_jack_info_callback : func;
00310 }
00311 
00312 EXPORT jack_client_t* jack_client_new(const char* client_name)
00313 {
00314 #ifdef __CLIENTDEBUG__
00315     JackGlobals::CheckContext("jack_client_new");
00316 #endif
00317     try {
00318         assert(JackGlobals::fOpenMutex);
00319         JackGlobals::fOpenMutex->Lock();
00320         jack_error("jack_client_new: deprecated");
00321         int options = JackUseExactName;
00322         if (getenv("JACK_START_SERVER") == NULL)
00323             options |= JackNoStartServer;
00324         jack_client_t* res = jack_client_new_aux(client_name, (jack_options_t)options, NULL);
00325         JackGlobals::fOpenMutex->Unlock();
00326         return res;
00327     } catch (std::bad_alloc& e) {
00328         jack_error("Memory allocation error...");
00329         return NULL;
00330     } catch (...) {
00331         jack_error("Unknown error...");
00332         return NULL;
00333     }
00334 }
00335 
00336 EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
00337 {
00338 #ifdef __CLIENTDEBUG__
00339     JackGlobals::CheckContext("jack_port_get_buffer");
00340 #endif
00341     uintptr_t port_aux = (uintptr_t)port;
00342     jack_port_id_t myport = (jack_port_id_t)port_aux;
00343     if (!CheckPort(myport)) {
00344         jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
00345         return NULL;
00346     } else {
00347         JackGraphManager* manager = GetGraphManager();
00348         return (manager ? manager->GetBuffer(myport, frames) : NULL);
00349     }
00350 }
00351 
00352 EXPORT const char* jack_port_name(const jack_port_t* port)
00353 {
00354 #ifdef __CLIENTDEBUG__
00355     JackGlobals::CheckContext("jack_port_name");
00356 #endif
00357     uintptr_t port_aux = (uintptr_t)port;
00358     jack_port_id_t myport = (jack_port_id_t)port_aux;
00359     if (!CheckPort(myport)) {
00360         jack_error("jack_port_name called with an incorrect port %ld", myport);
00361         return NULL;
00362     } else {
00363         JackGraphManager* manager = GetGraphManager();
00364         return (manager ? manager->GetPort(myport)->GetName() : NULL);
00365     }
00366 }
00367 
00368 EXPORT const char* jack_port_short_name(const jack_port_t* port)
00369 {
00370 #ifdef __CLIENTDEBUG__
00371     JackGlobals::CheckContext("jack_port_short_name");
00372 #endif
00373     uintptr_t port_aux = (uintptr_t)port;
00374     jack_port_id_t myport = (jack_port_id_t)port_aux;
00375     if (!CheckPort(myport)) {
00376         jack_error("jack_port_short_name called with an incorrect port %ld", myport);
00377         return NULL;
00378     } else {
00379         JackGraphManager* manager = GetGraphManager();
00380         return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
00381     }
00382 }
00383 
00384 EXPORT int jack_port_flags(const jack_port_t* port)
00385 {
00386 #ifdef __CLIENTDEBUG__
00387     JackGlobals::CheckContext("jack_port_flags");
00388 #endif
00389     uintptr_t port_aux = (uintptr_t)port;
00390     jack_port_id_t myport = (jack_port_id_t)port_aux;
00391     if (!CheckPort(myport)) {
00392         jack_error("jack_port_flags called with an incorrect port %ld", myport);
00393         return -1;
00394     } else {
00395         JackGraphManager* manager = GetGraphManager();
00396         return (manager ? manager->GetPort(myport)->GetFlags() : -1);
00397     }
00398 }
00399 
00400 EXPORT const char* jack_port_type(const jack_port_t* port)
00401 {
00402 #ifdef __CLIENTDEBUG__
00403     JackGlobals::CheckContext("jack_port_type");
00404 #endif
00405     uintptr_t port_aux = (uintptr_t)port;
00406     jack_port_id_t myport = (jack_port_id_t)port_aux;
00407    if (!CheckPort(myport)) {
00408         jack_error("jack_port_flags called an incorrect port %ld", myport);
00409         return NULL;
00410     } else {
00411         JackGraphManager* manager = GetGraphManager();
00412         return (manager ? manager->GetPort(myport)->GetType() : NULL);
00413     }
00414 }
00415 
00416 EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
00417 {
00418 #ifdef __CLIENTDEBUG__
00419     JackGlobals::CheckContext("jack_port_type_id");
00420 #endif
00421     uintptr_t port_aux = (uintptr_t)port;
00422     jack_port_id_t myport = (jack_port_id_t)port_aux;
00423     if (!CheckPort(myport)) {
00424         jack_error("jack_port_type_id called an incorrect port %ld", myport);
00425         return 0;
00426     } else {
00427         JackGraphManager* manager = GetGraphManager();
00428         return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
00429     }
00430 }
00431 
00432 EXPORT int jack_port_connected(const jack_port_t* port)
00433 {
00434 #ifdef __CLIENTDEBUG__
00435     JackGlobals::CheckContext("jack_port_connected");
00436 #endif
00437     uintptr_t port_aux = (uintptr_t)port;
00438     jack_port_id_t myport = (jack_port_id_t)port_aux;
00439     if (!CheckPort(myport)) {
00440         jack_error("jack_port_connected called with an incorrect port %ld", myport);
00441         return -1;
00442     } else {
00443         WaitGraphChange();
00444         JackGraphManager* manager = GetGraphManager();
00445         return (manager ? manager->GetConnectionsNum(myport) : -1);
00446     }
00447 }
00448 
00449 EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
00450 {
00451 #ifdef __CLIENTDEBUG__
00452     JackGlobals::CheckContext("jack_port_connected_to");
00453 #endif
00454     uintptr_t port_aux = (uintptr_t)port;
00455     jack_port_id_t src = (jack_port_id_t)port_aux;
00456     if (!CheckPort(src)) {
00457         jack_error("jack_port_connected_to called with an incorrect port %ld", src);
00458         return -1;
00459     } else if (port_name == NULL) {
00460         jack_error("jack_port_connected_to called with a NULL port name");
00461         return -1;
00462     } else {
00463         WaitGraphChange();
00464         JackGraphManager* manager = GetGraphManager();
00465         jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
00466         if (dst == NO_PORT) {
00467             jack_error("Unknown destination port port_name = %s", port_name);
00468             return 0;
00469         } else {
00470             return manager->IsConnected(src, dst);
00471         }
00472     }
00473 }
00474 
00475 EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
00476 {
00477 #ifdef __CLIENTDEBUG__
00478     JackGlobals::CheckContext("jack_port_tie");
00479 #endif
00480     uintptr_t src_aux = (uintptr_t)src;
00481     jack_port_id_t mysrc = (jack_port_id_t)src_aux;
00482     if (!CheckPort(mysrc)) {
00483         jack_error("jack_port_tie called with a NULL src port");
00484         return -1;
00485     }
00486     uintptr_t dst_aux = (uintptr_t)dst;
00487     jack_port_id_t mydst = (jack_port_id_t)dst_aux;
00488     if (!CheckPort(mydst)) {
00489         jack_error("jack_port_tie called with a NULL dst port");
00490         return -1;
00491     }
00492     JackGraphManager* manager = GetGraphManager();
00493     if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
00494         jack_error("jack_port_tie called with ports not belonging to the same client");
00495         return -1;
00496     } else {
00497         return manager->GetPort(mydst)->Tie(mysrc);
00498     }
00499 }
00500 
00501 EXPORT int jack_port_untie(jack_port_t* port)
00502 {
00503 #ifdef __CLIENTDEBUG__
00504     JackGlobals::CheckContext("jack_port_untie");
00505 #endif
00506     uintptr_t port_aux = (uintptr_t)port;
00507     jack_port_id_t myport = (jack_port_id_t)port_aux;
00508     if (!CheckPort(myport)) {
00509         jack_error("jack_port_untie called with an incorrect port %ld", myport);
00510         return -1;
00511     } else {
00512         JackGraphManager* manager = GetGraphManager();
00513         return (manager ? manager->GetPort(myport)->UnTie() : -1);
00514     }
00515 }
00516 
00517 EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
00518 {
00519 #ifdef __CLIENTDEBUG__
00520     JackGlobals::CheckContext("jack_port_get_latency");
00521 #endif
00522     uintptr_t port_aux = (uintptr_t)port;
00523     jack_port_id_t myport = (jack_port_id_t)port_aux;
00524     if (!CheckPort(myport)) {
00525         jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
00526         return 0;
00527     } else {
00528         WaitGraphChange();
00529         JackGraphManager* manager = GetGraphManager();
00530         return (manager ? manager->GetPort(myport)->GetLatency() : 0);
00531     }
00532 }
00533 
00534 EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
00535 {
00536 #ifdef __CLIENTDEBUG__
00537     JackGlobals::CheckContext("jack_port_set_latency");
00538 #endif
00539     uintptr_t port_aux = (uintptr_t)port;
00540     jack_port_id_t myport = (jack_port_id_t)port_aux;
00541     if (!CheckPort(myport)) {
00542         jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
00543     } else {
00544         JackGraphManager* manager = GetGraphManager();
00545         if (manager)
00546             manager->GetPort(myport)->SetLatency(frames);
00547     }
00548 }
00549 
00550 EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
00551 {
00552 #ifdef __CLIENTDEBUG__
00553     JackGlobals::CheckContext("jack_port_get_latency_range");
00554 #endif
00555     uintptr_t port_aux = (uintptr_t)port;
00556     jack_port_id_t myport = (jack_port_id_t)port_aux;
00557     if (!CheckPort(myport)) {
00558         jack_error("jack_port_get_latency_range called with an incorrect port %ld", myport);
00559     } else {
00560         WaitGraphChange();
00561         JackGraphManager* manager = GetGraphManager();
00562         if (manager)
00563             manager->GetPort(myport)->GetLatencyRange(mode, range);
00564     }
00565 }
00566 
00567 EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
00568 {
00569 #ifdef __CLIENTDEBUG__
00570     JackGlobals::CheckContext("jack_port_set_latency_range");
00571 #endif
00572     uintptr_t port_aux = (uintptr_t)port;
00573     jack_port_id_t myport = (jack_port_id_t)port_aux;
00574     if (!CheckPort(myport)) {
00575         jack_error("jack_port_set_latency_range called with an incorrect port %ld", myport);
00576     } else {
00577         WaitGraphChange();
00578         JackGraphManager* manager = GetGraphManager();
00579         if (manager)
00580             manager->GetPort(myport)->SetLatencyRange(mode, range);
00581     }
00582 }
00583 
00584 EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
00585 {
00586 #ifdef __CLIENTDEBUG__
00587     JackGlobals::CheckContext("jack_recompute_total_latency");
00588 #endif
00589 
00590     JackClient* client = (JackClient*)ext_client;
00591     uintptr_t port_aux = (uintptr_t)port;
00592     jack_port_id_t myport = (jack_port_id_t)port_aux;
00593     if (client == NULL) {
00594         jack_error("jack_recompute_total_latency called with a NULL client");
00595         return -1;
00596     } else if (!CheckPort(myport)) {
00597         jack_error("jack_recompute_total_latency called with a NULL port");
00598         return -1;
00599     } else {
00600         WaitGraphChange();
00601         JackGraphManager* manager = GetGraphManager();
00602         return (manager ? manager->ComputeTotalLatency(myport) : -1);
00603     }
00604 }
00605 
00606 EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
00607 {
00608 #ifdef __CLIENTDEBUG__
00609     JackGlobals::CheckContext("jack_recompute_total_latencies");
00610 #endif
00611 
00612     JackClient* client = (JackClient*)ext_client;
00613     if (client == NULL) {
00614         jack_error("jack_recompute_total_latencies called with a NULL client");
00615         return -1;
00616     } else {
00617         return client->ComputeTotalLatencies();
00618     }
00619 }
00620 
00621 /*
00622 This is unsafe if case of concurrent access, and should be "serialized" doing a server call.
00623 */
00624 
00625 EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
00626 {
00627 #ifdef __CLIENTDEBUG__
00628     JackGlobals::CheckContext("jack_port_set_name");
00629 #endif
00630     uintptr_t port_aux = (uintptr_t)port;
00631     jack_port_id_t myport = (jack_port_id_t)port_aux;
00632     if (!CheckPort(myport)) {
00633         jack_error("jack_port_set_name called with an incorrect port %ld", myport);
00634         return -1;
00635     } else if (name == NULL) {
00636         jack_error("jack_port_set_name called with a NULL port name");
00637         return -1;
00638     } else {
00639         JackGraphManager* manager = GetGraphManager();
00640         int refnum;
00641         if (manager && ((refnum = manager->GetPort(myport)->GetRefNum()) > 0)) {
00642             JackClient* client = JackGlobals::fClientTable[refnum];
00643             assert(client);
00644             return client->PortRename(myport, name);
00645         } else {
00646             return -1;
00647         }
00648     }
00649 }
00650 
00651 EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
00652 {
00653 #ifdef __CLIENTDEBUG__
00654     JackGlobals::CheckContext("jack_port_set_alias");
00655 #endif
00656     uintptr_t port_aux = (uintptr_t)port;
00657     jack_port_id_t myport = (jack_port_id_t)port_aux;
00658     if (!CheckPort(myport)) {
00659         jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
00660         return -1;
00661     } else if (name == NULL) {
00662         jack_error("jack_port_set_alias called with a NULL port name");
00663         return -1;
00664     } else {
00665         JackGraphManager* manager = GetGraphManager();
00666         return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
00667     }
00668 }
00669 
00670 EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
00671 {
00672 #ifdef __CLIENTDEBUG__
00673     JackGlobals::CheckContext("jack_port_unset_alias");
00674 #endif
00675     uintptr_t port_aux = (uintptr_t)port;
00676     jack_port_id_t myport = (jack_port_id_t)port_aux;
00677     if (!CheckPort(myport)) {
00678         jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
00679         return -1;
00680     } else if (name == NULL) {
00681         jack_error("jack_port_unset_alias called with a NULL port name");
00682         return -1;
00683     } else {
00684         JackGraphManager* manager = GetGraphManager();
00685         return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
00686     }
00687 }
00688 
00689 EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
00690 {
00691 #ifdef __CLIENTDEBUG__
00692     JackGlobals::CheckContext("jack_port_get_aliases");
00693 #endif
00694     uintptr_t port_aux = (uintptr_t)port;
00695     jack_port_id_t myport = (jack_port_id_t)port_aux;
00696     if (!CheckPort(myport)) {
00697         jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
00698         return -1;
00699     } else {
00700         JackGraphManager* manager = GetGraphManager();
00701         return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
00702     }
00703 }
00704 
00705 EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
00706 {
00707 #ifdef __CLIENTDEBUG__
00708     JackGlobals::CheckContext("jack_port_request_monitor");
00709 #endif
00710     uintptr_t port_aux = (uintptr_t)port;
00711     jack_port_id_t myport = (jack_port_id_t)port_aux;
00712     if (!CheckPort(myport)) {
00713         jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
00714         return -1;
00715     } else {
00716         JackGraphManager* manager = GetGraphManager();
00717         return (manager ? manager->RequestMonitor(myport, onoff) : -1);
00718     }
00719 }
00720 
00721 EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
00722 {
00723 #ifdef __CLIENTDEBUG__
00724     JackGlobals::CheckContext("jack_port_request_monitor_by_name");
00725 #endif
00726     JackClient* client = (JackClient*)ext_client;
00727     if (client == NULL) {
00728         jack_error("jack_port_request_monitor_by_name called with a NULL client");
00729         return -1;
00730     } else {
00731         JackGraphManager* manager = GetGraphManager();
00732         if (!manager)
00733             return -1;
00734         jack_port_id_t myport = manager->GetPort(port_name);
00735         if (!CheckPort(myport)) {
00736             jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
00737             return -1;
00738         } else {
00739             return manager->RequestMonitor(myport, onoff);
00740         }
00741     }
00742 }
00743 
00744 EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
00745 {
00746 #ifdef __CLIENTDEBUG__
00747     JackGlobals::CheckContext("jack_port_ensure_monitor");
00748 #endif
00749     uintptr_t port_aux = (uintptr_t)port;
00750     jack_port_id_t myport = (jack_port_id_t)port_aux;
00751     if (!CheckPort(myport)) {
00752         jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
00753         return -1;
00754     } else {
00755         JackGraphManager* manager = GetGraphManager();
00756         return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
00757     }
00758 }
00759 
00760 EXPORT int jack_port_monitoring_input(jack_port_t* port)
00761 {
00762 #ifdef __CLIENTDEBUG__
00763     JackGlobals::CheckContext("jack_port_monitoring_input");
00764 #endif
00765     uintptr_t port_aux = (uintptr_t)port;
00766     jack_port_id_t myport = (jack_port_id_t)port_aux;
00767     if (!CheckPort(myport)) {
00768         jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
00769         return -1;
00770     } else {
00771         JackGraphManager* manager = GetGraphManager();
00772         return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
00773     }
00774 }
00775 
00776 EXPORT int jack_is_realtime(jack_client_t* ext_client)
00777 {
00778 #ifdef __CLIENTDEBUG__
00779     JackGlobals::CheckContext("jack_is_realtime");
00780 #endif
00781     JackClient* client = (JackClient*)ext_client;
00782     if (client == NULL) {
00783         jack_error("jack_is_realtime called with a NULL client");
00784         return -1;
00785     } else {
00786         JackEngineControl* control = GetEngineControl();
00787         return (control ? control->fRealTime : -1);
00788     }
00789 }
00790 
00791 EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
00792 {
00793 #ifdef __CLIENTDEBUG__
00794     JackGlobals::CheckContext("jack_on_shutdown");
00795 #endif
00796     JackClient* client = (JackClient*)ext_client;
00797     if (client == NULL) {
00798         jack_error("jack_on_shutdown called with a NULL client");
00799     } else {
00800         client->OnShutdown(callback, arg);
00801     }
00802 }
00803 
00804 EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
00805 {
00806 #ifdef __CLIENTDEBUG__
00807     JackGlobals::CheckContext("jack_on_info_shutdown");
00808 #endif
00809     JackClient* client = (JackClient*)ext_client;
00810     if (client == NULL) {
00811         jack_error("jack_on_info_shutdown called with a NULL client");
00812     } else {
00813         client->OnInfoShutdown(callback, arg);
00814     }
00815 }
00816 
00817 EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
00818 {
00819 #ifdef __CLIENTDEBUG__
00820     JackGlobals::CheckContext("jack_set_process_callback");
00821 #endif
00822     JackClient* client = (JackClient*)ext_client;
00823     if (client == NULL) {
00824         jack_error("jack_set_process_callback called with a NULL client");
00825         return -1;
00826     } else {
00827         return client->SetProcessCallback(callback, arg);
00828     }
00829 }
00830 
00831 EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
00832 {
00833 #ifdef __CLIENTDEBUG__
00834     JackGlobals::CheckContext("jack_thread_wait");
00835 #endif
00836     JackClient* client = (JackClient*)ext_client;
00837     if (client == NULL) {
00838         jack_error("jack_thread_wait called with a NULL client");
00839         return 0;
00840     } else {
00841         jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
00842         return 0;
00843     }
00844 }
00845 
00846 EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
00847 {
00848 #ifdef __CLIENTDEBUG__
00849     JackGlobals::CheckContext("jack_cycle_wait");
00850 #endif
00851     JackClient* client = (JackClient*)ext_client;
00852     if (client == NULL) {
00853         jack_error("jack_cycle_wait called with a NULL client");
00854         return 0;
00855     } else {
00856         return client->CycleWait();
00857     }
00858 }
00859 
00860 EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
00861 {
00862 #ifdef __CLIENTDEBUG__
00863     JackGlobals::CheckContext("jack_cycle_signal");
00864 #endif
00865     JackClient* client = (JackClient*)ext_client;
00866     if (client == NULL) {
00867         jack_error("jack_cycle_signal called with a NULL client");
00868     } else {
00869         client->CycleSignal(status);
00870     }
00871 }
00872 
00873 EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
00874 {
00875 #ifdef __CLIENTDEBUG__
00876     JackGlobals::CheckContext("jack_set_process_thread");
00877 #endif
00878     JackClient* client = (JackClient*)ext_client;
00879     if (client == NULL) {
00880         jack_error("jack_set_process_thread called with a NULL client");
00881         return -1;
00882     } else {
00883         return client->SetProcessThread(fun, arg);
00884     }
00885 }
00886 
00887 EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
00888 {
00889 #ifdef __CLIENTDEBUG__
00890     JackGlobals::CheckContext("jack_set_freewheel_callback");
00891 #endif
00892     JackClient* client = (JackClient*)ext_client;
00893     if (client == NULL) {
00894         jack_error("jack_set_freewheel_callback called with a NULL client");
00895         return -1;
00896     } else {
00897         return client->SetFreewheelCallback(freewheel_callback, arg);
00898     }
00899 }
00900 
00901 EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
00902 {
00903 #ifdef __CLIENTDEBUG__
00904     JackGlobals::CheckContext("jack_set_freewheel");
00905 #endif
00906     JackClient* client = (JackClient*)ext_client;
00907     if (client == NULL) {
00908         jack_error("jack_set_freewheel called with a NULL client");
00909         return -1;
00910     } else {
00911         return client->SetFreeWheel(onoff);
00912     }
00913 }
00914 
00915 EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
00916 {
00917 #ifdef __CLIENTDEBUG__
00918     JackGlobals::CheckContext("jack_set_buffer_size");
00919 #endif
00920     JackClient* client = (JackClient*)ext_client;
00921     if (client == NULL) {
00922         jack_error("jack_set_buffer_size called with a NULL client");
00923         return -1;
00924     } else if (!CheckBufferSize(buffer_size)) {
00925         return -1;
00926     } else {
00927         return client->SetBufferSize(buffer_size);
00928     }
00929 }
00930 
00931 EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
00932 {
00933 #ifdef __CLIENTDEBUG__
00934     JackGlobals::CheckContext("jack_set_buffer_size_callback");
00935 #endif
00936     JackClient* client = (JackClient*)ext_client;
00937     if (client == NULL) {
00938         jack_error("jack_set_buffer_size_callback called with a NULL client");
00939         return -1;
00940     } else {
00941         return client->SetBufferSizeCallback(bufsize_callback, arg);
00942     }
00943 }
00944 
00945 EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
00946 {
00947 #ifdef __CLIENTDEBUG__
00948     JackGlobals::CheckContext("jack_set_sample_rate_callback");
00949 #endif
00950     JackClient* client = (JackClient*)ext_client;
00951     if (client == NULL) {
00952         jack_error("jack_set_sample_rate_callback called with a NULL client");
00953         return -1;
00954     } else {
00955         return client->SetSampleRateCallback(srate_callback, arg);
00956     }
00957 }
00958 
00959 EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
00960 {
00961 #ifdef __CLIENTDEBUG__
00962     JackGlobals::CheckContext("jack_set_client_registration_callback");
00963 #endif
00964     JackClient* client = (JackClient*)ext_client;
00965     if (client == NULL) {
00966         jack_error("jack_set_client_registration_callback called with a NULL client");
00967         return -1;
00968     } else {
00969         return client->SetClientRegistrationCallback(registration_callback, arg);
00970     }
00971 }
00972 
00973 EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
00974 {
00975 #ifdef __CLIENTDEBUG__
00976     JackGlobals::CheckContext("jack_set_port_registration_callback");
00977 #endif
00978     JackClient* client = (JackClient*)ext_client;
00979     if (client == NULL) {
00980         jack_error("jack_set_port_registration_callback called with a NULL client");
00981         return -1;
00982     } else {
00983         return client->SetPortRegistrationCallback(registration_callback, arg);
00984     }
00985 }
00986 
00987 EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
00988 {
00989 #ifdef __CLIENTDEBUG__
00990     JackGlobals::CheckContext("jack_set_port_connect_callback");
00991 #endif
00992     JackClient* client = (JackClient*)ext_client;
00993     if (client == NULL) {
00994         jack_error("jack_set_port_connect_callback called with a NULL client");
00995         return -1;
00996     } else {
00997         return client->SetPortConnectCallback(portconnect_callback, arg);
00998     }
00999 }
01000 
01001 EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
01002 {
01003 #ifdef __CLIENTDEBUG__
01004     JackGlobals::CheckContext("jack_set_port_rename_callback");
01005 #endif
01006     JackClient* client = (JackClient*)ext_client;
01007     if (client == NULL) {
01008         jack_error("jack_set_port_rename_callback called with a NULL client");
01009         return -1;
01010     } else {
01011         return client->SetPortRenameCallback(rename_callback, arg);
01012     }
01013 }
01014 
01015 EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
01016 {
01017 #ifdef __CLIENTDEBUG__
01018     JackGlobals::CheckContext("jack_set_graph_order_callback");
01019 #endif
01020     JackClient* client = (JackClient*)ext_client;
01021     jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
01022     if (client == NULL) {
01023         jack_error("jack_set_graph_order_callback called with a NULL client");
01024         return -1;
01025     } else {
01026         return client->SetGraphOrderCallback(graph_callback, arg);
01027     }
01028 }
01029 
01030 EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
01031 {
01032 #ifdef __CLIENTDEBUG__
01033     JackGlobals::CheckContext("jack_set_xrun_callback");
01034 #endif
01035     JackClient* client = (JackClient*)ext_client;
01036     if (client == NULL) {
01037         jack_error("jack_set_xrun_callback called with a NULL client");
01038         return -1;
01039     } else {
01040         return client->SetXRunCallback(xrun_callback, arg);
01041     }
01042 }
01043 
01044 EXPORT int jack_set_latency_callback(jack_client_t* ext_client, JackLatencyCallback latency_callback, void *arg)
01045 {
01046 #ifdef __CLIENTDEBUG__
01047     JackGlobals::CheckContext("jack_set_latency_callback");
01048 #endif
01049     JackClient* client = (JackClient*)ext_client;
01050     if (client == NULL) {
01051         jack_error("jack_set_latency_callback called with a NULL client");
01052         return -1;
01053     } else {
01054         return client->SetLatencyCallback(latency_callback, arg);
01055     }
01056 }
01057 
01058 EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
01059 {
01060 #ifdef __CLIENTDEBUG__
01061     JackGlobals::CheckContext("jack_set_thread_init_callback");
01062 #endif
01063     JackClient* client = (JackClient*)ext_client;
01064     jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
01065     if (client == NULL) {
01066         jack_error("jack_set_thread_init_callback called with a NULL client");
01067         return -1;
01068     } else {
01069         return client->SetInitCallback(init_callback, arg);
01070     }
01071 }
01072 
01073 EXPORT int jack_activate(jack_client_t* ext_client)
01074 {
01075 #ifdef __CLIENTDEBUG__
01076     JackGlobals::CheckContext("jack_activate");
01077 #endif
01078     JackClient* client = (JackClient*)ext_client;
01079     if (client == NULL) {
01080         jack_error("jack_activate called with a NULL client");
01081         return -1;
01082     } else {
01083         return client->Activate();
01084     }
01085 }
01086 
01087 EXPORT int jack_deactivate(jack_client_t* ext_client)
01088 {
01089 #ifdef __CLIENTDEBUG__
01090     JackGlobals::CheckContext("jack_deactivate");
01091 #endif
01092     JackClient* client = (JackClient*)ext_client;
01093     if (client == NULL) {
01094         jack_error("jack_deactivate called with a NULL client");
01095         return -1;
01096     } else {
01097         return client->Deactivate();
01098     }
01099 }
01100 
01101 EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
01102 {
01103 #ifdef __CLIENTDEBUG__
01104     JackGlobals::CheckContext("jack_port_register");
01105 #endif
01106     JackClient* client = (JackClient*)ext_client;
01107     if (client == NULL) {
01108         jack_error("jack_port_register called with a NULL client");
01109         return NULL;
01110     } else if ((port_name == NULL) || (port_type == NULL)) {
01111         jack_error("jack_port_register called with a NULL port name or a NULL port_type");
01112         return NULL;
01113     } else {
01114         return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
01115     }
01116 }
01117 
01118 EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
01119 {
01120 #ifdef __CLIENTDEBUG__
01121     JackGlobals::CheckContext("jack_port_unregister");
01122 #endif
01123     JackClient* client = (JackClient*)ext_client;
01124     if (client == NULL) {
01125         jack_error("jack_port_unregister called with a NULL client");
01126         return -1;
01127     }
01128     uintptr_t port_aux = (uintptr_t)port;
01129     jack_port_id_t myport = (jack_port_id_t)port_aux;
01130     if (!CheckPort(myport)) {
01131         jack_error("jack_port_unregister called with an incorrect port %ld", myport);
01132         return -1;
01133     }
01134     return client->PortUnRegister(myport);
01135 }
01136 
01137 EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
01138 {
01139 #ifdef __CLIENTDEBUG__
01140     JackGlobals::CheckContext("jack_port_is_mine");
01141 #endif
01142     JackClient* client = (JackClient*)ext_client;
01143     if (client == NULL) {
01144         jack_error("jack_port_is_mine called with a NULL client");
01145         return -1;
01146     }
01147     uintptr_t port_aux = (uintptr_t)port;
01148     jack_port_id_t myport = (jack_port_id_t)port_aux;
01149     if (!CheckPort(myport)) {
01150         jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
01151         return -1;
01152     }
01153     return client->PortIsMine(myport);
01154 }
01155 
01156 EXPORT const char** jack_port_get_connections(const jack_port_t* port)
01157 {
01158 #ifdef __CLIENTDEBUG__
01159     JackGlobals::CheckContext("jack_port_get_connections");
01160 #endif
01161     uintptr_t port_aux = (uintptr_t)port;
01162     jack_port_id_t myport = (jack_port_id_t)port_aux;
01163     if (!CheckPort(myport)) {
01164         jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
01165         return NULL;
01166     } else {
01167         WaitGraphChange();
01168         JackGraphManager* manager = GetGraphManager();
01169         return (manager ? manager->GetConnections(myport) : NULL);
01170     }
01171 }
01172 
01173 // Calling client does not need to "own" the port
01174 EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
01175 {
01176 #ifdef __CLIENTDEBUG__
01177     JackGlobals::CheckContext("jack_port_get_all_connections");
01178 #endif
01179     JackClient* client = (JackClient*)ext_client;
01180     if (client == NULL) {
01181         jack_error("jack_port_get_all_connections called with a NULL client");
01182         return NULL;
01183     }
01184 
01185     uintptr_t port_aux = (uintptr_t)port;
01186     jack_port_id_t myport = (jack_port_id_t)port_aux;
01187     if (!CheckPort(myport)) {
01188         jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
01189         return NULL;
01190     } else {
01191         WaitGraphChange();
01192         JackGraphManager* manager = GetGraphManager();
01193         return (manager ? manager->GetConnections(myport) : NULL);
01194     }
01195 }
01196 
01197 EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
01198 {
01199 #ifdef __CLIENTDEBUG__
01200     JackGlobals::CheckContext("jack_port_get_total_latency");
01201 #endif
01202     JackClient* client = (JackClient*)ext_client;
01203     if (client == NULL) {
01204         jack_error("jack_port_get_total_latency called with a NULL client");
01205         return 0;
01206     }
01207 
01208     uintptr_t port_aux = (uintptr_t)port;
01209     jack_port_id_t myport = (jack_port_id_t)port_aux;
01210     if (!CheckPort(myport)) {
01211         jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
01212         return 0;
01213     } else {
01214         WaitGraphChange();
01215         JackGraphManager* manager = GetGraphManager();
01216         if (manager) {
01217             manager->ComputeTotalLatency(myport);
01218             return manager->GetPort(myport)->GetTotalLatency();
01219         } else {
01220             return 0;
01221         }
01222     }
01223 }
01224 
01225 EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
01226 {
01227 #ifdef __CLIENTDEBUG__
01228     JackGlobals::CheckContext("jack_connect");
01229 #endif
01230     JackClient* client = (JackClient*)ext_client;
01231     if (client == NULL) {
01232         jack_error("jack_connect called with a NULL client");
01233         return -1;
01234     } else if ((src == NULL) || (dst == NULL)) {
01235         jack_error("jack_connect called with a NULL port name");
01236         return -1;
01237     } else {
01238         return client->PortConnect(src, dst);
01239     }
01240 }
01241 
01242 EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
01243 {
01244 #ifdef __CLIENTDEBUG__
01245     JackGlobals::CheckContext("jack_disconnect");
01246 #endif
01247     JackClient* client = (JackClient*)ext_client;
01248     if (client == NULL) {
01249         jack_error("jack_disconnect called with a NULL client");
01250         return -1;
01251     } else if ((src == NULL) || (dst == NULL)) {
01252         jack_error("jack_connect called with a NULL port name");
01253         return -1;
01254     } else {
01255         return client->PortDisconnect(src, dst);
01256     }
01257 }
01258 
01259 EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
01260 {
01261 #ifdef __CLIENTDEBUG__
01262     JackGlobals::CheckContext("jack_port_disconnect");
01263 #endif
01264     JackClient* client = (JackClient*)ext_client;
01265     if (client == NULL) {
01266         jack_error("jack_port_disconnect called with a NULL client");
01267         return -1;
01268     }
01269     uintptr_t port_aux = (uintptr_t)src;
01270     jack_port_id_t myport = (jack_port_id_t)port_aux;
01271     if (!CheckPort(myport)) {
01272         jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
01273         return -1;
01274     }
01275     return client->PortDisconnect(myport);
01276 }
01277 
01278 EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
01279 {
01280 #ifdef __CLIENTDEBUG__
01281     JackGlobals::CheckContext("jack_get_sample_rate");
01282 #endif
01283     JackClient* client = (JackClient*)ext_client;
01284     if (client == NULL) {
01285         jack_error("jack_get_sample_rate called with a NULL client");
01286         return 0;
01287     } else {
01288         JackEngineControl* control = GetEngineControl();
01289         return (control ? control->fSampleRate : 0);
01290     }
01291 }
01292 
01293 EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
01294 {
01295 #ifdef __CLIENTDEBUG__
01296     JackGlobals::CheckContext("jack_get_buffer_size");
01297 #endif
01298     JackClient* client = (JackClient*)ext_client;
01299     if (client == NULL) {
01300         jack_error("jack_get_buffer_size called with a NULL client");
01301         return 0;
01302     } else {
01303         JackEngineControl* control = GetEngineControl();
01304         return (control ? control->fBufferSize : 0);
01305     }
01306 }
01307 
01308 EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
01309 {
01310 #ifdef __CLIENTDEBUG__
01311     JackGlobals::CheckContext("jack_get_ports");
01312 #endif
01313     JackClient* client = (JackClient*)ext_client;
01314     if (client == NULL) {
01315         jack_error("jack_get_ports called with a NULL client");
01316         return NULL;
01317     }
01318     JackGraphManager* manager = GetGraphManager();
01319     return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
01320 }
01321 
01322 EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
01323 {
01324 #ifdef __CLIENTDEBUG__
01325     JackGlobals::CheckContext("jack_port_by_name");
01326 #endif
01327     JackClient* client = (JackClient*)ext_client;
01328     if (client == NULL) {
01329         jack_error("jack_get_ports called with a NULL client");
01330         return 0;
01331     }
01332 
01333     if (portname == NULL) {
01334         jack_error("jack_port_by_name called with a NULL port name");
01335         return NULL;
01336     } else {
01337         JackGraphManager* manager = GetGraphManager();
01338         if (!manager)
01339             return NULL;
01340         int res = manager->GetPort(portname); // returns a port index at least > 1
01341         return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
01342     }
01343 }
01344 
01345 EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
01346 {
01347 #ifdef __CLIENTDEBUG__
01348     JackGlobals::CheckContext("jack_port_by_id");
01349 #endif
01350     /* jack_port_t* type is actually the port index */
01351     return (jack_port_t*)((uintptr_t)id);
01352 }
01353 
01354 EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
01355 {
01356 #ifdef __CLIENTDEBUG__
01357     JackGlobals::CheckContext("jack_engine_takeover_timebase");
01358 #endif
01359     JackClient* client = (JackClient*)ext_client;
01360     if (client == NULL) {
01361         jack_error("jack_engine_takeover_timebase called with a NULL client");
01362         return -1;
01363     } else {
01364         jack_error("jack_engine_takeover_timebase: deprecated\n");
01365         return 0;
01366     }
01367 }
01368 
01369 EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
01370 {
01371 #ifdef __CLIENTDEBUG__
01372     JackGlobals::CheckContext("jack_frames_since_cycle_start");
01373 #endif
01374     JackTimer timer;
01375     JackEngineControl* control = GetEngineControl();
01376     if (control) {
01377         control->ReadFrameTime(&timer);
01378         return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
01379     } else {
01380         return 0;
01381     }
01382 }
01383 
01384 EXPORT jack_time_t jack_get_time()
01385 {
01386 #ifdef __CLIENTDEBUG__
01387     JackGlobals::CheckContext("jack_get_time");
01388 #endif
01389     return GetMicroSeconds();
01390 }
01391 
01392 EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
01393 {
01394 #ifdef __CLIENTDEBUG__
01395     JackGlobals::CheckContext("jack_frames_to_time");
01396 #endif
01397     JackClient* client = (JackClient*)ext_client;
01398     if (client == NULL) {
01399         jack_error("jack_frames_to_time called with a NULL client");
01400         return 0;
01401     } else {
01402         JackTimer timer;
01403         JackEngineControl* control = GetEngineControl();
01404         if (control) {
01405             control->ReadFrameTime(&timer);
01406             return timer.Frames2Time(frames, control->fBufferSize);
01407         } else {
01408             return 0;
01409         }
01410     }
01411 }
01412 
01413 EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
01414 {
01415 #ifdef __CLIENTDEBUG__
01416     JackGlobals::CheckContext("jack_time_to_frames");
01417 #endif
01418     JackClient* client = (JackClient*)ext_client;
01419     if (client == NULL) {
01420         jack_error("jack_time_to_frames called with a NULL client");
01421         return 0;
01422     } else {
01423         JackTimer timer;
01424         JackEngineControl* control = GetEngineControl();
01425         if (control) {
01426             control->ReadFrameTime(&timer);
01427             return timer.Time2Frames(time, control->fBufferSize);
01428         } else {
01429             return 0;
01430         }
01431     }
01432 }
01433 
01434 EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
01435 {
01436 #ifdef __CLIENTDEBUG__
01437     JackGlobals::CheckContext("jack_frame_time");
01438 #endif
01439     return jack_time_to_frames(ext_client, GetMicroSeconds());
01440 }
01441 
01442 EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
01443 {
01444 #ifdef __CLIENTDEBUG__
01445     JackGlobals::CheckContext("jack_last_frame_time");
01446 #endif
01447     JackEngineControl* control = GetEngineControl();
01448     return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
01449 }
01450 
01451 EXPORT float jack_cpu_load(jack_client_t* ext_client)
01452 {
01453 #ifdef __CLIENTDEBUG__
01454     JackGlobals::CheckContext("jack_cpu_load");
01455 #endif
01456     JackClient* client = (JackClient*)ext_client;
01457     if (client == NULL) {
01458         jack_error("jack_cpu_load called with a NULL client");
01459         return 0.0f;
01460     } else {
01461         JackEngineControl* control = GetEngineControl();
01462         return (control ? control->fCPULoad :  0.0f);
01463     }
01464 }
01465 
01466 EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
01467 {
01468 #ifdef __CLIENTDEBUG__
01469     JackGlobals::CheckContext("jack_client_thread_id");
01470 #endif
01471     JackClient* client = (JackClient*)ext_client;
01472     if (client == NULL) {
01473         jack_error("jack_client_thread_id called with a NULL client");
01474         return (jack_native_thread_t)NULL;
01475     } else {
01476         return client->GetThreadID();
01477     }
01478 }
01479 
01480 EXPORT char* jack_get_client_name(jack_client_t* ext_client)
01481 {
01482 #ifdef __CLIENTDEBUG__
01483     JackGlobals::CheckContext("jack_get_client_name");
01484 #endif
01485     JackClient* client = (JackClient*)ext_client;
01486     if (client == NULL) {
01487         jack_error("jack_get_client_name called with a NULL client");
01488         return NULL;
01489     } else {
01490         return client->GetClientControl()->fName;
01491     }
01492 }
01493 
01494 EXPORT int jack_client_name_size(void)
01495 {
01496     return JACK_CLIENT_NAME_SIZE;
01497 }
01498 
01499 EXPORT int jack_port_name_size(void)
01500 {
01501     return JACK_PORT_NAME_SIZE;
01502 }
01503 
01504 EXPORT int jack_port_type_size(void)
01505 {
01506     return JACK_PORT_TYPE_SIZE;
01507 }
01508 
01509 EXPORT size_t jack_port_type_get_buffer_size(jack_client_t* ext_client, const char* port_type)
01510 {
01511 #ifdef __CLIENTDEBUG__
01512     JackGlobals::CheckContext("jack_port_type_get_buffer_size");
01513 #endif
01514     JackClient* client = (JackClient*)ext_client;
01515     if (client == NULL) {
01516         jack_error("jack_port_type_get_buffer_size called with a NULL client");
01517         return 0;
01518     } else {
01519         jack_port_type_id_t port_id = GetPortTypeId(port_type);
01520         if (port_id == PORT_TYPES_MAX) {
01521             jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type);
01522             return 0;
01523         } else {
01524             return GetPortType(port_id)->size();
01525         }
01526     }
01527 }
01528 
01529 // transport.h
01530 EXPORT int jack_release_timebase(jack_client_t* ext_client)
01531 {
01532 #ifdef __CLIENTDEBUG__
01533     JackGlobals::CheckContext("jack_release_timebase");
01534 #endif
01535     JackClient* client = (JackClient*)ext_client;
01536     if (client == NULL) {
01537         jack_error("jack_release_timebase called with a NULL client");
01538         return -1;
01539     } else {
01540         return client->ReleaseTimebase();
01541     }
01542 }
01543 
01544 EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
01545 {
01546 #ifdef __CLIENTDEBUG__
01547     JackGlobals::CheckContext("jack_set_sync_callback");
01548 #endif
01549     JackClient* client = (JackClient*)ext_client;
01550     if (client == NULL) {
01551         jack_error("jack_set_sync_callback called with a NULL client");
01552         return -1;
01553     } else {
01554         return client->SetSyncCallback(sync_callback, arg);
01555     }
01556 }
01557 
01558 EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
01559 {
01560 #ifdef __CLIENTDEBUG__
01561     JackGlobals::CheckContext("jack_set_sync_timeout");
01562 #endif
01563     JackClient* client = (JackClient*)ext_client;
01564     if (client == NULL) {
01565         jack_error("jack_set_sync_timeout called with a NULL client");
01566         return -1;
01567     } else {
01568         return client->SetSyncTimeout(timeout);
01569     }
01570 }
01571 
01572 EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
01573 {
01574 #ifdef __CLIENTDEBUG__
01575     JackGlobals::CheckContext("jack_set_timebase_callback");
01576 #endif
01577     JackClient* client = (JackClient*)ext_client;
01578     if (client == NULL) {
01579         jack_error("jack_set_timebase_callback called with a NULL client");
01580         return -1;
01581     } else {
01582         return client->SetTimebaseCallback(conditional, timebase_callback, arg);
01583     }
01584 }
01585 
01586 EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
01587 {
01588 #ifdef __CLIENTDEBUG__
01589     JackGlobals::CheckContext("jack_transport_locate");
01590 #endif
01591     JackClient* client = (JackClient*)ext_client;
01592     if (client == NULL) {
01593         jack_error("jack_transport_locate called with a NULL client");
01594         return -1;
01595     } else {
01596         client->TransportLocate(frame);
01597         return 0;
01598     }
01599 }
01600 
01601 EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
01602 {
01603 #ifdef __CLIENTDEBUG__
01604     JackGlobals::CheckContext("jack_transport_query");
01605 #endif
01606     JackClient* client = (JackClient*)ext_client;
01607     if (client == NULL) {
01608         jack_error("jack_transport_query called with a NULL client");
01609         return JackTransportStopped;
01610     } else {
01611         return client->TransportQuery(pos);
01612     }
01613 }
01614 
01615 EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
01616 {
01617 #ifdef __CLIENTDEBUG__
01618     JackGlobals::CheckContext("jack_get_current_transport_frame");
01619 #endif
01620     JackClient* client = (JackClient*)ext_client;
01621     if (client == NULL) {
01622         jack_error("jack_get_current_transport_frame called with a NULL client");
01623         return 0;
01624     } else {
01625         return client->GetCurrentTransportFrame();
01626     }
01627 }
01628 
01629 EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
01630 {
01631 #ifdef __CLIENTDEBUG__
01632     JackGlobals::CheckContext("jack_transport_reposition");
01633 #endif
01634     JackClient* client = (JackClient*)ext_client;
01635     if (client == NULL) {
01636         jack_error("jack_transport_reposition called with a NULL client");
01637         return -1;
01638     } else {
01639         client->TransportReposition(pos);
01640         return 0;
01641     }
01642 }
01643 
01644 EXPORT void jack_transport_start(jack_client_t* ext_client)
01645 {
01646 #ifdef __CLIENTDEBUG__
01647     JackGlobals::CheckContext("jack_transport_start");
01648 #endif
01649     JackClient* client = (JackClient*)ext_client;
01650     if (client == NULL) {
01651         jack_error("jack_transport_start called with a NULL client");
01652     } else {
01653         client->TransportStart();
01654     }
01655 }
01656 
01657 EXPORT void jack_transport_stop(jack_client_t* ext_client)
01658 {
01659 #ifdef __CLIENTDEBUG__
01660     JackGlobals::CheckContext("jack_transport_stop");
01661 #endif
01662     JackClient* client = (JackClient*)ext_client;
01663     if (client == NULL) {
01664         jack_error("jack_transport_stop called with a NULL client");
01665     } else {
01666         client->TransportStop();
01667     }
01668 }
01669 
01670 // deprecated
01671 EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
01672 {
01673 #ifdef __CLIENTDEBUG__
01674     JackGlobals::CheckContext("jack_get_transport_info");
01675 #endif
01676     jack_error("jack_get_transport_info: deprecated");
01677     if (tinfo)
01678         memset(tinfo, 0, sizeof(jack_transport_info_t));
01679 }
01680 
01681 EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
01682 {
01683 #ifdef __CLIENTDEBUG__
01684     JackGlobals::CheckContext("jack_set_transport_info");
01685 #endif
01686     jack_error("jack_set_transport_info: deprecated");
01687     if (tinfo)
01688         memset(tinfo, 0, sizeof(jack_transport_info_t));
01689 }
01690 
01691 // statistics.h
01692 EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
01693 {
01694 #ifdef __CLIENTDEBUG__
01695     JackGlobals::CheckContext("jack_get_max_delayed_usecs");
01696 #endif
01697     JackClient* client = (JackClient*)ext_client;
01698     if (client == NULL) {
01699         jack_error("jack_get_max_delayed_usecs called with a NULL client");
01700         return 0.f;
01701     } else {
01702         JackEngineControl* control = GetEngineControl();
01703         return (control ? control->fMaxDelayedUsecs : 0.f);
01704     }
01705  }
01706 
01707 EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
01708 {
01709 #ifdef __CLIENTDEBUG__
01710     JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
01711 #endif
01712     JackClient* client = (JackClient*)ext_client;
01713     if (client == NULL) {
01714         jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
01715         return 0.f;
01716     } else {
01717         JackEngineControl* control = GetEngineControl();
01718         return (control ? control->fXrunDelayedUsecs : 0.f);
01719     }
01720 }
01721 
01722 EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
01723 {
01724 #ifdef __CLIENTDEBUG__
01725     JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
01726 #endif
01727     JackClient* client = (JackClient*)ext_client;
01728     if (client == NULL) {
01729         jack_error("jack_reset_max_delayed_usecs called with a NULL client");
01730     } else {
01731         JackEngineControl* control = GetEngineControl();
01732         control->ResetXRun();
01733     }
01734 }
01735 
01736 // thread.h
01737 EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
01738 {
01739 #ifdef __CLIENTDEBUG__
01740     JackGlobals::CheckContext("jack_client_real_time_priority");
01741 #endif
01742     JackClient* client = (JackClient*)ext_client;
01743     if (client == NULL) {
01744         jack_error("jack_client_real_time_priority called with a NULL client");
01745         return -1;
01746     } else {
01747         JackEngineControl* control = GetEngineControl();
01748         return (control->fRealTime) ? control->fClientPriority : -1;
01749     }
01750 }
01751 
01752 EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
01753 {
01754 #ifdef __CLIENTDEBUG__
01755     JackGlobals::CheckContext("jack_client_max_real_time_priority");
01756 #endif
01757     JackClient* client = (JackClient*)ext_client;
01758     if (client == NULL) {
01759         jack_error("jack_client_max_real_time_priority called with a NULL client");
01760         return -1;
01761     } else {
01762         JackEngineControl* control = GetEngineControl();
01763        return (control->fRealTime) ? control->fMaxClientPriority : -1;
01764     }
01765 }
01766 
01767 EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
01768 {
01769     JackEngineControl* control = GetEngineControl();
01770     return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
01771 }
01772 
01773 EXPORT int jack_client_create_thread(jack_client_t* client,
01774                                      jack_native_thread_t *thread,
01775                                      int priority,
01776                                      int realtime,      /* boolean */
01777                                      thread_routine routine,
01778                                      void *arg)
01779 {
01780 #ifdef __CLIENTDEBUG__
01781     JackGlobals::CheckContext("jack_client_create_thread");
01782 #endif
01783     return JackThread::StartImp(thread, priority, realtime, routine, arg);
01784 }
01785 
01786 EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
01787 {
01788     return JackThread::DropRealTimeImp(thread);
01789 }
01790 
01791 EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread)
01792 {
01793 #ifdef __CLIENTDEBUG__
01794     JackGlobals::CheckContext("jack_client_stop_thread");
01795 #endif
01796     return JackThread::StopImp(thread);
01797 }
01798 
01799 EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread)
01800 {
01801 #ifdef __CLIENTDEBUG__
01802     JackGlobals::CheckContext("jack_client_kill_thread");
01803 #endif
01804     return JackThread::KillImp(thread);
01805 }
01806 
01807 #ifndef WIN32
01808 EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
01809 {
01810     JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
01811 }
01812 #endif
01813 
01814 // intclient.h
01815 EXPORT int jack_internal_client_new (const char* client_name,
01816                                      const char* load_name,
01817                                      const char* load_init)
01818 {
01819     jack_error("jack_internal_client_new: deprecated");
01820     return -1;
01821 }
01822 
01823 EXPORT void jack_internal_client_close (const char* client_name)
01824 {
01825     jack_error("jack_internal_client_close: deprecated");
01826 }
01827 
01828 EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
01829 {
01830 #ifdef __CLIENTDEBUG__
01831     JackGlobals::CheckContext("jack_get_internal_client_name");
01832 #endif
01833     JackClient* client = (JackClient*)ext_client;
01834     if (client == NULL) {
01835         jack_error("jack_get_internal_client_name called with a NULL client");
01836         return NULL;
01837     } else if (intclient >= CLIENT_NUM) {
01838         jack_error("jack_get_internal_client_name: incorrect client");
01839         return NULL;
01840     } else {
01841         return client->GetInternalClientName(intclient);
01842     }
01843 }
01844 
01845 EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
01846 {
01847 #ifdef __CLIENTDEBUG__
01848     JackGlobals::CheckContext("jack_internal_client_handle");
01849 #endif
01850     JackClient* client = (JackClient*)ext_client;
01851     if (client == NULL) {
01852         jack_error("jack_internal_client_handle called with a NULL client");
01853         return 0;
01854     } else {
01855         jack_status_t my_status;
01856         if (status == NULL)             /* no status from caller? */
01857             status = &my_status;        /* use local status word */
01858         *status = (jack_status_t)0;
01859         return client->InternalClientHandle(client_name, status);
01860     }
01861 }
01862 
01863 EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
01864 {
01865 #ifdef __CLIENTDEBUG__
01866     JackGlobals::CheckContext("jack_internal_client_load_aux");
01867 #endif
01868     JackClient* client = (JackClient*)ext_client;
01869     if (client == NULL) {
01870         jack_error("jack_internal_client_load called with a NULL client");
01871         return 0;
01872     } else {
01873         jack_varargs_t va;
01874         jack_status_t my_status;
01875 
01876         if (status == NULL)                     /* no status from caller? */
01877             status = &my_status;        /* use local status word */
01878         *status = (jack_status_t)0;
01879 
01880         /* validate parameters */
01881         if ((options & ~JackLoadOptions)) {
01882             int my_status1 = *status | (JackFailure | JackInvalidOption);
01883             *status = (jack_status_t)my_status1;
01884             return 0;
01885         }
01886 
01887         /* parse variable arguments */
01888         jack_varargs_parse(options, ap, &va);
01889         return client->InternalClientLoad(client_name, options, status, &va);
01890     }
01891 }
01892 
01893 EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char* client_name, jack_options_t options, jack_status_t *status, ...)
01894 {
01895     va_list ap;
01896     va_start(ap, status);
01897     jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
01898     va_end(ap);
01899     return res;
01900 }
01901 
01902 EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
01903 {
01904 #ifdef __CLIENTDEBUG__
01905     JackGlobals::CheckContext("jack_internal_client_load");
01906 #endif
01907     JackClient* client = (JackClient*)ext_client;
01908     if (client == NULL) {
01909         jack_error("jack_internal_client_unload called with a NULL client");
01910         return (jack_status_t)(JackNoSuchClient | JackFailure);
01911     } else if (intclient >= CLIENT_NUM) {
01912         jack_error("jack_internal_client_unload: incorrect client");
01913         return (jack_status_t)(JackNoSuchClient | JackFailure);
01914     } else {
01915         jack_status_t my_status;
01916         client->InternalClientUnload(intclient, &my_status);
01917         return my_status;
01918     }
01919 }
01920 
01921 EXPORT
01922 void
01923 jack_get_version(
01924     int *major_ptr,
01925     int *minor_ptr,
01926     int *micro_ptr,
01927     int *proto_ptr)
01928 {
01929     // FIXME: We need these comming from build system
01930     *major_ptr = 0;
01931     *minor_ptr = 0;
01932     *micro_ptr = 0;
01933     *proto_ptr = 0;
01934 }
01935 
01936 EXPORT
01937 const char*
01938 jack_get_version_string()
01939 {
01940     return VERSION;
01941 }
01942 
01943 EXPORT void jack_free(void* ptr)
01944 {
01945     if (ptr) {
01946         free(ptr);
01947     }
01948 }
01949 
01950 // session.h
01951 EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg)
01952 {
01953 #ifdef __CLIENTDEBUG__
01954     JackGlobals::CheckContext("jack_set_session_callback");
01955 #endif
01956     JackClient* client = (JackClient*)ext_client;
01957     jack_log("jack_set_session_callback ext_client %x client %x ", ext_client, client);
01958     if (client == NULL) {
01959         jack_error("jack_set_session_callback called with a NULL client");
01960         return -1;
01961     } else {
01962         return client->SetSessionCallback(session_callback, arg);
01963     }
01964 }
01965 
01966 EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path)
01967 {
01968 #ifdef __CLIENTDEBUG__
01969     JackGlobals::CheckContext("jack_session_notify");
01970 #endif
01971     JackClient* client = (JackClient*)ext_client;
01972     jack_log("jack_session_notify ext_client %x client %x ", ext_client, client);
01973     if (client == NULL) {
01974         jack_error("jack_session_notify called with a NULL client");
01975         return NULL;
01976     } else {
01977         return client->SessionNotify(target, ev_type, path);
01978     }
01979 }
01980 
01981 EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event)
01982 {
01983 #ifdef __CLIENTDEBUG__
01984     JackGlobals::CheckContext("jack_session_reply");
01985 #endif
01986     JackClient* client = (JackClient*)ext_client;
01987     jack_log("jack_session_reply ext_client %x client %x ", ext_client, client);
01988     if (client == NULL) {
01989         jack_error("jack_session_reply called with a NULL client");
01990         return -1;
01991     } else {
01992         return client->SessionReply(event);
01993     }
01994 }
01995 
01996 EXPORT void jack_session_event_free(jack_session_event_t* ev)
01997 {
01998     if (ev) {
01999         if (ev->session_dir)
02000             free((void *)ev->session_dir);
02001         if (ev->client_uuid)
02002             free((void *)ev->client_uuid);
02003         if (ev->command_line)
02004             free(ev->command_line);
02005         free(ev);
02006     }
02007 }
02008 
02009 EXPORT char *jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name)
02010 {
02011 #ifdef __CLIENTDEBUG__
02012     JackGlobals::CheckContext("jack_get_uuid_for_client_name");
02013 #endif
02014     JackClient* client = (JackClient*)ext_client;
02015     jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
02016     if (client == NULL) {
02017         jack_error("jack_get_uuid_for_client_name called with a NULL client");
02018         return NULL;
02019     } else {
02020         return client->GetUUIDForClientName(client_name);
02021     }
02022 }
02023 
02024 EXPORT char *jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid)
02025 {
02026 #ifdef __CLIENTDEBUG__
02027     JackGlobals::CheckContext("jack_get_client_name_by_uuid");
02028 #endif
02029     JackClient* client = (JackClient*)ext_client;
02030     jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
02031     if (client == NULL) {
02032         jack_error("jack_get_client_name_by_uuid called with a NULL client");
02033         return NULL;
02034     } else {
02035         return client->GetClientNameByUUID(client_uuid);
02036     }
02037 }
02038 
02039 EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* client_name, const char* uuid)
02040 {
02041 #ifdef __CLIENTDEBUG__
02042     JackGlobals::CheckContext("jack_reserve_client_name");
02043 #endif
02044     JackClient* client = (JackClient*)ext_client;
02045     jack_log("jack_reserve_client_name ext_client %x client %x ", ext_client, client);
02046     if (client == NULL) {
02047         jack_error("jack_reserve_client_name called with a NULL client");
02048         return -1;
02049     } else {
02050         return client->ReserveClientName(client_name, uuid);
02051     }
02052 }
02053 
02054 EXPORT void jack_session_commands_free(jack_session_command_t *cmds)
02055 {
02056     if (!cmds)
02057         return;
02058 
02059     int i = 0;
02060     while (1) {
02061         if (cmds[i].client_name)
02062             free ((char *)cmds[i].client_name);
02063         if (cmds[i].command)
02064             free ((char *)cmds[i].command);
02065         if (cmds[i].uuid)
02066             free ((char *)cmds[i].uuid);
02067         else
02068             break;
02069 
02070         i += 1;
02071     }
02072 
02073     free(cmds);
02074 }
02075 
02076 EXPORT int jack_client_has_session_callback(jack_client_t* ext_client, const char* client_name)
02077 {
02078 #ifdef __CLIENTDEBUG__
02079     JackGlobals::CheckContext("jack_client_has_session_callback");
02080 #endif
02081     JackClient* client = (JackClient*)ext_client;
02082     jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client, client);
02083     if (client == NULL) {
02084         jack_error("jack_client_has_session_callback called with a NULL client");
02085         return -1;
02086     } else {
02087         return client->ClientHasSessionCallback(client_name);
02088     }
02089 }