bool InputManager::processKeyState(LSHandle* handle, LSMessage* msg, void* userData) { // {"get": string} VALIDATE_SCHEMA_AND_RETURN(handle, msg, SCHEMA_1(REQUIRED(get, string))); bool success = false; const char* keyString = NULL; QEvent::Type state = QEvent::None; LSError err; json_object* root = 0; LSErrorInit(&err); // get the text name of the key const char* str = LSMessageGetPayload(msg); if (!str) { g_debug("%s: Unable to get JSON payload from message", __PRETTY_FUNCTION__); return false; } root = json_tokener_parse(str); if (root && !is_error(root)) { // Get the key name from the msg -- the format will be {"get":"NAME"}, // where NAME is something like ringer, slider, etc keyString = json_object_get_string(json_object_object_get(root, "get")); if (keyString) { // lookup the state of the key Qt::Key key = stringToKey(keyString); state = getKeyState(key); success = true; } } json_object* response = 0; if (success) { response = createKeyJson(keyString, state); } else { response = json_object_new_object(); } json_object_object_add(response, "returnValue", json_object_new_boolean(success)); if (!LSMessageReply(handle, msg, json_object_to_json_string(response), &err)) { LSErrorPrint(&err, stderr); LSErrorFree(&err); } if (root && !is_error(root)) json_object_put(root); json_object_put(response); return true; }
//static bool ImageServices::lsImageInfo(LSHandle* lsHandle, LSMessage* message,void* user_data) { LSError lserror; LSErrorInit(&lserror); std::string errorText; json_object * root = NULL; const char* str; std::string srcfile; int srcWidth; int srcHeight; int srcBpp; const char* srcType; // {"src": string} VALIDATE_SCHEMA_AND_RETURN(lsHandle, message, SCHEMA_1(REQUIRED(src, string))); ImageServices * pImgSvc = instance(); if (pImgSvc == NULL) { errorText = "Image Service has not started"; goto Done_lsImageInfo; } if (pImgSvc->isValid() == false) { errorText = "Image Service has not started (failed init)"; goto Done_lsImageInfo; } str = LSMessageGetPayload( message ); if (!str) { errorText = "No payload provided"; goto Done_lsImageInfo; } root = json_tokener_parse( str ); if (!root || is_error(root)) { errorText = "Malformed JSON detected in payload"; root = 0; goto Done_lsImageInfo; } if (Utils::extractFromJson(root,"src",srcfile) == false) { errorText = "'src' parameter missing"; goto Done_lsImageInfo; } { QImageReader reader(QString::fromStdString(srcfile)); if(!reader.canRead()) { errorText = reader.errorString().toStdString(); return false; goto Done_lsImageInfo; } srcWidth = reader.size().width(); srcHeight = reader.size().height(); // QImageReader probably won't return all of these, but just to make sure we cover all cases switch(reader.imageFormat()) { case QImage::Format_ARGB32_Premultiplied: case QImage::Format_ARGB32: case QImage::Format_RGB32: srcBpp = 32; break; case QImage::Format_RGB888: case QImage::Format_RGB666: case QImage::Format_ARGB8565_Premultiplied: case QImage::Format_ARGB6666_Premultiplied: case QImage::Format_ARGB8555_Premultiplied: srcBpp = 24; break; case QImage::Format_RGB444: case QImage::Format_ARGB4444_Premultiplied: case QImage::Format_RGB16: case QImage::Format_RGB555: srcBpp = 16; break; case QImage::Format_Indexed8: srcBpp = 8; break; case QImage::Format_Mono: case QImage::Format_MonoLSB: srcBpp = 1; break; default: srcBpp = 0; } srcType = reader.format(); // png/jpg etc } Done_lsImageInfo: if (root) json_object_put(root); json_object * reply = json_object_new_object(); json_object_object_add(reply, "subscribed", json_object_new_boolean(false)); if (errorText.size() > 0) { json_object_object_add(reply, "returnValue", json_object_new_boolean(false)); json_object_object_add(reply, "errorCode", json_object_new_string(errorText.c_str())); } else { json_object_object_add(reply, "returnValue", json_object_new_boolean(true)); json_object_object_add(reply, "width",json_object_new_int(srcWidth)); json_object_object_add(reply, "height",json_object_new_int(srcHeight)); json_object_object_add(reply, "bpp",json_object_new_int(srcBpp)); json_object_object_add(reply, "type", json_object_new_string(srcType)); } if (!LSMessageReply(lsHandle, message, json_object_to_json_string(reply), &lserror)) LSErrorFree (&lserror); json_object_put(reply); return true; }