Ejemplo n.º 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;
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
int
main (int argc, char *argv[])
{
  NYX_CHANNEL *c1, *c2, *c3;
  NYX_NET     *net;
  NYX_QUEUE   *q;
  pthread_t   tid;
  nyx_init ();

  /* Create client channels */
  c1 = nyx_channel_new (NULL);
  nyx_channel_tcp_init (c1, "127.0.0.1", 8000, 0);
  nyx_channel_set_cb (c1, read_cb);


  c2 = nyx_channel_new (NULL);
  nyx_channel_tcp_init (c2, "127.0.0.1", 8001,0); 
  nyx_channel_set_cb (c2, read_cb);

  c3 = nyx_channel_new (NULL);
  nyx_channel_tcp_init (c3, "127.0.0.1", 8001,0); 
  nyx_channel_set_cb (c3, read_cb);


  /* Create Queue */
  q = nyx_queue_new (50);

  /* Create worker */
  pthread_create (&tid, NULL, consumer, q);
  
  /* Create net object */
  net = nyx_net_init ();

  /* register channels */
  nyx_net_register (net, c1, q);
  nyx_net_register (net, c2, q);
  nyx_net_register (net, c3, q);

  nyx_net_run (net);
  
  nyx_channel_free (c2);
  nyx_channel_free (c1);
  nyx_queue_free (q);
  nyx_net_free (net);

  nyx_cleanup ();
  return 0;
}
Ejemplo n.º 4
0
int ChargerInit(void)
{
	int ret = 0;
	nyx_init();

	nyx_error_t error = NYX_ERROR_NONE;
	nyx_device_iterator_handle_t iteraror = NULL;

	error = nyx_device_get_iterator(NYX_DEVICE_CHARGER, NYX_FILTER_DEFAULT, &iteraror);
	if(error != NYX_ERROR_NONE || iteraror == NULL) {
	   goto error;
	}
	else if (error == NYX_ERROR_NONE)
	{
		nyx_device_id_t id = NULL;
		while ((error = nyx_device_iterator_get_next_id(iteraror,
			&id)) == NYX_ERROR_NONE && NULL != id)
		{
			g_debug("Powerd: Charger device id \"%s\" found",id);
			error = nyx_device_open(NYX_DEVICE_CHARGER, id, &nyxDev);
			if(error != NYX_ERROR_NONE)
			{
				goto error;
			}
			break;
		}
	}

	memset(&currStatus,0,sizeof(nyx_charger_status_t));

	LSError lserror;
	LSErrorInit(&lserror);
	bool retVal;

	retVal = LSCall(GetLunaServiceHandle(),
		"luna://com.palm.lunabus/signal/addmatch",
			"{\"category\":\"/com/palm/power\","
			 "\"method\":\"chargerStatusQuery\"}",
			 chargerStatusQuerySignal, NULL, NULL, &lserror);
	if (!retVal)
		goto lserror;

	nyx_charger_register_charger_status_callback(nyxDev,notifyChargerStatus,NULL);

    if (!gChargeConfig.skip_battery_check && !gChargeConfig.disable_charging)
    	nyx_charger_register_state_change_callback(nyxDev,notifyStateChange,NULL);

out:
	if(iteraror)
		free(iteraror);
	return ret;

lserror:
	LSErrorPrint (&lserror, stderr);
	LSErrorFree (&lserror);
	ret = -1;
	goto out;

error:
	g_critical("Powerd: No charger device found\n");
	gChargeConfig.skip_battery_check = 1;
//	abort();
	return 0;
}
Ejemplo n.º 5
0
bool EffectNyquist::Process()
{
   bool success = true;

   if (mExternal) {
      mProgress->Hide();
   }

   // We must copy all the tracks, because Paste needs label tracks to ensure
   // correct sync-lock group behavior when the timeline is affected; then we just want
   // to operate on the selected wave tracks
   this->CopyInputTracks(Track::All);
   SelectedTrackListOfKindIterator iter(Track::Wave, mOutputTracks);
   mCurTrack[0] = (WaveTrack *) iter.First();
   mOutputTime = mT1 - mT0;
   mCount = 0;
   mProgressIn = 0;
   mProgressOut = 0;
   mProgressTot = 0;
   mScale = (GetEffectFlags() & PROCESS_EFFECT ? 0.5 : 1.0) / GetNumWaveGroups();

   mStop = false;
   mBreak = false;
   mCont = false;

   mDebugOutput = "";

   // Keep track of whether the current track is first selected in its sync-lock group
   // (we have no idea what the length of the returned audio will be, so we have
   // to handle sync-lock group behavior the "old" way).
   mFirstInGroup = true;
   Track *gtLast = NULL;

   while (mCurTrack[0]) {
      mCurNumChannels = 1;
      if (mT1 >= mT0) {
         if (mCurTrack[0]->GetLinked()) {
            mCurNumChannels = 2;

            mCurTrack[1] = (WaveTrack *)iter.Next();
            if (mCurTrack[1]->GetRate() != mCurTrack[0]->GetRate()) {
               wxMessageBox(_("Sorry, cannot apply effect on stereo tracks where the tracks don't match."), 
                            wxT("Nyquist"),
                            wxOK | wxCENTRE, mParent);
               success = false;
               goto finish;
            }
            mCurStart[1] = mCurTrack[1]->TimeToLongSamples(mT0);
         }

         // Check whether we're in the same group as the last selected track
         SyncLockedTracksIterator gIter(mOutputTracks);
         Track *gt = gIter.First(mCurTrack[0]);
         mFirstInGroup = !gtLast || (gtLast != gt);
         gtLast = gt;

         mCurStart[0] = mCurTrack[0]->TimeToLongSamples(mT0);
         sampleCount end = mCurTrack[0]->TimeToLongSamples(mT1);
         mCurLen = (sampleCount)(end - mCurStart[0]);

         mProgressIn = 0.0;
         mProgressOut = 0.0;

         // libnyquist breaks except in LC_NUMERIC=="C".
         //
         // Note that we must set the locale to "C" even before calling
         // nyx_init() because otherwise some effects will not work!
         //
         // MB: setlocale is not thread-safe.  Should use uselocale()
         //     if available, or fix libnyquist to be locale-independent.
         char *prevlocale = setlocale(LC_NUMERIC, NULL);
         setlocale(LC_NUMERIC, "C");

         nyx_init();
         nyx_set_os_callback(StaticOSCallback, (void *)this);
         nyx_capture_output(StaticOutputCallback, (void *)this);

         success = ProcessOne();

         nyx_capture_output(NULL, (void *)NULL);
         nyx_set_os_callback(NULL, (void *)NULL);
         nyx_cleanup();

         // Reset previous locale
         setlocale(LC_NUMERIC, prevlocale);

         if (!success) {
            goto finish;
         }
         mProgressTot += mProgressIn + mProgressOut;
      }

      mCurTrack[0] = (WaveTrack *) iter.Next();
      mCount += mCurNumChannels;
   }

   mT1 = mT0 + mOutputTime;

 finish:

   if (mDebug && !mExternal) {
      NyquistOutputDialog dlog(mParent, -1,
                               _("Nyquist"),
                               _("Nyquist Output: "),
                               NyquistToWxString(mDebugOutput.c_str()));
      dlog.CentreOnParent();
      dlog.ShowModal();
   }

   this->ReplaceProcessedTracks(success);

   //mDebug = false;

   return success;
}
Ejemplo n.º 6
0
/*!
\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;
}