void telephony_service_network_status_changed_notify(struct telephony_service *service, struct telephony_network_status *net_status)
{
	jvalue_ref reply_obj = NULL;
	jvalue_ref network_obj = NULL;

	if (service->power_off_pending)
		return;

	reply_obj = jobject_create();
	network_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	service->network_registered = (net_status->state == TELEPHONY_NETWORK_STATE_SERVICE);

	jobject_put(network_obj, J_CSTR_TO_JVAL("state"),
				jstring_create(telephony_network_state_to_string(net_status->state)));
	jobject_put(network_obj, J_CSTR_TO_JVAL("registration"),
				jstring_create(telephony_network_registration_to_string(net_status->registration)));
	jobject_put(network_obj, J_CSTR_TO_JVAL("networkName"), jstring_create(net_status->name != NULL ? net_status->name : ""));
	jobject_put(network_obj, J_CSTR_TO_JVAL("causeCode"), jstring_create(""));

	jobject_put(reply_obj, J_CSTR_TO_JVAL("eventNetwork"), network_obj);

	luna_service_post_subscription(service->private_service, "/", "networkStatusQuery", reply_obj);

	j_release(&reply_obj);
}
bool _service_device_lock_query_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct telephony_service *service = user_data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool subscribed = false;

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	subscribed = luna_service_check_for_subscription_and_process(handle, message);

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if (!service->powered) {
		jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(1));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("Phone Radio is off"));
	}
	else {
		jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success"));
	}

	/* FIXME we don't really now which properties are part of the extended object */

	jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed));

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);

	return true;
}
static int _service_rat_query_finish(const struct telephony_error *error,
									 enum telephony_radio_access_mode mode, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(success ? "success" : ""));

	if (success) {
		extended_obj = jobject_create();
		jobject_put(extended_obj, J_CSTR_TO_JVAL("mode"),
					jstring_create(telephony_radio_access_mode_to_string(mode)));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
static int _service_signal_strength_query_finish(const struct telephony_error *error, unsigned int bars, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	/* handle possible subscriptions */
	if (req_data->subscribed)
		jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed));

	if (success) {
		jobject_put(extended_obj, J_CSTR_TO_JVAL("bars"), jnumber_create_i32(bars));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
static bool handle_get_info_command(LSHandle *sh, LSMessage *message, void* context)
{
	jvalue_ref reply = jobject_create();
	LSError lserror;
	LSErrorInit(&lserror);
	char wifi_mac_address[32]={0}, wired_mac_address[32]={0};

	jobject_put(reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if(get_wifi_mac_address(CONNMAN_WIFI_INTERFACE_NAME, wifi_mac_address) == 0)
	{
		jvalue_ref wifi_info = jobject_create();
		jobject_put(wifi_info, J_CSTR_TO_JVAL("macAddress"),jstring_create(wifi_mac_address));
		jobject_put(reply, J_CSTR_TO_JVAL("wifiInfo"), wifi_info);
	}
	else
		WCA_LOG_ERROR("Error in fetching mac address for wifi interface");


	if(get_wifi_mac_address(CONNMAN_WIRED_INTERFACE_NAME, wired_mac_address) == 0)
	{
		jvalue_ref wired_info = jobject_create();
		jobject_put(wired_info, J_CSTR_TO_JVAL("macAddress"),jstring_create(wired_mac_address));
		jobject_put(reply, J_CSTR_TO_JVAL("wiredInfo"), wired_info);
	}
	else
		WCA_LOG_ERROR("Error in fetching mac address for wired interface");

	jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL);
	if(!response_schema)
	{
		LSMessageReplyErrorUnknown(sh,message);
		goto cleanup;
	}

	if (!LSMessageReply(sh, message, jvalue_tostring(reply, response_schema), &lserror))
	{
		LSErrorPrint(&lserror, stderr);
		LSErrorFree(&lserror);
	}

	jschema_release(&response_schema);

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

	j_release(&reply);
	return true;
}
static int _service_network_list_query_finish(const struct telephony_error *error, GList *networks, void *data)
{
	struct luna_service_req_data *req_data = data;
	struct telephony_service *service = req_data->user_data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	jvalue_ref networks_obj = NULL;
	jvalue_ref network_obj = NULL;
	bool success = (error == NULL);
	struct telephony_network *current_network = NULL;
	int n;

	reply_obj = jobject_create();
	extended_obj = jobject_create();
	networks_obj = jarray_create(NULL);

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	if (success) {
		for (n = 0; n < g_list_length(networks); n++) {
			current_network = g_list_nth_data(networks, n);

			network_obj = jobject_create();
			jobject_put(network_obj, J_CSTR_TO_JVAL("id"), jnumber_create_i32(current_network->id));
			jobject_put(network_obj, J_CSTR_TO_JVAL("name"),
						jstring_create(current_network->name ? current_network->name : ""));
			const char *rat_str = telephony_radio_access_mode_to_string(current_network->radio_access_mode);
			jobject_put(network_obj, J_CSTR_TO_JVAL("rat"), jstring_create(rat_str));
			jarray_append(networks_obj, network_obj);
		}

		jobject_put(extended_obj, J_CSTR_TO_JVAL("networks"), networks_obj);
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	service->network_status_query_pending = false;

	j_release(&reply_obj);
	luna_service_req_data_free(req_data);

	return 0;
}
static int _service_platform_query_finish(const struct telephony_error *error, struct telephony_platform_info *platform_info, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));

	if (success) {
		jobject_put(extended_obj, J_CSTR_TO_JVAL("platformType"),
			jstring_create(telephony_platform_type_to_string(platform_info->platform_type)));

		if (platform_info->imei != NULL)
			jobject_put(extended_obj, J_CSTR_TO_JVAL("imei"), jstring_create(platform_info->imei));

		if (platform_info->carrier != NULL)
			jobject_put(extended_obj, J_CSTR_TO_JVAL("carrier"), jstring_create(platform_info->carrier));

		if (platform_info->mcc > 0 && platform_info->mnc > 0) {
			jobject_put(extended_obj, J_CSTR_TO_JVAL("mcc"), jnumber_create_i32(platform_info->mcc));
			jobject_put(extended_obj, J_CSTR_TO_JVAL("mnc"), jnumber_create_i32(platform_info->mnc));
		}

		if (platform_info->version != NULL)
			jobject_put(extended_obj, J_CSTR_TO_JVAL("version"), jstring_create(platform_info->version));

		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}
	else {
		/* FIXME better error message */
		luna_service_message_reply_error_unknown(req_data->handle, req_data->message);
		goto cleanup;
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
Example #8
0
static bool get_status_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct audio_service *service = user_data;
	jvalue_ref reply_obj = NULL;
	bool subscribed = false;

	if (!service->context_initialized) {
		luna_service_message_reply_custom_error(handle, message, "Not yet initialized");
		return true;
	}

	subscribed = luna_service_check_for_subscription_and_process(handle, message);

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("volume"), jnumber_create_f64(service->volume));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("mute"), jboolean_create(service->mute));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("inCall"), jboolean_create(service->in_call));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("speakerMode"), jboolean_create(service->speaker_mode));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("micMute"), jboolean_create(service->mic_mute));
	if (subscribed)
		jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(true));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if (!luna_service_message_validate_and_send(handle, message, reply_obj))
		goto cleanup;

cleanup:
	if (!jis_null(reply_obj))
		j_release(&reply_obj);

	return true;
}
static int _service_network_list_query_cancel_finish(const struct telephony_error *error, void *data)
{
	struct luna_service_req_data *req_data = data;
	struct telephony_service *service = req_data->user_data;
	jvalue_ref reply_obj = NULL;
	bool success = (error == NULL);

	if (!success) {
		luna_service_message_reply_error_unknown(req_data->handle, req_data->message);
		goto cleanup;
	}

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success"));

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

	service->network_status_query_pending = false;

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
Example #10
0
static int dom_object_start(JSAXContextRef ctxt)
{
	DomInfo *data = getDOMContext(ctxt);
	jvalue_ref newParent;
	DomInfo *newChild;
	CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "object encountered without any context");

	newParent = jobject_create();
	newChild = calloc(1, sizeof(DomInfo));
	if (UNLIKELY(newChild == NULL || jis_null(newParent))) {
		PJ_LOG_ERR("Failed to allocate space for new object");
		j_release(&newParent);
		free(newChild);
		return 0;
	}
	newChild->m_prev = data;
	newChild->m_optInformation = data->m_optInformation;
	changeDOMContext(ctxt, newChild);

	if (data->m_prev != NULL) {
		if (jis_array(data->m_prev->m_value)) {
			assert(data->m_value == NULL);
			jarray_append(data->m_prev->m_value, newParent);
		} else {
			assert(jis_object(data->m_prev->m_value));
			CHECK_CONDITION_RETURN_VALUE(!jis_string(data->m_value), 0, "improper place for a child object");
			jobject_put(data->m_prev->m_value, data->m_value, newParent);
		}
	}

	// not using reference counting here on purpose
	data->m_value = newParent;

	return 1;
}
static int _service_network_selection_mode_query_finish(const struct telephony_error *error, bool automatic, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	if (success) {
		jobject_put(reply_obj, J_CSTR_TO_JVAL("automatic"), jboolean_create(automatic));
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
bool get_all_properties_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	jvalue_ref reply_obj = NULL;
	jvalue_ref props_obj = NULL;
	struct property_list list;

	reply_obj = jobject_create();
	props_obj = jarray_create(NULL);

	memset(&list, 0, sizeof(struct property_list));
	if (property_list(record_prop, props_obj) < 0) {
		luna_service_message_reply_error_internal(handle, message);
		goto cleanup;
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("properties"), props_obj);
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	if (!luna_service_message_validate_and_send(handle, message, reply_obj))
		goto cleanup;

cleanup:
	if (!jis_null(reply_obj))
		j_release(&reply_obj);

	if (!jis_null(props_obj))
		j_release(&props_obj);

	return true;
}
static int _service_subscriber_id_query_finish(const struct telephony_error *error, struct telephony_subscriber_info *info, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));

	if (success) {
		jobject_put(extended_obj, J_CSTR_TO_JVAL("platformType"),
					jstring_create(telephony_platform_type_to_string(info->platform_type)));

		switch (info->platform_type) {
		case TELEPHONY_PLATFORM_TYPE_GSM:
			jobject_put(extended_obj, J_CSTR_TO_JVAL("imsi"), jstring_create(info->imsi));
			jobject_put(extended_obj, J_CSTR_TO_JVAL("msisdn"), jstring_create(info->msisdn));
			break;
		case TELEPHONY_PLATFORM_TYPE_CDMA:
			jobject_put(extended_obj, J_CSTR_TO_JVAL("min"), jstring_create(info->min));
			jobject_put(extended_obj, J_CSTR_TO_JVAL("mdn"), jstring_create(info->mdn));
			break;
		}

		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}
	else {
		/* FIXME better error message */
		luna_service_message_reply_error_unknown(req_data->handle, req_data->message);
		goto cleanup;
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
static void send_connection_status(jvalue_ref *reply)
{
        if(NULL == reply)
                return;
	jobject_put(*reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
	gboolean online = connman_manager_is_manager_online(manager);
	jobject_put(*reply, J_CSTR_TO_JVAL("isInternetConnectionAvailable"), jboolean_create(online));

	jvalue_ref connected_wired_status = jobject_create();
	jvalue_ref disconnected_wired_status = jobject_create();
	jvalue_ref connected_wifi_status = jobject_create();
	jvalue_ref disconnected_wifi_status = jobject_create();

	jobject_put(disconnected_wired_status, J_CSTR_TO_JVAL("state"), jstring_create("disconnected"));
	jobject_put(disconnected_wifi_status, J_CSTR_TO_JVAL("state"), jstring_create("disconnected"));

	/* Get the service which is connecting or already in connected state */
	connman_service_t *connected_wired_service = connman_manager_get_connected_service(manager->wired_services);
	if(NULL != connected_wired_service)
	{
		update_connection_status(connected_wired_service, &connected_wired_status);
		jobject_put(*reply, J_CSTR_TO_JVAL("wired"), connected_wired_status);
		j_release(&disconnected_wired_status);
	}
	else
	{
		jobject_put(*reply, J_CSTR_TO_JVAL("wired"), disconnected_wired_status);
		j_release(&connected_wired_status);
	}

	connman_service_t *connected_wifi_service = connman_manager_get_connected_service(manager->wifi_services);
	if(NULL != connected_wifi_service)
	{
		update_connection_status(connected_wifi_service, &connected_wifi_status);
		jobject_put(*reply, J_CSTR_TO_JVAL("wifi"), connected_wifi_status);
		j_release(&disconnected_wifi_status);
	}
	else
	{
		jobject_put(*reply, J_CSTR_TO_JVAL("wifi"), disconnected_wifi_status);
		j_release(&connected_wifi_status);
	}
}
static void record_prop(const char *key, const char *value, void *user_data)
{
	jvalue_ref props_obj = user_data;
	jvalue_ref prop_obj = NULL;

	prop_obj = jobject_create();
	jobject_put(prop_obj, jstring_create(key), jstring_create(value));

	jarray_append(props_obj, prop_obj);
}
void telephony_service_signal_strength_changed_notify(struct telephony_service *service, int bars)
{
	jvalue_ref reply_obj = NULL;
	jvalue_ref signal_obj = NULL;

	if (service->power_off_pending)
		return;

	reply_obj = jobject_create();
	signal_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	jobject_put(signal_obj, J_CSTR_TO_JVAL("bars"), jnumber_create_i32(bars));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("eventSignal"), signal_obj);

	luna_service_post_subscription(service->private_service, "/", "signalStrengthQuery", reply_obj);

	j_release(&reply_obj);
}
static int _service_network_status_query_finish(const struct telephony_error *error, struct telephony_network_status *net_status, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create(""));

	/* handle possible subscriptions */
	if (req_data->subscribed)
		jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed));

	if (success) {
		jobject_put(extended_obj, J_CSTR_TO_JVAL("state"),
					jstring_create(telephony_network_state_to_string(net_status->state)));
		jobject_put(extended_obj, J_CSTR_TO_JVAL("registration"),
				jstring_create(telephony_network_registration_to_string(net_status->registration)));
		jobject_put(extended_obj, J_CSTR_TO_JVAL("networkName"), jstring_create(net_status->name != NULL ? net_status->name : ""));
		jobject_put(extended_obj, J_CSTR_TO_JVAL("causeCode"), jstring_create(""));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
Example #18
0
static void notify_status_subscribers(struct audio_service *service)
{
	jvalue_ref reply_obj = NULL;

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("volume"), jnumber_create_f64(service->volume));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("mute"), jboolean_create(service->mute));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	luna_service_post_subscription(service->handle, "/", "getStatus", reply_obj);

	j_release(&reply_obj);
}
void telephony_service_power_status_notify(struct telephony_service *service, bool power)
{
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;

	service->powered = power;

	if (!service->initialized) {
		g_message("Service not yet successfully initialized. Not sending power status notification");
		return;
	}

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	extended_obj = jobject_create();
	jobject_put(extended_obj, J_CSTR_TO_JVAL("powerState"), jstring_create(power ? "on": "off"));

	jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);

	luna_service_post_subscription(service->private_service, "/", "powerQuery", reply_obj);

	j_release(&reply_obj);
}
int _service_power_query_finish(const struct telephony_error *error, bool power, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));

	/* handle possible subscriptions */
	if (req_data->subscribed)
		jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(req_data->subscribed));

	if (success) {
		jobject_put(extended_obj, J_CSTR_TO_JVAL("powerState"), jstring_create(power ? "on" : "off"));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	}
	else {
		/* FIXME better error message */
		luna_service_message_reply_error_unknown(req_data->handle, req_data->message);
		goto cleanup;
	}

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
bool _service_is_telephony_ready_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct telephony_service *service = user_data;
	jvalue_ref reply_obj = NULL;
	jvalue_ref extended_obj = NULL;
	bool subscribed = false;

	reply_obj = jobject_create();
	extended_obj = jobject_create();

	subscribed = luna_service_check_for_subscription_and_process(handle, message);

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(0));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("success"));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("radioConnected"), jboolean_create(service->initialized));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("power"), jboolean_create(service->powered));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("ready"), jboolean_create(service->initialized));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("networkRegistered"), jboolean_create(service->network_registered));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("dataRegistered"), jboolean_create(service->data_registered));

	/* FIXME check in which situations the three fields below are set and updated */
	jobject_put(extended_obj, J_CSTR_TO_JVAL("emergency"), jboolean_create(false));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("security"), jboolean_create(false));
	jobject_put(extended_obj, J_CSTR_TO_JVAL("securityLocked"), jboolean_create(false));

	jobject_put(reply_obj, J_CSTR_TO_JVAL("extended"), extended_obj);
	jobject_put(reply_obj, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed));

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);

	return true;
}
void system_upgrade_progress_cb(const opkg_progress_data_t *progress, void *user_data)
{
	struct luna_service_req_data *req_data = user_data;
	jvalue_ref reply_obj = NULL;

	if (progress && progress->pkg) {
		g_message("[%i%] %s %s", progress->percentage, opkg_action_to_string(progress->action), progress->pkg->name);

		reply_obj = jobject_create();

		jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("state"), jstring_create("inprogress"));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("action"), jstring_create(opkg_action_to_string(progress->action)));
		jobject_put(reply_obj, J_CSTR_TO_JVAL("package"), jstring_create(progress->pkg->name));

		luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj);
	}
}
bool _service_charge_source_query_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	jvalue_ref reply_obj = NULL;

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	/* FIXME tested implementation in legacy webOS always returns the following error message */
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(103));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("errorText"), jstring_create("Not supported by this network type"));

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);

	return true;
}
int _service_power_set_finish(const struct telephony_error *error, void *data)
{
	struct luna_service_req_data *req_data = data;
	struct telephony_service *service = req_data->user_data;
	jvalue_ref reply_obj = NULL;

	reply_obj = jobject_create();

	service->power_off_pending = false;

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create((error == NULL)));

	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj))
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);

	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}
static bool handle_get_status_command(LSHandle* sh, LSMessage *message, void* context)
{

	jvalue_ref reply = jobject_create();
	LSError lserror;
	LSErrorInit(&lserror);
	bool subscribed = false;

	if (LSMessageIsSubscription(message))
	{
		if (!LSSubscriptionProcess(sh, message, &subscribed, &lserror))
		{
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
		jobject_put(reply, J_CSTR_TO_JVAL("subscribed"), jboolean_create(subscribed));
		if(!connman_manager_is_manager_available(manager))
			goto response;
	}
	if(!connman_status_check(manager, sh, message))
		goto cleanup;

	send_connection_status(&reply);

response:
	{
		jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL);
		if(!response_schema)
		{
			LSMessageReplyErrorUnknown(sh,message);
			goto cleanup;
		}
		if (!LSMessageReply(sh, message, jvalue_tostring(reply, response_schema), &lserror)) {
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
		jschema_release(&response_schema);
	}
cleanup:
	j_release(&reply);
	return true;
}
Example #26
0
int dom_object_start(JSAXContextRef ctxt)
{
	DomInfo *data = getDOMContext(ctxt);
	jvalue_ref newParent;
	DomInfo *newChild;

	CHECK_CONDITION_RETURN_VALUE(data == NULL, 0, "object encountered without any context");

	newParent = jobject_create();
	newChild = calloc(1, sizeof(DomInfo));

	if (UNLIKELY(newChild == NULL || !jis_valid(newParent))) {
		PJ_LOG_ERR("PBNJSON_OBJ_CALLOC_ERR", 0, "Failed to allocate space for new object");
		j_release(&newParent);
		free(newChild);
		return 0;
	}
	newChild->m_prev = data;
	newChild->m_optInformation = data->m_optInformation;
	changeDOMContext(ctxt, newChild);

	if (data->m_prev != NULL) {
		if (jis_array(data->m_prev->m_value)) {
			assert(data->m_value == NULL);
			jarray_append(data->m_prev->m_value, jvalue_copy(newParent));
		} else {
			assert(jis_object(data->m_prev->m_value));
			if (UNLIKELY(!jis_string(data->m_value)))
			{
				PJ_LOG_ERR("PBNJSON_OBJ_MISPLACED_CHILD", 0, "improper place for a child object");
				j_release(&newParent);
				return 0;
			}
			jobject_put(data->m_prev->m_value, data->m_value, jvalue_copy(newParent));
		}
	}

	data->m_value = newParent;

	return 1;
}
bool service_list_upgradable_packages_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct package_list_info plistinfo;
	GSList *iter;
	jvalue_ref reply_obj = NULL;
	jvalue_ref pkglist_obj = NULL;
	jvalue_ref pkgname_obj = NULL;

	if (opkg_new()) {
		luna_service_message_reply_error_internal(handle, message);
		return true;
	}

	plistinfo.pkgs = g_slist_alloc();
	opkg_list_upgradable_packages(upgradable_package_list_cb, &plistinfo);

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	pkglist_obj = jarray_create(NULL);

	for (iter = plistinfo.pkgs; iter != NULL; iter = g_slist_next(iter)) {
		if (iter->data != NULL) {
			gchar *pkgname = iter->data;
			pkgname_obj = jstring_create(pkgname);
			jarray_append(pkglist_obj, pkgname_obj);
		}
	}

	jobject_put(reply_obj, J_CSTR_TO_JVAL("upgradablePackages"), pkglist_obj);

	if(!luna_service_message_validate_and_send(handle, message, reply_obj))
		luna_service_message_reply_error_internal(handle, message);

	j_release(&reply_obj);
	g_slist_free_full(plistinfo.pkgs, g_free);

	opkg_free();

	return true;
}
bool service_run_upgrade_cb(LSHandle *handle, LSMessage *message, void *user_data)
{
	struct luna_service_req_data *req_data;
	jvalue_ref reply_obj;
	bool upgrade_succeeded = true;

	g_message("User requested starting a complete system upgrade ...");

	if (opkg_new()) {
		luna_service_message_reply_error_internal(handle, message);
		return true;
	}

	req_data = luna_service_req_data_new(handle, message);

	if (opkg_upgrade_all(system_upgrade_progress_cb, req_data) != 0) {
		g_warning("Failed to upgrade the system");
		upgrade_succeeded = false;
	}

	reply_obj = jobject_create();
	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(upgrade_succeeded));
	jobject_put(reply_obj, J_CSTR_TO_JVAL("state"), jstring_create(upgrade_succeeded ? "finished" : "failed"));

	if (!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

	if (upgrade_succeeded)
		g_message("Successfully finished system upgrade!");

cleanup:
	if (req_data)
		luna_service_req_data_free(req_data);

	opkg_free();

	return true;
}
void connectionmanager_send_status(void)
{
	jvalue_ref reply = jobject_create();
	jobject_put(reply, J_CSTR_TO_JVAL("returnValue"), jboolean_create(true));

	send_connection_status(&reply);

	jschema_ref response_schema = jschema_parse (j_cstr_to_buffer("{}"), DOMOPT_NOOPT, NULL);
	if(response_schema)
	{
		const char *payload = jvalue_tostring(reply, response_schema);
		LSError lserror;
		LSErrorInit(&lserror);
		WCA_LOG_INFO("Sending payload %s",payload);
		if (!LSSubscriptionPost(pLsHandle, "/", "getstatus", payload, &lserror))
		{
			LSErrorPrint(&lserror, stderr);
			LSErrorFree(&lserror);
		}
		jschema_release(&response_schema);
	}
	j_release(&reply);
}
int telephonyservice_common_finish(const struct telephony_error *error, void *data)
{
	struct luna_service_req_data *req_data = data;
	jvalue_ref reply_obj = NULL;
	bool success = (error == NULL);

	reply_obj = jobject_create();

	jobject_put(reply_obj, J_CSTR_TO_JVAL("returnValue"), jboolean_create(success));
	if (!success)
		jobject_put(reply_obj, J_CSTR_TO_JVAL("errorCode"), jnumber_create_i32(error->code));


	if(!luna_service_message_validate_and_send(req_data->handle, req_data->message, reply_obj)) {
		luna_service_message_reply_error_internal(req_data->handle, req_data->message);
		goto cleanup;
	}

cleanup:
	j_release(&reply_obj);
	luna_service_req_data_free(req_data);
	return 0;
}