##// END OF EJS Templates
SREC File parser working....
SREC File parser working. SREC Viewer working. Added toSREC function in elfFile class. codeFragment to SREC converter also working. All these objects also have Python bindings.

File last commit:

r16:146cfc42b7e9 default
r45:c6b44a3b51fa default
Show More
socexplorerproxy.cpp
370 lines | 11.0 KiB | text/x-c | CppLexer
/*------------------------------------------------------------------------------
-- This file is a part of the SocExplorer Software
-- Copyright (C) 2011, 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 2 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@lpp.polytechnique.fr
----------------------------------------------------------------------------*/
#include "socexplorerproxy.h"
#include <pluginmanagerWDGT.h>
#include <socexplorerengine.h>
#include <pluginloader.h>
#include <socexplorerplugin.h>
socexplorerproxy* socexplorerproxy::_self=NULL;
QMainWindow* socexplorerproxy::mainWindow=NULL;
QList<socexplorerplugin*>* socexplorerproxy::drivers=NULL;
QList<socexplorerplugin*>* socexplorerproxy::linearDriverList=NULL;
socexplorerplugin* socexplorerproxy::root=NULL;
socexplorerplugin* socexplorerproxy::parent=NULL;
PluginsCache* socexplorerproxy::cache=NULL;
socexplorerproxy::socexplorerproxy(QObject *parent) :
QObject(parent)
{
cache = new PluginsCache;
drivers = new QList<socexplorerplugin*>;
linearDriverList=new QList<socexplorerplugin*>;
root = NULL;
}
socexplorerproxy::socexplorerproxy(QMainWindow *Mainwindow, QObject *parent):
QObject(parent)
{
mainWindow = Mainwindow;
cache = new PluginsCache;
drivers = new QList<socexplorerplugin*>;
linearDriverList=new QList<socexplorerplugin*>;
root = NULL;
}
void socexplorerproxy::init()
{
if(!_self)
{
_self = new socexplorerproxy();
mainWindow = NULL;
}
}
void socexplorerproxy::setMainWindow(QMainWindow *Mainwindow)
{
if(!_self)init();
mainWindow=Mainwindow;
}
void socexplorerproxy::loadSysDriver(const QString name)
{
if(!_self)init();
if(pluginloader::libcanberoot(name))
{
socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
QString driverName = _self->getinstanceName(driver->baseName());
loadSysDriver(driver,driverName);
}
}
void socexplorerproxy::loadSysDriver(const QString name, const QString instanceName)
{
if(!_self)init();
if(pluginloader::libcanberoot(name) && !_self->instanceExists(instanceName))
{
socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
loadSysDriver(driver,instanceName);
}
}
void socexplorerproxy::loadSysDriver(socexplorerplugin *driver, const QString instanceName)
{
if(!_self)init();
driver->setInstanceName(instanceName);
driver->parent = NULL;
drivers->append(driver);
linearDriverList->append(driver);
connectChildToProxy(driver);
emit _self->addPluginGUI(driver);
emit _self->clearMenu();
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
SocExplorerEngine::addSOC(driver);
}
void socexplorerproxy::loadChildSysDriver(socexplorerplugin *parent, const QString child)
{
if(!_self)init();
if(pluginloader::libcanbechild(child))
{
socexplorerplugin* driver = pluginloader::newsocexplorerplugin(child);
QString driverName = _self->getinstanceName(driver->baseName());
bool ok=true;
if(ok)
{
if(parent!=NULL)_self->loadSysDriverToParent(driver,parent,driverName);
}
}
}
void socexplorerproxy::loadSysDriverToParent(const QString name,const QString ParentInst)
{
if(!_self)init();
if(pluginloader::libcanbechild(name))
{
socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
QString driverName = _self->getinstanceName(driver->baseName());
bool ok=true;
if(ok)
{
socexplorerplugin* parent=_self->getSysDriver(ParentInst);
if(parent!=NULL)loadSysDriverToParent(driver,parent,driverName);
}
}
}
void socexplorerproxy::loadSysDriverToParent(const QString name,const QString instanceName,const QString ParentInst)
{
if(!_self)init();
if(pluginloader::libcanbechild(name) && !_self->instanceExists(instanceName))
{
socexplorerplugin* driver = pluginloader::newsocexplorerplugin(name);
bool ok=true;
if(ok)
{
socexplorerplugin* parent=_self->getSysDriver(ParentInst);
if(parent!=NULL)loadSysDriverToParent(driver,parent,instanceName);
}
}
}
void socexplorerproxy::loadSysDriverToParent(socexplorerplugin *driver,socexplorerplugin *parent, const QString instanceName)
{
if(!_self)init();
linearDriverList->append(driver);
driver->parent = parent;
driver->setInstanceName(instanceName);
parent->childs.append(driver);
connectChildToProxy(driver);
connectChildToParent(parent,driver);
emit _self->clearMenu();
emit _self->addPluginGUI(driver);
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
driver->postInstantiationTrigger();
}
void socexplorerproxy::changeSysDriverInstName(const QString instanceName)
{
Q_UNUSED(instanceName)
}
void socexplorerproxy::changeSysDriverInstName(const QString newinstanceName, const QString previnstanceName)
{
if(!_self)init();
socexplorerplugin*temp=_self->getSysDriver(previnstanceName);
if(temp!=NULL)
{
if(NULL!=_self->getSysDriver(newinstanceName))
{
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
return;
}
temp->setInstanceName(newinstanceName);
}
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
}
void socexplorerproxy::connectChildToParent(socexplorerplugin *parent, socexplorerplugin *child)
{
if(!_self)init();
connect(parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));
child->activate(parent->isConnected());
}
void socexplorerproxy::disconnectChildToParent(socexplorerplugin *child)
{
if(!_self)init();
disconnect(child->parent,SIGNAL(activateSig(bool)),child,SLOT(activate(bool)));
}
void socexplorerproxy::connectChildToProxy(socexplorerplugin *child)
{
if(!_self)init();
connect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString)));
connect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriver(socexplorerplugin*)));
}
void socexplorerproxy::disconnectChildToProxy(socexplorerplugin *child)
{
if(!_self)init();
disconnect(child,SIGNAL(registerObject(QObject*,QString)),_self,SIGNAL(registerObject(QObject*,QString)));
disconnect(child,SIGNAL(closePlugin(socexplorerplugin*)),_self,SLOT(closeSysDriverFromDriver(socexplorerplugin*)));
}
QString socexplorerproxy::getinstanceName(const QString& baseName)
{
if(!_self)init();
int i=0;
QString name;
bool validName = false;
while(!validName)
{
name.clear();
name.append(baseName+QString::number(i));
validName = instanceNameIsValid(name);
i++;
}
return name;
}
void socexplorerproxy::changeSysDriverInstName(socexplorerplugin* driver)
{
if(!_self)init();
QString prevName(driver->instanceName());
}
bool socexplorerproxy::instanceNameIsValid(const QString& instanceName)
{
if(!_self)init();
for(int k=0;k<linearDriverList->count();k++)
{
if(!linearDriverList->at(k)->instanceName().compare(instanceName))
return false;
}
return true;
}
socexplorerplugin *socexplorerproxy::findPlugin(const QString &instanceName)
{
if(!_self)init();
for(int k=0;k<linearDriverList->count();k++)
{
if(linearDriverList->at(k)->instanceName().compare(instanceName))
return linearDriverList->at(k);
}
return NULL;
}
bool socexplorerproxy::instanceExists(const QString &instanceName)
{
return !socexplorerproxy::instanceNameIsValid(instanceName);
}
void socexplorerproxy::close()
{
if(!_self)init();
socexplorerplugin* tmpPtr;
while(drivers->count()>0)
{
tmpPtr = drivers->last();
drivers->removeLast();
_self->closeSysDriver(tmpPtr);
}
if(root!=NULL)
{
_self->closeSysDriver(root);
}
}
socexplorerplugin* socexplorerproxy::getSysDriver(const QString instanceName)
{
if(!_self)init();
for(int i=0;i<linearDriverList->count();i++)
{
if(!linearDriverList->at(i)->instanceName().compare(instanceName))
return linearDriverList->at(i);
}
return NULL;
}
void socexplorerproxy::closeSysDriver(const QString instanceName)
{
if(!_self)init();
closeSysDriver(getSysDriver(instanceName),false);
}
void socexplorerproxy::closeSysDriver(socexplorerplugin *driver, bool recursive)
{
if(!_self)init();
if(driver!=NULL)
{
emit _self->removePluginGUI(driver);
if(driver->parent==NULL)SocExplorerEngine::removeSOC(driver);
while(driver->childs.count()!=0)closeSysDriver(driver->childs.first());
linearDriverList->removeOne(driver);
if(driver->parent!= NULL)
{
driver->parent->childs.removeOne(driver); //Have parent so it's a child
disconnectChildToParent(driver);
disconnectChildToProxy(driver);
delete driver;
}
else
{
drivers->removeOne(driver);
disconnectChildToProxy(driver);
delete driver;
}
if(!recursive)
{
emit _self->clearMenu();
emit _self->registermenu(mainWindow);
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
}
}
}
void socexplorerproxy::geteplugintree()
{
if(!_self)init();
emit _self->treeChanged(QList<socexplorerplugin*>(*drivers));
}
void socexplorerproxy::closeSysDriverFromDriver(socexplorerplugin *driver)
{
if(!_self)init();
emit _self->closeSysDriverSig(driver);
}
void socexplorerproxy::updateText()
{
if(!_self)init();
emit _self->clearMenu();
emit _self->registermenu(mainWindow);
}
void socexplorerproxy::makeMenu(QMenu* menu)
{
if(!_self)init();
for(int i=0;i<drivers->count();i++)
{
drivers->at(i)->registermenu(menu);
}
}