コード例 #1
0
ファイル: luna-send.c プロジェクト: obriensp/luna-service2
static bool 
timingServiceResponse(LSHandle *sh, LSMessage *reply, void *ctx)
{
    LSError lserror;
    LSErrorInit(&lserror);
    LSMessageToken token;

    const char *payload;
    
    clock_gettime(CLOCK_MONOTONIC, &stopTime);

    token = LSMessageGetResponseToken(reply);
    payload = LSMessageGetPayload(reply);
    
    double duration = ((double)stopTime.tv_sec + (((double)stopTime.tv_nsec)/1000000000.0)) -
                     ((double)startTime.tv_sec + (((double)startTime.tv_nsec)/1000000000.0));
    
    roundtripTime += duration;
    roundtripCount++;
    rcvdBytes += strlen(payload);
    sentBytes += url ? strlen(url) : 0;
    sentBytes += message ? strlen(message) : 0;

    g_message("%s Got response: duration %.02f ms, token %ld, payload %s", __FUNCTION__, duration * 1000.0, token, payload);

    if (--count > 0)
    {
        // resend the message!
        LSMessageToken sessionToken;

        clock_gettime(CLOCK_MONOTONIC, &startTime);
        
        /* Basic sending */
        bool retVal = LSCallFromApplication(sh, url, message, appId,
                     timingServiceResponse, ctx, &sessionToken, &lserror);
        if (!retVal)
        {
            LSErrorPrint (&lserror, stderr);
            LSErrorFree (&lserror);
        }
    } else {
        bool retVal = LSCallCancel (sh, token, &lserror);
        if (!retVal)
        {
            LSErrorPrint (&lserror, stderr);
            LSErrorFree (&lserror);
        }
        g_timeout_add (300, goodbye, ctx);
        return true;
    }

    return true;
}
コード例 #2
0
ファイル: activity.cpp プロジェクト: Tofee/luna-webappmanager
void Activity::setup()
{
    LSError lserror;
    LSErrorInit(&lserror);

    if (!LSRegister(NULL, &mHandle, NULL)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    GMainLoop *mainloop = g_main_loop_new(g_main_context_default(), TRUE);
    if (!LSGmainAttach(mHandle, mainloop, &lserror)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    QJsonObject activity;
    activity.insert("name", mAppId);
    char *description = g_strdup_printf("%i", mProcessId);
    activity.insert("description", (qint64) mProcessId);

    QJsonObject activityType;
    activityType.insert("foreground", true);

    activity.insert("type", activityType);

    QJsonObject request;
    request.insert("activity", activity);
    request.insert("subscribe", true);
    request.insert("start", true);
    request.insert("replace", true);

    QJsonDocument payload(request);

    if (!LSCallFromApplication(mHandle, "palm://com.palm.activitymanager/create", payload.toJson().constData(),
                               mIdentifier.toUtf8().constData(), Activity::activityCallback, this, &mToken, &lserror)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    g_free(description);
}
コード例 #3
0
void WebAppBase::createActivity()
{
	if (!m_page)
		return;

	// Setup an activity for this app if it is the top level app
	if (m_page->parent())
		return;

	LSError lsError;
	LSErrorInit(&lsError);

	json_object* payload = json_object_new_object();
	json_object* activityObj = json_object_new_object();
	json_object_object_add(activityObj, (char*) "name",
						   json_object_new_string(m_appId.c_str()));
	json_object_object_add(activityObj, (char*) "description",
						   json_object_new_string(m_processId.c_str()));
	json_object* activityTypeObj = json_object_new_object();
	json_object_object_add(activityTypeObj, (char*) "foreground",
						   json_object_new_boolean(true));
	json_object_object_add(activityObj, (char*) "type",
						   activityTypeObj);	

	json_object_object_add(payload, "activity", activityObj);
	json_object_object_add(payload, "subscribe", json_object_new_boolean(true));
	json_object_object_add(payload, "start", json_object_new_boolean(true));
	json_object_object_add(payload, "replace", json_object_new_boolean(true));

	if (!LSCallFromApplication(WebAppManager::instance()->m_servicePrivate,
							   "palm://com.palm.activitymanager/create",
							   json_object_to_json_string(payload),
							   m_page->getIdentifier(),
							   WebAppManager::activityManagerCallback,
							   this, &m_activityManagerToken, &lsError)) {
		g_critical("%s: %d. Failed in calling activity manager create: %s",
				   __PRETTY_FUNCTION__, __LINE__, lsError.message);
		LSErrorFree(&lsError);
	}

	json_object_put(payload);
}
コード例 #4
0
ファイル: MojLunaService.cpp プロジェクト: sailesharya/db8
MojErr MojLunaService::sendImpl(MojServiceRequest* req, const MojChar* service, const MojChar* method, Token& tokenOut)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
	MojAssert(req && service && method);
	MojAssert(m_service || m_handle);
	MojAssertMutexLocked(m_mutex);

	MojLunaRequest* lunaReq = static_cast<MojLunaRequest*>(req);
	const MojChar* json = lunaReq->payload();
    LOG_DEBUG("[db_lunaService] request sent: %s", json);

	MojString uri;
	MojErr err = uri.format(_T("%s://%s/%s"), UriScheme, service, method);
	MojErrCheck(err);

	MojLunaErr lserr;
	LSMessageToken lsToken;
	LSHandle* handle = getHandle(lunaReq->onPublic());
	if (req->numRepliesExpected() > 1) {
		if (!lunaReq->isProxyRequest()) {
			bool retVal = LSCall(handle, uri, json, &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		} else {
			bool retVal = LSCallFromApplication(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		}
	} else {
		if (!lunaReq->isProxyRequest()) {
			bool retVal = LSCallOneReply(handle, uri, json, &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		} else {
			bool retVal = LSCallFromApplicationOneReply(handle, uri, json, lunaReq->getRequester(), &handleResponse, this, &lsToken, lserr);
			MojLsErrCheck(retVal, lserr);
		}
	}
	tokenOut = (Token) lsToken;

	return MojErrNone;
}
コード例 #5
0
ファイル: activity.cpp プロジェクト: Tofee/luna-webappmanager
void Activity::unfocus()
{
    if (!mFocus || mId == LSMESSAGE_TOKEN_INVALID)
        return;

    LSError lserror;
    LSErrorInit(&lserror);

    QJsonObject request;
    request.insert("activityId", mId);

    QJsonDocument payload(request);

    if (!LSCallFromApplication(mHandle, "palm://com.palm.activitymanager/unfocus", payload.toJson().constData(),
                               mIdentifier.toUtf8().constData(), 0, 0, 0, &lserror)) {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
        return;
    }

    mFocus = false;
}
コード例 #6
0
void WebAppBase::blurActivity()
{
	if (!m_page || m_page->activityId() < 0)
		return;

	LSError lsError;
	LSErrorInit(&lsError);

	json_object* payload = json_object_new_object();
	json_object_object_add(payload, "activityId", json_object_new_int(m_page->activityId()));

	if (!LSCallFromApplication(WebAppManager::instance()->m_servicePrivate,
							   "palm://com.palm.activitymanager/unfocus",
							   json_object_to_json_string(payload),
							   m_page->getIdentifier(),
							   NULL, NULL, NULL, &lsError)) {
		g_critical("%s: %d. Failed in calling activity manager focus: %s",
				   __PRETTY_FUNCTION__, __LINE__, lsError.message);
		LSErrorFree(&lsError);
	}

	json_object_put(payload);
}
コード例 #7
0
ファイル: luna-send.c プロジェクト: obriensp/luna-service2
int
main(int argc, char **argv)
{
    bool interactive = false;
    bool timing = false;
    bool signal = false;
    bool use_public_bus = false;
    char *serviceName = NULL;
    int optionCount = 0;
    int opt;

    while ((opt = getopt(argc, argv, "hdisPrlfn:t:m:a:q:")) != -1)
    {
    switch (opt) {
    case 'i':
        interactive = true;
        optionCount++;
        break;
    case 's':
        signal = true;
        optionCount++;
        break;
    case 'P':
        use_public_bus = true;
        optionCount++;
        break;
    case 'd':
        sLogLevel = G_LOG_LEVEL_DEBUG;
        optionCount++;
        break;
    case 'n':
        interactive = true;
        count = atoi(optarg);
        optionCount+=2;
        break;
    case 't':
        timing = true;
        count = atoi(optarg);
        optionCount+=2;
        break;
    case 'm':
        serviceName = g_strdup(optarg);
        optionCount+=2;
        break;
    case 'a':
        appId = g_strdup(optarg);
        optionCount+=2;
        break;
    case 'l':
        line_number = true;
        optionCount++;
        break;
    case 'f':
        format_response = true;
        optionCount++;
        break;
    case 'q':
        query_list = g_list_append(query_list, g_strdup(optarg));
        optionCount+=2;
        break;
    case 'h':
    default:
        PrintUsage(argv[0]);
        return 0;
        }
    }

    if (argc < 3 + optionCount) {
        PrintUsage(argv[0]);
        return 0;
    }

    g_log_set_default_handler(g_log_filter, NULL);

    GMainLoop *mainLoop = g_main_loop_new(NULL, FALSE); 

    if (mainLoop == NULL)
    {
        g_critical("Unable to create mainloop");
        exit(EXIT_FAILURE);
    }

    LSError lserror;
    LSErrorInit(&lserror);

    LSHandle *sh = NULL;
    bool serviceInit = LSRegisterPubPriv(serviceName, &sh,
                use_public_bus, &lserror);

    if (!serviceInit) goto exit;

    bool gmainAttach = LSGmainAttach(sh, mainLoop, &lserror);
    if (!gmainAttach) goto exit;    

    url = g_strdup(argv[optionCount + 1]);
    message = g_strdup(argv[optionCount + 2]);

    LSMessageToken sessionToken;
    bool retVal;

    if (timing) {

      /* Timing loop */
      clock_gettime(CLOCK_MONOTONIC, &startTime);
      retVal = LSCallFromApplication(sh, url, message, appId,
            timingServiceResponse, mainLoop, &sessionToken, &lserror);
      
      if (!retVal) goto exit;

      g_main_loop_run(mainLoop);
      
      printf("Total time %.02f ms, %d iterations, %.02f ms per iteration\n",
        roundtripTime * 1000.0, roundtripCount, (roundtripTime / roundtripCount) * 1000.0);
      
      printf("%d bytes sent, %d bytes received\n",
        sentBytes, rcvdBytes);
    
    } else {

      if (signal)
      {
          retVal = LSSignalSend(sh, url, message, &lserror);
      }
      else
      {
          /* Basic sending */
          retVal = LSCallFromApplication(sh, url, message, appId,
                serviceResponse, mainLoop, &sessionToken, &lserror);
      }
      
      if (!retVal) goto exit;

      if (interactive && !signal) 
      {
          g_io_add_watch(g_io_channel_unix_new(0), G_IO_ERR|G_IO_HUP, input_closed, mainLoop);
          g_main_loop_run(mainLoop);
      }
      else if (!signal)
      {
          /* 
           * NOV-93580: In the non-interactive case, we can't guarantee that
           * an LSCall() will necessarily get the QueryNameReply before
           * shutting down if it does not wait for (or have) a reply from the
           * far side.
           */
          g_critical("WARNING: you must always call luna-send with \"-i\" or \"-n\". Exiting with failure return code.");
          exit(EXIT_FAILURE);
      }
    }

exit:

    if (LSErrorIsSet(&lserror))
    {
        LSErrorPrint(&lserror, stderr);
        LSErrorFree(&lserror);
    }

    if (sh != NULL)
    {
        if (!LSUnregister(sh, &lserror))
        {
            LSErrorPrint(&lserror, stderr);
            LSErrorFree(&lserror);
        }
    }

    g_main_loop_unref(mainLoop);

    if (url)
        g_free (url);

    if (message)
        g_free (message);

    return 0;
}
コード例 #8
0
ファイル: luna_methods.c プロジェクト: rwhitby/impostah
//
// Impersonate a call to the requested service and return the output to webOS.
//
bool impersonate_method(LSHandle* lshandle, LSMessage *message, void *ctx) {
  bool retVal;
  LSError lserror;
  LSErrorInit(&lserror);
  LSMessageRef(message);

  if (access_denied(message)) return true;

  // Extract the method argument from the message
  json_t *object = json_parse_document(LSMessageGetPayload(message));
  json_t *id = json_find_first_label(object, "id");               
  if (!id || (id->child->type != JSON_STRING)) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing id\"}",
			&lserror)) goto error;
    return true;
  }

  // Extract the service argument from the message
  object = json_parse_document(LSMessageGetPayload(message));
  json_t *service = json_find_first_label(object, "service");               
  if (!service || (service->child->type != JSON_STRING)) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing service\"}",
			&lserror)) goto error;
    return true;
  }

  // Extract the method argument from the message
  object = json_parse_document(LSMessageGetPayload(message));
  json_t *method = json_find_first_label(object, "method");               
  if (!method || (method->child->type != JSON_STRING)) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing method\"}",
			&lserror)) goto error;
    return true;
  }

  // Extract the params argument from the message
  object = json_parse_document(LSMessageGetPayload(message));
  json_t *params = json_find_first_label(object, "params");               
  if (!params || (params->child->type != JSON_OBJECT)) {
    if (!LSMessageRespond(message,
			"{\"returnValue\": false, \"errorCode\": -1, \"errorText\": \"Invalid or missing params\"}",
			&lserror)) goto error;
    return true;
  }

  char uri[MAXLINLEN];
  sprintf(uri, "palm://%s/%s", service->child->text, method->child->text);

  char *paramstring = NULL;
  json_tree_to_string (params->child, &paramstring);
  if (!LSCallFromApplication(priv_serviceHandle, uri, paramstring, id->child->text,
			     impersonate_handler, message, NULL, &lserror)) goto error;

  return true;
 error:
  LSErrorPrint(&lserror, stderr);
  LSErrorFree(&lserror);
 end:
  return false;
}