- Timestamp:
- Sep 8, 2011, 8:44:50 AM (13 years ago)
- Location:
- branches/vtkvis_threaded
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/vtkvis_threaded/PPMWriter.cpp
r2482 r2487 86 86 Response *responsePtr; 87 87 responsePtr = new Response(MESG_IMAGE); 88 responsePtr->SetMessage(mesg, length );88 responsePtr->SetMessage(mesg, length, Response::DYNAMIC); 89 89 queuePtr->Enqueue(responsePtr); 90 90 TRACE("Leaving (%dx%d)\n", width, height); -
branches/vtkvis_threaded/ResponseQueue.h
r2482 r2487 16 16 17 17 class Response { 18 unsigned char *_mesg; /* (Malloc-ed by caller, freed by19 * destructor) Contains the20 * message/bytes to be sent to the21 * client. */22 size_t _length; /* # of bytes in the above message. */23 ResponseType _type;24 25 18 public: 19 typedef enum AllocTypes { 20 STATIC, DYNAMIC, VOLATILE 21 } AllocationType; 26 22 Response(ResponseType type) { 27 23 _length = 0; … … 40 36 ~Response(void) { 41 37 if (_length > 0) { 42 free(_mesg); 38 if (_allocType == DYNAMIC) { 39 free(_mesg); 40 } 43 41 } 44 42 } 45 void SetMessage(unsigned char *mesg, size_t length) { 46 _length = length; 47 _mesg = mesg; 43 void SetMessage(unsigned char *mesg, size_t length, AllocationType type) { 44 if (type == VOLATILE) { 45 _length = length; 46 _mesg = (unsigned char *)malloc(length); 47 memcpy(_mesg, mesg, length); 48 _allocType = DYNAMIC; 49 } else { 50 _length = length; 51 _mesg = mesg; 52 _allocType = type; 53 } 48 54 } 55 private: 56 unsigned char *_mesg; /* (Malloc-ed by caller, freed by 57 * destructor) Contains the 58 * message/bytes to be sent to the 59 * client. */ 60 size_t _length; /* # of bytes in the above message. */ 61 ResponseType _type; 62 AllocationType _allocType; 49 63 }; 50 64 -
branches/vtkvis_threaded/RpVtkRendererCmd.cpp
r2483 r2487 30 30 31 31 static void 32 SendResponse(ClientData clientData, const void *bytes, size_t len) 32 QueueResponse(ClientData clientData, const void *bytes, size_t len, 33 Response::AllocationType allocType) 33 34 { 34 35 ResponseQueue *queuePtr = (ResponseQueue *)clientData; … … 37 38 38 39 responsePtr = new Response(MESG_DATA); 39 responsePtr->SetMessage((unsigned char *)bytes, len );40 responsePtr->SetMessage((unsigned char *)bytes, len, allocType); 40 41 queuePtr->Enqueue(responsePtr); 41 42 } … … 367 368 pos[0], pos[1], pos[2], focalPt[0], focalPt[1], focalPt[2], viewUp[0], viewUp[1], viewUp[2]); 368 369 369 SendResponse(clientData, buf, strlen(buf));370 QueueResponse(clientData, buf, strlen(buf), Response::VOLATILE); 370 371 return TCL_OK; 371 372 } … … 1320 1321 } 1321 1322 char *data = (char *)malloc(nbytes); 1322 #ifdef notdef1323 size_t ofs = 0;1324 ssize_t bytesRead = 0;1325 while ((bytesRead = read(g_fdIn, data + ofs, nbytes - ofs)) > 0) {1326 ofs += bytesRead;1327 if (ofs == nbytes)1328 break;1329 }1330 TRACE("bytesRead: %d", ofs);1331 if (bytesRead < 0) {1332 free(data);1333 return TCL_ERROR;1334 }1335 #else1336 1323 size_t bytesRead = fread(data, 1, nbytes, g_fIn); 1337 1324 TRACE("bytesRead: %d", bytesRead); … … 1340 1327 return TCL_ERROR; 1341 1328 } 1342 #endif1343 1329 g_renderer->addDataSet(name); 1344 1330 g_renderer->setData(name, data, nbytes); … … 1378 1364 1379 1365 char buf[256]; 1380 snprintf(buf, sizeof(buf), "nv>dataset scalar pixel %d %d %g %s\n", x, y, value, name); 1381 1382 SendResponse(clientData, buf, strlen(buf)); 1366 int length; 1367 1368 length = snprintf(buf, sizeof(buf), "nv>dataset scalar pixel %d %d %g %s\n", 1369 x, y, value, name); 1370 1371 QueueResponse(clientData, buf, length, Response::VOLATILE); 1383 1372 return TCL_OK; 1384 1373 } … … 1402 1391 1403 1392 char buf[256]; 1404 snprintf(buf, sizeof(buf), "nv>dataset scalar world %g %g %g %g %s\n", x, y, z, value, name); 1405 1406 SendResponse(clientData, buf, strlen(buf)); 1393 int length; 1394 1395 length = snprintf(buf, sizeof(buf), 1396 "nv>dataset scalar world %g %g %g %g %s\n", x, y, z, value, name); 1397 1398 QueueResponse(clientData, buf, length, Response::VOLATILE); 1407 1399 return TCL_OK; 1408 1400 } … … 1445 1437 1446 1438 char buf[256]; 1447 snprintf(buf, sizeof(buf), "nv>dataset vector pixel %d %d %g %g %g %s\n", x, y, 1448 value[0], value[1], value[2], name); 1449 1450 SendResponse(clientData, buf, strlen(buf)); 1439 int length; 1440 length = snprintf(buf, sizeof(buf), 1441 "nv>dataset vector pixel %d %d %g %g %g %s\n", x, y, value[0], 1442 value[1], value[2], name); 1443 1444 QueueResponse(clientData, buf, length, Response::VOLATILE); 1451 1445 return TCL_OK; 1452 1446 } … … 1470 1464 1471 1465 char buf[256]; 1472 snprintf(buf, sizeof(buf), "nv>dataset vector world %g %g %g %g %g %g %s\n", x, y, z, 1473 value[0], value[1], value[2], name); 1474 1475 SendResponse(clientData, buf, strlen(buf)); 1466 int length; 1467 length = snprintf(buf, sizeof(buf), 1468 "nv>dataset vector world %g %g %g %g %g %g %s\n", x, y, z, 1469 value[0], value[1], value[2], name); 1470 QueueResponse(clientData, buf, length, Response::VOLATILE); 1476 1471 return TCL_OK; 1477 1472 } … … 1536 1531 oss << "}\n"; 1537 1532 len += 2; 1538 1539 SendResponse(clientData, oss.str().c_str(), len); 1533 QueueResponse(clientData, oss.str().c_str(), len, Response::VOLATILE); 1540 1534 return TCL_OK; 1541 1535 }
Note: See TracChangeset
for help on using the changeset viewer.