jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
5.2KB

  1. /*
  2. Copyright (C) 2010 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #ifndef __weakjack_h__
  16. #define __weakjack_h__
  17. /**
  18. * @defgroup WeakLinkage Managing support for newer/older versions of JACK
  19. * @{ One challenge faced by developers is that of taking
  20. * advantage of new features introduced in new versions
  21. * of [ JACK ] while still supporting older versions of
  22. * the system. Normally, if an application uses a new
  23. * feature in a library/API, it is unable to run on
  24. * earlier versions of the library/API that do not
  25. * support that feature. Such applications would either
  26. * fail to launch or crash when an attempt to use the
  27. * feature was made. This problem cane be solved using
  28. * weakly-linked symbols.
  29. *
  30. * When a symbol in a framework is defined as weakly
  31. * linked, the symbol does not have to be present at
  32. * runtime for a process to continue running. The static
  33. * linker identifies a weakly linked symbol as such in
  34. * any code module that references the symbol. The
  35. * dynamic linker uses this same information at runtime
  36. * to determine whether a process can continue
  37. * running. If a weakly linked symbol is not present in
  38. * the framework, the code module can continue to run as
  39. * long as it does not reference the symbol. However, if
  40. * the symbol is present, the code can use it normally.
  41. *
  42. * (adapted from: http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html)
  43. *
  44. * A concrete example will help. Suppose that someone uses a version
  45. * of a JACK client we'll call "Jill". Jill was linked against a version
  46. * of JACK that contains a newer part of the API (say, jack_set_latency_callback())
  47. * and would like to use it if it is available.
  48. *
  49. * When Jill is run on a system that has a suitably "new" version of
  50. * JACK, this function will be available entirely normally. But if Jill
  51. * is run on a system with an old version of JACK, the function isn't
  52. * available.
  53. *
  54. * With normal symbol linkage, this would create a startup error whenever
  55. * someone tries to run Jill with the "old" version of JACK. However, functions
  56. * added to JACK after version 0.116.2 are all declared to have "weak" linkage
  57. * which means that their abscence doesn't cause an error during program
  58. * startup. Instead, Jill can test whether or not the symbol jack_set_latency_callback
  59. * is null or not. If its null, it means that the JACK installed on this machine
  60. * is too old to support this function. If its not null, then Jill can use it
  61. * just like any other function in the API. For example:
  62. *
  63. * \code
  64. * if (jack_set_latency_callback) {
  65. * jack_set_latency_callback (jill_client, jill_latency_callback, arg);
  66. * }
  67. * \endcode
  68. *
  69. * However, there are clients that may want to use this approach to parts of the
  70. * the JACK API that predate 0.116.2. For example, they might want to see if even
  71. * really old basic parts of the API like jack_client_open() exist at runtime.
  72. *
  73. * Such clients should include <jack/weakjack.h> before any other JACK header.
  74. * This will make the \b entire JACK API be subject to weak linkage, so that any
  75. * and all functions can be checked for existence at runtime. It is important
  76. * to understand that very few clients need to do this - if you use this
  77. * feature you should have a clear reason to do so.
  78. *
  79. *
  80. */
  81. #ifdef __APPLE__
  82. #define WEAK_ATTRIBUTE weak_import
  83. #else
  84. #define WEAK_ATTRIBUTE __weak__
  85. #endif
  86. #ifndef JACK_OPTIONAL_WEAK_EXPORT
  87. /* JACK_OPTIONAL_WEAK_EXPORT needs to be a macro which
  88. expands into a compiler directive. If non-null, the directive
  89. must tell the compiler to arrange for weak linkage of
  90. the symbol it used with. For this to work fully may
  91. require linker arguments for the client as well.
  92. */
  93. #ifdef __GNUC__
  94. #define JACK_OPTIONAL_WEAK_EXPORT __attribute__((WEAK_ATTRIBUTE))
  95. #else
  96. /* Add other things here for non-gcc platforms */
  97. #endif
  98. #endif
  99. #ifndef JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
  100. /* JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT needs to be a macro
  101. which expands into a compiler directive. If non-null, the directive
  102. must tell the compiler to arrange for weak linkage of the
  103. symbol it is used with AND optionally to mark the symbol
  104. as deprecated. For this to work fully may require
  105. linker arguments for the client as well.
  106. */
  107. #ifdef __GNUC__
  108. #define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT __attribute__((WEAK_ATTRIBUTE,__deprecated__))
  109. #else
  110. /* Add other things here for non-gcc platforms */
  111. #endif
  112. #endif
  113. /*@}*/
  114. #endif /* weakjack */