/**************************************************************************** * * * This file is part of guh. * * * * Guh 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, version 2 of the License. * * * * Guh 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 guh. If not, see . * * * ***************************************************************************/ #include "devicepluginmock.h" #include "httpdaemon.h" #include "device.h" #include "devicemanager.h" #include #include QUuid mockEvent1Id = QUuid("45bf3752-0fc6-46b9-89fd-ffd878b5b22b"); QUuid mockEvent2Id = QUuid("863d5920-b1cf-4eb9-88bd-8f7b8583b1cf"); QUuid mockIntStateId = QUuid("80baec19-54de-4948-ac46-31eabfaceb83"); QUuid mockBoolStateId = QUuid("9dd6a97c-dfd1-43dc-acbd-367932742310"); QUuid mockAction1Id = QUuid("dea0f4e1-65e3-4981-8eaa-2701c53a9185"); QUuid mockAction2Id = QUuid("defd3ed6-1a0d-400b-8879-a0202cf39935"); DevicePluginMock::DevicePluginMock() { } QList DevicePluginMock::supportedDevices() const { QList ret; DeviceClass deviceClassMock(pluginId(), QUuid("753f0d32-0468-4d08-82ed-1964aab03298")); deviceClassMock.setName("Mock Device"); QVariantList mockParams; QVariantMap portParam; portParam.insert("name", "httpport"); portParam.insert("type", "int"); mockParams.append(portParam); deviceClassMock.setParams(mockParams); QList mockStates; StateType intState(mockIntStateId); intState.setName("Dummy int state"); intState.setType(QVariant::Int); intState.setDefaultValue(10); mockStates.append(intState); StateType boolState(mockBoolStateId); boolState.setName("Dummy bool state"); boolState.setType(QVariant::Int); boolState.setDefaultValue(false); mockStates.append(boolState); deviceClassMock.setStates(mockStates); QList mockEvents; EventType event1(mockEvent1Id); event1.setName("Mock Event 1"); mockEvents.append(event1); EventType event2(mockEvent2Id); event2.setName("Mock Event 2"); mockEvents.append(event2); deviceClassMock.setEvents(mockEvents); QList mockActions; ActionType action1(mockAction1Id); action1.setName("Mock Action 1"); mockActions.append(action1); ActionType action2(mockAction2Id); action2.setName("Mock Action 2"); mockActions.append(action2); deviceClassMock.setActions(mockActions); ret.append(deviceClassMock); return ret; } DeviceManager::HardwareResources DevicePluginMock::requiredHardware() const { return DeviceManager::HardwareResourceTimer; } QString DevicePluginMock::pluginName() const { return "Mock Devices"; } QUuid DevicePluginMock::pluginId() const { return QUuid("727a4a9a-c187-446f-aadf-f1b2220607d1"); } bool DevicePluginMock::deviceCreated(Device *device) { qDebug() << "Mockdevice created returning true" << device->params().value("httpport").toInt(); HttpDaemon *daemon = new HttpDaemon(device, this); m_daemons.insert(device, daemon); if (!daemon->isListening()) { qDebug() << "couldn't setup mockdevice"; return false; } connect(daemon, SIGNAL(triggerEvent(QUuid)), SLOT(triggerEvent(QUuid))); connect(daemon, SIGNAL(setState(QUuid, QVariant)), SLOT(setState(QUuid,QVariant))); return true; } void DevicePluginMock::executeAction(Device *device, const Action &action) { qDebug() << "Should execute action" << action.actionTypeId(); m_daemons.value(device)->actionExecuted(action.actionTypeId()); } void DevicePluginMock::setState(const QUuid &stateTypeId, const QVariant &value) { HttpDaemon *daemon = qobject_cast(sender()); if (!daemon) { return; } Device *device = m_daemons.key(daemon); device->setStateValue(stateTypeId, value); } void DevicePluginMock::triggerEvent(const QUuid &id) { HttpDaemon *daemon = qobject_cast(sender()); if (!daemon) { return; } Device *device = m_daemons.key(daemon); Event event(id, device->id(), QVariantMap()); qDebug() << "Emitting event " << event.eventTypeId(); emit emitEvent(event); }