static jack_driver_desc_t * jack_get_descriptor (JSList * drivers, const char * sofile, const char * symbol) { jack_driver_desc_t * descriptor, * other_descriptor; JackDriverDescFunction so_get_descriptor = NULL; JSList * node; void * dlhandle; char * filename; #ifdef WIN32 int dlerr; #else const char * dlerr; #endif int err; const char* driver_dir; if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { // for WIN32 ADDON_DIR is defined in JackConstants.h as relative path // for posix systems, it is absolute path of default driver dir #ifdef WIN32 char temp_driver_dir1[512]; char temp_driver_dir2[512]; GetCurrentDirectory(512, temp_driver_dir1); sprintf(temp_driver_dir2, "%s/%s", temp_driver_dir1, ADDON_DIR); driver_dir = temp_driver_dir2; #else driver_dir = ADDON_DIR; #endif } filename = (char *)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1); sprintf (filename, "%s/%s", driver_dir, sofile); if ((dlhandle = LoadDriverModule(filename)) == NULL) { #ifdef WIN32 jack_error ("could not open driver .dll '%s': %ld", filename, GetLastError()); #else jack_error ("could not open driver .so '%s': %s", filename, dlerror()); #endif free(filename); return NULL; } so_get_descriptor = (JackDriverDescFunction)GetDriverProc(dlhandle, symbol); #ifdef WIN32 if ((so_get_descriptor == NULL) && (dlerr = GetLastError()) != 0) { jack_error("jack_get_descriptor : dll is not a driver, err = %ld", dlerr); #else if ((so_get_descriptor == NULL) && (dlerr = dlerror ()) != NULL) { jack_error("jack_get_descriptor err = %s", dlerr); #endif UnloadDriverModule(dlhandle); free(filename); return NULL; } if ((descriptor = so_get_descriptor ()) == NULL) { jack_error("driver from '%s' returned NULL descriptor", filename); UnloadDriverModule(dlhandle); free(filename); return NULL; } #ifdef WIN32 if ((err = UnloadDriverModule(dlhandle)) == 0) { jack_error ("error closing driver .so '%s': %ld", filename, GetLastError ()); } #else if ((err = UnloadDriverModule(dlhandle)) != 0) { jack_error ("error closing driver .so '%s': %s", filename, dlerror ()); } #endif /* check it doesn't exist already */ for (node = drivers; node; node = jack_slist_next (node)) { other_descriptor = (jack_driver_desc_t *) node->data; if (strcmp(descriptor->name, other_descriptor->name) == 0) { jack_error("the drivers in '%s' and '%s' both have the name '%s'; using the first", other_descriptor->file, filename, other_descriptor->name); /* FIXME: delete the descriptor */ free(filename); return NULL; } } strncpy(descriptor->file, filename, JACK_PATH_MAX); free(filename); return descriptor; } static bool check_symbol(const char* sofile, const char* symbol) { void * dlhandle; bool res = false; const char* driver_dir; if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { // for WIN32 ADDON_DIR is defined in JackConstants.h as relative path // for posix systems, it is absolute path of default driver dir #ifdef WIN32 char temp_driver_dir1[512]; char temp_driver_dir2[512]; GetCurrentDirectory(512, temp_driver_dir1); sprintf(temp_driver_dir2, "%s/%s", temp_driver_dir1, ADDON_DIR); driver_dir = temp_driver_dir2; #else driver_dir = ADDON_DIR; #endif } char* filename = (char *)malloc(strlen (driver_dir) + 1 + strlen(sofile) + 1); sprintf (filename, "%s/%s", driver_dir, sofile); if ((dlhandle = LoadDriverModule(filename)) == NULL) { #ifdef WIN32 jack_error ("could not open component .dll '%s': %ld", filename, GetLastError()); #else jack_error ("could not open component .so '%s': %s", filename, dlerror()); #endif } else { res = (GetDriverProc(dlhandle, symbol)) ? true : false; UnloadDriverModule(dlhandle); } free(filename); return res; }
static jack_driver_desc_t * jack_drivers_get_descriptor (JSList * drivers, const char * sofile) { jack_driver_desc_t * descriptor, * other_descriptor; JackDriverDescFunction so_get_descriptor; JSList * node; void * dlhandle; char * filename; const char * dlerr; int err; char* driver_dir; if ((driver_dir = getenv("JACK_DRIVER_DIR")) == 0) { driver_dir = ADDON_DIR; } filename = malloc (strlen (driver_dir) + 1 + strlen (sofile) + 1); sprintf (filename, "%s/%s", driver_dir, sofile); // if (verbose) { // jack_info ("getting driver descriptor from %s", filename); // } if ((dlhandle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL)) == NULL) { jack_error ("could not open driver .so '%s': %s\n", filename, dlerror ()); free (filename); return NULL; } so_get_descriptor = (JackDriverDescFunction) dlsym (dlhandle, "driver_get_descriptor"); if ((dlerr = dlerror ()) != NULL) { jack_error("%s", dlerr); dlclose (dlhandle); free (filename); return NULL; } if ((descriptor = so_get_descriptor ()) == NULL) { jack_error ("driver from '%s' returned NULL descriptor\n", filename); dlclose (dlhandle); free (filename); return NULL; } if ((err = dlclose (dlhandle)) != 0) { jack_error ("error closing driver .so '%s': %s\n", filename, dlerror ()); } /* check it doesn't exist already */ for (node = drivers; node; node = jack_slist_next (node)) { other_descriptor = (jack_driver_desc_t *) node->data; if (strcmp (descriptor->name, other_descriptor->name) == 0) { jack_error ("the drivers in '%s' and '%s' both have the name '%s'; using the first\n", other_descriptor->file, filename, other_descriptor->name); /* FIXME: delete the descriptor */ free (filename); return NULL; } } snprintf (descriptor->file, sizeof(descriptor->file), "%s", filename); free (filename); return descriptor; }