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

cmd_plugin.C

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

Generated on Sat Aug 30 01:26:32 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002