Revision: 75506
          http://sourceforge.net/p/brlcad/code/75506
Author:   starseeker
Date:     2020-04-21 19:59:48 +0000 (Tue, 21 Apr 2020)
Log Message:
-----------
dm code is only half the story - next up is dynamic recognition of the fb 
logic.  Stub in a single test case for experimentation.  (Also confirms that 
the logging works, as most of the plugins don't satisfy this and the printed 
message notes that...)

Modified Paths:
--------------
    brlcad/branches/dm-fb-merge/include/dm.h
    brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp
    brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
    brlcad/branches/dm-fb-merge/src/libdm/glx/if_ogl.c

Modified: brlcad/branches/dm-fb-merge/include/dm.h
===================================================================
--- brlcad/branches/dm-fb-merge/include/dm.h    2020-04-21 19:39:33 UTC (rev 
75505)
+++ brlcad/branches/dm-fb-merge/include/dm.h    2020-04-21 19:59:48 UTC (rev 
75506)
@@ -366,6 +366,10 @@
 };
 #define FB_NULL (struct fb *) 0
 
+struct fb_plugin {
+    const struct fb * const p;
+};
+
 /**
  * assert the integrity of a framebuffer struct.
  */
@@ -431,7 +435,7 @@
 
 FB_EXPORT extern void fb_set_interface(struct fb *ifp, const char 
*interface_type);
 FB_EXPORT extern void fb_set_name(struct fb *ifp, const char *name);
-FB_EXPORT extern char *fb_get_name(struct fb *ifp);
+FB_EXPORT extern const char *fb_get_name(const struct fb *ifp);
 FB_EXPORT extern void fb_set_magic(struct fb *ifp, uint32_t magic);
 FB_EXPORT extern long fb_get_pagebuffer_pixel_size(struct fb *ifp);
 

Modified: brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp   2020-04-21 19:39:33 UTC 
(rev 75505)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm_init.cpp   2020-04-21 19:59:48 UTC 
(rev 75506)
@@ -40,7 +40,9 @@
 #include "./include/private.h"
 
 static std::map<std::string, const struct dm *> dm_map;
+static std::map<std::string, const struct fb *> fb_map;
 void *dm_backends;
+void *fb_backends;
 
 static std::set<void *> dm_handles;
 struct bu_vls *dm_init_msg_str;
@@ -61,7 +63,6 @@
 
     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);
@@ -68,7 +69,7 @@
     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;
+       void *dl_handle;
        if (!(dl_handle = bu_dlopen(pfile, BU_RTLD_NOW))) {
            const char * const error_msg = bu_dlerror();
            if (error_msg)
@@ -77,38 +78,76 @@
            bu_vls_printf(dm_init_msg_str, "Unable to dynamically load '%s' 
(skipping)\n", pfile);
            continue;
        }
-       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();
+       {
+           const char *psymbol = "dm_plugin_info";
+           void *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_vls_printf(dm_init_msg_str, "%s\n", error_msg);
+               if (error_msg)
+                   bu_vls_printf(dm_init_msg_str, "%s\n", error_msg);
 
-           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;
+               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;
+           }
+
+           const struct dm_plugin *plugin = plugin_info();
+
+           if (!plugin || !plugin->p) {
+               bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from 
'%s' (skipping)\n", pfile);
+               bu_dlclose(dl_handle);
+               continue;
+           }
+
+           const struct dm *d = plugin->p;
+           const char *dname = dm_get_name(d);
+           std::string key(dname);
+           if (dm_map.find(key) != dm_map.end()) {
+               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;
+           }
+           dm_handles.insert(dl_handle);
+           dm_map[key] = d;
        }
 
-       const struct dm_plugin *plugin = plugin_info();
+       // If we've gotten this far, we have a dm - see if we also have a 
framebuffer */
+       {
+           const char *psymbol = "fb_plugin_info";
+           void *info_val = bu_dlsym(dl_handle, psymbol);
+           const struct fb_plugin *(*plugin_info)() = (const struct fb_plugin 
*(*)())(intptr_t)info_val;
+           if (!plugin_info) {
+               const char * const error_msg = bu_dlerror();
 
-       if (!plugin || !plugin->p) {
-           bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from 
'%s' (skipping)\n", pfile);
-           bu_dlclose(dl_handle);
-           continue;
+               if (error_msg)
+                   bu_vls_printf(dm_init_msg_str, "%s\n", error_msg);
+
+               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);
+               continue;
+           }
+
+           const struct fb_plugin *plugin = plugin_info();
+
+           if (!plugin || !plugin->p) {
+               bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from 
'%s' (skipping)\n", pfile);
+               continue;
+           }
+
+           const struct fb *f = plugin->p;
+           const char *fname = fb_get_name(f);
+           std::string key(fname);
+           if (fb_map.find(key) != fb_map.end()) {
+               bu_vls_printf(dm_init_msg_str, "Warning - file '%s' provides 
framebuffer backend '%s' but that backend has already been loaded, skipping\n", 
pfile, fname);
+               continue;
+           }
+           fb_map[key] = f;
        }
 
-       const struct dm *d = plugin->p;
-       const char *dname = dm_get_name(d);
-       std::string key(dname);
-       if (dm_map.find(key) != dm_map.end()) {
-           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;
-       }
-       dm_handles.insert(dl_handle);
-       dm_map[key] = d;
+
     }
 
     dm_backends = (void *)&dm_map;

Modified: brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c  2020-04-21 19:39:33 UTC 
(rev 75505)
+++ brlcad/branches/dm-fb-merge/src/libdm/fb_generic.c  2020-04-21 19:59:48 UTC 
(rev 75506)
@@ -183,7 +183,7 @@
     bu_strlcpy(ifp->i->if_name, name, strlen(name)+1);
 }
 
-char *fb_get_name(struct fb *ifp)
+const char *fb_get_name(const struct fb *ifp)
 {
     if (!ifp) return NULL;
     return ifp->i->if_name;

Modified: brlcad/branches/dm-fb-merge/src/libdm/glx/if_ogl.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/glx/if_ogl.c  2020-04-21 19:39:33 UTC 
(rev 75505)
+++ brlcad/branches/dm-fb-merge/src/libdm/glx/if_ogl.c  2020-04-21 19:59:48 UTC 
(rev 75506)
@@ -2347,6 +2347,15 @@
 
 struct fb ogl_interface =  { &ogl_interface_impl };
 
+#ifdef DM_PLUGIN
+static const struct fb_plugin finfo = { &ogl_interface };
+
+DM_EXPORT const struct fb_plugin *fb_plugin_info()
+{
+    return &finfo;
+}
+#endif
+
 /* Because class is actually used to access a struct
  * entry in this file, preserve our redefinition
  * of class for the benefit of avoiding C++ name

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

Reply via email to