Commit fb7466cc authored by fred's avatar fred
Browse files

removed useless mutex

parent 8ecca1d7
......@@ -163,7 +163,7 @@ bool Nodeftp::ncs_auth(QString email, QString &token, QString &directory)
return true;
}
Nodeftp::Nodeftp(QString a_directory, int port) : m_directory(a_directory), m_port(port)
Nodeftp::Nodeftp(QString a_directory, int port, QObject *parent) : m_directory(a_directory), m_port(port), QObject(parent)
{
mongodb_ = Mongodb::getInstance ();
FtpServer = new CFtpServer();
......@@ -238,14 +238,9 @@ void Nodeftp::ftp_init()
qDebug( "FTP : Server successfuly started !" );
populate();
for( ;; )
sleep(1);
} else
qDebug( "FTP : Unable to accept incoming connections" );
FtpServer->StopListening();
} else
qErrnoWarning( "FTP : Unable to listen" );
......@@ -266,6 +261,7 @@ void Nodeftp::populate()
Nodeftp::~Nodeftp()
{
qErrnoWarning( "FTP Exiting" );
qDebug() << "FTP Exiting";
FtpServer->StopListening();
delete FtpServer;
}
......@@ -31,7 +31,7 @@ class Nodeftp : public QObject
{
Q_OBJECT
public:
Nodeftp(QString a_directory, int port);
Nodeftp(QString a_directory, int port, QObject *parent = 0);
~Nodeftp();
private:
......
......@@ -50,7 +50,7 @@ Http_admin::Http_admin(QString basedirectory, QxtAbstractWebSessionManager * sm,
Http_admin::~Http_admin()
{
qDebug() << "Http_admin : close socket";
qDebug() << "Http_admin : close";
}
bool Http_admin::check_user_login(QxtWebRequestEvent *event, QString &alert)
......
......@@ -86,7 +86,6 @@ QBool Http_api::checkAuth(QString token, BSONObjBuilder &payload_builder, BSONOb
*/
BSONObj auth = BSON("token" << token.toStdString());
std::cout << "USER TOKEN : " << auth << std::endl;
BSONObj l_user = mongodb_->Find("users", auth);
......
......@@ -136,24 +136,20 @@ void Dispatcher::handleSigHup()
char tmp;
::read(sighupFd[1], &tmp, sizeof(tmp));
// do Qt stuff
std::cout << "Received SIGHUP" << std::endl;
/* delete(alert);
delete(service);
delete(zeromq);*/
alert->deleteLater();
thread_alert->wait();
service->deleteLater();
zeromq->deleteLater();
mongodb_->kill ();
//mongodb_->kill ();
mongodb_->deleteLater();
snHup->setEnabled(true);
std::cout << "ncs shutdown successfull" << std::endl;
std::cout << "ncs shutdown init" << std::endl;
qApp->exit();
}
......
......@@ -24,7 +24,9 @@ Mongodb *Mongodb::_singleton = NULL;
Mongodb::~Mongodb()
{}
{
qDebug() << "Mongodb connection shutdown";
}
......@@ -58,8 +60,8 @@ Mongodb::Mongodb(QString a_server, QString a_database) : m_server(a_server), m_d
{
qDebug() << "Mongodb construct param";
m_mutex = new QMutex();
m_rf_mutex = new QMutex();
// m_mutex = new QMutex();
// m_rf_mutex = new QMutex();
user_buffer_lock = new QMutex();
torrent_buffer_lock = new QMutex();
......@@ -215,7 +217,7 @@ void Mongodb::push_payload(BSONObj a_payload)
int Mongodb::Count(QString a_document)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Count";
......@@ -236,7 +238,7 @@ int Mongodb::Count(QString a_document)
void Mongodb::Flush(string a_document, BSONObj query)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
std::cout << "Mongodb::Flush, query : " << query.toString() << std::endl;
......@@ -269,7 +271,7 @@ void Mongodb::Flush(string a_document, BSONObj query)
BSONObj Mongodb::Find(string a_document, const bo a_query)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Find";
QString tmp;
......@@ -325,7 +327,7 @@ BSONObj Mongodb::Find(string a_document, const bo a_query)
BSONObj Mongodb::Find(string a_document, const BSONObj a_query, BSONObj *a_fields)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Find with field's filter";
QString tmp;
......@@ -373,7 +375,7 @@ BSONObj Mongodb::Find(string a_document, const BSONObj a_query, BSONObj *a_field
QList <BSONObj> Mongodb::FindAll(string a_document, const bo datas)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::FindAll";
QString tmp;
......@@ -414,7 +416,7 @@ QList <BSONObj> Mongodb::FindAll(string a_document, const bo datas)
bo Mongodb::ExtractJSON(const be &gfs_id)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::ExtractJSON";
bo m_bo_json;
......@@ -472,7 +474,7 @@ bo Mongodb::ExtractJSON(const be &gfs_id)
QBool Mongodb::ExtractBinary(const be &gfs_id, string path, QString &filename)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::ExtractBinary";
......@@ -539,7 +541,7 @@ QBool Mongodb::ReadFile(const be &gfs_id, const mongo::GridFile **a_gf)
int Mongodb::GetNumChunck(const be &gfs_id)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
std::cout << "Mongodb::GetNumChunck : " << gfs_id << std::endl;
try {
......@@ -584,7 +586,7 @@ int Mongodb::GetNumChunck(const be &gfs_id)
string Mongodb::GetFilename(const be &gfs_id)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
std::cout << "Mongodb::GetFilename : " << gfs_id << std::endl;
......@@ -628,7 +630,7 @@ string Mongodb::GetFilename(const be &gfs_id)
BSONObj Mongodb::GetGfsid(const string filename)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
std::cout << "Mongodb::GetGfsid : " << filename << std::endl;
BSONElement gfsid;
......@@ -677,7 +679,7 @@ BSONObj Mongodb::GetGfsid(const string filename)
QBool Mongodb::ExtractByChunck(const be &gfs_id, int chunk_index, QByteArray &chunk_data, int &chunk_length)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
std::cout << "Mongodb::ExtractByChunck : " << gfs_id << std::endl;
try {
......@@ -760,7 +762,7 @@ QBool Mongodb::ExtractByChunck(const be &gfs_id, int chunk_index, QByteArray &ch
BSONObj Mongodb::WriteFile(const string filename, const char *data, int size)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
BSONObj struct_file;
try {
......@@ -784,7 +786,7 @@ BSONObj Mongodb::WriteFile(const string filename, const char *data, int size)
QBool Mongodb::Insert(QString a_document, BSONObj a_datas)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Insert";
QString tmp;
......@@ -817,7 +819,7 @@ QBool Mongodb::Insert(QString a_document, BSONObj a_datas)
QBool Mongodb::Remove(QString a_document, BSONObj a_datas)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Remove";
QString tmp;
......@@ -853,7 +855,7 @@ QBool Mongodb::Remove(QString a_document, BSONObj a_datas)
QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONObj &a_datas, bool upsert, bool multi)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Update";
QString tmp;
......@@ -888,7 +890,7 @@ QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONO
QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONObj &a_datas, BSONObj a_options, bool upsert, bool multi)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Update with options";
QString tmp;
......@@ -925,7 +927,7 @@ QBool Mongodb::Update(QString a_document, const BSONObj &element_id, const BSONO
QBool Mongodb::Update_raw(mongo_query a_query)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Update_raw";
QString db;
......@@ -958,7 +960,7 @@ QBool Mongodb::Update_raw(mongo_query a_query)
QBool Mongodb::Addtoarray(QString a_document, const BSONObj &element_id, const BSONObj &a_datas)
{
QMutexLocker locker(m_mutex);
// QMutexLocker locker(m_mutex);
qDebug() << "Mongodb::Addtoarray";
QString tmp;
......
......@@ -66,7 +66,7 @@ Nodetrack::Nodetrack(QString basedirectory, QxtAbstractWebSessionManager * sm, Q
Nodetrack::~Nodetrack()
{
qDebug() << "Nodetrack : close socket";
qDebug() << "Nodetrack : close";
z_push_api->close ();
delete(z_push_api);
}
......
......@@ -22,23 +22,10 @@
ZerogwProxy::ZerogwProxy(params a_ncs_params, int port, QObject *parent) : m_ncs_params(a_ncs_params), m_port(port), QObject(parent)
{
/* thread = new QThread;
connect(thread, SIGNAL(started()), this, SLOT(init()));
connect(thread, SIGNAL(finished()), this, SLOT(end()));
this->moveToThread(thread);
thread->start();
*/
// QObject::connect(this, SIGNAL(destroyed()), this, SLOT(end()), Qt::DirectConnection);
{
qDebug() << "ZerogwProxy::ZerogwProxy";
zeromq_ = Zeromq::getInstance ();
qDebug() << "ZerogwProxy::getInstance";
}
ZerogwProxy::~ZerogwProxy()
......@@ -49,24 +36,14 @@ ZerogwProxy::~ZerogwProxy()
zerogw->close();
worker_payload->close();
}
void ZerogwProxy::end()
{
qDebug() << "!!!!!!! ZerogwProxy::clear 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
sleep(1);
api_payload_thread[0].clear();
qDebug() << "!!!!!!! ZerogwProxy::wait 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
qDebug() << "!!!!!!! ApiPayload clear !!!!!!!!!!!!!!!!!!!!!!!";
api_payload_thread.clear();
qDebug() << "!!!!!!! ApiPayload::wait 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
thread_payload[0]->wait();
qDebug() << "!!!!!!! ZerogwProxy::clear 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
api_payload_thread[1].clear();
thread_payload[1]->wait();
qDebug() << "!!!!!!! ApiPayload::wait 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
thread_payload[1]->wait();
}
void ZerogwProxy::init()
......@@ -119,18 +96,9 @@ void ZerogwProxy::init()
thread_payload[i]->start();
}
/* thread_api_payload = new QThread(this);
api_payload = new Api_payload(m_ncs_params.base_directory, 0, "/payloads_" + QString::number(m_port));
connect(thread_api_payload, SIGNAL(started()), api_payload, SLOT(init()));
connect(api_payload, SIGNAL(destroyed()), thread_api_payload, SLOT(quit()), Qt::DirectConnection);
api_payload->moveToThread(thread_api_payload);
thread_api_payload->start();
*/
/* qDebug() << "ZerogwProxy::init BEFORE PROXY";
* Do not use because of blocked zmq device.
zmq::proxy (*zerogw, *worker_payload, NULL);
qDebug() << "ZerogwProxy::init AFTER PROXY";
*/
......@@ -209,7 +177,7 @@ Service::Service(params a_ncs_params, QObject *parent) : m_ncs_params(a_ncs_para
{
m_nodetrack = NULL;
m_nodeftp = NULL;
m_http_api = NULL;
// m_http_api = NULL;
m_xmpp_server = NULL;
m_xmpp_client = NULL;
zerogwToPayload[0] = NULL;
......@@ -218,31 +186,32 @@ Service::Service(params a_ncs_params, QObject *parent) : m_ncs_params(a_ncs_para
Service::~Service()
{
qDebug() << "delete http api server";
if (m_http_api) delete(m_http_api);
//qDebug() << "delete http api server";
//if (m_http_api) delete(m_http_api);
qDebug() << "delete http admin server";
m_admin_session.deleteLater();
delete(m_http_admin);
qDebug() << "delete tracker";
if (m_nodetrack) delete(m_nodetrack);
if (m_nodetrack)
{
qDebug() << "delete tracker";
m_nodetrack_session.deleteLater();
delete(m_nodetrack);
}
qDebug() << "delete ftp";
if (m_nodeftp) {
//m_nodeftp->deleteLater();
delete(m_nodeftp);
node_thread_ftp->quit();
m_nodeftp->deleteLater();
node_thread_ftp->wait();
}
qDebug() << "delete xmpp server";
if (m_xmpp_server)
{
m_xmpp_server->deleteLater();
thread_xmpp_server->wait();
}
//if (m_xmpp_server) delete(m_xmpp_server);
qDebug() << "delete xmpp client";
if (m_xmpp_client)
......@@ -251,11 +220,8 @@ Service::~Service()
thread_xmpp_client->wait();
}
//if (m_xmpp_client) delete(m_xmpp_client);
qDebug() << "delete worker api";
//emit shutdown();
// delete(worker_api);
worker_api->deleteLater();
worker_thread_api->wait();
......@@ -455,14 +421,14 @@ void Service::Xmpp_init()
{
qRegisterMetaType<QXmppLogger::MessageType>("QXmppLogger::MessageType");
thread_xmpp_server = new QThread;
thread_xmpp_server = new QThread(this);
m_xmpp_server = new Xmpp_server(m_ncs_params.domain_name, m_ncs_params.xmpp_client_port, m_ncs_params.xmpp_server_port);
connect(m_xmpp_server, SIGNAL(destroyed()), thread_xmpp_server, SLOT(quit()), Qt::DirectConnection);
m_xmpp_server->moveToThread(thread_xmpp_server);
thread_xmpp_server->start();
thread_xmpp_client = new QThread;
thread_xmpp_client = new QThread(this);
m_xmpp_client = new Xmpp_client(m_ncs_params.base_directory, m_ncs_params.domain_name, m_ncs_params.xmpp_client_port);
connect(m_xmpp_client, SIGNAL(destroyed()), thread_xmpp_client, SLOT(quit()), Qt::DirectConnection);
m_xmpp_client->moveToThread(thread_xmpp_client);
......@@ -473,7 +439,7 @@ void Service::Xmpp_init()
void Service::Worker_init()
{
worker_thread_api = new QThread;
worker_thread_api = new QThread(this);;
worker_api = new Worker_api(m_ncs_params.base_directory);
connect(worker_api, SIGNAL(destroyed()), worker_thread_api, SLOT(quit()), Qt::DirectConnection);
......
......@@ -49,7 +49,6 @@ public:
private slots:
void init();
void end();
signals:
void shutdown();
......
......@@ -20,7 +20,7 @@
#include "worker_api.h"
Worker_api::Worker_api(QString basedirectory)
Worker_api::Worker_api(QString basedirectory, QObject *parent) : QObject(parent)
{
mongodb_ = Mongodb::getInstance ();
zeromq_ = Zeromq::getInstance ();
......
......@@ -28,7 +28,7 @@ class Worker_api : public QObject
{
Q_OBJECT
public:
Worker_api(QString basedirectory);
Worker_api(QString basedirectory, QObject *parent = 0);
~Worker_api();
......
......@@ -26,26 +26,13 @@ Zerogw::Zerogw(QString basedirectory, int port, QString ipc_name="", QObject *pa
{
std::cout << "Zerogw::Zerogw construct" << std::endl;
// thread = new QThread;
// connect(thread, SIGNAL(started()), this, SLOT(init()));
// connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
// moveToThread(thread);
// thread->start();
mongodb_ = Mongodb::getInstance();
zeromq_ = Zeromq::getInstance ();
m_context = zeromq_->m_context;
m_mutex = new QMutex();
}
void Zerogw::init()
{
// Socket to ZPULL class
z_message = new zmq::message_t(2);
z_push_api = new zmq::socket_t(*m_context, ZMQ_PUSH);
......@@ -58,7 +45,6 @@ void Zerogw::init()
z_push_api->connect(directory.toLatin1());
// socket from ZEROGW
m_message = new zmq::message_t(2);
m_socket_zerogw = new zmq::socket_t (*m_context, ZMQ_REP);
......@@ -95,19 +81,10 @@ Zerogw::~Zerogw()
z_push_api->close();
m_socket_zerogw->close();
qDebug() << "Zerogw DELETE destruct";
delete(m_socket_zerogw);
delete(z_push_api);
}
void Zerogw::destructor()
{
qDebug() << "Zerogw destructor";
}
void Zerogw::receive_http_payload()
{}
......
......@@ -68,7 +68,6 @@ public:
protected:
QString m_ipc_name;
QThread *thread;
QBool checkAuth(QString token, BSONObjBuilder &payload_builder, BSONObj &a_user);
QString buildResponse(QString action, QString data1, QString data2="");
QString m_basedirectory;
......@@ -81,7 +80,6 @@ protected:
zmq::socket_t *m_socket_zerogw;
QMutex *m_mutex_http;
zmq::message_t *m_message;
QMutex *m_mutex;
zmq::socket_t *z_push_api;
zmq::message_t *z_message;
......@@ -92,7 +90,6 @@ signals:
private slots:
void init();
void destructor();
virtual void receive_http_payload()=0;
void forward_payload_to_zpull(BSONObj payload);
};
......
......@@ -26,7 +26,7 @@ Ztracker::Ztracker(zmq::context_t *a_context, QObject *parent) : m_context(a_con
{
std::cout << "Ztracker::Ztracker construct" << std::endl;
m_mutex = new QMutex();
// m_mutex = new QMutex();
mongodb_ = Mongodb::getInstance();
......@@ -268,7 +268,7 @@ void Ztracker::worker_update_ticker()
{
std::cout << "Ztracker::update_ticker" << std::endl;
m_mutex->lock();
// m_mutex->lock();
QDateTime l_timestamp = QDateTime::currentDateTime();
......@@ -363,7 +363,7 @@ void Ztracker::worker_update_ticker()
}
m_mutex->unlock();
//m_mutex->unlock();
}
......@@ -393,9 +393,9 @@ Zpull::Zpull(QString base_directory, zmq::context_t *a_context, QObject *parent)
std::cout << "Zpull::Zpull constructeur" << std::endl;
QString directory;
m_mutex_zeromq = new QMutex();
m_mutex_http = new QMutex();
m_mutex_worker_response = new QMutex();
// m_mutex_zeromq = new QMutex();
// m_mutex_http = new QMutex();
// m_mutex_worker_response = new QMutex();
m_socket_http = new zmq::socket_t (*m_context, ZMQ_PULL);
......@@ -464,11 +464,11 @@ Zpull::~Zpull()
check_http_data->setEnabled(false);
m_socket_http->close ();
m_mutex_zeromq->lock();
// m_mutex_zeromq->lock();
check_zeromq_data->setEnabled(false);
m_socket_zeromq->close ();
m_mutex_worker_response->lock();
// m_mutex_worker_response->lock();
check_worker_response->setEnabled(false);
m_socket_workers->close ();
......@@ -482,7 +482,7 @@ Zpull::~Zpull()
void Zpull::receive_http_payload()
{
m_mutex_http->lock();
// m_mutex_http->lock();
check_http_data->setEnabled(false);
......@@ -564,7 +564,7 @@ void Zpull::receive_http_payload()
}
check_http_data->setEnabled(true);
m_mutex_http->unlock();
// m_mutex_http->unlock();
}
......@@ -572,7 +572,7 @@ void Zpull::receive_http_payload()
void Zpull::receive_zeromq_payload()
{
m_mutex_zeromq->lock();
// m_mutex_zeromq->lock();
check_zeromq_data->setEnabled(false);
std::cout << "Zpull::receive_zeromq_payload" << std::endl;
......@@ -653,14 +653,14 @@ void Zpull::receive_zeromq_payload()
}
check_zeromq_data->setEnabled(true);
m_mutex_zeromq->unlock();
// m_mutex_zeromq->unlock();
}
void Zpull::worker_response()
{
m_mutex_worker_response->lock();
// m_mutex_worker_response->lock();
check_worker_response->setEnabled(false);
......@@ -742,7 +742,7 @@ void Zpull::worker_response()
}
}
check_worker_response->setEnabled(true);
m_mutex_worker_response->unlock();
// m_mutex_worker_response->unlock();
}
......@@ -750,8 +750,8 @@ void Zpull::worker_response()
Zdispatch::Zdispatch(zmq::context_t *a_context, QObject *parent) : m_context(a_context), QObject(parent)
{
m_mutex_replay_payload = new QMutex();