bool ShellCommandService::executeService(TasCommandModel& model, TasResponse& response) { if(model.service() == serviceName() ){ TasCommand* command = getCommandParameters(model, "shellCommand"); if(command && !command->text().isEmpty()){ if (command->parameter("detached") == "true"){ detachedShellCommand(command->text(), response); } else if (command->parameter("threaded") == "true") { shellTask(command->text(), response); } else if (command->parameter("status") == "true") { TasCommand* command = getCommandParameters(model, "shellCommand"); if(command && !command->text().isEmpty()){ qint64 pid = command->text().toInt(); if (command->parameter("kill") == "true") { killTask(pid, response); } else { shellStatus(pid, response); } } } else{ shellCommand(command->text(), response); } } else{ response.setErrorMessage(NO_COMMAND_TO_EXECUTE); } return true; } else{ return false; } }
bool RegisterService::executeService(TasCommandModel& model, TasResponse& response) { if(model.service() == serviceName() ){ TasCommand* command = getCommandParameters(model, COMMAND_REGISTER); if(command){ ClientDetails client; bool ok; //this should not really ever fail (app pid used to generate in client side) quint64 clientPid = command->parameter(PLUGIN_ID).toULongLong(&ok); client.processId = clientPid; client.processName = command->parameter(PLUGIN_NAME); #ifdef Q_OS_SYMBIAN client.applicationUid = command->parameter(APP_UID); #endif client.pluginType = command->parameter(PLUGIN_TYPE); client.socket = response.requester(); registerPlugin(client); } else{ command = getCommandParameters(model, COMMAND_UNREGISTER); if(command){ unRegisterPlugin(*command); } } return true; } else{ return false; } }
bool ObjectService::executeService(TasCommandModel& model, TasResponse& response) { if(model.service() == serviceName() ){ performObjectService(model, response); return true; } else{ return false; } }
/*! Passes service directed to plugins on to the correct plugin. */ bool InfoService::executeService(TasCommandModel& model, TasResponse& response) { if(model.service() == serviceName() ){ mLogger->performLogService(model, response); return true; } else{ return false; } }
void TestabilityService::enableSignalTracking(QString signal, QString timeStamp) { //need to make a commandmodel for the fixture TasCommandModel* model = TasCommandModel::createModel(); model->addDomAttribute("service", FIXTURE); TasTarget& target = model->addTarget(); target.addDomAttribute("TasId", TasCoreUtils::objectId( qApp )); target.addDomAttribute("type", TYPE_APPLICATION_VIEW); TasCommand& command = target.addCommand(); command.addDomAttribute("name", "Fixture"); command.addDomAttribute("plugin","tassignal"); command.addDomAttribute("method","enable_signal"); command.addApiParameter(SIGNAL_KEY,signal, "QString"); command.addApiParameter(PROCESS_START_TIME,timeStamp, "QString"); QString message; if(!mFixtureService->performFixture(*model, message)){ TasLogger::logger()->error("TestabilityService::enableSignalTracking failed. " + message); } delete model; }
bool ScreenshotService::executeService(TasCommandModel& model, TasResponse& response) { if(model.service() == serviceName() ){ TasLogger::logger()->debug("ScreenshotService::executeService in"); QGuiApplication *app = qobject_cast<QGuiApplication*>(qApp); if(app){ getScreenshot(model, response); } else{ TasLogger::logger()->debug("ScreenshotService::executeService application has no ui!"); response.setErrorMessage(NO_UI_ERROR); } return true; } else{ return false; } }
void ObjectService::performObjectService(TasCommandModel& model, TasResponse& response) { TasLogger::logger()->debug(QString("TasCommander::performObjectService entry")); QListIterator<TasTarget*> i(model.targetList()); QString errorString; while (i.hasNext()){ TasTarget* commandTarget = i.next(); QString targetId = commandTarget->id(); QString targetType = commandTarget->type(); QObject* target = 0; if(targetType == TYPE_GRAPHICS_VIEW){ QGraphicsItem* item = findGraphicsItem(targetId); //target = TestabilityUtils::castToGraphicsWidget(item); target = item->toGraphicsObject(); } else if(targetType == TYPE_STANDARD_VIEW){ target = findWidget(targetId); //If Type is Standard View check QObjects in cache too. if(!target) { target = findObject(targetId); } } else if(targetType == TYPE_QSCENEGRAPH){ target = findQuickItem(targetId); } else if(targetType == TYPE_APPLICATION_VIEW ){ target = qApp; } // TODO: add support //else if(targetType == TYPE_ACTION_VIEW = "Action"; //else if(targetType == TYPE_LAYOUT = "Layout"; //else if(targetType == TYPE_LAYOUT_ITEM = "LayoutItem"; //else if(targetType == TYPE_WEB = "Web"; //else if(targetType == TYPE_QWEB = "QWeb"; else { errorString.append(targetType + " target type not supported. "); } TasLogger::logger()->debug( QString("TasCommander::performObjectService %1 %2 found: %3") .arg(targetType).arg(targetId).arg(target!=NULL)); if (target) { QListIterator<TasCommand*> j(commandTarget->commandList()); while (j.hasNext()){ TasCommand* command = j.next(); if(command->name() == "SetAttribute"){ doSetAttribute(command, target, errorString); } else if (command->name() == "CallMethod"){ response.setData(doCallMethod(command, target, errorString)); } else { TasLogger::logger()->debug( QString("TasCommander::performObjectService %1 %2: unsupported %3") .arg(targetType).arg(targetId).arg(command->name())); } } } } if(!errorString.isEmpty()){ response.setErrorMessage(errorString); TasLogger::logger()->debug( QString("TasCommander::performObjectService errors: %1") .arg(errorString)); } else { TasLogger::logger()->debug( QString("TasCommander::performObjectService, no errors.")); } }
void ScreenshotService::getScreenshot(TasCommandModel& model, TasResponse& response) { QListIterator<TasTarget*> i(model.targetList()); QString errorMsg = PARSE_ERROR; QImage screenshot; QString pictureFormat = "PNG"; while (i.hasNext()) { TasTarget* commandTarget = i.next(); QString targetId = commandTarget->id(); QString targetType = commandTarget->type(); TasCommand* command = commandTarget->findCommand("Screenshot"); // are required for command completion if (targetId.isEmpty() || targetType.isEmpty() || !command) { continue; } if (!command->parameter("format").isEmpty()) { pictureFormat = command->parameter("format"); } if (!isFormatSupported(pictureFormat)) { errorMsg = "Given format " + pictureFormat + "is not supported. Supported formats are: PNG, JPEG and BMP."; break; } bool draw = (command->parameter("draw") == "true"); QWidget* widget = 0; QQuickWindow* qtQuickWindow = 0; WId winId = 0; QRect rect(0,0,-1,-1); errorMsg = "Taking screenshot failed!"; if (targetType == TYPE_GRAPHICS_VIEW) { //TasLogger::logger()->debug("TYPE_GRAPHICS_VIEW Target id:" + targetId); QGraphicsItem* item = findGraphicsItem(targetId); if (item) { QGraphicsView* view = getViewForItem(item); if(view) { ItemLocationDetails locationDetails = TestabilityUtils::getItemLocationDetails(item); rect = QRect(locationDetails.windowPoint.x(), locationDetails.windowPoint.y(), locationDetails.width, locationDetails.height); if (draw) { widget = view->window(); } else { winId = view->window()->winId(); } } else { errorMsg = "Could not find a GraphicsView for the GraphicsItem!"; } } else { errorMsg = "Could not find the GraphicsItem!"; } } else if (targetType == TYPE_STANDARD_VIEW) { //TasLogger::logger()->debug("TYPE_STANDARD_VIEW about to find widget Target id:" + targetId); widget = findWidget(targetId); if (widget) { if ((widget->isWindow() && !draw) || widget->inherits("QDesktopWidget")) { winId = widget->winId(); widget = 0; } else if (!draw) { QPoint point = widget->mapToGlobal(QPoint(0,0)); QPoint windowPoint = widget->window()->mapFromGlobal(point); rect = QRect(windowPoint.x(), windowPoint.y(), widget->rect().width(), widget->rect().width()); winId = widget->window()->winId(); widget = 0; } } else { TasLogger::logger()->debug("ScreenshotService::executeService application has no visible ui!"); errorMsg = "Application has no visible ui!"; } } else if (targetType == TYPE_QSCENEGRAPH) { QQuickItem* item = TestabilityUtils::findQuickItem(targetId); if (item) { QPointF offset = item->mapToScene(QPointF(0,0)); rect = QRect(-offset.x(), -offset.y(), item->width(), item->height()); qtQuickWindow = item->window(); } } else { //TasLogger::logger()->debug("TYPE_APPLICATION_VIEW about to find application window Target id:" + targetId); widget = getApplicationWidget(); if (!widget) { QWindow *window = getApplicationWindow(); //in case no window false, return the desktop qtQuickWindow = qobject_cast<QQuickWindow *>(window); if (!window) { widget = qApp->desktop(); } } } if (widget) { screenshot = widget->grab(rect).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(widget)); } } else if (qtQuickWindow) { screenshot = qtQuickWindow->grabWindow(); if (!screenshot.isNull()) { screenshot.setText("tas_id", objectId(qtQuickWindow)); } } else if (winId) { screenshot = QPixmap::grabWindow(winId, rect.x(), rect.y(), rect.width(), rect.height()).toImage(); if (!screenshot.isNull()) { screenshot.setText("tas_id", QString::number(winId)); } } break; } if (!screenshot.isNull()) { QByteArray bytes; QBuffer buffer(&bytes); buffer.open(QIODevice::WriteOnly); screenshot.save(&buffer, pictureFormat.toLatin1()); response.setData(bytes); buffer.close(); } else { response.setErrorMessage(errorMsg); } }
/*! Passes service directed to plugins on to the correct plugin. */ void InfoLogger::performLogService(TasCommandModel& model, TasResponse& response) { TasTarget* target = model.findTarget(APPLICATION_TARGET); if(!mTimer.isActive() && model.interval() > 100){ mTimer.setInterval(model.interval()); } if(target){ TasCommand* command = target->findCommand(CPU); if(command){ if(command->parameter(ACTION) == "start"){ QString fileName; if(!makeFileName(command, CPU, fileName)){ response.setErrorMessage("File path must be defined for cpu logging!"); } else{ mLastCpuTime = mDeviceUtils->currentProcessCpuTime(); mInterval.start(); mState |= CpuLogging; if(mCpu){ delete mCpu; mCpu = 0; } mCpu = openFile(fileName, command); } } else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){ loadCpuData(response, command); } } command = target->findCommand(MEM); if(command){ if(command->parameter(ACTION) == "start"){ QString fileName; if(!makeFileName(command, MEM, fileName)){ response.setErrorMessage("File path must be defined for mem logging!"); } else{ mState |= MemLogging; if(mMem){ delete mMem; mMem = 0; } mMem = openFile(fileName, command); } } else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){ loadMemData(response, command); } } command = target->findCommand(GPU); if(command){ if(command->parameter(ACTION) == "start"){ QString fileName; if(!makeFileName(command, GPU, fileName)){ response.setErrorMessage("File path must be defined for mem logging!"); } else{ mState |= GpuLogging; if(mGpu){ delete mGpu; mGpu = 0; } mGpu = openFile(fileName, command); } } else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){ loadGpuData(response, command); } } command = target->findCommand(PWR); if(command){ if(command->parameter(ACTION) == "start"){ QString fileName; if(!makeFileName(command, PWR, fileName)){ response.setErrorMessage("File path must be defined for pwr logging!"); } else{ mState |= PwrLogging; if(mPwr){ delete mPwr; mPwr = 0; } mPwr = openFile(fileName, command); } //to launch measuring if not running mDeviceUtils->pwrDetails(); } else if(command->parameter(ACTION) == "stop" || command->parameter(ACTION) == "load"){ loadPwrData(response, command); if(command->parameter(ACTION) == "stop" ){ mDeviceUtils->stopPwrData(); } } } //determines that does the interval need to be started or stopped checkLoggerState(); } }
/*! Servers servicemanager first looks for a client to relay the message to. If none found then use the servers command chain to handle the service request. */ void TasServerServiceManager::handleServiceRequest(TasCommandModel& commandModel, TasSocket* requester, qint32 responseId) { TasLogger::logger()->debug("TasServerServiceManager::handleServiceRequest: " + commandModel.service() + ": " + commandModel.id()); TasClient* targetClient = 0; if (!commandModel.id().isEmpty() && commandModel.id() != "1"){ bool ok; quint64 clientPid = commandModel.id().toULongLong(&ok); targetClient = mClientManager->findByProcessId(clientPid); //no registered client check for platform specific handles for the process id if(!targetClient && extensionHandled(commandModel, requester, responseId)){ return; } if(!targetClient){ TasLogger::logger()->debug("TasServerServiceManager::handleServiceRequest: no target client send error..."); TasResponse response(responseId); response.setIsError(true); response.setErrorMessage("The application with Id " + commandModel.id() + " is no longer available."); requester->sendMessage(response); return; } } if(!targetClient && (commandModel.service() == APPLICATION_STATE || commandModel.service() == SCREEN_SHOT || commandModel.service() == FIND_OBJECT_SERVICE)){ targetClient = mClientManager->findClient(commandModel); } else if (commandModel.service() == RESOURCE_LOGGING_SERVICE){ targetClient = mClientManager->logMemClient(); } else{ } if(targetClient){ TasLogger::logger()->debug("TasServerServiceManager::handleServiceRequest client is: " + targetClient->processId() + "," + targetClient->applicationName()); int timeout = 10000; if(!commandModel.parameter("plugin_timeout").isEmpty()){ TasLogger::logger()->debug("TasServerServiceManager::handleServiceRequest set timeout " + commandModel.parameter("plugin_timeout")); timeout = commandModel.parameter("plugin_timeout").toInt(); } ResponseWaiter* waiter = new ResponseWaiter(responseId, requester, timeout); if(commandModel.service() == CLOSE_APPLICATION){ waiter->setResponseFilter(new CloseFilter(commandModel)); } connect(waiter, SIGNAL(responded(qint32)), this, SLOT(removeWaiter(qint32))); mResponseQueue.insert(responseId, waiter); if(commandModel.service() == APPLICATION_STATE || commandModel.service() == FIND_OBJECT_SERVICE){ commandModel.addDomAttribute("needFragment", "true"); //send request for qt uistate to client targetClient->socket()->sendRequest(responseId, commandModel.sourceString(false)); //in the meantime process native getNativeUiState(responseId, commandModel); } else{ //can respond as soon as response from qt side waiter->okToRespond(); targetClient->socket()->sendRequest(responseId, commandModel.sourceString()); } } else{ handleClientLess(commandModel, requester, responseId); } }