8 #ifndef TCPSERVERPOOL_H_ 9 #define TCPSERVERPOOL_H_ 14 #include <QtCore/QThread> 15 #include <QtCore/QSemaphore> 24 QSemaphore * sharedSemaphore,
25 int maxSemaphoreResources,
26 QObject * parent = 0) :
34 UASSERT(maxSemaphoreResources > 0);
41 UINFO(
"Thread %p detecting...", (
void *)this->thread());
52 UINFO(
"Thread %p adding object %d (%s)...", (
void *)this->thread(),
id, filePath.toStdString().c_str());
60 UINFO(
"Thread %p removing object %d...", (
void *)this->thread(),
id);
84 qRegisterMetaType<cv::Mat>(
"cv::Mat");
86 threadPool_.resize(threads);
87 for(
int i=0; i<threads; ++i)
90 UINFO(
"TcpServer set on port: %d (IP=%s)",
94 threadPool_[i] =
new QThread(
this);
97 tcpServer->moveToThread(threadPool_[i]);
98 worker->moveToThread(threadPool_[i]);
99 connect(threadPool_[i], SIGNAL(finished()), tcpServer, SLOT(deleteLater()));
100 connect(threadPool_[i], SIGNAL(finished()), worker, SLOT(deleteLater()));
104 QObject::connect(tcpServer, SIGNAL(detectObject(
const cv::Mat &)), worker, SLOT(
detect(
const cv::Mat &)));
105 QObject::connect(tcpServer, SIGNAL(addObject(
const cv::Mat &,
int,
const QString &)), worker, SLOT(
addObjectAndUpdate(
const cv::Mat &,
int,
const QString &)));
107 threadPool_[i]->start();
113 for(
int i=0; i<threadPool_.size(); ++i)
115 threadPool_[i]->quit();
116 threadPool_[i]->wait();
QSemaphore sharedSemaphore_
QHostAddress getHostAddress() const
QSemaphore * sharedSemaphore_
bool detect(const cv::Mat &image, find_object::DetectionInfo &info) const
void addObjectAndUpdate(const cv::Mat &image, int id=0, const QString &filePath=QString())
#define UASSERT(condition)
void detect(const cv::Mat &image)
int maxSemaphoreResources_
void addObjectAndUpdate(const cv::Mat &image, int id, const QString &filePath)
TcpServerPool(find_object::FindObject *sharedFindObject, int threads, int port)
QVector< QThread * > threadPool_
ULogger class and convenient macros.
void objectsFound(const find_object::DetectionInfo &)
void removeObjectAndUpdate(int id)
FindObjectWorker(find_object::FindObject *sharedFindObject, QSemaphore *sharedSemaphore, int maxSemaphoreResources, QObject *parent=0)
find_object::FindObject * sharedFindObject_
void removeObjectAndUpdate(int id)