##// END OF EJS Templates
A lot of cleaning,...
A lot of cleaning, -removed deadlock on spwplugin -ambaplugin used to read too much data -removed several build warnings

File last commit:

r50:9c702d65566a default
r50:9c702d65566a default
Show More
gr_esb_bridge.cpp
242 lines | 6.4 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------
-- This file is a part of the SocExplorer Software
-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS
--
-- 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
-- (at your option) 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------*/
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
#include "gr_esb_bridge.h"
#include "gr_esb_ui.h"
#include <unistd.h>
#include "spw.h"
#include <socexplorerengine.h>
GR_ESB_bridge::GR_ESB_bridge(socexplorerplugin *parent) :
abstractSpwBridge(parent)
{
this->p_GUI = new GR_ESB_ui();
this->manager = new GR_ESB_Manager(parent,this);
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(ipchanged(QString)),this,SLOT(setIP(QString)));
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(vlinkchanged(QString)),this,SLOT(setVirtualLink(QString)));
connect((GR_ESB_ui*)(this->p_GUI),SIGNAL(connectClicked()),this,SLOT(toggleBridgeConnection()));
this->manager->virtualLinkIndex = 0;
this->manager->start();
}
GR_ESB_bridge::~GR_ESB_bridge()
{
this->manager->requestInterruption();
while(this->manager->isRunning());
}
void GR_ESB_bridge::toggleBridgeConnection()
{
if(this->plugin->isConnected())
{
this->disconnectBridge();
}
else
{
this->connectBridge();
}
}
bool GR_ESB_bridge::connectBridge()
{
if(this->manager->connectBridge())
{
((GR_ESB_ui*)this->p_GUI)->lock(true);
emit setConnected(true);
return true;
}
return false;
}
bool GR_ESB_bridge::disconnectBridge()
{
if(this->manager->disconnectBridge())
{
((GR_ESB_ui*)this->p_GUI)->lock(false);
emit setConnected(false);
return true;
}
return false;
}
void GR_ESB_bridge::setIP(QString ip)
{
this->manager->IP = ip;
}
void GR_ESB_bridge::setVirtualLink(QString vlink)
{
vlink = vlink.section("Virtual link",0,0);
bool success;
int vlinkTmp = vlink.toInt(&success);
if(success)
{
setVirtualLink(vlinkTmp);
}
}
void GR_ESB_bridge::setVirtualLink(qint32 vlink)
{
if(vlink<6 && vlink>=0)
{
this->manager->virtualLinkIndex = vlink;
}
}
unsigned int GR_ESB_bridge::Write(unsigned int *Value, unsigned int count, unsigned int address)
{
// TODO write ME!
Q_UNUSED(count)
Q_UNUSED(Value)
Q_UNUSED(address)
return 0;
}
unsigned int GR_ESB_bridge::Read(unsigned int *Value, unsigned int count, unsigned int address)
{
// TODO write ME!
Q_UNUSED(Value)
Q_UNUSED(count)
Q_UNUSED(address)
return 0;
}
int GR_ESB_bridge::pushRMAPPacket(char *packet, int size)
{
return this->manager->sendPacket(packet,size);
}
GR_ESB_Manager::GR_ESB_Manager(socexplorerplugin *plugin, QObject *parent)
:QThread((QObject*)parent)
{
this->Read_soc = new QTcpSocket(this);
this->Write_soc = new QTcpSocket(this);
this->RMAPtimeout = 2000;
this->handleMutex = new QMutex(QMutex::NonRecursive);
this->RMAP_AnswersSem = new QSemaphore(0);
this->RMAP_AnswersMtx=new QMutex(QMutex::Recursive);
this->RMAP_pending_transaction_IDsMtx=new QMutex(QMutex::Recursive);
this->plugin = plugin;
connected = false;
this->moveToThread(this);
}
GR_ESB_Manager::~GR_ESB_Manager()
{
}
void GR_ESB_Manager::run()
{
SocExplorerEngine::message(this->plugin,"Starting GRESB pooling thread",1);
while (!this->isInterruptionRequested())
{
if(this->connected)
{
handleMutex->lock();
SocExplorerEngine::message(this->plugin,"Looking for new RMAP packets",4);
}
else
{
//do some sanity checks!
usleep(RMAPtimeout/2);
}
usleep(1000);
}
SocExplorerEngine::message(this->plugin,"Exiting Startdundee USB pooling thread",1);
}
bool GR_ESB_Manager::connectBridge()
{
int timeout=60;
if(this->Read_soc->state()==QTcpSocket::UnconnectedState)
{
this->Read_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Read_port);
this->Read_soc->waitForConnected(30000);
}
if(this->Write_soc->state()==QTcpSocket::UnconnectedState)
{
this->Write_soc->connectToHost(IP,gresb_Conf[virtualLinkIndex].Write_port);
this->Write_soc->waitForConnected(30000);
}
while((this->Read_soc->state()!=QTcpSocket::ConnectedState) && (this->Write_soc->state()!=QTcpSocket::ConnectedState))
{
usleep(100000);
if(timeout--==0)return false;
}
return true;
}
bool GR_ESB_Manager::disconnectBridge()
{
int timeout=60;
if(this->Read_soc->state()!=QTcpSocket::UnconnectedState)
{
this->Read_soc->disconnectFromHost();
this->Read_soc->waitForDisconnected(30000);
}
if(this->Write_soc->state()!=QTcpSocket::UnconnectedState)
{
this->Write_soc->disconnectFromHost();
this->Write_soc->waitForDisconnected(30000);
}
while((this->Read_soc->state()!=QTcpSocket::UnconnectedState) && (this->Write_soc->state()!=QTcpSocket::UnconnectedState))
{
usleep(100000);
if(timeout--==0)return false;
}
return true;
}
int GR_ESB_Manager::getRMAPtransactionID()
{
// TODO write ME!
return -1;
}
int GR_ESB_Manager::getRMAPanswer(int transactionID, char **buffer)
{
// TODO write ME!
Q_UNUSED(transactionID)
Q_UNUSED(buffer)
return -1;
}
bool GR_ESB_Manager::sendPacket(char *packet, int size)
{
// TODO write ME!
Q_UNUSED(packet)
Q_UNUSED(size)
return false;
}
void GR_ESB_Manager::pushRmapPacket(char *packet, int len)
{
// TODO write ME!
Q_UNUSED(packet)
Q_UNUSED(len)
}