From 71082cf581776e1237b965a2dc0b8efe38d53af8 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:38:15 +0200 Subject: [PATCH 1/5] + Add indexer destructor (to avoid compilation warning with "non-virtual destructor") --- src/common/kiwix/indexer.cpp | 4 ++++ src/common/kiwix/indexer.h | 2 ++ src/common/kiwix/xapianIndexer.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/kiwix/indexer.cpp b/src/common/kiwix/indexer.cpp index 99cb2870a..34357561f 100644 --- a/src/common/kiwix/indexer.cpp +++ b/src/common/kiwix/indexer.cpp @@ -54,6 +54,10 @@ namespace kiwix { pthread_mutex_init(&verboseMutex, NULL); } + /* Destructor */ + Indexer::~Indexer() { + } + /* Read the stopwords */ void Indexer::readStopWords(const string languageCode) { std::string stopWord; diff --git a/src/common/kiwix/indexer.h b/src/common/kiwix/indexer.h index 42476bb99..1452ddf4e 100644 --- a/src/common/kiwix/indexer.h +++ b/src/common/kiwix/indexer.h @@ -62,6 +62,8 @@ namespace kiwix { public: Indexer(); + virtual ~Indexer(); + bool start(const string zimPath, const string indexPath); bool stop(); bool isRunning(); diff --git a/src/common/kiwix/xapianIndexer.cpp b/src/common/kiwix/xapianIndexer.cpp index 9272d4b2b..612b4ff93 100644 --- a/src/common/kiwix/xapianIndexer.cpp +++ b/src/common/kiwix/xapianIndexer.cpp @@ -28,7 +28,7 @@ namespace kiwix { this->indexer.set_stemmer(this->stemmer); */ } - + void XapianIndexer::indexingPrelude(const string indexPath) { this->writableDatabase = Xapian::WritableDatabase(indexPath, Xapian::DB_CREATE_OR_OVERWRITE); this->writableDatabase.begin_transaction(true); From ae390de24b76507d603fe213e522b5bb246cae5a Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:43:56 +0200 Subject: [PATCH 2/5] + Stub class to store custom generic varia functions --- src/common/otherTools.cpp | 20 ++++++++++++++++++++ src/common/otherTools.h | 27 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/common/otherTools.cpp create mode 100644 src/common/otherTools.h diff --git a/src/common/otherTools.cpp b/src/common/otherTools.cpp new file mode 100644 index 000000000..b0b93ed36 --- /dev/null +++ b/src/common/otherTools.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2014 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "otherTools.h" diff --git a/src/common/otherTools.h b/src/common/otherTools.h new file mode 100644 index 000000000..a247a4b0b --- /dev/null +++ b/src/common/otherTools.h @@ -0,0 +1,27 @@ +/* + * Copyright 2014 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#ifndef KIWIX_OTHERTOOLS_H +#define KIWIX_OTHERTOOLS_H + +namespace kiwix { + +} + +#endif From aeaede3834af1fbef5efbaea1235cfcb792c35fb Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 16:55:35 +0200 Subject: [PATCH 3/5] + add kiwix::sleep() method --- src/common/otherTools.cpp | 8 ++++++++ src/common/otherTools.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/common/otherTools.cpp b/src/common/otherTools.cpp index b0b93ed36..355b672b0 100644 --- a/src/common/otherTools.cpp +++ b/src/common/otherTools.cpp @@ -18,3 +18,11 @@ */ #include "otherTools.h" + +void kiwix::sleep(unsigned int milliseconds) { +#ifdef _WIN32 + Sleep(milliseconds); +#else + sleep(1000 * milliseconds); +#endif +} diff --git a/src/common/otherTools.h b/src/common/otherTools.h index a247a4b0b..d2fe5d795 100644 --- a/src/common/otherTools.h +++ b/src/common/otherTools.h @@ -22,6 +22,8 @@ namespace kiwix { + void sleep(unsigned int milliseconds); + } #endif From 69684009e3fb582dfb737eac6c086c8972001063 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:03:53 +0200 Subject: [PATCH 4/5] + Add necessary header includes --- src/common/otherTools.cpp | 2 +- src/common/otherTools.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/otherTools.cpp b/src/common/otherTools.cpp index 355b672b0..4603254f6 100644 --- a/src/common/otherTools.cpp +++ b/src/common/otherTools.cpp @@ -23,6 +23,6 @@ void kiwix::sleep(unsigned int milliseconds) { #ifdef _WIN32 Sleep(milliseconds); #else - sleep(1000 * milliseconds); + usleep(1000 * milliseconds); #endif } diff --git a/src/common/otherTools.h b/src/common/otherTools.h index d2fe5d795..4c7ae3b34 100644 --- a/src/common/otherTools.h +++ b/src/common/otherTools.h @@ -20,10 +20,14 @@ #ifndef KIWIX_OTHERTOOLS_H #define KIWIX_OTHERTOOLS_H +#ifdef _WIN32 +#include +#else +#include +#endif + namespace kiwix { - void sleep(unsigned int milliseconds); - } #endif From 3265de15799088c923b908accce4757b37c24804 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 2 Apr 2014 17:04:19 +0200 Subject: [PATCH 5/5] + Use now kiwix::sleep(0 --- src/common/kiwix/indexer.cpp | 40 ++++++++---------------------------- src/common/kiwix/indexer.h | 9 ++------ 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/common/kiwix/indexer.cpp b/src/common/kiwix/indexer.cpp index 34357561f..0092bc8d0 100644 --- a/src/common/kiwix/indexer.cpp +++ b/src/common/kiwix/indexer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2012 Emmanuel Engelhart + * Copyright 2011-2014 Emmanuel Engelhart * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -250,11 +250,8 @@ namespace kiwix { writeTextFile(path, self->getZimId()); self->setProgression(100); -#ifdef _WIN32 - Sleep(100); -#else - usleep(100000); -#endif + kiwix::sleep(100); + self->articleIndexerRunning(false); pthread_exit(NULL); return NULL; @@ -285,21 +282,12 @@ namespace kiwix { pthread_mutex_lock(&toParseQueueMutex); this->toParseQueue.push(token); pthread_mutex_unlock(&toParseQueueMutex); -#ifdef _WIN32 - Sleep(int(this->toParseQueue.size() / 200) / 10 * 1000); -#else - usleep(int(this->toParseQueue.size() / 200) / 10 * 1000000); -#endif + kiwix::sleep(int(this->toParseQueue.size() / 200) / 10 * 1000); } bool Indexer::popFromToParseQueue(indexerToken &token) { while (this->isToParseQueueEmpty() && this->isArticleExtractorRunning()) { -#ifdef _WIN32 - Sleep(500); -#else - usleep(500000); -#endif - + kiwix::sleep(500); if (this->getVerboseFlag()) { std::cout << "Waiting... ToParseQueue is empty for now..." << std::endl; } @@ -331,20 +319,12 @@ namespace kiwix { pthread_mutex_lock(&toIndexQueueMutex); this->toIndexQueue.push(token); pthread_mutex_unlock(&toIndexQueueMutex); -#ifdef _WIN32 - Sleep(int(this->toIndexQueue.size() / 200) / 10 * 1000); -#else - usleep(int(this->toIndexQueue.size() / 200) / 10 * 1000000); -#endif + kiwix::sleep(int(this->toIndexQueue.size() / 200) / 10 * 1000); } bool Indexer::popFromToIndexQueue(indexerToken &token) { while (this->isToIndexQueueEmpty() && this->isArticleParserRunning()) { -#ifdef _WIN32 - Sleep(500); -#else - usleep(500000); -#endif + kiwix::sleep(500); if (this->getVerboseFlag()) { std::cout << "Waiting... ToIndexQueue is empty for now..." << std::endl; } @@ -447,11 +427,7 @@ namespace kiwix { pthread_detach(this->articleExtractor); while(this->isArticleExtractorRunning() && this->getArticleCount() == 0) { -#ifdef _WIN32 - Sleep(100); -#else - usleep(100000); -#endif + kiwix::sleep(100); } this->articleParserRunning(true); diff --git a/src/common/kiwix/indexer.h b/src/common/kiwix/indexer.h index 1452ddf4e..410509336 100644 --- a/src/common/kiwix/indexer.h +++ b/src/common/kiwix/indexer.h @@ -1,5 +1,5 @@ /* - * Copyright 2011 Emmanuel Engelhart + * Copyright 2014 Emmanuel Engelhart * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,14 +28,9 @@ #include #include -#ifdef _WIN32 -#include -#else -#include -#endif - #include #include +#include #include #include #include