Revision: 75494
          http://sourceforge.net/p/brlcad/code/75494
Author:   starseeker
Date:     2020-04-21 15:53:32 +0000 (Tue, 21 Apr 2020)
Log Message:
-----------
more plugin testing

Modified Paths:
--------------
    brlcad/branches/dm-fb-merge/include/dm.h
    brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
    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 15:25:36 UTC (rev 
75493)
+++ brlcad/branches/dm-fb-merge/include/dm.h    2020-04-21 15:53:32 UTC (rev 
75494)
@@ -179,6 +179,10 @@
 DM_EXPORT extern const char *dm_version(void);
 
 
+/* Test plugin functions */
+DM_EXPORT extern void dm_list_backends(const char *separator);
+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[]);
 
 /* functions to make a dm struct hideable - will need to
  * sort these out later */
@@ -197,7 +201,6 @@
 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);

Modified: brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c  2020-04-21 15:25:36 UTC 
(rev 75493)
+++ brlcad/branches/dm-fb-merge/src/libdm/dm_plugins.c  2020-04-21 15:53:32 UTC 
(rev 75494)
@@ -9,6 +9,7 @@
 #include "bu/vls.h"
 
 #include "dm.h"
+#include "./include/private.h"
 
 int
 dm_load_backends(struct bu_ptbl *plugins, struct bu_ptbl *handles)
@@ -74,6 +75,38 @@
     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;
+    }
+
+    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);
+
+    return dmp;
+}
+
+
 void
 dm_list_backends(const char *separator)
 {
@@ -82,7 +115,6 @@
     bu_vls_init(list);
     bu_vls_trunc(list, 0);
 
-
     struct bu_ptbl plugins = BU_PTBL_INIT_ZERO;
     struct bu_ptbl handles = BU_PTBL_INIT_ZERO;
     int dm_cnt = dm_load_backends(&plugins, &handles);
@@ -116,6 +148,40 @@
     BU_PUT(list, struct bu_vls);
 }
 
+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");
+       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);
+
+    return is_valid;
+}
+
+
 /*
  * Local Variables:
  * tab-width: 8

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 
15:25:36 UTC (rev 75493)
+++ brlcad/branches/dm-fb-merge/src/libdm/tests/dm_test.c       2020-04-21 
15:53:32 UTC (rev 75494)
@@ -32,6 +32,30 @@
 main(int UNUSED(argc), const char **UNUSED(argv))
 {
     dm_list_backends(NULL);
+    int vtype;
+    vtype = dm_valid_type("nu", NULL);
+    bu_log("nu valid: %d\n", vtype);
+    vtype = dm_valid_type("plot", NULL);
+    bu_log("plot valid: %d\n", vtype);
+    vtype = dm_valid_type("X", NULL);
+    bu_log("X valid: %d\n", vtype);
+    vtype = dm_valid_type("ogl", NULL);
+    bu_log("ogl valid: %d\n", vtype);
+    vtype = dm_valid_type("osgl", NULL);
+    bu_log("osgl valid: %d\n", vtype);
+    vtype = dm_valid_type("wgl", NULL);
+    bu_log("wgl valid: %d\n", vtype);
+
+    const char *av0 = "attach";
+    struct dm *dmp;
+    dmp = dm_popen(NULL, "nu", 1, &av0);
+    bu_log("dmp name: %s\n", dm_get_name(dmp));
+    dm_close(dmp);
+    dmp = dm_popen(NULL, "txt", 1, &av0);
+    bu_log("dmp name: %s\n", dm_get_name(dmp));
+    dm_close(dmp);
+
+
     return 0;
 }
 

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