File indexing completed on 2024-04-14 14:10:47

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "blobmanager.h"
0008 
0009 #include <basedevice.h>
0010 
0011 #include "indi_debug.h"
0012 
0013 BlobManager::BlobManager(QObject *parent, const QString &host, int port, const QString &device,
0014                          const QString &prop) : QObject(parent), m_Device(device), m_Property(prop)
0015 {
0016     // Set INDI server params
0017     setServer(host.toLatin1().constData(), port);
0018 
0019     // We're only interested in a particular device
0020     watchDevice(m_Device.toLatin1().constData());
0021 
0022     // Connect immediately
0023     connectServer();
0024 }
0025 
0026 void BlobManager::serverDisconnected(int exit_code)
0027 {
0028     qCDebug(KSTARS_INDI) << "INDI server disconnected from BLOB manager for Device:" << m_Device << "Property:" << m_Property <<
0029                          "Exit code:" << exit_code;
0030 }
0031 
0032 void BlobManager::updateProperty(INDI::Property prop)
0033 {
0034     if (prop.getType() == INDI_BLOB)
0035         emit propertyUpdated(prop);
0036 }
0037 
0038 void BlobManager::newDevice(INDI::BaseDevice device)
0039 {
0040     // Got out target device, let's now set to BLOB ONLY for the particular property we want
0041     if (QString(device.getDeviceName()) == m_Device)
0042     {
0043         setBLOBMode(B_ONLY, m_Device.toLatin1().constData(), m_Property.toLatin1().constData());
0044         // enable Direct Blob Access for faster BLOB loading.
0045         enableDirectBlobAccess(m_Device.toLatin1().constData(), m_Property.toLatin1().constData());
0046         emit connected();
0047     }
0048 }
0049 
0050 void BlobManager::setEnabled(bool enabled)
0051 {
0052     m_Enabled = enabled;
0053     setBLOBMode(enabled ? B_ONLY : B_NEVER, m_Device.toLatin1().constData(), m_Property.toLatin1().constData());
0054 }