Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
DotManager Class Reference

#include <dot.h>

Public Member Functions

void addRun (DotRunner *run)
 
int addMap (const QCString &file, const QCString &mapFile, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &label)
 
int addFigure (const QCString &file, const QCString &baseName, const QCString &figureName, bool heightCheck)
 
int addSVGConversion (const QCString &file, const QCString &relPath, bool urlOnly, const QCString &context, bool zoomable, int graphId)
 
int addSVGObject (const QCString &file, const QCString &baseName, const QCString &figureNAme, const QCString &relPath)
 
bool run ()
 

Static Public Member Functions

static DotManagerinstance ()
 

Private Member Functions

 DotManager ()
 
virtual ~DotManager ()
 

Private Attributes

QList< DotRunnerm_dotRuns
 
SDict< DotFilePatcherm_dotMaps
 
DotRunnerQueuem_queue
 
QList< DotWorkerThreadm_workers
 

Static Private Attributes

static DotManagerm_theInstance = 0
 

Detailed Description

Singleton that manages dot relation actions

Definition at line 454 of file dot.h.

Constructor & Destructor Documentation

DotManager::DotManager ( )
private

Definition at line 1230 of file dot.cpp.

1230  : m_dotMaps(1009)
1231 {
1234  m_queue = new DotRunnerQueue;
1235  int i;
1236  int numThreads = QMIN(32,Config_getInt("DOT_NUM_THREADS"));
1237  if (numThreads!=1)
1238  {
1239  if (numThreads==0) numThreads = QMAX(2,QThread::idealThreadCount()+1);
1240  for (i=0;i<numThreads;i++)
1241  {
1242  DotWorkerThread *thread = new DotWorkerThread(m_queue);
1243  thread->start();
1244  if (thread->isRunning())
1245  {
1246  m_workers.append(thread);
1247  }
1248  else // no more threads available!
1249  {
1250  delete thread;
1251  }
1252  }
1253  ASSERT(m_workers.count()>0);
1254  }
1255 }
void append(const type *d)
Definition: qlist.h:73
void start()
void setAutoDelete(bool val)
Definition: sortdict.h:222
#define QMIN(a, b)
Definition: qglobal.h:391
#define Config_getInt(val)
Definition: config.cpp:661
uint count() const
Definition: qlist.h:66
QList< DotRunner > m_dotRuns
Definition: dot.h:473
#define QMAX(a, b)
Definition: qglobal.h:390
bool isRunning() const
Definition: qthread.cpp:64
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
QList< DotWorkerThread > m_workers
Definition: dot.h:477
DotRunnerQueue * m_queue
Definition: dot.h:476
void setAutoDelete(bool enable)
Definition: qlist.h:99
const bool TRUE
Definition: qglobal.h:371
#define ASSERT(x)
Definition: qglobal.h:590
static int idealThreadCount()
DotManager::~DotManager ( )
privatevirtual

Definition at line 1257 of file dot.cpp.

1258 {
1259  delete m_queue;
1260 }
DotRunnerQueue * m_queue
Definition: dot.h:476

Member Function Documentation

int DotManager::addFigure ( const QCString file,
const QCString baseName,
const QCString figureName,
bool  heightCheck 
)

Definition at line 1280 of file dot.cpp.

1282 {
1283  DotFilePatcher *map = m_dotMaps.find(file);
1284  if (map==0)
1285  {
1286  map = new DotFilePatcher(file);
1287  m_dotMaps.append(file,map);
1288  }
1289  return map->addFigure(baseName,figureName,heightCheck);
1290 }
void append(const char *key, const T *d)
Definition: sortdict.h:135
int addFigure(const QCString &baseName, const QCString &figureName, bool heightCheck)
Definition: dot.cpp:902
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
T * find(const char *key)
Definition: sortdict.h:232
int DotManager::addMap ( const QCString file,
const QCString mapFile,
const QCString relPath,
bool  urlOnly,
const QCString context,
const QCString label 
)

Definition at line 1267 of file dot.cpp.

1270 {
1271  DotFilePatcher *map = m_dotMaps.find(file);
1272  if (map==0)
1273  {
1274  map = new DotFilePatcher(file);
1275  m_dotMaps.append(file,map);
1276  }
1277  return map->addMap(mapFile,relPath,urlOnly,context,label);
1278 }
void append(const char *key, const T *d)
Definition: sortdict.h:135
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
int addMap(const QCString &mapFile, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &label)
Definition: dot.cpp:886
T * find(const char *key)
Definition: sortdict.h:232
void DotManager::addRun ( DotRunner run)

Definition at line 1262 of file dot.cpp.

1263 {
1264  m_dotRuns.append(run);
1265 }
void append(const type *d)
Definition: qlist.h:73
QList< DotRunner > m_dotRuns
Definition: dot.h:473
int DotManager::addSVGConversion ( const QCString file,
const QCString relPath,
bool  urlOnly,
const QCString context,
bool  zoomable,
int  graphId 
)

Definition at line 1292 of file dot.cpp.

1295 {
1296  DotFilePatcher *map = m_dotMaps.find(file);
1297  if (map==0)
1298  {
1299  map = new DotFilePatcher(file);
1300  m_dotMaps.append(file,map);
1301  }
1302  return map->addSVGConversion(relPath,urlOnly,context,zoomable,graphId);
1303 }
void append(const char *key, const T *d)
Definition: sortdict.h:135
int addSVGConversion(const QCString &relPath, bool urlOnly, const QCString &context, bool zoomable, int graphId)
Definition: dot.cpp:916
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
T * find(const char *key)
Definition: sortdict.h:232
int DotManager::addSVGObject ( const QCString file,
const QCString baseName,
const QCString figureNAme,
const QCString relPath 
)

Definition at line 1305 of file dot.cpp.

1307 {
1308  DotFilePatcher *map = m_dotMaps.find(file);
1309  if (map==0)
1310  {
1311  map = new DotFilePatcher(file);
1312  m_dotMaps.append(file,map);
1313  }
1314  return map->addSVGObject(baseName,absImgName,relPath);
1315 }
void append(const char *key, const T *d)
Definition: sortdict.h:135
int addSVGObject(const QCString &baseName, const QCString &figureName, const QCString &relPath)
Definition: dot.cpp:931
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
T * find(const char *key)
Definition: sortdict.h:232
DotManager * DotManager::instance ( )
static

Definition at line 1221 of file dot.cpp.

1222 {
1223  if (!m_theInstance)
1224  {
1225  m_theInstance = new DotManager;
1226  }
1227  return m_theInstance;
1228 }
DotManager()
Definition: dot.cpp:1230
static DotManager * m_theInstance
Definition: dot.h:475
bool DotManager::run ( )

Definition at line 1317 of file dot.cpp.

1318 {
1319  uint numDotRuns = m_dotRuns.count();
1320  uint numDotMaps = m_dotMaps.count();
1321  if (numDotRuns+numDotMaps>1)
1322  {
1323  if (m_workers.count()==0)
1324  {
1325  msg("Generating dot graphs in single threaded mode...\n");
1326  }
1327  else
1328  {
1329  msg("Generating dot graphs using %d parallel threads...\n",QMIN(numDotRuns+numDotMaps,m_workers.count()));
1330  }
1331  }
1332  int i=1;
1334 
1335  bool setPath=FALSE;
1336  if (Config_getBool("GENERATE_HTML"))
1337  {
1338  setDotFontPath(Config_getString("HTML_OUTPUT"));
1339  setPath=TRUE;
1340  }
1341  else if (Config_getBool("GENERATE_LATEX"))
1342  {
1343  setDotFontPath(Config_getString("LATEX_OUTPUT"));
1344  setPath=TRUE;
1345  }
1346  else if (Config_getBool("GENERATE_RTF"))
1347  {
1348  setDotFontPath(Config_getString("RTF_OUTPUT"));
1349  setPath=TRUE;
1350  }
1352  // fill work queue with dot operations
1353  DotRunner *dr;
1354  int prev=1;
1355  if (m_workers.count()==0) // no threads to work with
1356  {
1357  for (li.toFirst();(dr=li.current());++li)
1358  {
1359  msg("Running dot for graph %d/%d\n",prev,numDotRuns);
1360  dr->run();
1361  prev++;
1362  }
1363  }
1364  else // use multiple threads to run instances of dot in parallel
1365  {
1366  for (li.toFirst();(dr=li.current());++li)
1367  {
1368  m_queue->enqueue(dr);
1369  }
1370  // wait for the queue to become empty
1371  while ((i=m_queue->count())>0)
1372  {
1373  i = numDotRuns - i;
1374  while (i>=prev)
1375  {
1376  msg("Running dot for graph %d/%d\n",prev,numDotRuns);
1377  prev++;
1378  }
1379  portable_sleep(100);
1380  }
1381  while ((int)numDotRuns>=prev)
1382  {
1383  msg("Running dot for graph %d/%d\n",prev,numDotRuns);
1384  prev++;
1385  }
1386  // signal the workers we are done
1387  for (i=0;i<(int)m_workers.count();i++)
1388  {
1389  m_queue->enqueue(0); // add terminator for each worker
1390  }
1391  // wait for the workers to finish
1392  for (i=0;i<(int)m_workers.count();i++)
1393  {
1394  m_workers.at(i)->wait();
1395  }
1396  // clean up dot files from main thread
1397  for (i=0;i<(int)m_workers.count();i++)
1398  {
1399  m_workers.at(i)->cleanup();
1400  }
1401  }
1403  if (setPath)
1404  {
1405  unsetDotFontPath();
1406  }
1407 
1408  // patch the output file and insert the maps and figures
1409  i=1;
1411  DotFilePatcher *map;
1412  // since patching the svg files may involve patching the header of the SVG
1413  // (for zoomable SVGs), and patching the .html files requires reading that
1414  // header after the SVG is patched, we first process the .svg files and
1415  // then the other files.
1416  for (di.toFirst();(map=di.current());++di)
1417  {
1418  if (map->file().right(4)==".svg")
1419  {
1420  msg("Patching output file %d/%d\n",i,numDotMaps);
1421  if (!map->run()) return FALSE;
1422  i++;
1423  }
1424  }
1425  for (di.toFirst();(map=di.current());++di)
1426  {
1427  if (map->file().right(4)!=".svg")
1428  {
1429  msg("Patching output file %d/%d\n",i,numDotMaps);
1430  if (!map->run()) return FALSE;
1431  i++;
1432  }
1433  }
1434  return TRUE;
1435 }
void portable_sleep(int ms)
Definition: portable.cpp:425
void portable_sysTimerStop()
Definition: portable.cpp:415
void msg(const char *fmt,...)
Definition: message.cpp:107
Definition: dot.h:356
void enqueue(DotRunner *runner)
Definition: dot.cpp:1160
const bool FALSE
Definition: qglobal.h:370
type * at(uint i) const
Definition: qlist.h:94
int count() const
Definition: sortdict.h:284
QCString file() const
Definition: dot.cpp:881
bool run()
Definition: dot.cpp:946
void portable_sysTimerStart()
Definition: portable.cpp:410
#define QMIN(a, b)
Definition: qglobal.h:391
Definition: sortdict.h:73
uint count() const
Definition: qlist.h:66
QList< DotRunner > m_dotRuns
Definition: dot.h:473
bool run()
Definition: dot.cpp:819
static void unsetDotFontPath()
Definition: dot.cpp:466
QCString right(uint len) const
Definition: qcstring.cpp:231
SDict< DotFilePatcher > m_dotMaps
Definition: dot.h:474
#define Config_getString(val)
Definition: config.cpp:660
#define Config_getBool(val)
Definition: config.cpp:664
uint count() const
Definition: dot.cpp:1179
void cleanup()
Definition: dot.cpp:1207
static void setDotFontPath(const char *path)
Definition: dot.cpp:444
QList< DotWorkerThread > m_workers
Definition: dot.h:477
void wait()
DotRunnerQueue * m_queue
Definition: dot.h:476
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371

Member Data Documentation

SDict<DotFilePatcher> DotManager::m_dotMaps
private

Definition at line 474 of file dot.h.

QList<DotRunner> DotManager::m_dotRuns
private

Definition at line 473 of file dot.h.

DotRunnerQueue* DotManager::m_queue
private

Definition at line 476 of file dot.h.

DotManager * DotManager::m_theInstance = 0
staticprivate

Definition at line 475 of file dot.h.

QList<DotWorkerThread> DotManager::m_workers
private

Definition at line 477 of file dot.h.


The documentation for this class was generated from the following files: