00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #include "CommandQueue.h"
00022 #include "VMDApp.h"
00023 #include "MoleculeList.h"
00024 #include "utilities.h"
00025 #include "config.h"    
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