first incarnation of indexing thread

This commit is contained in:
dockes
2005-01-31 14:31:10 +00:00
parent a9200df71a
commit a93e619960
18 changed files with 601 additions and 259 deletions
+50
View File
@@ -0,0 +1,50 @@
#include <stdio.h>
#include <qthread.h>
#include "indexer.h"
#include "debuglog.h"
class IdxThread : public QThread {
virtual void run();
public:
ConfIndexer *indexer;
};
int startindexing;
int indexingdone;
bool indexingstatus;
int stopidxthread;
void IdxThread::run()
{
DebugLog::getdbl()->setloglevel(DEBDEB1);
for (;;) {
if (stopidxthread) {
delete indexer;
return;
}
if (startindexing) {
indexingdone = indexingstatus = startindexing = 0;
fprintf(stderr, "Index thread :start index\n");
indexingstatus = indexer->index();
indexingdone = 1;
}
msleep(100);
}
}
static IdxThread idxthread;
void start_idxthread(RclConfig *cnf)
{
ConfIndexer *ix = new ConfIndexer(cnf);
idxthread.indexer = ix;
idxthread.start();
}
void stop_idxthread()
{
stopidxthread = 1;
while (idxthread.running())
sleep(1);
}
+35 -11
View File
@@ -1,35 +1,54 @@
#include <signal.h>
#include <qapplication.h>
#include <qthread.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include "recollmain.h"
#include "rcldb.h"
#include "rclconfig.h"
#include "pathut.h"
RclConfig *rclconfig;
Rcl::Db *rcldb;
static void cleanup()
extern void start_idxthread(RclConfig *cnf);
extern void stop_idxthread();
extern int startindexing;
void recollCleanup()
{
stop_idxthread();
delete rcldb;
rcldb = 0;
delete rclconfig;
rclconfig = 0;
}
int recollNeedsExit;
static void sigcleanup(int sig)
{
fprintf(stderr, "sigcleanup\n");
cleanup();
exit(1);
// Cant call exit from here, because the atexit cleanup does some
// thread stuff that we can't do from signal context.
// Just set a flag and let the watchdog timer do the work
recollNeedsExit = 1;
}
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
QApplication a(argc, argv);
RecollMain w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
QTimer *timer = new QTimer(&a);
w.connect(timer, SIGNAL(timeout()), &w, SLOT(checkExit()));
timer->start(100);
atexit(cleanup);
atexit(recollCleanup);
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, sigcleanup);
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
@@ -54,14 +73,19 @@ int main( int argc, char ** argv )
QString("No db directory in configuration"));
exit(1);
}
dbdir = path_tildexpand(dbdir);
rcldb = new Rcl::Db;
if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
QMessageBox::critical(0, "Recoll",
QString("Could not open database in ") +
QString(dbdir));
exit(1);
startindexing = 1;
QMessageBox::information(0, "Recoll",
QString("Could not open database in ") +
QString(dbdir) + ". Starting indexation");
startindexing = 1;
}
start_idxthread(rclconfig);
return a.exec();
}
+2 -1
View File
@@ -3,7 +3,8 @@ LANGUAGE = C++
CONFIG += qt warn_on release
SOURCES += main.cpp
SOURCES += main.cpp \
idxthread.cpp
FORMS = recollmain.ui
+1 -6
View File
@@ -214,12 +214,6 @@
</action>
</actions>
<connections>
<connection>
<sender>fileExitAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>fileExit()</slot>
</connection>
<connection>
<sender>fileExitAction</sender>
<signal>activated()</signal>
@@ -272,6 +266,7 @@
</variables>
<slots>
<slot>fileExit()</slot>
<slot>checkExit()</slot>
<slot>reslistTE_doubleClicked( int par, int car )</slot>
<slot>reslistTE_clicked( int par, int car )</slot>
<slot>queryText_returnPressed()</slot>
+38 -7
View File
@@ -27,12 +27,19 @@
extern RclConfig *rclconfig;
extern Rcl::Db *rcldb;
extern void recollCleanup();
void RecollMain::fileExit()
{
LOGDEB(("RecollMain: fileExit\n"));
exit(0);
}
extern int recollNeedsExit;
void RecollMain::checkExit()
{
if (recollNeedsExit)
fileExit();
}
static string plaintorich(const string &in)
{
@@ -175,12 +182,30 @@ void RecollMain::reslistTE_clicked(int par, int car)
void RecollMain::queryText_returnPressed()
{
LOGDEB(("RecollMain::queryText_returnPressed()\n"));
if (!rcldb->isopen()) {
string dbdir;
if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) {
QMessageBox::critical(0, "Recoll",
QString("No db directory in configuration"));
exit(1);
}
dbdir = path_tildexpand(dbdir);
if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
QMessageBox::information(0, "Recoll",
QString("Could not open database in ") +
QString(dbdir) + " wait for indexing " +
"to complete?");
return;
}
}
reslist_current = -1;
reslist_winfirst = -1;
QCString u8 = queryText->text().utf8();
rcldb->setQuery(string((const char *)u8));
if (!rcldb->setQuery(string((const char *)u8)))
return;
listNextPB_clicked();
}
@@ -218,13 +243,18 @@ void RecollMain::listNextPB_clicked()
Rcl::Doc doc;
doc.erase();
int percent;
if (!rcldb->getDoc(reslist_winfirst + i, doc, &percent))
break;
int resCnt = rcldb->getResCnt();
int last = MIN(resCnt, reslist_winfirst+respagesize);
if (i == 0) {
reslistTE->clear();
previewTextEdit->clear();
}
if (!rcldb->getDoc(reslist_winfirst + i, doc, &percent)) {
if (i == 0)
reslist_winfirst = -1;
break;
}
int resCnt = rcldb->getResCnt();
int last = MIN(resCnt, reslist_winfirst+respagesize);
if (i == 0) {
reslistTE->append("<qt><head></head><body><p>");
char line[80];
sprintf(line, "<p><b>Displaying results %d-%d out of %d</b><br>",
@@ -276,3 +306,4 @@ void RecollMain::listNextPB_clicked()
reslist_winfirst = 0;
}
}