pqEventRecorder.cxx 6.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*=========================================================================

   Program: ParaView
   Module:    pqEventDispatcher.h

   Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

// Qt includes
#include <QIODevice>
#include <QTextStream>

// QtTesting includes
#include "pqEventObserver.h"
#include "pqEventRecorder.h"
#include "pqEventTranslator.h"

// ----------------------------------------------------------------------------
pqEventRecorder::pqEventRecorder(QObject *parent)
  : Superclass(parent)
{
  this->ActiveObserver = 0;
  this->ActiveTranslator = 0;
48
  this->File = 0;
49

50
  this->Recording = false;
51 52 53 54 55 56 57 58 59 60 61 62 63
  this->ContinuousFlush = false;
}

// ----------------------------------------------------------------------------
pqEventRecorder::~pqEventRecorder()
{
  this->ActiveObserver = 0;
  this->ActiveTranslator = 0;
}

// ----------------------------------------------------------------------------
void pqEventRecorder::setContinuousFlush(bool value)
{
64 65 66 67 68
  if (!this->ActiveObserver)
    {
    return;
    }

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
  if (value)
    {
    QObject::connect(this->ActiveObserver,
                     SIGNAL(eventRecorded(QString,QString,QString)),
                     this, SLOT(flush()));
    }
  else
    {
    QObject::disconnect(this->ActiveObserver,
                        SIGNAL(eventRecorded(QString,QString,QString)),
                        this, SLOT(flush()));
    }
  this->ContinuousFlush = value;
}

// ----------------------------------------------------------------------------
bool pqEventRecorder::continuousFlush() const
{
  return this->ContinuousFlush;
}

// ----------------------------------------------------------------------------
void pqEventRecorder::setFile(QIODevice* file)
{
  this->File = file;
}

// ----------------------------------------------------------------------------
QIODevice* pqEventRecorder::file() const
{
  return this->File;
}

// ----------------------------------------------------------------------------
void pqEventRecorder::setObserver(pqEventObserver* observer)
{
  this->ActiveObserver = observer;
}

// ----------------------------------------------------------------------------
pqEventObserver* pqEventRecorder::observer() const
{
  return this->ActiveObserver;
}

// ----------------------------------------------------------------------------
void pqEventRecorder::setTranslator(pqEventTranslator* translator)
{
  this->ActiveTranslator = translator;
}

// ----------------------------------------------------------------------------
pqEventTranslator* pqEventRecorder::translator() const
{
  return this->ActiveTranslator;
}

126 127 128 129 130 131
// ----------------------------------------------------------------------------
bool pqEventRecorder::isRecording() const
{
  return this->Recording;
}

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
// ----------------------------------------------------------------------------
void pqEventRecorder::recordEvents(pqEventTranslator* translator,
                                   pqEventObserver* observer,
                                   QIODevice* file,
                                   bool continuousFlush)
{
  this->setTranslator(translator);
  this->setObserver(observer);
  this->setFile(file);
  this->setContinuousFlush(continuousFlush);

  this->start();
}

// ----------------------------------------------------------------------------
void pqEventRecorder::flush()
{
  this->Stream.flush();
}

// ----------------------------------------------------------------------------
void pqEventRecorder::start()
{
  if (!this->File || !this->ActiveObserver || !this->ActiveTranslator)
    {
    return;
    }

  QObject::connect(
    this->ActiveTranslator,
    SIGNAL(recordEvent(QString,QString,QString)),
    this->ActiveObserver,
    SLOT(onRecordEvent(QString,QString,QString)));

  // Set the device
  this->Stream.setDevice(this->File);

  // Set the Stream to the Observer
  this->ActiveObserver->setStream(&this->Stream);

  // Start the Translator
  this->ActiveTranslator->start();

175
  this->Recording = true;
176 177 178 179
  emit this->started();
}

// ----------------------------------------------------------------------------
180
void pqEventRecorder::stop(int value)
181 182 183 184 185 186 187 188 189 190
{
  QObject::disconnect(
    this->ActiveTranslator,
    SIGNAL(recordEvent(QString,QString,QString)),
    this->ActiveObserver,
    SLOT(onRecordEvent(QString,QString,QString)));

  this->ActiveObserver->setStream(NULL);
  this->ActiveTranslator->stop();

191 192
  this->Recording = false;

193 194 195 196 197 198
  if (!value)
    {
    return;
    }

  this->flush();
199 200 201 202
  emit this->stopped();
}

// ----------------------------------------------------------------------------
203
void pqEventRecorder::pause(bool value)
204
{
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  if (!value)
    {
    QObject::disconnect(
      this->ActiveTranslator,
      SIGNAL(recordEvent(QString,QString,QString)),
      this->ActiveObserver,
      SLOT(onRecordEvent(QString,QString,QString)));
    }
  else
    {
    QObject::connect(
      this->ActiveTranslator,
      SIGNAL(recordEvent(QString,QString,QString)),
      this->ActiveObserver,
      SLOT(onRecordEvent(QString,QString,QString)),
      Qt::UniqueConnection);
    }

  this->Recording = value;
  emit this->paused(value);
225
}