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_collab.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.10 $ $Date: 2019年01月17日 21:21:03 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * text commands for collaborative/remote control of VMD sessions 00019 ***************************************************************************/ 00020 00021 #include "CommandQueue.h" 00022 #include "VMDApp.h" 00023 #include "MoleculeList.h" 00024 #include "utilities.h" 00025 #include "config.h" // for CMDLEN 00026 #include <stdlib.h> 00027 #include <tcl.h> 00028 00029 #include "VMDCollab.h" 00030 00031 int text_cmd_collab(ClientData cd, Tcl_Interp *interp, int argc, 00032 const char *argv[]) { 00033 VMDApp *app = (VMDApp *)cd; 00034 00035 if (argc == 4 && !strupncmp(argv[1], "connect", CMDLEN)) { 00036 const char *host = argv[2]; 00037 int port; 00038 if (Tcl_GetInt(interp, argv[3], &port) != TCL_OK) return TCL_ERROR; 00039 if (!strcmp(host, Tcl_GetHostName())) { 00040 if (!app->vmdcollab->startserver(port)) { 00041 Tcl_AppendResult(interp, "Failed to start server on port ", argv[3], NULL); 00042 return TCL_ERROR; 00043 } 00044 } 00045 if (!app->vmdcollab->connect(host, port)) { 00046 Tcl_AppendResult(interp, "Failed to connect to vmdcollab at ", host, 00047 "port: ", argv[3], NULL); 00048 return TCL_ERROR; 00049 } 00050 return TCL_OK; 00051 } 00052 if (argc == 2 && !strupncmp(argv[1], "disconnect", CMDLEN)) { 00053 app->vmdcollab->disconnect(); 00054 return TCL_OK; 00055 } 00056 00057 Tcl_SetResult(interp, (char *) "Usage: vmdcollab [connect <host> <port> | disconnect", 00058 TCL_STATIC); 00059 return TCL_ERROR; 00060 } 00061 00062