Commit 759b4129 authored by fred's avatar fred
Browse files

zerogw payload api refactoring

parent 257ff17b
......@@ -51,14 +51,14 @@ void ZerogwProxy::init()
QString zgw_uri = "tcp://*:" + QString::number(m_port);
zerogw->bind (zgw_uri.toLatin1());
worker_payload = new zmq::socket_t(*zeromq_->m_context, ZMQ_DEALER);
QString uri = "ipc://" + m_ncs_params.base_directory + "/payloads";
QString uri = "ipc://" + m_ncs_params.base_directory + "/payloads_" + QString::number(m_port);
worker_payload->bind (uri.toLatin1());
// 4 threads to receive HTTP payload from zerogw API
// should be enough for everybody :)
for(int i=0; i<4; i++)
for(int i=0; i<2; i++)
{
api_payload_thread[i] = QSharedPointer<Api_payload> (new Api_payload(m_ncs_params.base_directory, 0));
api_payload_thread[i] = QSharedPointer<Api_payload> (new Api_payload(m_ncs_params.base_directory, 0, "/payloads_" + QString::number(m_port)));
}
qDebug() << "ZerogwProxy::init BEFORE PROXY";
......@@ -75,7 +75,8 @@ Service::Service(params a_ncs_params, QObject *parent) : m_ncs_params(a_ncs_para
m_http_api = NULL;
m_xmpp_server = NULL;
m_xmpp_client = NULL;
zerogwToPayload = NULL;
zerogwToPayload[0] = NULL;
zerogwToPayload[1] = NULL;
}
Service::~Service()
......@@ -103,7 +104,8 @@ Service::~Service()
emit shutdown();
delete(worker_api);
//delete(api_payload);
if (zerogwToPayload) delete(zerogwToPayload);
if (zerogwToPayload[0]) delete(zerogwToPayload[0]);
if (zerogwToPayload[1]) delete(zerogwToPayload[1]);
delete(api_node);
delete(api_workflow);
......@@ -135,7 +137,8 @@ void Service::Http_api_init()
m_ncs_params.api_port == 0 ? port = 2502 : port = m_ncs_params.api_port;
zerogwToPayload = new ZerogwProxy(m_ncs_params, port);
zerogwToPayload[0] = new ZerogwProxy(m_ncs_params, port);
zerogwToPayload[1] = new ZerogwProxy(m_ncs_params, port+1);
/*
......@@ -166,17 +169,17 @@ void Service::Http_api_init()
//connect(api_payload, SIGNAL(forward_payload(BSONObj)), dispatch, SLOT(push_payload(BSONObj)), Qt::QueuedConnection);
api_node = new Api_node(m_ncs_params.base_directory, port + 1);
api_node = new Api_node(m_ncs_params.base_directory, port + 2);
//connect(this, SIGNAL(shutdown()), api_node, SLOT(destructor()), Qt::BlockingQueuedConnection);
//connect(api_node, SIGNAL(forward_payload(BSONObj)), dispatch, SLOT(push_payload(BSONObj)), Qt::QueuedConnection);
api_workflow = new Api_workflow(m_ncs_params.base_directory, port + 2);
api_workflow = new Api_workflow(m_ncs_params.base_directory, port + 3);
//connect(this, SIGNAL(shutdown()), api_workflow, SLOT(destructor()), Qt::BlockingQueuedConnection);
//connect(api_workflow, SIGNAL(forward_payload(BSONObj)), dispatch, SLOT(push_payload(BSONObj)), Qt::QueuedConnection);
api_user = new Api_user(m_ncs_params.base_directory, port + 3);
api_user = new Api_user(m_ncs_params.base_directory, port + 4);
}
......
......@@ -79,7 +79,7 @@ public:
void Worker_init();
void link();
Worker_api *worker_api;
ZerogwProxy *zerogwToPayload;
ZerogwProxy *zerogwToPayload[2];
Api_node *api_node;
Api_workflow *api_workflow;
......
......@@ -22,7 +22,7 @@
Zerogw::Zerogw(QString basedirectory, int port, QObject *parent) : m_basedirectory(basedirectory), m_port(port), QObject(parent)
Zerogw::Zerogw(QString basedirectory, int port, QString ipc_name="", QObject *parent) : m_basedirectory(basedirectory), m_port(port), m_ipc_name(ipc_name), QObject(parent)
{
std::cout << "Zerogw::Zerogw construct" << std::endl;
......@@ -59,14 +59,14 @@ void Zerogw::init()
// socket from ZEROGW
m_message = new zmq::message_t(2);
m_socket_zerogw = new zmq::socket_t (*m_context, ZMQ_REP);
int hwm = 1;
int hwm = 50;
m_socket_zerogw->setsockopt(ZMQ_SNDHWM, &hwm, sizeof (hwm));
m_socket_zerogw->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
if (m_port == 0)
if (m_port == 0 && !m_ipc_name.isEmpty())
{
// QString uri = "tcp://127.0.0.1:2504" + QString::number(port);
QString uri = "ipc://" + m_basedirectory + "/payloads";
QString uri = "ipc://" + m_basedirectory + m_ipc_name;
m_socket_zerogw->connect(uri.toAscii());
}
else
......@@ -201,7 +201,7 @@ QString Zerogw::buildResponse(QString action, QString data1, QString data2)
Api_payload::Api_payload(QString basedirectory, int port) : Zerogw(basedirectory, port)
Api_payload::Api_payload(QString basedirectory, int port, QString ipc_name) : Zerogw(basedirectory, port, ipc_name)
{
std::cout << "Api_payload::Api_payload constructeur" << std::endl;
......
......@@ -63,10 +63,11 @@ class Zerogw : public QObject
{
Q_OBJECT
public:
Zerogw(QString basedirectory, int port, QObject *parent = 0);
Zerogw(QString basedirectory, int port, QString ipc_name, QObject *parent = 0);
~Zerogw();
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="");
......@@ -101,7 +102,7 @@ class Api_payload : public Zerogw
{
Q_OBJECT
public:
Api_payload(QString basedirectory, int port);
Api_payload(QString basedirectory, int port, QString ipc_name);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment