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.

108 lines
5.1KB

  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 advantage of new features introduced in new versions of [ JACK ] while still
  20. * supporting older versions of the system. Normally, if an application uses a new feature in a library/API, it is unable to run on
  21. * earlier versions of the library/API that do not support that feature. Such applications would either fail to launch or crash when
  22. * an attempt to use the feature was made. This problem cane be solved using weakly-linked symbols.
  23. *
  24. * When a symbol in a framework is defined as weakly linked, the symbol does not have to be present at runtime for a process to
  25. * continue running. The static linker identifies a weakly linked symbol as such in any code module that references the symbol. The
  26. * dynamic linker uses this same information at runtime to determine whether a process can continue running. If a weakly linked symbol
  27. * is not present in the framework, the code module can continue to run as long as it does not reference the symbol. However, if the
  28. * symbol is present, the code can use it normally.
  29. *
  30. * (adapted from: http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html)
  31. *
  32. * A concrete example will help. Suppose that someone uses a version
  33. * of a JACK client we'll call "Jill". Jill was linked against a version
  34. * of JACK that contains a newer part of the API (say, jack_set_latency_callback())
  35. * and would like to use it if it is available.
  36. *
  37. * When Jill is run on a system that has a suitably "new" version of
  38. * JACK, this function will be available entirely normally. But if Jill
  39. * is run on a system with an old version of JACK, the function isn't
  40. * available.
  41. *
  42. * With normal symbol linkage, this would create a startup error whenever
  43. * someone tries to run Jill with the "old" version of JACK. However, functions
  44. * added to JACK after version 0.116.2 are all declared to have "weak" linkage
  45. * which means that their abscence doesn't cause an error during program
  46. * startup. Instead, Jill can test whether or not the symbol jack_set_latency_callback
  47. * is null or not. If its null, it means that the JACK installed on this machine
  48. * is too old to support this function. If its not null, then Jill can use it
  49. * just like any other function in the API. For example:
  50. *
  51. * \code
  52. * if (jack_set_latency_callback) {
  53. * jack_set_latency_callback (jill_client, jill_latency_callback, arg);
  54. * }
  55. * \endcode
  56. *
  57. * However, there are clients that may want to use this approach to parts of the
  58. * the JACK API that predate 0.116.2. For example, they might want to see if even
  59. * really old basic parts of the API like jack_client_open() exist at runtime.
  60. *
  61. * Such clients should include <jack/weakjack.h> before any other JACK header.
  62. * This will make the \b entire JACK API be subject to weak linkage, so that any
  63. * and all functions can be checked for existence at runtime. It is important
  64. * to understand that very few clients need to do this - if you use this
  65. * feature you should have a clear reason to do so.
  66. *
  67. *
  68. */
  69. #ifndef JACK_OPTIONAL_WEAK_EXPORT
  70. /* JACK_OPTIONAL_WEAK_EXPORT needs to be a macro which
  71. expands into a compiler directive. If non-null, the directive
  72. must tell the compiler to arrange for weak linkage of
  73. the symbol it used with. For this to work fully may
  74. require linker arguments for the client as well.
  75. */
  76. #ifdef __GNUC__
  77. #define JACK_OPTIONAL_WEAK_EXPORT __attribute__((__weak__))
  78. #else
  79. /* Add other things here for non-gcc platforms */
  80. #endif
  81. #endif
  82. #ifndef JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT
  83. /* JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT needs to be a macro
  84. which expands into a compiler directive. If non-null, the directive
  85. must tell the compiler to arrange for weak linkage of the
  86. symbol it is used with AND optionally to mark the symbol
  87. as deprecated. For this to work fully may require
  88. linker arguments for the client as well.
  89. */
  90. #ifdef __GNUC__
  91. #define JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT __attribute__((__weak__,__deprecated__))
  92. #else
  93. /* Add other things here for non-gcc platforms */
  94. #endif
  95. #endif
  96. /*@}*/
  97. #endif /* weakjack */