Changeset 3943

Show
Ignore:
Timestamp:
03/05/10 22:54:15 (5 months ago)
Author:
sletz
Message:

Change error return code for functions that return a pointer.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jack2/trunk/jackmp/common/JackWeakAPI.cpp

    r3941 r3943  
    1 /* 
    2 Copyright (C) 2009 Grame 
    3  
    4 This program is free software; you can redistribute it and/or modify 
    5 it under the terms of the GNU Lesser General Public License as published by 
    6 the Free Software Foundation; either version 2.1 of the License, or 
    7 (at your option) any later version. 
    8  
    9 This program is distributed in the hope that it will be useful, 
    10 but WITHOUT ANY WARRANTY; without even the implied warranty of 
    11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    12 GNU Lesser General Public License for more details. 
    13  
    14 You should have received a copy of the GNU Lesser General Public License 
    15 along with this program; if not, write to the Free Software 
    16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
    17  
    18 */ 
    19  
    20 /* 
    21     Completed from Julien Pommier (PianoTeq : http://www.pianoteq.com/) code. 
    22 */ 
     1//============================================================================= 
     2//  MuseScore 
     3//  Linux Music Score Editor 
     4//  $Id: 
     5// 
     6//  jackWeakAPI based on code from Stéphane Letz (Grame) 
     7//  partly based on Julien Pommier (PianoTeq : http://www.pianoteq.com/) code. 
     8// 
     9//  Copyright (C) 2002-2007 Werner Schweer and others 
     10//  Copyright (C) 2009 Grame 
     11 
     12//  This program is free software; you can redistribute it and/or modify 
     13//  it under the terms of the GNU Lesser General Public License as published by 
     14//  the Free Software Foundation; either version 2.1 of the License, or 
     15//  (at your option) any later version. 
     16 
     17//  This program is distributed in the hope that it will be useful, 
     18//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     19//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     20//  GNU Lesser General Public License for more details. 
     21 
     22//  You should have received a copy of the GNU Lesser General Public License 
     23//  along with this program; if not, write to the Free Software 
     24//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
    2325 
    2426#include <jack/jack.h> 
     
    2628#include <jack/midiport.h> 
    2729#include <math.h> 
     30#ifndef WIN32 
     31#include <dlfcn.h> 
     32#endif 
    2833#include <stdlib.h> 
    29 #include <cassert> 
    3034#include <iostream> 
    3135 
     
    4246 
    4347#ifdef WIN32 
    44 #include <windows.h> 
    4548HMODULE libjack_handle = 0; 
    4649#else 
    47 #include <dlfcn.h> 
    4850static void *libjack_handle = 0; 
    4951#endif 
     52 
    5053 
    5154static void __attribute__((constructor)) tryload_libjack() 
     
    6871    void *fn = 0; 
    6972    if (!libjack_handle) {  
    70         std::cerr << "libjack not found, so do not try to load " << fn_name << " ffs !\n"
     73        fprintf (stderr, "libjack not found, so do not try to load  %s ffs  !\n", fn_name)
    7174        return 0; 
    7275    } 
     
    7780#endif 
    7881    if (!fn) {  
    79         std::cerr << "could not dlsym(" << libjack_handle << "), " << dlerror() << "\n";  
     82#ifdef WIN32 
     83        char* lpMsgBuf; 
     84        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf,0,NULL ); 
     85        fprintf (stderr, "could not GetProcAddress( %s ), %s \n", fn_name, lpMsgBuf) ; 
     86#else         
     87        fprintf (stderr, "could not dlsym( %s ), %s \n", fn_name, dlerror()) ;  
     88#endif 
    8089    } 
    8190    return fn; 
     
    91100  } 
    92101 
     102#define DECL_FUNCTION_NULL(return_type, fn_name, arguments_types, arguments) \ 
     103  typedef return_type (*fn_name##_ptr_t)arguments_types;                \ 
     104  return_type fn_name arguments_types {                                 \ 
     105    static fn_name##_ptr_t fn = 0;                                      \ 
     106    if (fn == 0) { fn = (fn_name##_ptr_t)load_jack_function(#fn_name); } \ 
     107    if (fn) return (*fn)arguments;                                      \ 
     108    else return (return_type)0;                                                      \ 
     109  } 
     110   
    93111#define DECL_VOID_FUNCTION(fn_name, arguments_types, arguments)         \ 
    94112  typedef void (*fn_name##_ptr_t)arguments_types;                       \ 
     
    99117  } 
    100118 
     119 
    101120DECL_VOID_FUNCTION(jack_get_version, (int *major_ptr, int *minor_ptr, int *micro_ptr, int *proto_ptr), (major_ptr, minor_ptr, micro_ptr, proto_ptr)); 
    102 DECL_FUNCTION(const char *, jack_get_version_string, (), ());       
    103 DECL_FUNCTION(jack_client_t *, jack_client_open, (const char *client_name, jack_options_t options, jack_status_t *status, ...),  
     121DECL_FUNCTION_NULL(const char *, jack_get_version_string, (), ());       
     122DECL_FUNCTION_NULL(jack_client_t *, jack_client_open, (const char *client_name, jack_options_t options, jack_status_t *status, ...),  
    104123              (client_name, options, status)); 
    105124DECL_FUNCTION(int, jack_client_close, (jack_client_t *client), (client)); 
    106 DECL_FUNCTION(jack_client_t *, jack_client_new, (const char *client_name), (client_name)); 
     125DECL_FUNCTION_NULL(jack_client_t *, jack_client_new, (const char *client_name), (client_name)); 
    107126DECL_FUNCTION(int, jack_client_name_size, (), ()); 
    108 DECL_FUNCTION(char*, jack_get_client_name, (jack_client_t *client), (client)); 
     127DECL_FUNCTION_NULL(char*, jack_get_client_name, (jack_client_t *client), (client)); 
    109128DECL_FUNCTION(int, jack_internal_client_new, (const char *client_name, 
    110129                                            const char *load_name, 
     
    113132DECL_FUNCTION(int, jack_is_realtime, (jack_client_t *client), (client)); 
    114133DECL_VOID_FUNCTION(jack_on_shutdown, (jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg), (client, shutdown_callback, arg)); 
    115 DECL_VOID_FUNCTION(jack_on_info_shutdown, (jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg), (client, shutdown_callback, arg)); 
     134//DECL_VOID_FUNCTION(jack_on_info_shutdown, (jack_client_t* client, JackInfoShutdownCallback shutdown_callback, void* arg), (client, shutdown_callback, arg)); 
    116135DECL_FUNCTION(int, jack_set_process_callback, (jack_client_t *client, 
    117136                                            JackProcessCallback process_callback, 
     
    159178DECL_FUNCTION(int, jack_activate, (jack_client_t *client), (client)); 
    160179DECL_FUNCTION(int, jack_deactivate, (jack_client_t *client), (client)); 
    161 DECL_FUNCTION(jack_port_t *, jack_port_register, (jack_client_t *client, const char *port_name, const char *port_type, 
     180DECL_FUNCTION_NULL(jack_port_t *, jack_port_register, (jack_client_t *client, const char *port_name, const char *port_type, 
    162181                                                  unsigned long flags, unsigned long buffer_size), 
    163182              (client, port_name, port_type, flags, buffer_size)); 
    164183DECL_FUNCTION(int, jack_port_unregister, (jack_client_t *client, jack_port_t* port), (client, port)); 
    165 DECL_FUNCTION(void *, jack_port_get_buffer, (jack_port_t *port, jack_nframes_t nframes), (port, nframes)); 
    166 DECL_FUNCTION(const char*, jack_port_name, (const jack_port_t *port), (port)); 
    167 DECL_FUNCTION(const char*, jack_port_short_name, (const jack_port_t *port), (port)); 
     184DECL_FUNCTION_NULL(void *, jack_port_get_buffer, (jack_port_t *port, jack_nframes_t nframes), (port, nframes)); 
     185DECL_FUNCTION_NULL(const char*, jack_port_name, (const jack_port_t *port), (port)); 
     186DECL_FUNCTION_NULL(const char*, jack_port_short_name, (const jack_port_t *port), (port)); 
    168187DECL_FUNCTION(int, jack_port_flags, (const jack_port_t *port), (port)); 
    169 DECL_FUNCTION(const char*, jack_port_type, (const jack_port_t *port), (port)); 
     188DECL_FUNCTION_NULL(const char*, jack_port_type, (const jack_port_t *port), (port)); 
    170189DECL_FUNCTION(jack_port_type_id_t, jack_port_type_id, (const jack_port_t *port), (port)); 
    171190DECL_FUNCTION(int, jack_port_is_mine, (const jack_client_t *client, const jack_port_t* port), (client, port)); 
    172191DECL_FUNCTION(int, jack_port_connected, (const jack_port_t *port), (port)); 
    173192DECL_FUNCTION(int, jack_port_connected_to, (const jack_port_t *port, const char *port_name), (port, port_name)); 
    174 DECL_FUNCTION(const char**, jack_port_get_connections, (const jack_port_t *port), (port)); 
    175 DECL_FUNCTION(const char**, jack_port_get_all_connections, (const jack_client_t *client,const jack_port_t *port), (client, port)); 
     193DECL_FUNCTION_NULL(const char**, jack_port_get_connections, (const jack_port_t *port), (port)); 
     194DECL_FUNCTION_NULL(const char**, jack_port_get_all_connections, (const jack_client_t *client,const jack_port_t *port), (client, port)); 
    176195DECL_FUNCTION(int, jack_port_tie, (jack_port_t *src, jack_port_t *dst), (src, dst)); 
    177196DECL_FUNCTION(int, jack_port_untie, (jack_port_t *port), (port)); 
     
    198217DECL_FUNCTION(jack_nframes_t, jack_get_sample_rate, (jack_client_t *client), (client)); 
    199218DECL_FUNCTION(jack_nframes_t, jack_get_buffer_size, (jack_client_t *client), (client)); 
    200 DECL_FUNCTION(const char**, jack_get_ports, (jack_client_t *client, const char *port_name_pattern, const char *       type_name_pattern, 
     219DECL_FUNCTION_NULL(const char**, jack_get_ports, (jack_client_t *client, const char *port_name_pattern, const char *  type_name_pattern, 
    201220                                             unsigned long flags), (client, port_name_pattern, type_name_pattern, flags)); 
    202 DECL_FUNCTION(jack_port_t *, jack_port_by_name, (jack_client_t * client, const char *port_name), (client, port_name)); 
    203 DECL_FUNCTION(jack_port_t *, jack_port_by_id, (jack_client_t *client, jack_port_id_t port_id), (client, port_id)); 
     221DECL_FUNCTION_NULL(jack_port_t *, jack_port_by_name, (jack_client_t * client, const char *port_name), (client, port_name)); 
     222DECL_FUNCTION_NULL(jack_port_t *, jack_port_by_id, (jack_client_t *client, jack_port_id_t port_id), (client, port_id)); 
    204223 
    205224DECL_FUNCTION(int, jack_engine_takeover_timebase, (jack_client_t * client), (client)); 
     
    211230DECL_FUNCTION(jack_nframes_t, jack_last_frame_time, (const jack_client_t *client), (client)); 
    212231DECL_FUNCTION(float, jack_cpu_load, (jack_client_t *client), (client)); 
    213 DECL_FUNCTION(pthread_t, jack_client_thread_id, (jack_client_t *client), (client)); 
     232DECL_FUNCTION_NULL(pthread_t, jack_client_thread_id, (jack_client_t *client), (client)); 
    214233DECL_VOID_FUNCTION(jack_set_error_function, (print_function fun), (fun)); 
    215234DECL_VOID_FUNCTION(jack_set_info_function, (print_function fun), (fun)); 
     
    269288DECL_VOID_FUNCTION(jack_midi_clear_buffer, (void* port_buffer), (port_buffer)); 
    270289DECL_FUNCTION(size_t, jack_midi_max_event_size, (void* port_buffer), (port_buffer)); 
    271 DECL_FUNCTION(jack_midi_data_t*, jack_midi_event_reserve, (void* port_buffer, jack_nframes_t time, size_t data_size), (port_buffer, time, data_size)); 
     290DECL_FUNCTION_NULL(jack_midi_data_t*, jack_midi_event_reserve, (void* port_buffer, jack_nframes_t time, size_t data_size), (port_buffer, time, data_size)); 
    272291DECL_FUNCTION(int, jack_midi_event_write, (void* port_buffer, jack_nframes_t time, const jack_midi_data_t* data, size_t data_size), (port_buffer, time, data, data_size)); 
    273292DECL_FUNCTION(jack_nframes_t, jack_midi_get_lost_event_count, (void* port_buffer), (port_buffer));