Changeset 2495 for branches


Ignore:
Timestamp:
Sep 8, 2011 8:03:53 PM (13 years ago)
Author:
ldelgass
Message:

A few mostly style changes to make more consistent with style in vtkvis. Also
fix queueTGA -- no need to copy one scanline at a time and bytes per pixel can
be 3 or 4).

Location:
branches/vtkvis_threaded
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/vtkvis_threaded/CmdProc.cpp

    r2123 r2495  
    1010
    1111#include "CmdProc.h"
     12
     13using namespace Rappture;
    1214
    1315/**
     
    2224 */
    2325static int
    24 BinaryOpSearch(Rappture::CmdSpec *specs,
     26BinaryOpSearch(CmdSpec *specs,
    2527               int nSpecs,
    2628               char *string)       /* Name of minor operation to search for */
     
    3537    length = strlen(string);
    3638    while (low <= high) {
    37         Rappture::CmdSpec *specPtr;
     39        CmdSpec *specPtr;
    3840        int compare;
    3941        int median;
     
    7678 */
    7779static int
    78 LinearOpSearch(Rappture::CmdSpec *specs,
     80LinearOpSearch(CmdSpec *specs,
    7981               int nSpecs,
    8082               char *string)       /* Name of minor operation to search for */
    8183{
    82     Rappture::CmdSpec *specPtr;
     84    CmdSpec *specPtr;
    8385    char c;
    8486    size_t length;
     
    120122 */
    121123Tcl_ObjCmdProc *
    122 Rappture::GetOpFromObj(Tcl_Interp *interp,              /* Interpreter to report errors to */
    123                        int nSpecs,                      /* Number of specifications in array */
    124                        Rappture::CmdSpec *specs,        /* Op specification array */
    125                        int operPos,                     /* Position of operation in argument
    126                                                          * list. */
    127                        int objc,                        /* Number of arguments in the argument
    128                                                          * vector.  This includes any prefixed
    129                                                          * arguments */
    130                        Tcl_Obj *const *objv,            /* Argument vector */
     124Rappture::GetOpFromObj(Tcl_Interp *interp,      /* Interpreter to report errors to */
     125                       int nSpecs,              /* Number of specifications in array */
     126                       CmdSpec *specs,          /* Op specification array */
     127                       int operPos,             /* Position of operation in argument
     128                                                 * list. */
     129                       int objc,                /* Number of arguments in the argument
     130                                                 * vector.  This includes any prefixed
     131                                                 * arguments */
     132                       Tcl_Obj *const *objv,    /* Argument vector */
    131133                       int flags)
    132134{
  • branches/vtkvis_threaded/CmdProc.h

    r2123 r2495  
    1919 * for a function pointer associated with the operation name.
    2020 */
    21 typedef struct {
     21struct CmdSpec {
    2222    const char *name;           /**< Name of operation */
    2323    int minChars;               /**< Minimum # characters to disambiguate */
     
    2626    int maxArgs;                /**< Maximum # args required */
    2727    const char *usage;          /**< Usage message */
    28 } CmdSpec;
     28};
    2929
    30 typedef enum {
     30enum CmdSpecIndex {
    3131    CMDSPEC_ARG0,               /**< Op is the first argument. */
    3232    CMDSPEC_ARG1,               /**< Op is the second argument. */
     
    3434    CMDSPEC_ARG3,               /**< Op is the fourth argument. */
    3535    CMDSPEC_ARG4                /**< Op is the fifth argument. */
    36 } CmdSpecIndex;
     36};
    3737
    3838#define CMDSPEC_LINEAR_SEARCH   1
  • branches/vtkvis_threaded/Makefile.in

    r2488 r2495  
    8080                ColorMap.cpp \
    8181                PPMWriter.cpp \
    82                 ResponseQueue.cpp \
    8382                RpContour2D.cpp \
    8483                RpContour3D.cpp \
     
    10099ifdef USE_CUSTOM_AXES
    101100SERVER_SRCS+=vtkRpCubeAxesActor2D.cpp
     101endif
     102ifdef USE_THREADS
     103SERVER_SRCS+=ResponseQueue.cpp
    102104endif
    103105
     
    134136CmdProc.o: CmdProc.h
    135137ColorMap.o: ColorMap.h RpMolecule.h Trace.h
    136 PPMWriter.o: PPMWriter.h Trace.h
     138PPMWriter.o: PPMWriter.h ResponseQueue.h Trace.h
     139ResponseQueue.o: ResponseQueue.h Trace.h
    137140RpContour2D.o: RpContour2D.h RpVtkGraphicsObject.h RpVtkDataSet.h Trace.h
    138141RpContour3D.o: RpContour3D.h RpVtkGraphicsObject.h RpVtkDataSet.h ColorMap.h Trace.h
     
    147150RpVtkDataSet.o: RpVtkDataSet.h Trace.h
    148151RpVtkRenderer.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h
    149 RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h
    150 RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h Trace.h PPMWriter.h TGAWriter.h
     152RpVtkRendererCmd.o: RpVtkRenderer.h RpVtkDataSet.h RpContour2D.h RpContour3D.h RpGlyphs.h RpHeightMap.h RpLIC.h RpMolecule.h RpPolyData.h RpPseudoColor.h RpStreamlines.h RpVolume.h ColorMap.h ResponseQueue.h Trace.h CmdProc.h PPMWriter.h TGAWriter.h
     153RpVtkRenderServer.o: RpVtkRenderServer.h RpVtkRendererCmd.h RpVtkRenderer.h ResponseQueue.h Trace.h PPMWriter.h TGAWriter.h
    151154Trace.o: Trace.h
    152 TGAWriter.o: TGAWriter.h Trace.h
     155TGAWriter.o: TGAWriter.h ResponseQueue.h Trace.h
    153156vtkRpCubeAxesActor2D.o: vtkRpCubeAxesActor2D.h
  • branches/vtkvis_threaded/PPMWriter.cpp

    r2488 r2495  
    1010#include <cstring>
    1111#include <cerrno>
    12 #include <stdlib.h>
    1312#include <sys/uio.h>
    1413
     
    1716#ifdef USE_THREADS
    1817#include "ResponseQueue.h"
    19 #endif  /*USE_THREADS*/
     18#endif
    2019
    2120using namespace Rappture::VtkVis;
     21
     22#ifdef USE_THREADS
    2223
    2324/**
     
    3637 * to bottom scanlines.
    3738 *
    38  * \param[in] fd File descriptor that will be written to
     39 * \param[in] queue Pointer to ResponseQueue to write to
    3940 * \param[in] cmdName Command name to send (byte length will be appended)
    4041 * \param[in] data Image data
     
    4243 * \param[in] height Height of image in pixels
    4344 */
    44 
    45 #ifdef USE_THREADS
    4645void
    47 Rappture::VtkVis::QueuePPM(ResponseQueue *queuePtr, const char *cmdName,
     46Rappture::VtkVis::queuePPM(ResponseQueue *queue, const char *cmdName,
    4847                           const unsigned char *data, int width, int height)
    4948{
     
    5453    // Generate the PPM binary file header
    5554    snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height,
    56         PPM_MAXVAL);
     55             PPM_MAXVAL);
    5756
    5857    size_t headerLength = strlen(header);
     
    8887    }
    8988
    90     Response *responsePtr;
     89    Response *response;
    9190    if (strncmp(cmdName, "nv>legend", 9) == 0) {
    92         responsePtr = new Response(Response::LEGEND);
     91        response = new Response(Response::LEGEND);
    9392    } else {
    94         responsePtr = new Response(Response::IMAGE);
     93        response = new Response(Response::IMAGE);
    9594    }
    96     responsePtr->SetMessage(mesg, length, Response::DYNAMIC);
    97     queuePtr->Enqueue(responsePtr);
     95    response->setMessage(mesg, length, Response::DYNAMIC);
     96    queue->enqueue(response);
    9897    TRACE("Leaving (%dx%d)\n", width, height);
    9998}
    10099#else
    101100
     101/**
     102 * \brief Writes image data as PPM binary data to the client.
     103 *
     104 * The PPM binary format is very simple.
     105 *
     106 *     P6 w h 255\n
     107 *     3-byte RGB pixel data.
     108 *
     109 * The client (using the TkImg library) will do less work to unpack this
     110 * format, as opposed to BMP or PNG.
     111 *
     112 * Note that currently the image data has bottom to top scanlines.  This
     113 * routine could be made even simpler (faster) if the image data had top
     114 * to bottom scanlines.
     115 *
     116 * \param[in] fd File descriptor that will be written to
     117 * \param[in] cmdName Command name to send (byte length will be appended)
     118 * \param[in] data Image data
     119 * \param[in] width Width of image in pixels
     120 * \param[in] height Height of image in pixels
     121 */
    102122void
    103123Rappture::VtkVis::writePPM(int fd, const char *cmdName,
     
    109129    TRACE("Entering (%dx%d)\n", width, height);
    110130    // Generate the PPM binary file header
    111     snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height, PPM_MAXVAL);
     131    snprintf(header, sizeof(header), "P6 %d %d %d\n", width, height,
     132             PPM_MAXVAL);
    112133
    113134    size_t headerLength = strlen(header);
     
    141162    }
    142163    if (writev(fd, iov, nRecs) < 0) {
    143         ERROR("write failed: %s\n", strerror(errno));
     164        ERROR("write failed: %s\n", strerror(errno));
    144165    }
    145166    free(iov);
  • branches/vtkvis_threaded/PPMWriter.h

    r2488 r2495  
    1111#ifdef USE_THREADS
    1212#include "ResponseQueue.h"
    13 #endif /*USE_THREADS*/
     13#endif
    1414
    1515namespace Rappture {
    16     namespace VtkVis {
     16namespace VtkVis {
    1717#ifdef USE_THREADS
    18         extern void QueuePPM(ResponseQueue *queuePtr, const char *cmdName,
    19                              const unsigned char *data, int width, int height);
     18extern
     19void queuePPM(ResponseQueue *queue, const char *cmdName,
     20              const unsigned char *data, int width, int height);
    2021#else
    21         extern void writePPM(int fd, const char *cmdName,
    22                              const unsigned char *data, int width, int height);
    23 #endif  /*USE_THREADS*/
    24     }
     22extern
     23void writePPM(int fd, const char *cmdName,
     24              const unsigned char *data, int width, int height);
     25#endif
     26}
    2527}
    2628#endif
  • branches/vtkvis_threaded/ResponseQueue.cpp

    r2488 r2495  
    1 
    2 #ifdef USE_THREADS
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2/*
     3 * Copyright (C) 2011, Purdue Research Foundation
     4 *
     5 * Author: George A. Howlett <gah@purdue.edu>
     6 */
    37
    48#include <pthread.h>
    59#include <semaphore.h>
    6 #include <errno.h>
    7 #include <list>
    8 #include <stdlib.h>
    9 #include <errno.h>
     10#include <cerrno>
    1011#include <cstring>
    1112#include <cstdlib>
     13#include <list>
     14
    1215#include "Trace.h"
    1316#include "ResponseQueue.h"
    1417
    15 ResponseQueue::ResponseQueue(void *clientData)
     18using namespace Rappture::VtkVis;
     19
     20ResponseQueue::ResponseQueue(void *clientData)  :
     21    _clientData(clientData)
    1622{
    1723    pthread_mutex_init(&_idle, NULL);
    1824    if (sem_init(&_ready, 0, 0) < 0) {
    19         ERROR("can't initialize semaphore: %s", strerror(errno));
     25        ERROR("can't initialize semaphore: %s", strerror(errno));
    2026    }
    21     _clientData = clientData;
    2227}
    2328
    24 ResponseQueue::~ResponseQueue(void)
     29ResponseQueue::~ResponseQueue()
    2530{
    2631    pthread_mutex_destroy(&_idle);
    2732    if (sem_destroy(&_ready) < 0) {
    28         ERROR("can't destroy semaphore: %s", strerror(errno));
     33        ERROR("can't destroy semaphore: %s", strerror(errno));
    2934    }
    3035}
    3136
    3237void
    33 ResponseQueue::Enqueue(Response *responsePtr)
     38ResponseQueue::enqueue(Response *response)
    3439{
    3540    if (pthread_mutex_lock(&_idle) != 0) {
    36         ERROR("can't lock mutex: %s", strerror(errno));
     41        ERROR("can't lock mutex: %s", strerror(errno));
    3742    }   
    3843    /* Examine the list and remove any queued responses of the same type. */
    3944    INFO("before # of elements is %d\n", _list.size());
    40     std::list<Response *>::iterator iter;
    41     for (iter = _list.begin(); iter != _list.end(); iter++) {
    42         /* Remove any responses of the same type. There should be no more than
    43         * one. */
    44         if ((*iter)->Type() == responsePtr->Type()) {
    45             _list.erase(iter);
    46         }
     45    for (std::list<Response *>::iterator itr = _list.begin();
     46         itr != _list.end(); ++itr) {
     47        /* Remove any responses of the same type. There should be no more than
     48        * one. */
     49        if ((*itr)->type() == response->type()) {
     50            _list.erase(itr);
     51        }
    4752    }
    4853    /* Add the new response to the end of the list. */
    49     _list.push_back(responsePtr);
     54    _list.push_back(response);
    5055    if (sem_post(&_ready) < 0) {
    51         ERROR("can't post semaphore: %s", strerror(errno));
     56        ERROR("can't post semaphore: %s", strerror(errno));
    5257    }
    5358    if (pthread_mutex_unlock(&_idle) != 0) {
    54         ERROR("can't unlock mutex: %s", strerror(errno));
     59        ERROR("can't unlock mutex: %s", strerror(errno));
    5560    }   
    5661}
    5762
    5863Response *
    59 ResponseQueue::Dequeue(void)
     64ResponseQueue::dequeue()
    6065{
    61     Response *responsePtr;
     66    Response *response;
    6267
    6368    if (sem_wait(&_ready) < 0) {
    64         ERROR("can't wait on semaphore: %s", strerror(errno));
     69        ERROR("can't wait on semaphore: %s", strerror(errno));
    6570    }
    6671    if (pthread_mutex_lock(&_idle) != 0) {
    67         ERROR("can't lock mutex: %s", strerror(errno));
     72        ERROR("can't lock mutex: %s", strerror(errno));
    6873    }   
    69     responsePtr = _list.front();
     74    response = _list.front();
    7075    _list.pop_front();
    7176    if (pthread_mutex_unlock(&_idle) != 0) {
    72         ERROR("can't unlock mutex: %s", strerror(errno));
     77        ERROR("can't unlock mutex: %s", strerror(errno));
    7378    }   
    74     return responsePtr;
     79    return response;
    7580}
    76 
    77 #endif /*USE_THREADS*/
  • branches/vtkvis_threaded/ResponseQueue.h

    r2488 r2495  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2/*
     3 * Copyright (C) 2011, Purdue Research Foundation
     4 *
     5 * Author: George A. Howlett <gah@purdue.edu>
     6 */
    17
    28#include <pthread.h>
    39#include <semaphore.h>
     10#include <cstdlib>
    411#include <list>
    5 #include <stdlib.h>
    6 #include <cstdlib>
    712
    813#ifndef _RESPONSE_QUEUE_H
    914#define _RESPONSE_QUEUE_H
    1015
     16namespace Rappture {
     17namespace VtkVis {
    1118
    12 class Response {
     19class Response
     20{
    1321public:
    14     typedef enum AllocTypes {
    15         STATIC, DYNAMIC, VOLATILE
    16     } AllocationType;
    17     typedef enum ResponseTypes {
    18         IMAGE,                          /* Image to be displayed. */
    19         LEGEND,                         /* Legend to be displayed. */
    20         DATA                            /* Any other type of message. */
    21     } ResponseType;
    22     Response(ResponseType type) {
    23         _length = 0;
    24         _type = type;
    25         _mesg = NULL;
     22    enum AllocationType {
     23        STATIC,
     24        DYNAMIC,
     25        VOLATILE
     26    };
     27    enum ResponseType {
     28        IMAGE,          /**< Image to be displayed. */
     29        LEGEND,         /**< Legend to be displayed. */
     30        DATA            /**< Any other type of message. */
     31    };
     32
     33    Response(ResponseType type) :
     34        _mesg(NULL),
     35        _length(0),
     36        _type(type)
     37    {
    2638    }
    27     ResponseType Type(void) {
    28         return _type;
    29     }
    30     unsigned char *Message(void) {
    31         return _mesg;
    32     }
    33     size_t Length(void) {
    34         return _length;
    35     }
    36     ~Response(void) {
     39
     40    virtual ~Response()
     41    {
    3742        if (_length > 0) {
    3843            if (_allocType == DYNAMIC) {
     
    4146        }
    4247    }
    43     void SetMessage(unsigned char *mesg, size_t length, AllocationType type) {
     48
     49    ResponseType type()
     50    {
     51        return _type;
     52    }
     53
     54    unsigned char *message()
     55    {
     56        return _mesg;
     57    }
     58
     59    size_t length()
     60    {
     61        return _length;
     62    }
     63
     64    void setMessage(unsigned char *mesg, size_t length, AllocationType type)
     65    {
    4466        if (type == VOLATILE) {
    4567            _length = length;
     
    5375        }
    5476    }
     77
    5578private:
    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. */
     79    /**
     80     * (Malloc-ed by caller, freed by destructor)
     81     * Contains the message/bytes to be sent to the client. */
     82    unsigned char *_mesg;
     83    size_t _length;       /**< # of bytes in the above message. */
    6184    ResponseType _type;
    6285    AllocationType _allocType;
    6386};
    6487
    65 class ResponseQueue {
     88class ResponseQueue
     89{
     90public:
     91    ResponseQueue(void *clientData);
     92
     93    virtual ~ResponseQueue();
     94
     95    void *clientData()
     96    {
     97        return _clientData;
     98    }
     99
     100    void enqueue(Response *response);
     101
     102    Response *dequeue();
     103
     104private:
    66105    pthread_mutex_t _idle;
    67     sem_t _ready;                       /* Semaphore indicating that a
    68                                          * response has been queued. */
     106    sem_t _ready; /**< Semaphore indicating that a response has been queued. */
    69107    std::list<Response *> _list;
    70108    void *_clientData;
    71 
    72 public:
    73     ResponseQueue(void *clientData);
    74     ~ResponseQueue(void);
    75     void *ClientData(void) {
    76         return _clientData;
    77     }
    78     void Enqueue(Response *responsePtr);
    79     Response *Dequeue();
    80109};
    81110
     111}
     112}
     113
    82114#endif
  • branches/vtkvis_threaded/RpVtkRenderServer.cpp

    r2488 r2495  
    1010#include <cstring>
    1111#include <cstdlib>
    12 #include <string>
    13 #include <sstream>
     12#include <cerrno>
    1413#include <unistd.h>
    1514#include <signal.h>
    16 #include <errno.h>
    1715
    1816#ifdef WANT_TRACE
    1917#include <sys/time.h>
    2018#endif
     19
     20#include <string>
     21#include <sstream>
    2122
    2223#include "Trace.h"
     
    2930#include <pthread.h>
    3031#include "ResponseQueue.h"
    31 #endif  /*USE_THREADS*/
     32#endif
    3233
    3334using namespace Rappture::VtkVis;
     
    4647#ifdef USE_THREADS
    4748static void
    48 QueueFrame(ResponseQueue *queuePtr, vtkUnsignedCharArray *imgData)
     49queueFrame(ResponseQueue *queue, vtkUnsignedCharArray *imgData)
    4950{
    5051#ifdef DEBUG
     
    8990
    9091#ifdef RENDER_TARGA
    91         QueueTGA(queuePtr, oss.str().c_str(),
    92                  imgData->GetPointer(0),
    93                  g_renderer->getWindowWidth(),
    94                  g_renderer->getWindowHeight(),
    95                  TARGA_BYTES_PER_PIXEL);
    96 #else
    97         QueuePPM(queuePtr, oss.str().c_str(),
     92        queueTGA(queue, oss.str().c_str(),
     93                 imgData->GetPointer(0),
     94                 g_renderer->getWindowWidth(),
     95                 g_renderer->getWindowHeight(),
     96                 TARGA_BYTES_PER_PIXEL);
     97#else
     98        queuePPM(queue, oss.str().c_str(),
    9899                 imgData->GetPointer(0),
    99100                 g_renderer->getWindowWidth(),
     
    102103    } else {
    103104#ifdef RENDER_TARGA
    104         QueueTGA(queuePtr, "nv>image -type image -bytes",
    105                  imgData->GetPointer(0),
    106                  g_renderer->getWindowWidth(),
    107                  g_renderer->getWindowHeight(),
    108                  TARGA_BYTES_PER_PIXEL);
    109 #else
    110         QueuePPM(queuePtr, "nv>image -type image -bytes",
     105        queueTGA(queue, "nv>image -type image -bytes",
     106                 imgData->GetPointer(0),
     107                 g_renderer->getWindowWidth(),
     108                 g_renderer->getWindowHeight(),
     109                 TARGA_BYTES_PER_PIXEL);
     110#else
     111        queuePPM(queue, "nv>image -type image -bytes",
    111112                 imgData->GetPointer(0),
    112113                 g_renderer->getWindowWidth(),
     
    237238#ifdef USE_THREADS
    238239static void *
    239 ReaderThread(void *clientData)
    240 {
    241     ResponseQueue *queuePtr = (ResponseQueue *)clientData;
     240readerThread(void *clientData)
     241{
     242    ResponseQueue *queue = (ResponseQueue *)clientData;
    242243    Tcl_Interp *interp;
    243244
    244245    INFO("starting reader thread");
    245     interp = (Tcl_Interp *)queuePtr->ClientData();
     246    interp = (Tcl_Interp *)queue->clientData();
    246247    vtkSmartPointer<vtkUnsignedCharArray> imgData =
    247248        vtkSmartPointer<vtkUnsignedCharArray>::New();
     
    255256            TRACE("Rendering new frame");
    256257            g_renderer->getRenderedFrame(imgData);
    257             QueueFrame(queuePtr, imgData);
     258            queueFrame(queue, imgData);
    258259        } else {
    259260            TRACE("No render required");
     
    266267
    267268static void *
    268 WriterThread(void *clientData)
    269 {
    270     ResponseQueue *queuePtr = (ResponseQueue *)clientData;
     269writerThread(void *clientData)
     270{
     271    ResponseQueue *queue = (ResponseQueue *)clientData;
    271272
    272273    INFO("starting writer thread");
    273274    for (;;) {
    274         Response *responsePtr;
    275 
    276         responsePtr = queuePtr->Dequeue();
    277         if (fwrite(responsePtr->Message(), sizeof(char), responsePtr->Length(),
    278                    g_fOut) != responsePtr->Length()) {
     275        Response *response;
     276
     277        response = queue->dequeue();
     278        if (fwrite(response->message(), sizeof(char), response->length(),
     279                   g_fOut) != response->length()) {
    279280            ERROR("short write while trying to write %ld bytes",
    280                   responsePtr->Length());
     281                  response->length());
    281282        }
    282283        fflush(g_fOut);
    283         delete responsePtr;
     284        delete response;
    284285        if (feof(g_fOut))
    285286            break;
     
    296297    signal(SIGPIPE, SIG_IGN);
    297298    initService();
    298     InitLog();
     299    initLog();
    299300
    300301    TRACE("Starting VTKVis Server");
     
    321322
    322323    pthread_t readerThreadId, writerThreadId;
    323     if (pthread_create(&readerThreadId, NULL, &ReaderThread, &queue) < 0) {
     324    if (pthread_create(&readerThreadId, NULL, &readerThread, &queue) < 0) {
    324325        ERROR("can't create reader thread: %s", strerror(errno));
    325326    }
    326     if (pthread_create(&writerThreadId, NULL, &WriterThread, &queue) < 0) {
     327    if (pthread_create(&writerThreadId, NULL, &writerThread, &queue) < 0) {
    327328        ERROR("can't create writer thread: %s", strerror(errno));
    328329    }
     
    365366    TRACE("Exiting VTKVis Server");
    366367
    367     CloseLog();
     368    closeLog();
    368369    exitService();
    369370
  • branches/vtkvis_threaded/RpVtkRendererCmd.cpp

    r2488 r2495  
    2525#ifdef USE_THREADS
    2626#include "ResponseQueue.h"
    27 #endif  /*USE_THREADS*/
     27#endif
    2828
    2929using namespace Rappture::VtkVis;
     
    3434static void
    3535QueueResponse(ClientData clientData, const void *bytes, size_t len,
    36              Response::AllocationType allocType)
    37 {
    38     ResponseQueue *queuePtr = (ResponseQueue *)clientData;
    39 
    40     Response *responsePtr;
    41    
    42     responsePtr = new Response(Response::DATA);
    43     responsePtr->SetMessage((unsigned char *)bytes, len, allocType);
    44     queuePtr->Enqueue(responsePtr);
     36              Response::AllocationType allocType)
     37{
     38    ResponseQueue *queue = (ResponseQueue *)clientData;
     39
     40    Response *response;
     41
     42    response = new Response(Response::DATA);
     43    response->setMessage((unsigned char *)bytes, len, allocType);
     44    queue->enqueue(response);
    4545}
    4646#else
     
    26882688#else
    26892689#ifdef USE_THREADS
    2690     ResponseQueue *queuePtr = (ResponseQueue *)clientData;
    2691     QueuePPM(queuePtr, cmd, imgData->GetPointer(0), width, height);
     2690    ResponseQueue *queue = (ResponseQueue *)clientData;
     2691    queuePPM(queue, cmd, imgData->GetPointer(0), width, height);
    26922692#else
    26932693    writePPM(g_fdOut, cmd, imgData->GetPointer(0), width, height);
  • branches/vtkvis_threaded/RpVtkRendererCmd.h

    r2482 r2495  
    1313
    1414namespace Rappture {
    15     namespace VtkVis {
    16         extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout);
    17         extern void initTcl(Tcl_Interp *interp, ClientData clientData);
    18         extern void exitTcl(Tcl_Interp *interp);
    19     }
     15namespace VtkVis {
     16
     17extern int processCommands(Tcl_Interp *interp, FILE *fin, FILE *fout);
     18extern void initTcl(Tcl_Interp *interp, ClientData clientData);
     19extern void exitTcl(Tcl_Interp *interp);
     20
     21}
    2022}
    2123
  • branches/vtkvis_threaded/TGAWriter.cpp

    r2488 r2495  
    1919#ifdef USE_THREADS
    2020#include "ResponseQueue.h"
    21 #endif  /*USE_THREADS*/
     21#endif
     22
     23#ifdef USE_THREADS
    2224
    2325/**
     
    2729 * top scanline ordering.
    2830 *
    29  * \param[in] fd File descriptor that will be written to
     31 * \param[in] queue Pointer to ResponseQueue to write to
    3032 * \param[in] cmdName Command name to send (byte length will be appended)
    3133 * \param[in] data Image data
     
    3436 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha
    3537 */
    36 #ifdef USE_THREADS
    3738void
    38 Rappture::VtkVis::QueueTGA(ResponseQueue *queuePtr, const char *cmdName,
     39Rappture::VtkVis::queueTGA(ResponseQueue *queue, const char *cmdName,
    3940                           const unsigned char *data,
    4041                           int width, int height,
     
    5960    char command[200];
    6061    cmdLength = snprintf(command, sizeof(command), "%s %lu\n", cmdName,
    61              (unsigned long)headerLength + dataLength);
     62                         (unsigned long)headerLength + dataLength);
    6263
    6364    size_t length;
    64     unsigned char *mesg;
     65    unsigned char *mesg = NULL;
    6566
    6667    length = headerLength + dataLength + cmdLength;
     
    7273    memcpy(mesg, command, cmdLength);
    7374    memcpy(mesg + cmdLength, header, headerLength);
    74 
    75     size_t bytesPerRow = width * 3;
    76     unsigned char *destRowPtr = mesg + cmdLength + headerLength;
    77     int y;
    78     unsigned char *srcRowPtr = const_cast<unsigned char *>(data);
    79     for (y = 0; y < height; y++) {
    80         memcpy(destRowPtr, srcRowPtr, bytesPerRow);
    81         srcRowPtr += bytesPerRow;
    82         destRowPtr += bytesPerRow;
    83     }
    84 
    85     Response *responsePtr;
     75    memcpy(mesg + cmdLength + headerLength,
     76           const_cast<unsigned char *>(data), dataLength);
     77
     78    Response *response = NULL;
    8679    if (strncmp(cmdName, "nv>legend", 9) == 0) {
    87         responsePtr = new Response(Response::LEGEND);
     80        response = new Response(Response::LEGEND);
    8881    } else {
    89         responsePtr = new Response(Response::IMAGE);
    90     }
    91     responsePtr->SetMessage(mesg, length, Response::DYNAMIC);
    92     queuePtr->Enqueue(responsePtr);
     82        response = new Response(Response::IMAGE);
     83    }
     84    response->setMessage(mesg, length, Response::DYNAMIC);
     85    queue->enqueue(response);
    9386    TRACE("Leaving (%dx%d)\n", width, height);
    9487}
    9588#else
    9689
     90/**
     91 * \brief Writes image command + data to supplied file descriptor.
     92 *
     93 * The image data must be supplied in BGR(A) order with bottom to
     94 * top scanline ordering.
     95 *
     96 * \param[in] fd File descriptor that will be written to
     97 * \param[in] cmdName Command name to send (byte length will be appended)
     98 * \param[in] data Image data
     99 * \param[in] width Width of image in pixels
     100 * \param[in] height Height of image in pixels
     101 * \param[in] bytesPerPixel Should be 3 or 4, depending on alpha
     102 */
    97103void
    98104Rappture::VtkVis::writeTGA(int fd, const char *cmdName,
  • branches/vtkvis_threaded/TGAWriter.h

    r2488 r2495  
    1111#ifdef USE_THREADS
    1212#include "ResponseQueue.h"
    13 #endif /*USE_THREADS*/
     13#endif
    1414
    1515namespace Rappture {
    16     namespace VtkVis {
     16namespace VtkVis {
    1717#ifdef USE_THREADS
    18         extern void QueueTGA(ResponseQueue *queuePtr, const char *cmdName,
    19                 const unsigned char *data, int width, int height,
    20                 int bytesPerPixel);
     18extern
     19void queueTGA(ResponseQueue *queue, const char *cmdName,
     20              const unsigned char *data, int width, int height,
     21              int bytesPerPixel);
    2122#else
    22         extern void writeTGA(int fd, const char *cmdName,
    23                 const unsigned char *data, int width, int height,
    24                 int bytesPerPixel);
    25 #endif  /*USE_THREADS*/
    26         extern void writeTGAFile(const char *filename,
    27                 const unsigned char *data, int width, int height,
    28                 int bytesPerPixel, bool srcIsRGB = false);
    29     }
     23extern
     24void writeTGA(int fd, const char *cmdName,
     25              const unsigned char *data, int width, int height,
     26              int bytesPerPixel);
     27#endif
     28extern
     29void writeTGAFile(const char *filename,
     30                  const unsigned char *data, int width, int height,
     31                  int bytesPerPixel, bool srcIsRGB = false);
     32}
    3033}
    3134
    32 #endif  /*__RAPPTURE_VTKVIS_TGA_WRITER_H__*/
     35#endif
  • branches/vtkvis_threaded/Trace.cpp

    r2100 r2495  
    2121 */
    2222void
    23 Rappture::VtkVis::InitLog()
     23Rappture::VtkVis::initLog()
    2424{
    2525    openlog("vtkvis", LOG_CONS | LOG_PERROR | LOG_PID,  LOG_USER);
     
    3030 */
    3131void
    32 Rappture::VtkVis::CloseLog()
     32Rappture::VtkVis::closeLog()
    3333{
    3434    closelog();
     
    3939 */
    4040void
    41 Rappture::VtkVis::LogMessage(int priority, const char *funcname,
     41Rappture::VtkVis::logMessage(int priority, const char *funcname,
    4242                             const char *path, int lineNum, const char* fmt, ...)
    4343{
  • branches/vtkvis_threaded/Trace.h

    r2482 r2495  
    1414namespace VtkVis {
    1515
    16 extern void InitLog();
     16extern void initLog();
    1717
    18 extern void CloseLog();
     18extern void closeLog();
    1919
    20 extern void LogMessage(int priority, const char *funcname, const char *fileName,
     20extern void logMessage(int priority, const char *funcname, const char *fileName,
    2121                       int lineNum, const char* format, ...);
    2222
    23 #define ERROR(...)      Rappture::VtkVis::LogMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     23#define ERROR(...)      Rappture::VtkVis::logMessage(LOG_ERR, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    2424#ifdef WANT_TRACE
    25 #define TRACE(...)      Rappture::VtkVis::LogMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     25#define TRACE(...)      Rappture::VtkVis::logMessage(LOG_DEBUG, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    2626#else
    2727#define TRACE(...)
    2828#endif  /*WANT_TRACE*/
    29 #define WARN(...)       Rappture::VtkVis::LogMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    30 #define INFO(...)       Rappture::VtkVis::LogMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     29#define WARN(...)       Rappture::VtkVis::logMessage(LOG_WARNING, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
     30#define INFO(...)       Rappture::VtkVis::logMessage(LOG_INFO, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
    3131
    3232}
Note: See TracChangeset for help on using the changeset viewer.