tizendevicemonitor.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Jarek Pelczar <jpelczar@gmail.com>
  4. ** Copyright (C) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Digia. For licensing terms and
  13. ** conditions see http://qt.digia.com/licensing. For further information
  14. ** use the contact form at http://qt.digia.com/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 as published by the Free Software
  19. ** Foundation and appearing in the file LICENSE.LGPL included in the
  20. ** packaging of this file. Please review the following information to
  21. ** ensure the GNU Lesser General Public License version 2.1 requirements
  22. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  23. **
  24. ** In addition, as a special exception, Digia gives you certain additional
  25. ** rights. These rights are described in the Digia Qt LGPL Exception
  26. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  27. **
  28. ****************************************************************************/
  29. #include "tizendebug.h"
  30. #include "tizenconfigurations.h"
  31. #include "tizendevicemonitor.h"
  32. #include "tizenconstants.h"
  33. #include "tizendevice.h"
  34. #include "sdbpacketutils.h"
  35. #include <utils/qtcassert.h>
  36. #include <projectexplorer/devicesupport/idevice.h>
  37. #include <projectexplorer/devicesupport/devicemanager.h>
  38. #include <QDebug>
  39. #include <QStringList>
  40. namespace Tizen {
  41. namespace Internal {
  42. TizenDeviceMonitor::TizenDeviceMonitor(QObject *parent) :
  43. QObject(parent)
  44. {
  45. qCDebug(QTC_TIZEN);
  46. m_connector = new SdbConnector(this);
  47. m_connector->setSdbPath(TizenConfigurations::currentConfig().sdbLocation().toString());
  48. connect(m_connector, SIGNAL(deviceListUpdated(SdbDeviceList)), SLOT(deviceListUpdated(SdbDeviceList)));
  49. connect(m_connector, SIGNAL(stateChanged(SdbState)), SLOT(stateChanged(SdbState)));
  50. connect(TizenConfigurations::instance(), SIGNAL(updated()), SLOT(updateConfiguration()));
  51. m_connector->startConnector();
  52. }
  53. void TizenDeviceMonitor::stateChanged(SdbState state)
  54. {
  55. qCDebug(QTC_TIZEN) << "state:" << state;
  56. switch(state)
  57. {
  58. case SdbDisconnected:
  59. break;
  60. case SdbConnecting:
  61. break;
  62. case SdbConnected:
  63. break;
  64. case SdbDisconnecting:
  65. break;
  66. case SdbRestarting:
  67. break;
  68. case SdbError:
  69. break;
  70. }
  71. }
  72. void TizenDeviceMonitor::deviceListUpdated(SdbDeviceList list)
  73. {
  74. qCDebug(QTC_TIZEN);
  75. ProjectExplorer::DeviceManager * deviceManager = ProjectExplorer::DeviceManager::instance();
  76. QMap<QString, ProjectExplorer::IDevice::ConstPtr> toRemove;
  77. for (int i = 0; i < deviceManager->deviceCount(); i++) {
  78. ProjectExplorer::IDevice::ConstPtr device = deviceManager->deviceAt(i);
  79. if (device->type() == Constants::TIZEN_DEVICE_TYPE)
  80. toRemove.insert(device->id().toString(), device);
  81. }
  82. foreach(const SdbDevice& dev, list) {
  83. QString deviceId(QLatin1String(dev.serialNumber.constData()));
  84. ProjectExplorer::IDevice::ConstPtr device;
  85. if (toRemove.contains(deviceId)) {
  86. device = toRemove.value(deviceId);
  87. toRemove.remove(deviceId);
  88. }
  89. if(device) {
  90. // Device already exists
  91. if(dev.state == SdbDevice::Offline)
  92. deviceManager->setDeviceState(Core::Id::fromString(deviceId), ProjectExplorer::IDevice::DeviceDisconnected);
  93. else if(dev.state == SdbDevice::Device)
  94. deviceManager->setDeviceState(Core::Id::fromString(deviceId), ProjectExplorer::IDevice::DeviceReadyToUse);
  95. else
  96. deviceManager->setDeviceState(Core::Id::fromString(deviceId), ProjectExplorer::IDevice::DeviceStateUnknown);
  97. } else {
  98. qCDebug(QTC_TIZEN);
  99. ProjectExplorer::IDevice::DeviceState state;
  100. if(dev.state == SdbDevice::Offline)
  101. state = ProjectExplorer::IDevice::DeviceDisconnected;
  102. else if(dev.state == SdbDevice::Device)
  103. state = ProjectExplorer::IDevice::DeviceReadyToUse;
  104. else
  105. state = ProjectExplorer::IDevice::DeviceStateUnknown;
  106. Internal::TizenDevice *tizenDevice = new Internal::TizenDevice(Core::Id::fromString(deviceId));
  107. tizenDevice->setDeviceState(state);
  108. tizenDevice->setDisplayName(dev.name);
  109. device = ProjectExplorer::IDevice::Ptr(tizenDevice);
  110. deviceManager->addDevice(device);
  111. }
  112. }
  113. foreach(QString deviceId, toRemove.keys())
  114. deviceManager->removeDevice(Core::Id::fromString(deviceId));
  115. }
  116. void TizenDeviceMonitor::updateConfiguration()
  117. {
  118. qCDebug(QTC_TIZEN);
  119. m_connector->setSdbPath(TizenConfigurations::currentConfig().sdbLocation().toString());
  120. m_connector->stopConnector();
  121. m_connector->startConnector();
  122. }
  123. } // namespace Internal
  124. } // namespace Tizen