tizendevicemonitor.cpp 4.4 KB

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