2 * tel-plugin-packetservice
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongHoo Park <donghoo.park@samsung.com>
7 * Arun Shukla <arun.shukla@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <libxml/xmlmemory.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
30 #include "ps_common.h"
31 #include <co_context.h>
33 GSource *ps_util_gsource_dispatch(GMainContext *main_context,
34 gint priority, GSourceFunc cb, gpointer data)
36 GSource *request_source = NULL;
38 request_source = g_idle_source_new();
39 g_source_set_callback(request_source, cb, data, NULL);
40 g_source_set_priority(request_source, priority);
41 g_source_attach(request_source, main_context);
43 return request_source;
46 gboolean ps_util_thread_dispatch(GMainContext *main_context,
47 gint priority, GSourceFunc cb, gpointer data)
50 GSource *request_source;
52 if (main_context == NULL || cb == NULL) {
53 err("Failed to dispatch");
60 request_source = ps_util_gsource_dispatch(main_context, priority, cb, data);
61 g_source_unref(request_source);
66 int ps_util_system_command(char *command)
70 const char *environ[] = { NULL };
86 argv[2] = (char *)command;
89 execve("/bin/sh", argv, (char **)environ);
90 err("execve() failed");
94 if (waitpid(pid, &status, 0) == -1) {
98 if (WIFEXITED(status))
99 return WEXITSTATUS(status);
100 else if (WIFSIGNALED(status))
101 return WTERMSIG(status);
102 else if (WIFSTOPPED(status))
103 return WSTOPSIG(status);
105 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
110 void ps_util_load_xml_file(const char *docname,
111 const char *groupname, void **i_doc, void **i_root_node)
113 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
114 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
116 dbg("docname: [%s] groupname: [%s]", docname, groupname);
118 *doc = xmlParseFile(docname);
120 *root_node = xmlDocGetRootElement(*doc);
122 dbg("*root_node->name: [%s]", (*root_node)->name);
123 if (0 == xmlStrcmp((*root_node)->name,
124 (const unsigned char *)groupname)) {
125 dbg("root_node is found !!!");
128 err("Cannot find root node.");
137 err("Failed to parse doc: [%s]", docname);
141 void ps_util_unload_xml_file(void **i_doc, void **i_root_node)
143 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
144 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
146 dbg("unloading XML");
157 gboolean ps_util_check_permanent_reject_cause(int cause, gboolean roaming)
159 /* No permanent reject cause in platform side */
163 UserRequest *ps_util_peek_waiting_job(GQueue *queue, unsigned int id)
166 struct work_queue_data *wqd = NULL;
168 g_return_val_if_fail((NULL != queue), NULL);
171 wqd = g_queue_peek_nth(queue, iter);
180 warn("Work queue data is 0");
187 gboolean ps_util_add_waiting_job(GQueue *queue, unsigned int id, UserRequest *ur)
189 struct work_queue_data *wqd;
194 wqd = calloc(sizeof(struct work_queue_data), 1);
200 g_queue_push_tail(queue, wqd);
202 dbg("id = %d, ur = 0x%x", wqd->id, wqd->ur);
206 guint ps_util_get_waiting_job_count(GQueue *queue, unsigned int id)
210 struct work_queue_data *wqd = NULL;
215 dbg("job count: %d", g_queue_get_length(queue));
218 wqd = g_queue_peek_nth(queue, i);
226 } while (wqd != NULL);
228 dbg("count: %d, id = %d", count, id);
233 UserRequest *ps_util_pop_waiting_job(GQueue *queue, unsigned int id)
237 struct work_queue_data *wqd;
242 dbg("before waiting job count: %d", g_queue_get_length(queue));
245 wqd = g_queue_peek_nth(queue, i);
250 wqd = g_queue_pop_nth(queue, i);
255 } while (wqd != NULL);
257 dbg("after waiting job count: %d", g_queue_get_length(queue));