/** * @brief Create a new alarm and assign it an new id. * * @param key * @param calendar_time * @param expiry * @param serviceName * @param applicationName * @param subscribe * @param message * @param ret_id * */ bool alarm_queue_new(const char *key, bool calendar_time, time_t expiry, const char *serviceName, const char *applicationName, bool subscribe, LSMessage *message, int *ret_id) { bool retVal; uint32_t id = gAlarmQueue->seq_id++; if (ret_id) { *ret_id = id; } retVal = alarm_queue_add(id, key, calendar_time, expiry, serviceName, applicationName, subscribe, message); if (retVal) { alarm_write_db(); } return retVal; }
static void alarm_read_db(void) { bool retVal; xmlDocPtr db = xmlReadFile(gAlarmQueue->alarm_db, NULL, 0); if (!db) { return; } xmlNodePtr cur = xmlDocGetRootElement(db); xmlNodePtr sub; if (!cur) { return; } sub = cur->children; while (sub != NULL) { if (!xmlStrcmp(sub->name, (const xmlChar *)"alarm")) { xmlChar *id = xmlGetProp(sub, (const xmlChar *)"id"); xmlChar *key = xmlGetProp(sub, (const xmlChar *)"key"); xmlChar *expiry = xmlGetProp(sub, (const xmlChar *)"expiry"); xmlChar *calendar = xmlGetProp(sub, (const xmlChar *)"calendar"); xmlChar *service = xmlGetProp(sub, (const xmlChar *)"serviceName"); xmlChar *app = xmlGetProp(sub, (const xmlChar *)"applicationName"); if (!id || !expiry) { goto clean_round; } unsigned long expiry_secs = 0; uint32_t alarmId = 0; bool isCalendar = false; if (expiry) { expiry_secs = atol((const char *)expiry); } if (id) { alarmId = atoi((const char *)id); } if (calendar) { isCalendar = atoi((const char *)calendar) > 0; } retVal = alarm_queue_add(alarmId, (const char *)key, isCalendar, expiry_secs, (const char *)service, (const char *)app, false, NULL); if (!retVal) { SLEEPDLOG_WARNING(MSGID_ALARM_NOT_SET, 3, PMLOGKFV(ALARM_ID, "%d", alarmId), PMLOGKS(SRVC_NAME, service), PMLOGKS(APP_NAME, app), "could not add alarm"); } clean_round: xmlFree(expiry); xmlFree(service); xmlFree(app); } sub = sub->next; } xmlFreeDoc(db); }
static void alarm_read_db(void) { bool retVal; xmlDocPtr db = xmlReadFile(gAlarmQueue->alarm_db, NULL, 0); if (!db) return; xmlNodePtr cur = xmlDocGetRootElement(db); xmlNodePtr sub; if (!cur) return; sub = cur->children; while (sub != NULL) { if (!xmlStrcmp(sub->name, (const xmlChar*)"alarm")) { xmlChar *id = xmlGetProp(sub, (const xmlChar*)"id"); xmlChar *key = xmlGetProp(sub, (const xmlChar*)"key"); xmlChar *expiry = xmlGetProp(sub, (const xmlChar*)"expiry"); xmlChar *calendar = xmlGetProp(sub, (const xmlChar*)"calendar"); xmlChar *service = xmlGetProp(sub, (const xmlChar*)"serviceName"); xmlChar *app = xmlGetProp(sub, (const xmlChar*)"applicationName"); if (!id || !expiry) { goto clean_round; } unsigned long expiry_secs = 0; uint32_t alarmId = 0; bool isCalendar = false; if (expiry) { expiry_secs = atol((const char*)expiry); } if (id) { alarmId = atoi((const char*)id); } if (calendar) { isCalendar = atoi((const char*)calendar) > 0; } retVal = alarm_queue_add(alarmId, (const char *)key, isCalendar, expiry_secs, (const char*)service, (const char*)app, false, NULL); if (!retVal) { g_critical("%s: could not add alarm.", __FUNCTION__); } clean_round: xmlFree(expiry); xmlFree(service); xmlFree(app); } sub = sub->next; } xmlFreeDoc(db); }