domprocessor.h

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Gav Wood                                        *
00003  *   gav@cs.york.ac.uk                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  ***************************************************************************/
00010 #ifndef _GEDDEI_DOMPROCESSOR_H
00011 #define _GEDDEI_DOMPROCESSOR_H
00012 
00013 #include <qmutex.h>
00014 #include <qptrlist.h>
00015 
00016 #ifdef __GEDDEI_BUILD
00017 #include "properties.h"
00018 #include "processor.h"
00019 #include "qfastwaitcondition.h"
00020 #else
00021 #include <qtextra/qfastwaitcondition.h>
00022 #include <geddei/properties.h>
00023 #include <geddei/processor.h>
00024 #endif
00025 
00026 namespace Geddei
00027 {
00028 
00029 class DSCoupling;
00030 class DxCoupling;
00031 class SubProcessor;
00032 
00077 class DomProcessor: public Processor
00078 {
00079  //* Attributes of the data processing pipeline.
00080  uint theSamplesIn, theSamplesStep, theSamplesOut;
00081 
00082  //* Attributes that define how much data we want to take in normally.
00083  uint theNomChunks, theMaxChunks;
00084  double theWeighting;
00085  bool theAlterBuffer;
00086  uint theOptimalThroughput, theWantSize;
00087 
00088  //* Queue management stuff.
00089  QPtrList<DxCoupling> theWorkers;
00090  QPtrList<DxCoupling>::Iterator theQueuePos;
00091  uint theQueueLen;
00092  QMutex theQueueLock;
00093  QFastWaitCondition theQueueChanged;
00094 
00095  //* A flag to tell us if we've been stopped.
00096  bool theStopped;
00097  
00098  //* A flag to tell us if we should debug our action.
00099  bool theDebug;
00100  
00101  //* Settings for the load sharing stuff.
00102  bool theBalanceLoad;
00103  uint theBalanceInterval;
00104  float theLocalFudge;
00105  
00106  //* A cache of our properties, since we may need it after init.
00107  Properties theProperties;
00108 
00113  bool theLimbo;
00114 
00115  //* Primary processor references.
00116  friend class DxCoupling;
00117  SubProcessor *thePrimary;
00118  DSCoupling *thePrimaryCoupling;
00119 
00120  //* A quick QThread object for running eater().
00121  class EaterThread: public QThread
00122  {
00123   DomProcessor *theDomProcessor;
00124   virtual void run();
00125  public:
00126   EaterThread(DomProcessor *d) : theDomProcessor(d) {}
00127   virtual ~EaterThread() {}
00128  } theEaterThread;
00129 
00134  void eater();
00135 
00142  void checkExitDontLock();
00143 
00162  void setupVisual(const uint width = 50, const uint height = 30, const uint redrawPeriod = 0) { Processor::setupVisual(width, height, redrawPeriod); }
00163  friend class SubProcessor;
00164 
00165  //* Reimplementations from Processor.
00166  virtual const bool processorStarted();
00167  virtual void processor();
00168  virtual void wantToStopNow();
00169  virtual void haveStoppedNow();
00170  virtual const bool verifyAndSpecifyTypes(const SignalTypeRefs &inTypes, SignalTypeRefs &outTypes);
00171  virtual PropertiesInfo specifyProperties() const;
00172  virtual void initFromProperties(const Properties &properties);
00173  virtual void specifyInputSpace(QValueVector<uint> &samples);
00174  virtual void specifyOutputSpace(QValueVector<uint> &samples);
00175  virtual void paintProcessor(QPainter &p);
00176 
00183  virtual void checkExit();
00184 
00194  void addWorker(SubProcessor *worker);
00195 
00196 public:
00205  void ratify(DxCoupling *c);
00206  
00217  const bool createAndAddWorker();
00218 
00228  const bool createAndAddWorker(const QString &host, const uint key);
00229 
00237  DomProcessor(SubProcessor *primary);
00238 
00245  DomProcessor(const QString &primaryType);
00246 
00250  virtual ~DomProcessor();
00251 };
00252 
00253 };
00254 
00255 #endif

Generated on Fri Nov 10 21:58:26 2006 for Exscalibar by  doxygen 1.5.1