Changeset 2614 for trunk/packages
- Timestamp:
- Oct 12, 2011, 1:02:01 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/pymolproxy/pymolproxy.c
r2460 r2614 96 96 static Stats stats; 97 97 98 #define READTRACE 098 #define READTRACE 1 99 99 #define EXPECTTRACE 0 100 100 #define WRITETRACE 0 101 101 102 static int debug = FALSE;102 static int debug = TRUE; 103 103 104 104 static FILE *flog; … … 446 446 proxyPtr->error = 0; 447 447 proxyPtr->status = TCL_OK; 448 }449 450 static int451 CreateTmpDir(Tcl_Interp *interp)452 {453 const char script[] = {454 "set path \"/tmp/pymol[pid]\"\n"455 "if { [file exists $path] } {\n"456 " file delete -force $path\n"457 "}\n"458 "file mkdir $path\n"459 };460 return Tcl_GlobalEval(interp, script);461 }462 463 static void464 DestroyTmpDir()465 {466 char cmd[BUFSIZ];467 468 sprintf(cmd, "/bin/rm -rf /tmp/pymol%d", getpid());469 if (system(cmd) < 0) {470 ERROR("can't delete tmp directory: %s\n", strerror(errno));471 }472 448 } 473 449 … … 872 848 } 873 849 874 875 850 static int 876 851 BmpCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) … … 1245 1220 } 1246 1221 { 1222 int f; 1223 ssize_t nWritten; 1247 1224 char fileName[200]; 1248 FILE *f; 1249 ssize_t nWritten; 1250 static unsigned long count = 0; 1251 1225 1226 strcpy(fileName, "/tmp/pdb.XXXXXX"); 1252 1227 proxyPtr->status = TCL_ERROR; 1253 sprintf(fileName, "/tmp/pymol%d/%ld.pdb", getpid(), count); 1254 count++; 1255 f = fopen(fileName, "w"); 1256 if (f == NULL) { 1257 Tcl_AppendResult(interp, "can't create temporary file \"", 1258 fileName, "\": ", Tcl_PosixError(interp), 1259 (char *)NULL); 1228 f = mkstemp(fileName); 1229 if (f < 0) { 1230 Tcl_AppendResult(interp, "can't create temporary file \"", 1231 fileName, "\":", Tcl_PosixError(interp), (char *)NULL); 1260 1232 goto error; 1261 1233 } 1262 nWritten = fwrite(data, sizeof(char), nBytes, f);1234 nWritten = write(f, data, nBytes); 1263 1235 if (nBytes != nWritten) { 1264 1236 Tcl_AppendResult(interp, "can't write PDB data to \"", 1265 1237 fileName, "\": ", Tcl_PosixError(interp), 1266 1238 (char *)NULL); 1267 fclose(f);1239 close(f); 1268 1240 goto error; 1269 1241 } 1270 fclose(f);1271 Pymol(proxyPtr, "load %s,%s,%d\n", fileName, name, state);1242 close(f); 1243 Pymol(proxyPtr, "loadandremovepdbfile %s,%s,%d\n", fileName, name, state); 1272 1244 proxyPtr->status = TCL_OK; 1273 1245 } … … 1400 1372 return TCL_ERROR; 1401 1373 } 1374 stats.nFrames++; 1375 stats.nBytes += nBytes; 1376 return proxyPtr->status; 1377 } 1378 1379 1380 static int 1381 PpmCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) 1382 { 1383 char buffer[BUFSIZ]; 1384 int nBytes=0; 1385 PymolProxy *proxyPtr = clientData; 1386 size_t length; 1387 Image *imgPtr; 1388 1389 clear_error(proxyPtr); 1390 1391 /* Force pymol to update the current scene. */ 1392 Pymol(proxyPtr, "refresh\n"); 1393 Pymol(proxyPtr, "png -,format=1\n"); 1394 1395 if (Expect(proxyPtr, "ppm image follows: ", buffer, BUFSIZ-1) != TCL_OK) { 1396 return TCL_ERROR; 1397 } 1398 if (sscanf(buffer, "ppm image follows: %d\n", &nBytes) != 1) { 1399 Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"", 1400 (char *)NULL); 1401 return TCL_ERROR; 1402 } 1403 sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId, 1404 proxyPtr->frame, proxyPtr->rockOffset); 1405 length = strlen(buffer); 1406 imgPtr = NewImage(proxyPtr, nBytes + length); 1407 strcpy(imgPtr->data, buffer); 1408 if (ReadFollowingData(&proxyPtr->server, imgPtr->data + length, nBytes) 1409 != BUFFER_OK) { 1410 ERROR("can't read %d bytes for \"image follows\" buffer: %s", nBytes, 1411 strerror(errno)); 1412 return TCL_ERROR; 1413 } 1414 #ifdef notdef 1415 if (Expect(proxyPtr, " ScenePNG", buffer, BUFSIZ-1) != TCL_OK) { 1416 return TCL_ERROR; 1417 } 1418 #endif 1402 1419 stats.nFrames++; 1403 1420 stats.nBytes += nBytes; … … 2006 2023 ProxyInit(int cin, int cout, char *const *argv) 2007 2024 { 2025 char stderrFile[200]; 2008 2026 int status, result = 0; 2009 2027 int sin[2]; … … 2027 2045 2028 2046 parent = getpid(); 2047 sprintf(stderrFile, "/tmp/pymol%d.stderr", parent); 2029 2048 2030 2049 /* Fork the new process. Connect I/O to the new socket. */ … … 2037 2056 2038 2057 interp = Tcl_CreateInterp(); 2039 if (CreateTmpDir(interp) != TCL_OK) {2040 ERROR(Tcl_GetStringResult(interp));2041 }2042 2058 Tcl_MakeSafe(interp); 2043 2059 … … 2059 2075 dup2(sin[0], 0); // stdin 2060 2076 dup2(sout[1], 1); // stdout 2061 sprintf(path, "/tmp/pymol%d/stderr", parent); 2062 f = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600); 2077 f = open(stderrFile, O_WRONLY | O_CREAT | O_TRUNC, 0600); 2063 2078 if (f < 0) { 2064 2079 ERROR("can't open server error file `%s': %s", path, … … 2108 2123 Tcl_CreateCommand(interp, "pan", PanCmd, &proxy, NULL); 2109 2124 Tcl_CreateCommand(interp, "png", PngCmd, &proxy, NULL); 2125 Tcl_CreateCommand(interp, "ppm", PpmCmd, &proxy, NULL); 2110 2126 Tcl_CreateCommand(interp, "print", PrintCmd, &proxy, NULL); 2111 2127 Tcl_CreateCommand(interp, "raw", RawCmd, &proxy, NULL); … … 2133 2149 PollForEvents(&proxy); 2134 2150 2151 unlink(stderrFile); 2135 2152 close(proxy.cout); 2136 2153 close(proxy.sout); … … 2159 2176 INFO("pymol server process ended (result=%d)", result); 2160 2177 2161 DestroyTmpDir();2162 2178 Tcl_DeleteInterp(interp); 2163 2179 … … 2301 2317 if ((nChannels == 0) || (proxyPtr->flags & FORCE_UPDATE)) { 2302 2318 if (proxyPtr->flags & UPDATE_PENDING) { 2303 Tcl_Eval(proxyPtr->interp, " bmp");2319 Tcl_Eval(proxyPtr->interp, "ppm"); 2304 2320 proxyPtr->flags &= ~UPDATE_PENDING; 2305 2321 }
Note: See TracChangeset
for help on using the changeset viewer.