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; }
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_open(NYX_DEVICE_HAPTICS, "Main", &d); if (error != NYX_ERROR_NONE) g_critical("HapticsControllerCastle failed to open device successfully!"); }
int BatteryInit(void) { int ret = 0; nyx_error_t error = NYX_ERROR_NONE; nyx_device_iterator_handle_t iteraror = NULL; error = nyx_device_get_iterator(NYX_DEVICE_BATTERY, 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: Battery device id \"%s\" found",id); error = nyx_device_open(NYX_DEVICE_BATTERY, id, &battDev); if(error != NYX_ERROR_NONE) { goto error; } break; } } LSError lserror; LSErrorInit(&lserror); bool retVal; retVal = LSCall(GetLunaServiceHandle(), "luna://com.palm.lunabus/signal/addmatch", "{\"category\":\"/com/palm/power\"," "\"method\":\"batteryStatusQuery\"}", batteryStatusQuerySignal, NULL, NULL, &lserror); if (!retVal) goto lserror; if (gChargeConfig.fake_battery) { retVal = LSCall(GetLunaServiceHandle(), "luna://com.palm.lunabus/signal/addmatch", "{\"category\":\"/com/palm/power\"," "\"method\":\"fakeBatteryStatus\"}", fakeBatteryStatus, NULL, NULL, &lserror); if (!retVal) goto lserror; } nyx_battery_register_battery_status_callback(battDev,notifyBatteryStatus,NULL); out: if(iteraror) free(iteraror); return ret; lserror: LSErrorPrint (&lserror, stderr); LSErrorFree (&lserror); ret = -1; goto out; error: g_critical("Powerd: No battery device found\n"); battDev = NULL; // abort(); return 0; }
int main(int argc, char **argv) { bool retVal; int opt; bool invertCarrier = false; LSPalmService * lsps = NULL; while ((opt = getopt(argc, argv, "chdst")) != -1) { switch (opt) { case 'c': invertCarrier = true; break; case 'd': setLogLevel(G_LOG_LEVEL_DEBUG); break; case 's': setUseSyslog(true); break; case 'h': default: PrintUsage(argv[0]); return EXIT_SUCCESS; } } // make sure we aren't already running. if (!LockProcess("storaged")) { g_error("%s: %s daemon is already running.\n", __func__, argv[0]); exit(EXIT_FAILURE); } g_log_set_default_handler(logFilter, NULL); g_debug( "entering %s in %s", __func__, __FILE__ ); signal(SIGTERM, term_handler); g_mainloop = g_main_loop_new(NULL, FALSE); int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if(ret != NYX_ERROR_NONE) { g_critical("Unable to open the nyx device system"); abort(); } else g_debug("Initialized nyx system device"); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.storage", &lsps, &lserror); if (!retVal) { g_critical ("failed in function %s with erro %s", lserror.func, lserror.message); LSErrorFree(&lserror); return EXIT_FAILURE; } SignalsInit( lsps ); LSHandle *lsh_priv = LSPalmServiceGetPrivateConnection(lsps); LSHandle *lsh_pub = LSPalmServiceGetPublicConnection(lsps); DiskModeInterfaceInit( g_mainloop, lsh_priv, lsh_pub, invertCarrier ); EraseInit(g_mainloop, lsh_priv); retVal = LSGmainAttach( lsh_priv, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach private returned %s", lserror.message ); LSErrorFree(&lserror); } retVal = LSGmainAttach( lsh_pub, g_mainloop, &lserror ); if ( !retVal ) { g_critical( "LSGmainAttach public returned %s", lserror.message ); LSErrorFree(&lserror); } g_main_loop_run(g_mainloop); g_main_loop_unref(g_mainloop); if (!LSUnregister( lsh_priv, &lserror)) { g_critical( "LSUnregister private returned %s", lserror.message ); } if (!LSUnregister( lsh_pub, &lserror)) { g_critical( "LSUnregister public returned %s", lserror.message ); } UnlockProcess(); g_debug( "exiting %s in %s", __func__, __FILE__ ); if (!retVal) return EXIT_FAILURE; else return EXIT_SUCCESS; }
/** * Main entry point for sleepd - runs the initialization hooks installed at program load time * * A bit counter-intuitively, this is not the first part of this program which * is run. * * First, everything which uses the {@link INIT_FUNC} macro in init.h are run, * which registers a bunch of hooks with the initialization system so that * individual modules can be registered without touching the main sleepd * initialization code. Then, once all of those hooks are installed, execution * proceeds to this function which actually runs those hooks. * * - Initializes sleepd. * - Attaches as a Luna service under com.palm.sleep. * - Attaches to Nyx. * - Subscribes to events related to the charger being plugged and unplugged from the com.palm.power service. * - Calls {@link TheOneInit()} to finish initialization of the service. * - Issues a request to the com.palm.power service to check on the plugged/unplugged status of the charger. * * @param argc Number of command-line arguments. * @param argv List of command-line arguments. * * @todo Move the logging initialization functionality into {@link TheOneInit()}. */ int main(int argc, char **argv) { bool retVal; /* * Register a function to be able to gracefully handle termination signals * from the OS or other processes. */ signal(SIGTERM, term_handler); signal(SIGINT, term_handler); #if !GLIB_CHECK_VERSION(2,32,0) if (!g_thread_supported()) { g_thread_init(NULL); } #endif mainloop = g_main_loop_new(NULL, FALSE); /* * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); /* * Register ourselves as the com.palm.sleep service. */ retVal = LSRegisterPalmService("com.palm.sleep", &psh, &lserror); if (retVal) { /* * Attach our main loop to the service so we can process IPC messages addressed to us. */ retVal = LSGmainAttachPalmService(psh, mainloop, &lserror); if (retVal) { /* * Get our private bus for our service so we can pass a message to com.palm.power. */ private_sh = LSPalmServiceGetPrivateConnection(psh); /* * Register with com.palm.power for events regarding changes in status * to the plug/unplug state of any chargers which may be attached to our * device. */ retVal = LSCall(private_sh, "luna://com.palm.lunabus/signal/addmatch", "{\"category\":\"/com/palm/power\"," "\"method\":\"USBDockStatus\"}", ChargerStatus, NULL, NULL, &lserror); if (retVal) { /* * Connect to Nyx so we can use it later. */ int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if (ret != NYX_ERROR_NONE) { SLEEPDLOG_CRITICAL(MSGID_NYX_DEVICE_OPEN_FAIL, 1, PMLOGKS(CAUSE, "Unable to open the nyx device system"), ""); abort(); } /* * Call our main initialization function - this is the function which * is supposed to handle initializing pretty much everything for us. */ TheOneInit(); /* * Now that we've got something listening for charger status changes, * request the current state of the charger from com.palm.power. */ LSCall(private_sh, "luna://com.palm.power/com/palm/power/chargerStatusQuery", "{}", ChargerStatus, NULL, NULL, &lserror); SLEEPDLOG_DEBUG("Sleepd daemon started"); g_main_loop_run(mainloop); } } } else { SLEEPDLOG_CRITICAL(MSGID_SRVC_REGISTER_FAIL, 1, PMLOGKS(ERRTEXT, lserror.message), "Could not initialize sleepd"); LSErrorFree(&lserror); } g_main_loop_unref(mainloop); return 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; }
int main(int argc, char **argv) { bool retVal; // FIXME integrate this into TheOneInit() LOGInit(); LOGSetHandler(LOGSyslog); signal(SIGTERM, term_handler); signal(SIGINT, term_handler); if (!g_thread_supported ()) g_thread_init (NULL); mainloop = g_main_loop_new(NULL, FALSE); /** * initialize the lunaservice and we want it before all the init * stuff happening. */ LSError lserror; LSErrorInit(&lserror); retVal = LSRegisterPalmService("com.palm.sleep", &psh, &lserror); if (!retVal) { goto ls_error; } retVal = LSGmainAttachPalmService(psh, mainloop, &lserror); if (!retVal) { goto ls_error; } private_sh = LSPalmServiceGetPrivateConnection(psh); retVal = LSCall(private_sh,"luna://com.palm.lunabus/signal/addmatch","{\"category\":\"/com/palm/power\"," "\"method\":\"USBDockStatus\"}", ChargerStatus, NULL, NULL, &lserror); if (!retVal) { SLEEPDLOG(LOG_CRIT,"Error in registering for luna-signal \"chargerStatus\""); goto ls_error; } int ret = nyx_device_open(NYX_DEVICE_SYSTEM, "Main", &nyxSystem); if(ret != NYX_ERROR_NONE) { SLEEPDLOG(LOG_CRIT,"Sleepd: Unable to open the nyx device system"); abort(); } TheOneInit(); LSCall(private_sh,"luna://com.palm.power/com/palm/power/chargerStatusQuery","{}",ChargerStatus,NULL,NULL,&lserror); SLEEPDLOG(LOG_INFO,"Sleepd daemon started\n"); g_main_loop_run(mainloop); end: g_main_loop_unref(mainloop); return 0; ls_error: SLEEPDLOG(LOG_CRIT,"Fatal - Could not initialize sleepd. Is LunaService Down?. %s", lserror.message); LSErrorFree(&lserror); goto end; }
/*! \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; }