jack1 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.

107 lines
2.7KB

  1. /*
  2. Copyright (C) 2001 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. $Id$
  15. */
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #include <stdlib.h>
  19. #include <jack/driver.h>
  20. #include <jack/internal.h>
  21. #include <jack/error.h>
  22. static int dummy_attach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
  23. static int dummy_detach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
  24. static int dummy_wait (jack_driver_t *drv) { return 0; }
  25. static int dummy_stop (jack_driver_t *drv) { return 0; }
  26. static int dummy_start (jack_driver_t *drv) { return 0; }
  27. void
  28. jack_driver_init (jack_driver_t *driver)
  29. {
  30. memset (driver, 0, sizeof (*driver));
  31. driver->attach = dummy_attach;
  32. driver->detach = dummy_detach;
  33. driver->wait = dummy_wait;
  34. driver->start = dummy_start;
  35. driver->stop = dummy_stop;
  36. }
  37. jack_driver_t *
  38. jack_driver_load (const char *path_to_so, ...)
  39. {
  40. va_list ap;
  41. const char *errstr;
  42. dlhandle handle;
  43. jack_driver_t *driver;
  44. jack_driver_t *(*initialize)(va_list);
  45. void (*finish)(jack_driver_t *);
  46. va_start (ap, path_to_so);
  47. handle = dlopen (path_to_so, RTLD_NOW|RTLD_GLOBAL);
  48. if (handle == 0) {
  49. if ((errstr = dlerror ()) != 0) {
  50. jack_error ("can't load \"%s\": %s", path_to_so, errstr);
  51. } else {
  52. jack_error ("bizarre error loading driver shared object %s", path_to_so);
  53. }
  54. va_end (ap);
  55. return 0;
  56. }
  57. initialize = dlsym (handle, "driver_initialize");
  58. if ((errstr = dlerror ()) != 0) {
  59. jack_error ("no initialize function in shared object %s\n", path_to_so);
  60. dlclose (handle);
  61. va_end (ap);
  62. return 0;
  63. }
  64. finish = dlsym (handle, "driver_finish");
  65. if ((errstr = dlerror ()) != 0) {
  66. jack_error ("no finish function in in shared driver object %s", path_to_so);
  67. dlclose (handle);
  68. va_end (ap);
  69. return 0;
  70. }
  71. if ((driver = initialize (ap)) != 0) {
  72. driver->handle = handle;
  73. driver->finish = finish;
  74. }
  75. va_end (ap);
  76. return driver;
  77. }
  78. void
  79. jack_driver_unload (jack_driver_t *driver)
  80. {
  81. driver->finish (driver);
  82. dlclose (driver->handle);
  83. }