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.

109 lines
2.9KB

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