4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <libxml/parser.h>
26 #include "deviced/dd-led.h"
29 #include "core/list.h"
32 #define DATADIR "/usr/share/deviced"
35 #define LED_XML DATADIR"/led.xml"
38 static const char* led_str[] = {
40 [LED_LOW_BATTERY] = "low battery",
41 [LED_CHARGING] = "charging",
42 [LED_FULLY_CHARGED] = "fully charged",
43 [LED_CHARGING_ERROR] = "charging error",
44 [LED_MISSED_NOTI] = "missed noti",
45 [LED_VOICE_RECORDING] = "voice recording",
46 [LED_POWER_OFF] = "power off",
47 [LED_CUSTOM] = "custom",
50 static dd_list *led_head;
52 static xmlDocPtr xml_open(const char *xml)
56 doc = xmlReadFile(xml, NULL, 0);
58 _E("xmlReadFile fail");
65 static void xml_close(xmlDocPtr doc)
70 static xmlNodePtr xml_find(xmlDocPtr doc, const xmlChar* expr)
79 root = xmlDocGetRootElement(doc);
81 _E("xmlDocGetRootElement fail");
85 for (cur = root->children; cur != NULL; cur = cur->next) {
86 if (xmlStrcmp(cur->name, (const xmlChar*)LED_STR))
89 key = xmlGetProp(cur, (const xmlChar*)"label");
90 if (key && !xmlStrcmp(key, expr)) {
100 static struct led_mode *xml_parse(xmlDocPtr doc, xmlNodePtr cur)
104 struct led_mode *led;
111 led = (struct led_mode*)malloc(sizeof(struct led_mode));
117 for (node = cur->children; node != NULL; node = node->next) {
118 if (node->type != XML_ELEMENT_NODE)
121 if (!xmlStrcmp(node->name, "priority")) {
122 key = xmlNodeListGetString(doc, node->children, 1);
125 led->data.priority = atoi(key);
127 } else if (!xmlStrcmp(node->name, "data")) {
128 key = xmlGetProp(node, (const xmlChar*)"on");
131 led->data.on = atoi(key);
134 key = xmlGetProp(node, (const xmlChar*)"off");
137 led->data.off = atoi(key);
140 key = xmlGetProp(node, (const xmlChar*)"color");
143 led->data.color = (unsigned int)strtoul(key, NULL, 16);
146 key = xmlGetProp(node, (const xmlChar*)"wave");
147 if (!key || xmlStrcmp(key, "on"))
148 led->data.wave = false;
150 led->data.wave = true;
155 _D("priority : %d, on : %d, off : %d, color : %x, wave : %d",
156 led->data.priority, led->data.on, led->data.off,
157 led->data.color, led->data.wave);
161 int get_led_data(void)
165 struct led_mode *led;
169 doc = xml_open(LED_XML);
171 _E("xml_open(%s) fail", LED_XML);
176 for (i = 0; i < LED_MODE_MAX; ++i) {
177 cur = xml_find(doc, (const xmlChar*)led_str[i]);
179 _E("xml_find(%s) fail", led_str[i]);
183 led = xml_parse(doc, cur);
185 _E("xml_parse fail");
191 DD_LIST_APPEND(led_head, led);
198 void release_led_data(void)
201 struct led_mode *node;
203 DD_LIST_FOREACH(led_head, l, node) {
204 _D("node name : %d", node->mode);
205 DD_LIST_REMOVE(led_head, node);
210 struct led_mode *find_led_data(int mode)
213 struct led_mode *node;
215 DD_LIST_FOREACH(led_head, l, node) {
216 if (node->mode == mode)
223 struct led_mode *get_valid_led_data(void)
226 struct led_mode *node;
227 struct led_mode *cur = NULL;
230 DD_LIST_FOREACH(led_head, l, node) {
233 if (node->data.priority <= pr) {
234 pr = node->data.priority;
242 void print_all_data(void)
245 struct led_mode *node;
247 _D("Mode State priority on off color wave");
248 DD_LIST_FOREACH(led_head, l, node) {
249 _D("%4d %5d %8d %4d %4d %x %4d",
250 node->mode, node->state, node->data.priority,
251 node->data.on, node->data.off, node->data.color, node->data.wave);