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