Commit 46529382 authored by Jasem Mutlaq's avatar Jasem Mutlaq

Improve handling of multiple devices per driver

parent f059cd19
......@@ -8,6 +8,7 @@ if (CFITSIO_FOUND)
set (fits_SRCS
fitsviewer/fitshistogram.cpp
fitsviewer/fitsimage.cpp
fitsviewer/fitsview.cpp
fitsviewer/fitsviewer.cpp
fitsviewer/fitshistogramdraw.cpp
fitsviewer/fitstab.cpp
......@@ -28,6 +29,7 @@ if (INDI_FOUND)
indi/clientmanager.cpp
indi/guimanager.cpp
indi/driverinfo.cpp
indi/deviceinfo.cpp
indi/indidevice.cpp
indi/indigroup.cpp
indi/indiproperty.cpp
......
......@@ -1018,7 +1018,7 @@ void DetailDialog::centerTelescope()
foreach(ISD::GDInterface *gd, INDIListener::Instance()->getDevices())
{
INDI::BaseDevice *bd = gd->getDriverInfo()->getBaseDevice();
INDI::BaseDevice *bd = gd->getBaseDevice();
if (gd->getType() != KSTARS_TELESCOPE)
continue;
......
......@@ -25,7 +25,7 @@
#include "drivermanager.h"
#include "servermanager.h"
#include "driverinfo.h"
#include "deviceinfo.h"
ClientManager::ClientManager()
{
......@@ -52,46 +52,22 @@ bool ClientManager::isDriverManaged(DriverInfo *di)
void ClientManager::newDevice(INDI::BaseDevice *dp)
{
setBLOBMode(B_ALSO, dp->getDeviceName());
foreach(DriverInfo *dv, managedDrivers)
{
if (dv->getUniqueLabel() == dp->getDeviceName() || dv->getDriverSource() == HOST_SOURCE)
if (dv->getUniqueLabel() == dp->getDeviceName() ||
QString(dp->getDeviceName()).startsWith(dv->getName(), Qt::CaseInsensitive) || dv->getDriverSource() == HOST_SOURCE)
{
if (dv->getDriverSource() == HOST_SOURCE)
{
DriverInfo *drv = new DriverInfo(dv->getName());
drv->setDriverSource(dv->getDriverSource());
drv->setServerState(dv->getServerState());
drv->setClientState(dv->getClientState());
drv->setClientManager(this);
drv->setServerManager(dv->getServerManager());
dv->setUniqueLabel(dp->getDeviceName());
drv->setHostParameters(dv->getHost(), dv->getPort());
drv->setUniqueLabel(DriverManager::Instance()->getUniqueDeviceLabel(dp->getDeviceName()));
drv->setBaseDevice(dp);
managedDrivers.append(drv);
emit newINDIDevice(drv);
return;
}
else
{
dv->setBaseDevice(dp);
emit newINDIDevice(dv);
return;
}
DeviceInfo *devInfo = new DeviceInfo(dv, dp);
dv->addDevice(devInfo);
emit newINDIDevice(devInfo);
return;
}
}
}
void ClientManager::newProperty(INDI::Property *prop)
......@@ -104,7 +80,6 @@ void ClientManager::newProperty(INDI::Property *prop)
emit newCCD();
emit newINDIProperty(prop);
}
void ClientManager::removeProperty(INDI::Property *prop)
......@@ -158,14 +133,15 @@ void ClientManager::removeManagedDriver(DriverInfo *dv)
dv->setClientState(false);
emit INDIDeviceRemoved(dv);
foreach(DeviceInfo *di, dv->getDevices())
emit INDIDeviceRemoved(di);
foreach(DriverInfo *dv, managedDrivers)
{
if (dv->getDriverSource() == HOST_SOURCE)
{
managedDrivers.removeOne(dv);
emit INDIDeviceRemoved(dv);
//emit INDIDeviceRemoved(dv);
delete (dv);
}
}
......
......@@ -15,6 +15,7 @@
#include <QObject>
class DeviceInfo;
class DriverInfo;
class ServerManager;
......@@ -61,7 +62,7 @@ signals:
void connectionSuccessful();
void connectionFailure(ClientManager *);
void newINDIDevice(DriverInfo *dv);
void newINDIDevice(DeviceInfo *dv);
void newINDIProperty(INDI::Property *prop);
void removeINDIProperty(INDI::Property *prop);
......@@ -76,7 +77,7 @@ signals:
void newTelescope();
void newCCD();
void INDIDeviceRemoved(DriverInfo *dv);
void INDIDeviceRemoved(DeviceInfo *dv);
};
......
/* INDI Device Info
Copyright (C) 2012 Jasem Mutlaq (mutlaqja@ikarustech.com)
This application 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.
*/
#include "deviceinfo.h"
DeviceInfo::DeviceInfo(DriverInfo *parent, INDI::BaseDevice *ibd)
{
drv = parent;
dp = ibd;
}
#ifndef DEVICEINFO_H
#define DEVICEINFO_H
/* INDI Device Info
Copyright (C) 2012 Jasem Mutlaq (mutlaqja@ikarustech.com)
This application 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.
*/
#include <basedevice.h>
#include "driverinfo.h"
class DeviceInfo
{
public:
DeviceInfo(DriverInfo *parent, INDI::BaseDevice *ibd);
DriverInfo *getDriverInfo() { return drv;}
INDI::BaseDevice *getBaseDevice() { return dp;}
private:
DriverInfo *drv;
INDI::BaseDevice *dp;
};
#endif // DEVICEINFO_H
......@@ -9,11 +9,14 @@
*/
#include <QDebug>
#include <basedevice.h>
#include "driverinfo.h"
#include "deviceinfo.h"
#include "servermanager.h"
DriverInfo::DriverInfo(const QString &inName)
{
uniqueLabel.clear();
......@@ -26,7 +29,6 @@ DriverInfo::DriverInfo(const QString &inName)
clientState = false;
serverManager = NULL;
baseDevice = NULL;
hostname = "localhost";
port = "-1";
......@@ -36,7 +38,7 @@ DriverInfo::DriverInfo(const QString &inName)
DriverInfo::~DriverInfo()
{
qDeleteAll(devices);
}
void DriverInfo::clear()
......@@ -45,9 +47,10 @@ void DriverInfo::clear()
serverState = false;
clientState = false;
serverManager = NULL;
baseDevice = NULL;
uniqueLabel.clear();
qDeleteAll(devices);
devices.clear();
}
QString DriverInfo::getServerBuffer()
......@@ -97,4 +100,21 @@ void DriverInfo::setUserPort(const QString &inUserPort)
userPort = "-1";
}
void DriverInfo::addDevice(DeviceInfo *idv)
{
devices.append(idv);
}
DeviceInfo* DriverInfo::getDevice(const QString &deviceName)
{
foreach(DeviceInfo *idv, devices)
{
if (idv->getBaseDevice()->getDeviceName() == deviceName)
return idv;
}
return NULL;
}
#include "driverinfo.moc"
#ifndef DRIVERINFO_H
#define DRIVERINFO_H
/* INDI Device
/* INDI Driver Info
Copyright (C) 2012 Jasem Mutlaq (mutlaqja@ikarustech.com)
This application is free software; you can redistribute it and/or
......@@ -19,6 +19,7 @@
class DriverManager;
class ServerManager;
class ClientManager;
class DeviceInfo;
class DriverInfo : public QObject
{
......@@ -62,6 +63,9 @@ public:
void setUserPort(const QString &inUserPort);
const QString & getUserPort() { return userPort;}
void setSkeletonFile(const QString &inSkeleton) { skelFile = inSkeleton; }
const QString &getSkeletonFile() { return skelFile; }
void setServerState(bool inState);
bool getServerState() { return serverState;}
......@@ -74,8 +78,12 @@ public:
const QString &getHost() { return hostname; }
const QString &getPort() { return port; }
void setBaseDevice(INDI::BaseDevice *idv) { baseDevice = idv;}
INDI::BaseDevice* getBaseDevice() { return baseDevice; }
//void setBaseDevice(INDI::BaseDevice *idv) { baseDevice = idv;}
//INDI::BaseDevice* getBaseDevice() { return baseDevice; }
void addDevice(DeviceInfo *idv);
DeviceInfo* getDevice(const QString &deviceName);
QList<DeviceInfo *> getDevices() { return devices; }
private:
......@@ -86,6 +94,7 @@ private:
QString driver; // Exec for the driver
QString version; // Version of the driver (optional)
QString userPort; // INDI server port as the user wants it.
QString skelFile; // Skeleton file, if any;
QString port; // INDI Host port
QString hostname; // INDI Host hostname
......@@ -99,7 +108,8 @@ private:
ServerManager *serverManager; // Who is managing this device?
ClientManager *clientManager; // Any GUI client handling this device?
INDI::BaseDevice *baseDevice; // Pointer to base device, if any.
//INDI::BaseDevice *baseDevice; // Pointer to base device, if any.
QList<DeviceInfo *> devices;
signals:
void deviceStateChanged(DriverInfo *);
......
......@@ -1045,6 +1045,7 @@ bool DriverManager::buildDriverElement(XMLEle *root, QTreeWidgetItem *DGroup, De
QString version;
QString name;
QString port;
QString skel;
//double focal_length (-1), aperture (-1);
......@@ -1062,6 +1063,12 @@ bool DriverManager::buildDriverElement(XMLEle *root, QTreeWidgetItem *DGroup, De
if (ap)
port = valuXMLAtt(ap);
// Search for skel file, if any
// Search for optional port attribute
ap = findXMLAtt(root, "skel");
if (ap)
skel = valuXMLAtt(ap);
// Let's look for telescope-specific attributes: focal length and aperture
/*ap = findXMLAtt(root, "focal_length");
if (ap)
......@@ -1112,7 +1119,7 @@ bool DriverManager::buildDriverElement(XMLEle *root, QTreeWidgetItem *DGroup, De
dv->setTreeLabel(label);
dv->setVersion(version);
dv->setDriver(driver);
dv->setSkeletonFile(skel);
dv->setType(groupType);
dv->setDriverSource(driverSource);
......
......@@ -38,6 +38,7 @@
#include "indidevice.h"
#include "guimanager.h"
#include "driverinfo.h"
#include "deviceinfo.h"
extern const char *libindi_strings_context;
......@@ -125,9 +126,10 @@ void GUIManager::addClient(ClientManager *cm)
{
clients.append(cm);
connect(cm, SIGNAL(newINDIDevice(DriverInfo*)), this, SLOT(buildDevice(DriverInfo*)), Qt::BlockingQueuedConnection);
connect(cm, SIGNAL(INDIDeviceRemoved(DriverInfo*)), this, SLOT(removeDevice(DriverInfo*)));
connect(cm, SIGNAL(newINDIDevice(DeviceInfo*)), this, SLOT(buildDevice(DeviceInfo*)), Qt::BlockingQueuedConnection);
connect(cm, SIGNAL(INDIDeviceRemoved(DeviceInfo*)), this, SLOT(removeDevice(DeviceInfo*)));
//INDI_D *gdm = new INDI_D(this, cm);
......@@ -162,11 +164,11 @@ void GUIManager::removeClient(ClientManager *cm)
hide();
}
void GUIManager::removeDevice(DriverInfo *di)
void GUIManager::removeDevice(DeviceInfo *di)
{
INDI_D *dp=NULL;
dp = findGUIDevice(di->getUniqueLabel());
dp = findGUIDevice(di->getDriverInfo()->getUniqueLabel());
if (dp == NULL)
return;
......@@ -180,11 +182,11 @@ void GUIManager::removeDevice(DriverInfo *di)
guidevices.at(i)->setTabID(i);
}
void GUIManager::buildDevice(DriverInfo *di)
void GUIManager::buildDevice(DeviceInfo *di)
{
//qDebug() << "In build Device for device with tree label " << di->getTreeLabel() << endl;
int nset=0;
ClientManager *cm = di->getClientManager();
ClientManager *cm = di->getDriverInfo()->getClientManager();
if (cm == NULL)
{
......@@ -208,7 +210,7 @@ void GUIManager::buildDevice(DriverInfo *di)
//qDebug() << "About to add to tab main widget with name " << di->getBaseDevice()->getDeviceName() << endl;
//nset = mainTabWidget->addTab(gdm->getDeviceBox(), di->getBaseDevice()->getDeviceName());
nset = mainTabWidget->addTab(gdm->getDeviceBox(), i18nc(libindi_strings_context, di->getUniqueLabel().toUtf8()));
nset = mainTabWidget->addTab(gdm->getDeviceBox(), i18nc(libindi_strings_context, di->getDriverInfo()->getUniqueLabel().toUtf8()));
gdm->setTabID(nset);
......@@ -218,4 +220,5 @@ void GUIManager::buildDevice(DriverInfo *di)
}
#include "guimanager.moc"
......@@ -80,8 +80,8 @@ public:
public slots:
void clearLog();
void buildDevice(DriverInfo *di);
void removeDevice(DriverInfo *di);
void buildDevice(DeviceInfo *di);
void removeDevice(DeviceInfo *di);
};
#endif // GUIMANAGER_H
......@@ -43,7 +43,7 @@ CCDChip::CCDChip(INDI::BaseDevice *bDevice, ClientManager *cManager, ChipType cT
normalImage = focusImage = guideImage = calibrationImage = NULL;
}
FITSImage * CCDChip::getImage(FITSMode imageType)
FITSView * CCDChip::getImage(FITSMode imageType)
{
switch (imageType)
{
......@@ -68,7 +68,7 @@ FITSImage * CCDChip::getImage(FITSMode imageType)
}
void CCDChip::setImage(FITSImage *image, FITSMode imageType)
void CCDChip::setImage(FITSView *image, FITSMode imageType)
{
switch (imageType)
......
......@@ -15,7 +15,7 @@
#include <QStringList>
class FITSImage;
class FITSView;
namespace ISD
{
......@@ -27,8 +27,8 @@ public:
CCDChip(INDI::BaseDevice *bDevice, ClientManager *cManager, ChipType cType);
FITSImage * getImage(FITSMode imageType);
void setImage(FITSImage *image, FITSMode imageType);
FITSView * getImage(FITSMode imageType);
void setImage(FITSView *image, FITSMode imageType);
void setCaptureMode(FITSMode mode) { captureMode = mode; }
void setCaptureFilter(FITSScale fType) { captureFilter = fType; }
......@@ -58,7 +58,7 @@ public:
void addFrameLabel(const QString & label) { frameTypes << label; }
private:
FITSImage *normalImage, *focusImage, *guideImage, *calibrationImage;
FITSView *normalImage, *focusImage, *guideImage, *calibrationImage;
FITSMode captureMode;
FITSScale captureFilter;
INDI::BaseDevice *baseDevice;
......
......@@ -9,6 +9,11 @@
Handle INDI Standard properties.
*/
#include <QDebug>
#include <KMessageBox>
#include <KStatusBar>
#include <baseclient.h>
#include <basedevice.h>
......@@ -20,17 +25,12 @@
#include "indifilter.h"
#include "clientmanager.h"
#include "driverinfo.h"
#include "deviceinfo.h"
#include "fitsviewer/fitsviewer.h"
#include "kstars.h"
#include "Options.h"
#include <QDebug>
#include <KMessageBox>
#include <KStatusBar>
#define NINDI_STD 27
/* INDI standard property used across all clients to enable interoperability. */
......@@ -81,8 +81,9 @@ void INDIListener::addClient(ClientManager *cm)
//qDebug() << "add client for listener called " << endl;
clients.append(cm);
connect(cm, SIGNAL(newINDIDevice(DriverInfo*)), this, SLOT(processDevice(DriverInfo*)));
connect(cm, SIGNAL(INDIDeviceRemoved(DriverInfo*)), this, SLOT(removeDevice(DriverInfo*)));
connect(cm, SIGNAL(newINDIDevice(DeviceInfo*)), this, SLOT(processDevice(DeviceInfo*)));
connect(cm, SIGNAL(INDIDeviceRemoved(DeviceInfo*)), this, SLOT(removeDevice(DeviceInfo*)));
connect(cm, SIGNAL(newINDIProperty(INDI::Property*)), this, SLOT(registerProperty(INDI::Property*)));
//connect(cm, SIGNAL(removeINDIProperty(INDI::Property*)), this, SLOT(removeProperty(INDI::Property*)), Qt::BlockingQueuedConnection);
......@@ -113,7 +114,7 @@ void INDIListener::removeClient(ClientManager *cm)
}
}
void INDIListener::processDevice(DriverInfo *dv)
void INDIListener::processDevice(DeviceInfo *dv)
{
//qDebug() << "process Device called for " << dv->getBaseDevice()->getDeviceName() << endl;
......@@ -126,17 +127,17 @@ void INDIListener::processDevice(DriverInfo *dv)
emit newDevice(gd);
}
void INDIListener::removeDevice(DriverInfo *dv)
void INDIListener::removeDevice(DeviceInfo *dv)
{
foreach(ISD::GDInterface *gd, devices)
{
if (dv->getUniqueLabel() == gd->getDeviceName() || dv->getDriverSource() == HOST_SOURCE)
if (dv->getDriverInfo()->getUniqueLabel() == gd->getDeviceName() || dv->getDriverInfo()->getDriverSource() == HOST_SOURCE)
{
emit deviceRemoved(gd);
devices.removeOne(gd);
delete(gd);
if (dv->getDriverSource() != HOST_SOURCE)
if (dv->getDriverInfo()->getDriverSource() != HOST_SOURCE)
return;
}
}
......
......@@ -20,6 +20,7 @@
class ClientManager;
class FITSViewer;
class DriverInfo;
class DeviceInfo;
class INDIListener : public QObject
{
......@@ -58,13 +59,13 @@ public slots:
void registerProperty(INDI::Property *prop);
void removeProperty(INDI::Property *prop);
void processDevice(DriverInfo *dv);
void processDevice(DeviceInfo *dv);
void processSwitch(ISwitchVectorProperty *svp);
void processText(ITextVectorProperty* tvp);
void processNumber(INumberVectorProperty *nvp);
void processLight(ILightVectorProperty *lvp);
void processBLOB(IBLOB *bp);
void removeDevice(DriverInfo *dv);
void removeDevice(DeviceInfo *dv);
signals:
void newDevice(ISD::GDInterface*);
......
......@@ -9,11 +9,18 @@
Handle INDI Standard properties.
*/
#include <basedevice.h>
#include <QDebug>
#include <KMessageBox>
#include <KStatusBar>
#include "indistd.h"
#include "indicommon.h"
#include "clientmanager.h"
#include "driverinfo.h"
#include "deviceinfo.h"
#include "skypoint.h"
#include "kstars.h"
......@@ -21,14 +28,6 @@
#include "skymap.h"
#include "Options.h"
#include <basedevice.h>
#include <QDebug>
#include <KMessageBox>
#include <KStatusBar>
const int MAX_FILENAME_LEN = 1024;
namespace ISD
......@@ -43,22 +42,24 @@ GDSetCommand::GDSetCommand(INDI_TYPE inPropertyType, const QString &inProperty,
elementValue = qValue;
}
GenericDevice::GenericDevice(DriverInfo *idv)
GenericDevice::GenericDevice(DeviceInfo *idv)
{
driverTimeUpdated = false;
driverLocationUpdated = false;
connected = false;
driverInfo = idv;
Q_ASSERT(idv != NULL);
deviceInfo = idv;
driverInfo = idv->getDriverInfo();
baseDevice = idv->getBaseDevice();
clientManager = idv->getClientManager();
clientManager = driverInfo->getClientManager();
dType = KSTARS_UNKNOWN;
}
GenericDevice::~GenericDevice()
{
......@@ -627,7 +628,7 @@ DeviceDecorator::DeviceDecorator(GDInterface *iPtr)
{
interfacePtr = iPtr;
baseDevice = interfacePtr->getDriverInfo()->getBaseDevice();
baseDevice = interfacePtr->getBaseDevice();
clientManager = interface