Revision: 75465
http://sourceforge.net/p/brlcad/code/75465
Author: starseeker
Date: 2020-04-18 14:39:02 +0000 (Sat, 18 Apr 2020)
Log Message:
-----------
Get as far as being able to find the null display manager from a libdm plugin
loading function.
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-generic.c
brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c
Added Paths:
-----------
brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
brlcad/branches/dm-fb-merge/src/libdm/tests/
brlcad/branches/dm-fb-merge/src/libdm/tests/CMakeLists.txt
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-18 13:47:10 UTC (rev
75464)
+++ brlcad/branches/dm-fb-merge/include/dm.h 2020-04-18 14:39:02 UTC (rev
75465)
@@ -81,6 +81,11 @@
struct dm_impl *i;
};
+struct dm_plugin {
+ const struct dm * const p;
+};
+
+
DM_EXPORT extern struct dm dm_ogl;
DM_EXPORT extern struct dm dm_plot;
DM_EXPORT extern struct dm dm_ps;
@@ -191,6 +196,7 @@
DM_EXPORT extern fastf_t dm_get_aspect(struct dm *dmp);
DM_EXPORT extern const char *dm_get_type(struct dm *dmp);
DM_EXPORT extern struct bu_vls *dm_list_types(const char separator); /* free
return list with bu_vls_free(list); BU_PUT(list, struct bu_vls); */
+DM_EXPORT extern void dm_list_backends();
DM_EXPORT extern unsigned long dm_get_id(struct dm *dmp);
DM_EXPORT extern void dm_set_id(struct dm *dmp, unsigned long new_id);
DM_EXPORT extern int dm_get_displaylist(struct dm *dmp);
@@ -210,6 +216,7 @@
DM_EXPORT extern int dm_configure_win(struct dm *dmp, int force);
DM_EXPORT extern struct bu_vls *dm_get_pathname(struct dm *dmp);
DM_EXPORT extern struct bu_vls *dm_get_dname(struct dm *dmp);
+DM_EXPORT extern const char *dm_get_name(const struct dm *dmp);
DM_EXPORT extern struct bu_vls *dm_get_tkname(struct dm *dmp);
DM_EXPORT extern int dm_get_fontsize(struct dm *dmp);
DM_EXPORT extern void dm_set_fontsize(struct dm *dmp, int size);
Modified: brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt 2020-04-18
13:47:10 UTC (rev 75464)
+++ brlcad/branches/dm-fb-merge/src/libdm/CMakeLists.txt 2020-04-18
14:39:02 UTC (rev 75465)
@@ -118,6 +118,7 @@
clip.c
dm-generic.c
dm_obj.c
+ dm_plugins.c
dm_util.c
fb_generic.c
fb_log.c
@@ -140,6 +141,7 @@
vers.c
)
set_property(SOURCE dm_obj.c APPEND PROPERTY COMPILE_DEFINITIONS
FB_USE_INTERNAL_API)
+set_property(SOURCE dm_plugins.c 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)
@@ -157,6 +159,8 @@
add_dependencies(libdm profont_ProFont_ttf_cp)
endif (TARGET profont_ProFont_ttf_cp)
+add_subdirectory(tests)
+
set(libdm_ignore_files
CMakeLists.txt
README
Modified: brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c 2020-04-18 13:47:10 UTC
(rev 75464)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm-generic.c 2020-04-18 14:39:02 UTC
(rev 75465)
@@ -684,6 +684,12 @@
return &(dmp->i->dm_pathName);
}
+const char *
+dm_get_name(const struct dm *dmp)
+{
+ if (UNLIKELY(!dmp)) return NULL;
+ return dmp->i->dm_name;
+}
struct bu_vls *
dm_get_dname(struct dm *dmp)
Added: brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
(rev 0)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c 2020-04-18 14:39:02 UTC
(rev 75465)
@@ -0,0 +1,108 @@
+#include "common.h"
+#include <string.h>
+
+#include "bu/app.h"
+#include "bu/dylib.h"
+#include "bu/file.h"
+#include "bu/log.h"
+#include "bu/ptbl.h"
+#include "bu/vls.h"
+
+#include "dm.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;
+}
+
+void
+dm_list_backends()
+{
+ 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;
+ }
+
+ for (size_t i = 0; i < BU_PTBL_LEN(&plugins); i++) {
+ const struct dm *d = (const struct dm *)BU_PTBL_GET(&plugins, i);
+ bu_log("Have backend: %s\n", dm_get_name(d));
+ }
+ bu_ptbl_free(&plugins);
+
+ if (dm_close_backends(&handles)) {
+ bu_log("bu_dlclose failed to unload plugins.\n");
+ }
+ bu_ptbl_free(&handles);
+}
+
+/*
+ * Local Variables:
+ * tab-width: 8
+ * mode: C
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c 2020-04-18
13:47:10 UTC (rev 75464)
+++ brlcad/branches/dm-fb-merge/src/libdm/null/dm-Null.c 2020-04-18
14:39:02 UTC (rev 75465)
@@ -375,6 +375,13 @@
struct dm dm_null = { &dm_null_impl };
+const struct dm_plugin pinfo = { &dm_null };
+
+DM_EXPORT const struct dm_plugin *dm_plugin_info()
+{
+ return &pinfo;
+}
+
/*
* Local Variables:
* mode: C
Added: brlcad/branches/dm-fb-merge/src/libdm/tests/CMakeLists.txt
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/tests/CMakeLists.txt
(rev 0)
+++ brlcad/branches/dm-fb-merge/src/libdm/tests/CMakeLists.txt 2020-04-18
14:39:02 UTC (rev 75465)
@@ -0,0 +1,47 @@
+# C M A K E L I S T S . T X T
+# BRL-CAD
+#
+# Copyright (c) 2010-2020 United States Government as represented by
+# the U.S. Army Research Laboratory.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+#
+# 3. The name of the author may not be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+# ************ libdm tests *************
+
+BRLCAD_ADDEXEC(dm_test dm_test.c "libdm;libbu" TEST)
+
+CMAKEFILES(CMakeLists.txt)
+
+# Local Variables:
+# tab-width: 8
+# mode: cmake
+# indent-tabs-mode: t
+# End:
+# ex: shiftwidth=2 tabstop=8 textwidth=0 wrapmargin=0
Property changes on: brlcad/branches/dm-fb-merge/src/libdm/tests/CMakeLists.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c
(rev 0)
+++ brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c 2020-04-18
14:39:02 UTC (rev 75465)
@@ -0,0 +1,48 @@
+/* D M _ T E S T . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2013-2020 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#include "common.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "bu.h"
+#include "vmath.h"
+#include "dm.h"
+
+int
+main(int UNUSED(argc), const char **UNUSED(argv))
+{
+ dm_list_backends();
+ return 0;
+}
+
+
+/** @} */
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */
Property changes on: brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
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