Revision: 75500
http://sourceforge.net/p/brlcad/code/75500
Author: starseeker
Date: 2020-04-21 18:32:49 +0000 (Tue, 21 Apr 2020)
Log Message:
-----------
Have all the test functions use the initially loaded dm set
Modified Paths:
--------------
brlcad/branches/dm-fb-merge/include/dm.h
brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt
brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp
brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.cpp
brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c
Modified: brlcad/branches/dm-fb-merge/include/dm.h
===================================================================
--- brlcad/branches/dm-fb-merge/include/dm.h 2020-04-21 18:11:41 UTC (rev
75499)
+++ brlcad/branches/dm-fb-merge/include/dm.h 2020-04-21 18:32:49 UTC (rev
75500)
@@ -184,6 +184,7 @@
DM_EXPORT extern int dm_valid_type(const char *name, const char *dpy_string);
DM_EXPORT struct dm * dm_popen(void *interp, const char *type, int argc, const
char *argv[]);
DM_EXPORT const char * dm_recommend_type(const char *dpy_string);
+DM_EXPORT const char * dm_init_msgs();
/* functions to make a dm struct hideable - will need to
* sort these out later */
Modified: brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt 2020-04-21
18:11:41 UTC (rev 75499)
+++ brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt 2020-04-21
18:32:49 UTC (rev 75500)
@@ -163,7 +163,6 @@
vers.c
)
set_property(SOURCE dm_obj.c APPEND PROPERTY COMPILE_DEFINITIONS
FB_USE_INTERNAL_API)
-set_property(SOURCE dm_plugins.cpp APPEND PROPERTY COMPILE_DEFINITIONS
"DM_PLUGIN_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\"")
set_property(SOURCE dm_init.cpp APPEND PROPERTY COMPILE_DEFINITIONS
"DM_PLUGIN_SUFFIX=\"${CMAKE_SHARED_LIBRARY_SUFFIX}\"")
BRLCAD_ADDLIB(libdm "${LIBDM_SRCS}"
"librt;libbu;libpkg;${DM_EXTRA_LIBS};${PNG_LIBRARIES}")
set_target_properties(libdm PROPERTIES VERSION 20.0.1 SOVERSION 20)
Modified: brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp 2020-04-21 18:11:41 UTC
(rev 75499)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp 2020-04-21 18:32:49 UTC
(rev 75500)
@@ -43,12 +43,22 @@
void *dm_backends;
static std::set<void *> dm_handles;
-struct bu_vls dm_plugin_msgs = BU_VLS_INIT_ZERO;
+struct bu_vls *dm_init_msg_str;
+const char *
+dm_init_msgs()
+{
+ return bu_vls_cstr(dm_init_msg_str);
+}
+
static void
libdm_init(void)
{
+
+ BU_GET(dm_init_msg_str, struct bu_vls);
+ bu_vls_init(dm_init_msg_str);
+
const char *ppath = bu_dir(NULL, 0, BU_DIR_LIBEXEC, "dm", NULL);
char **filenames;
const char *psymbol = "dm_plugin_info";
@@ -62,9 +72,9 @@
if (!(dl_handle = bu_dlopen(pfile, BU_RTLD_NOW))) {
const char * const error_msg = bu_dlerror();
if (error_msg)
- bu_vls_printf(&dm_plugin_msgs, "%s\n", error_msg);
+ bu_vls_printf(dm_init_msg_str, "%s\n", error_msg);
- bu_vls_printf(&dm_plugin_msgs, "Unable to dynamically load '%s'
(skipping)\n", pfile);
+ bu_vls_printf(dm_init_msg_str, "Unable to dynamically load '%s'
(skipping)\n", pfile);
continue;
}
info_val = bu_dlsym(dl_handle, psymbol);
@@ -73,10 +83,10 @@
const char * const error_msg = bu_dlerror();
if (error_msg)
- bu_vls_printf(&dm_plugin_msgs, "%s\n", error_msg);
+ bu_vls_printf(dm_init_msg_str, "%s\n", error_msg);
- bu_vls_printf(&dm_plugin_msgs, "Unable to load symbols from '%s'
(skipping)\n", pfile);
- bu_vls_printf(&dm_plugin_msgs, "Could not find '%s' symbol in
plugin\n", psymbol);
+ bu_vls_printf(dm_init_msg_str, "Unable to load symbols from '%s'
(skipping)\n", pfile);
+ bu_vls_printf(dm_init_msg_str, "Could not find '%s' symbol in
plugin\n", psymbol);
bu_dlclose(dl_handle);
continue;
}
@@ -84,7 +94,7 @@
const struct dm_plugin *plugin = plugin_info();
if (!plugin || !plugin->p) {
- bu_vls_printf(&dm_plugin_msgs, "Invalid plugin encountered from
'%s' (skipping)\n", pfile);
+ bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from
'%s' (skipping)\n", pfile);
bu_dlclose(dl_handle);
continue;
}
@@ -93,7 +103,7 @@
const char *dname = dm_get_name(d);
std::string key(dname);
if (dm_map.find(key) != dm_map.end()) {
- bu_vls_printf(&dm_plugin_msgs, "Warning - file '%s' provides
backend '%s' but that backend has already been loaded, skipping\n", pfile,
dname);
+ bu_vls_printf(dm_init_msg_str, "Warning - file '%s' provides
backend '%s' but that backend has already been loaded, skipping\n", pfile,
dname);
bu_dlclose(dl_handle);
continue;
}
@@ -115,6 +125,9 @@
bu_dlclose(handle);
}
dm_handles.clear();
+
+ bu_vls_free(dm_init_msg_str);
+ BU_PUT(dm_init_msg_str, struct bu_vls);
}
Modified: brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.cpp
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.cpp 2020-04-21
18:11:41 UTC (rev 75499)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.cpp 2020-04-21
18:32:49 UTC (rev 75500)
@@ -11,102 +11,21 @@
#include "dm.h"
#include "./include/private.h"
-int
-dm_load_backends(struct bu_ptbl *plugins, struct bu_ptbl *handles)
-{
- const char *ppath = bu_dir(NULL, 0, BU_DIR_LIBEXEC, "dm", NULL);
- char **filenames;
- const char *psymbol = "dm_plugin_info";
- struct bu_vls plugin_pattern = BU_VLS_INIT_ZERO;
- bu_vls_sprintf(&plugin_pattern, "*%s", DM_PLUGIN_SUFFIX);
- size_t nfiles = bu_file_list(ppath, bu_vls_cstr(&plugin_pattern),
&filenames);
- for (size_t i = 0; i < nfiles; i++) {
- char pfile[MAXPATHLEN] = {0};
- bu_dir(pfile, MAXPATHLEN, BU_DIR_LIBEXEC, "dm", filenames[i], NULL);
- void *dl_handle, *info_val;
- if (!(dl_handle = bu_dlopen(pfile, BU_RTLD_NOW))) {
- const char * const error_msg = bu_dlerror();
- if (error_msg)
- bu_log("%s\n", error_msg);
-
- bu_log("Unable to dynamically load '%s' (skipping)\n", pfile);
- continue;
- }
- if (handles) {
- bu_ptbl_ins(handles, (long *)dl_handle);
- }
- info_val = bu_dlsym(dl_handle, psymbol);
- const struct dm_plugin *(*plugin_info)() = (const struct dm_plugin
*(*)())(intptr_t)info_val;
- if (!plugin_info) {
- const char * const error_msg = bu_dlerror();
-
- if (error_msg)
- bu_log("%s\n", error_msg);
-
- bu_log("Unable to load symbols from '%s' (skipping)\n", pfile);
- bu_log("Could not find '%s' symbol in plugin\n", psymbol);
- continue;
- }
-
- const struct dm_plugin *plugin = plugin_info();
-
- if (!plugin || !plugin->p) {
- bu_log("Invalid plugin encountered from '%s' (skipping)\n", pfile);
- continue;
- }
-
- const struct dm *d = plugin->p;
- bu_ptbl_ins(plugins, (long *)d);
- }
-
- return BU_PTBL_LEN(plugins);
-}
-
-int
-dm_close_backends(struct bu_ptbl *handles)
-{
- int ret = 0;
- for (size_t i = 0; i < BU_PTBL_LEN(handles); i++) {
- if (bu_dlclose((void *)BU_PTBL_GET(handles, i))) {
- ret = 1;
- }
- }
-
- return ret;
-}
-
-
struct dm *
dm_popen(void *interp, const char *type, int argc, const char *argv[])
{
struct dm *dmp = DM_NULL;
- struct bu_ptbl plugins = BU_PTBL_INIT_ZERO;
- struct bu_ptbl handles = BU_PTBL_INIT_ZERO;
- int dm_cnt = dm_load_backends(&plugins, &handles);
- if (!dm_cnt) {
- bu_log("No display manager implementations found!\n");
- return DM_NULL;
+ std::map<std::string, const struct dm *> *dmb = (std::map<std::string,
const struct dm *> *)dm_backends;
+ std::map<std::string, const struct dm *>::iterator d_it =
dmb->find(std::string(type));
+ if (d_it == dmb->end()) {
+ return dmp;
}
-
- for (size_t i = 0; i < BU_PTBL_LEN(&plugins); i++) {
- const struct dm *d = (const struct dm *)BU_PTBL_GET(&plugins, i);
- if (BU_STR_EQUIV(type, dm_get_name(d))) {
- dmp = d->i->dm_open(interp, argc, argv);
- break;
- }
- }
- bu_ptbl_free(&plugins);
-
- if (dm_close_backends(&handles)) {
- bu_log("bu_dlclose failed to unload plugins.\n");
- }
- bu_ptbl_free(&handles);
-
+ const struct dm *d = d_it->second;
+ dmp = d->i->dm_open(interp, argc, argv);
return dmp;
}
-
void
dm_list_backends(const char *separator)
{
@@ -140,33 +59,13 @@
int
dm_valid_type(const char *name, const char *dpy_string)
{
- struct bu_ptbl plugins = BU_PTBL_INIT_ZERO;
- struct bu_ptbl handles = BU_PTBL_INIT_ZERO;
- int dm_cnt = dm_load_backends(&plugins, &handles);
- if (!dm_cnt) {
- bu_log("No display manager implementations found!\n");
+ std::map<std::string, const struct dm *> *dmb = (std::map<std::string,
const struct dm *> *)dm_backends;
+ std::map<std::string, const struct dm *>::iterator d_it =
dmb->find(std::string(name));
+ if (d_it == dmb->end()) {
return 0;
}
-
- int is_valid = 0;
-
- for (size_t i = 0; i < BU_PTBL_LEN(&plugins); i++) {
- const struct dm *d = (const struct dm *)BU_PTBL_GET(&plugins, i);
- if (BU_STR_EQUIV(name, dm_get_name(d))) {
- if (d->i->dm_viable(dpy_string) != 1) {
- bu_log("WARNING: found matching plugin %s, but viability test
failed - skipping.\n", dm_get_name(d));
- } else {
- is_valid = 1;
- break;
- }
- }
- }
- bu_ptbl_free(&plugins);
- if (dm_close_backends(&handles)) {
- bu_log("bu_dlclose failed to unload plugins.\n");
- }
- bu_ptbl_free(&handles);
-
+ const struct dm *d = d_it->second;
+ int is_valid = d->i->dm_viable(dpy_string);
return is_valid;
}
@@ -177,44 +76,29 @@
dm_recommend_type(const char *dpy_string)
{
static const char *priority_list[] = {"osgl", "wgl", "ogl", "X", "tk",
"nu"};
-
- struct bu_ptbl plugins = BU_PTBL_INIT_ZERO;
- struct bu_ptbl handles = BU_PTBL_INIT_ZERO;
- int dm_cnt = dm_load_backends(&plugins, &handles);
- if (!dm_cnt) {
- bu_log("No display manager implementations found!\n");
- return NULL;
- }
-
+ std::map<std::string, const struct dm *> *dmb = (std::map<std::string,
const struct dm *> *)dm_backends;
const char *ret = NULL;
int i = 0;
const char *b = priority_list[i];
while (!BU_STR_EQUAL(b, "nu")) {
- for (size_t j = 0; j < BU_PTBL_LEN(&plugins); j++) {
- const struct dm *d = (const struct dm *)BU_PTBL_GET(&plugins, j);
- if (BU_STR_EQUIV(b, dm_get_name(d))) {
- if (d->i->dm_viable(dpy_string) == 1) {
- ret = b;
- break;
- }
- }
+ std::map<std::string, const struct dm *>::iterator d_it =
dmb->find(std::string(b));
+ if (d_it == dmb->end()) {
+ i++;
+ b = priority_list[i];
+ continue;
}
- if (ret) {
+ const struct dm *d = d_it->second;
+ if (d->i->dm_viable(dpy_string) == 1) {
+ ret = b;
break;
- }
+ }
i++;
b = priority_list[i];
}
- bu_ptbl_free(&plugins);
- if (dm_close_backends(&handles)) {
- bu_log("bu_dlclose failed to unload plugins.\n");
- }
- bu_ptbl_free(&handles);
-
return (ret) ? ret : b;
-}
+}
/*
* Local Variables:
Modified: brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c 2020-04-21
18:11:41 UTC (rev 75499)
+++ brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c 2020-04-21
18:32:49 UTC (rev 75500)
@@ -31,6 +31,9 @@
int
main(int UNUSED(argc), const char **UNUSED(argv))
{
+
+ bu_log("load msgs: %s\n", dm_init_msgs());
+
dm_list_backends(NULL);
int vtype;
vtype = dm_valid_type("nu", NULL);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits