Пример #1
0
static bool read_modem_present()
{
    // read the modem present using Nyx
    nyx_error_t error = NYX_ERROR_GENERIC;
    nyx_device_handle_t device = NULL;
    const char *modem_present;
    bool ismodem_present=true;

    error = nyx_init();
    if (NYX_ERROR_NONE == error)
    {
        error = nyx_device_open(NYX_DEVICE_DEVICE_INFO, "Main", &device);

        if (NYX_ERROR_NONE == error && NULL != device)
        {
            error = nyx_device_info_query(device, NYX_DEVICE_INFO_MODEM_PRESENT, &modem_present);

            if (NYX_ERROR_NONE == error)
            {
                if(g_strcmp0(modem_present,"N")==0)
                {
                    ismodem_present=false;
                }

            }

            nyx_device_close(device);
        }
        nyx_deinit();
    }
    return ismodem_present;
}
Пример #2
0
void novacom_nduid_init(void)
{
	int i;

	//initialize nduid for cases nyx-lib is not usable
	for (i=0; i < NOVACOM_NDUID_CHRLEN; i++) {
		nduid[i] = "0123456789abcdef"[rand() & 0xf];
	}
	nduid[NOVACOM_NDUID_CHRLEN] = '\0';

#ifndef WEBOS_TARGET_MACHINE_IMPL_HOST
	nyx_device_handle_t device = NULL;
	nyx_error_t error = NYX_ERROR_NONE;

	error = nyx_init();

	if(NYX_ERROR_NONE == error)
	{
		error = nyx_device_open(NYX_DEVICE_DEVICE_INFO, "Main", &device);

		if(NULL != device && NYX_ERROR_NONE == error)
		{
			// Error value left unchecked on purpose. If NDUID reading fails for
			// some reason, initialized value is used.
			(void) nyx_device_info_get_info(device, NYX_DEVICE_INFO_NDUID, nduid,
			                                NOVACOM_NDUID_STRLEN);

			nyx_device_close(device);
		}

		nyx_deinit();
	}

#endif // !WEBOS_TARGET_MACHINE_IMPL_HOST
}
HapticsControllerCastle::~HapticsControllerCastle()
{
    nyx_error_t error = NYX_ERROR_NONE;

    error = nyx_device_close(d);

    if (error != NYX_ERROR_NONE)
        g_critical("HapticsControllerCastle failed to close device successfully!");
  
}
/*!
\page com_palm_device_info_service
\n
\section device_info_query query

\e Private. Available only at the private bus.

com.palm.systemservice/deviceInfo/query

\subsection device_info_query_syntax Syntax:
\code
{
    "parameters": [string array]
}
\endcode

\param parameters List of requested parameters. If not specified, all available parameters wiil be returned. 

\subsection os_info_query_return Returns:
\code
{
    "returnValue": boolean,
    "errorCode": string
    "board_type": string
    "bt_addr": string
    "device_name": string
    "hardware_id": string
    "hardware_revision": string
    "installer": string
    "keyboard_type": string
    "modem_present": string
    "nduid": string
    "product_id": string
    "radio_type": string
    "ram_size": string
    "serial_number": string
    "storage_free": string
    "storage_size": string
    "wifi_addr": string
    "last_reset_type": string
    "battery_challange": string
    "battery_response": string
}
\endcode

\param returnValue Indicates if the call was succesful.
\param errorCode Description of the error if call was not succesful.
\param board_type Board type
\param bt_addr Bluetooth address
\param device_name Device name
\param hardware_id Hardware ID
\param hardware_revision Hardware revision
\param installer Installer
\param keyboard_type Keyboard type
\param modem_present Modem availability
\param nduid NDUID
\param product_id Product ID
\param radio_type Radio type
\param ram_size RAM size
\param serial_number Serial number
\param storage_free Free storage size
\param storage_size Storage size
\param wifi_addr WiFi MAC address
\param last_reset_type Reason code for last reboot (may come from /proc/cmdline)
\param battery_challange Battery challenge
\param battery_response Battery response

All listed parameters can have `not supported` value, if not supported by the device.

\subsection device_info_qeury_examples Examples:
\code
luna-send -n 1 -f luna://com.palm.systemservice/deviceInfo/query '{"parameters":["device_name", "storage_size"]}'
\endcode

Example response for a succesful call:
\code
{
    "device_name": "qemux86",
    "storage_size": "32 GB",
    "returnValue": true
}
\endcode

Example response for a failed call:
\code
{
    "errorCode": "Cannot parse json payload"
    "returnValue": false,
}
\endcode
*/
bool DeviceInfoService::cbGetDeviceInformation(LSHandle* lsHandle, LSMessage *message, void *user_data)
{
	std::string reply;
	std::string parameter;

	const char *nyx_result = NULL;
	bool is_parameters_verified = false; // Becomes `true` if we've formed parameter ourself.
	LSError lsError;

	json_object *payload = NULL;
	json_object *payloadParameterList = NULL;
	json_object *jsonResult = json_object_new_object();

	LSErrorInit(&lsError);

	nyx_error_t error = NYX_ERROR_GENERIC;
	nyx_device_handle_t device = NULL;

	const char *payload_data = LSMessageGetPayload(message);
	if (!payload_data) {
	    reply = "{\"returnValue\": false, "
			" \"errorText\": \"No payload specifed for message\"}";
		goto Done;
	}

	payload = json_tokener_parse(payload_data);
	if (!payload || is_error(payload) || !json_object_is_type(payload, json_type_object)) {
		reply = "{\"returnValue\": false, "
		        " \"errorText\": \"Cannot parse/validate json payload\"}";
		goto Done;
	}

	if (json_object_object_get_ex(payload, "parameters", &payloadParameterList))
	{
		if (!payloadParameterList || !json_object_is_type(payloadParameterList, json_type_array)) {
			reply = "{\"returnValue\": false, "
				" \"errorText\": \"`parameters` needs to be an array\"}";
			goto Done;
		}
	}
	else
	{
		// No parameters. Fill array with all available parameters from the s_commandMap.
		is_parameters_verified = true;
		payloadParameterList = json_object_new_array();
		for (command_map_t::iterator it = s_commandMap.begin(); it != s_commandMap.end(); ++it)
		{
			json_object_array_add(payloadParameterList, json_object_new_string(it->first.c_str()));
		}
	}

	error = nyx_init();
	if (NYX_ERROR_NONE != error)
	{
		qCritical() << "Failed to inititalize nyx library: " << error;
		reply = "{\"returnValue\": false, "
			" \"errorText\": \"Can not initialize nyx\"}";
		goto Done;
	}

	error = nyx_device_open(NYX_DEVICE_DEVICE_INFO, "Main", &device);
	if ((NYX_ERROR_NONE != error) || (NULL == device))
	{
		qCritical() << "Failed to open `Main` nyx device: " << error;
		reply = "{\"returnValue\": false, "
			" \"errorText\": \"Internal error. Can't open nyx device\"}";
		goto Done;
	}

	for (int i = 0; i < json_object_array_length(payloadParameterList); i++)
	{
		parameter = json_object_get_string(json_object_array_get_idx(payloadParameterList, i));
		command_map_t::iterator query = s_commandMap.find(parameter);

		if (!is_parameters_verified && query == s_commandMap.end())
		{
			reply = "{\"returnValue\": false, "
				" \"errorText\": \"Invalid parameter: " + parameter + "\"}";
			goto Done;
		}

	    // Some device don't have all available parameters. We will just ignore them.
		error = nyx_device_info_query(device, query->second, &nyx_result);
		if (NYX_ERROR_NONE == error)
		{
			json_object_object_add(jsonResult, parameter.c_str(), json_object_new_string(nyx_result));
		}
		else
		{
			json_object_object_add(jsonResult, parameter.c_str(), json_object_new_string("not supported"));
		}
	}

	json_object_object_add(jsonResult, "returnValue", json_object_new_boolean(true));
	reply = json_object_to_json_string(jsonResult);

Done:
	bool ret = LSMessageReply(lsHandle, message, reply.c_str(), &lsError);
	if (!ret)
		LSErrorFree(&lsError);

	if (NULL != device)
		nyx_device_close(device);
	nyx_deinit();

	if (payload && !is_error(payload))
		json_object_put(payload);
	if (payloadParameterList && !is_error(payloadParameterList))
		json_object_put(payloadParameterList);
	if (jsonResult && !is_error(jsonResult))
		json_object_put(jsonResult);

	return true;
}