Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

cmd_plugin.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: cmd_plugin.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.25 $       $Date: 2019/01/17 21:21:03 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   text commands for control of plugin loading
00019  ***************************************************************************/
00020 
00021 #include <tcl.h>
00022 #include "tcl_commands.h"
00023 #include "VMDApp.h"
00024 #include "config.h"
00025 
00026 int text_cmd_plugin(ClientData cd, Tcl_Interp *interp, int argc,
00027                      const char *argv[]) {
00028 
00029   VMDApp *app = (VMDApp *)cd;
00030   if (!app) 
00031     return TCL_ERROR;
00032 
00033   // plugin dlopen <filename>
00034   if (argc == 3 && !strupncmp(argv[1], "dlopen", CMDLEN)) {
00035     int rc = app->plugin_dlopen(argv[2]);
00036     if (rc < 0) {
00037       Tcl_AppendResult(interp, "Unable to dlopen plugin file ", argv[2], NULL);
00038       return TCL_ERROR;
00039     } 
00040     Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
00041     return TCL_OK;
00042   }
00043   // plugin update  -- updates list of plugins
00044   if (argc == 2 && !strupncmp(argv[1], "update", CMDLEN)) {
00045     app->plugin_update();
00046     return TCL_OK;
00047   }
00048 
00049   // plugin list [type]: returns list of category/name pairs.  If optional
00050   // type is specified, return only plugins of that type.
00051   if ((argc == 2 || argc == 3) && !strupncmp(argv[1], "list", CMDLEN)) {
00052     const char *type = NULL;
00053     if (argc == 3)
00054       type = argv[2];
00055     
00056     PluginList pluginlist;
00057     app->list_plugins(pluginlist, type);
00058     const int num = pluginlist.num();
00059     Tcl_Obj *result = Tcl_NewListObj(0, NULL);
00060     for (int i=0; i<num; i++) {
00061       vmdplugin_t *p = pluginlist[i];
00062       Tcl_Obj *listelem = Tcl_NewListObj(0, NULL);
00063       Tcl_ListObjAppendElement(interp, listelem, Tcl_NewStringObj(p->type,-1));
00064       Tcl_ListObjAppendElement(interp, listelem, Tcl_NewStringObj(p->name,-1));
00065       Tcl_ListObjAppendElement(interp, result, listelem);
00066     }
00067     Tcl_SetObjResult(interp, result);
00068     return TCL_OK;
00069   }
00070   // plugin info <type> <name> <varname>
00071   // Puts plugin information for the specified plugin into the array variable
00072   // specified by varname.  The following array keys will be used: type,
00073   // name, author, majorversion, minorversion, reentrant.
00074   // returns 1 if plugin information was found, or 0 if no plugin information
00075   // is available for that type and name.
00076   if (argc == 5 && !strupncmp(argv[1], "info", CMDLEN)) {
00077     vmdplugin_t *p = app->get_plugin(argv[2], argv[3]);
00078     if (!p) {
00079       Tcl_SetResult(interp, (char *) "0", TCL_STATIC);
00080       return TCL_OK;
00081     }
00082     char major[32], minor[32], reentrant[32];
00083     sprintf(major, "%d", p->majorv);
00084     sprintf(minor, "%d", p->minorv);
00085     sprintf(reentrant, "%d", p->is_reentrant);
00086 
00087     if (!Tcl_SetVar2(interp,argv[4], "type", p->type, TCL_LEAVE_ERR_MSG) ||
00088         !Tcl_SetVar2(interp,argv[4], "name", p->name, TCL_LEAVE_ERR_MSG) ||
00089         !Tcl_SetVar2(interp,argv[4], "author", p->author, TCL_LEAVE_ERR_MSG)  ||
00090         !Tcl_SetVar2(interp,argv[4], "majorversion", major, TCL_LEAVE_ERR_MSG) ||
00091         !Tcl_SetVar2(interp,argv[4], "minorversion", minor, TCL_LEAVE_ERR_MSG) ||
00092         !Tcl_SetVar2(interp,argv[4], "reentrant", reentrant, TCL_LEAVE_ERR_MSG)) {
00093       Tcl_AppendResult(interp, "Unable to return plugin information in variable ", argv[4], NULL);
00094       return TCL_ERROR;
00095     }
00096     Tcl_SetResult(interp, (char *) "1", TCL_STATIC);
00097     return TCL_OK;
00098   }
00099   Tcl_AppendResult(interp, "Usage: \n\tplugin dlopen <filename> -- Load plugins from a dynamic library\n",
00100       "\tplugin update -- Update the list of plugins in the GUI\n",
00101       "\tplugin list [<plugin type>] -- List all plugins of the given type\n", 
00102       "\tplugin info <type> <name> <arrayname> -- Store info about plugin in array\n",
00103       NULL);
00104   return TCL_ERROR;
00105 }
00106 

Generated on Sat Nov 9 02:43:56 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002