4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
31 #include <glib-object.h>
39 static Server *_server;
41 static gboolean load_plugins(Server *s, const char *path, int flag_test_load)
50 struct tcore_plugin_define_desc *desc;
52 dir = g_dir_open(path, 0, NULL);
56 while ((file = g_dir_read_name(dir)) != NULL) {
57 if (g_str_has_prefix(file, "lib") == TRUE || g_str_has_suffix(file, ".so") == FALSE)
60 filename = g_build_filename(path, file, NULL);
62 handle = dlopen(filename, RTLD_NOW);
64 dbg("fail to load '%s': %s", filename, dlerror());
70 dbg("success to load '%s'", filename);
76 desc = dlsym(handle, "plugin_define_desc");
78 dbg("fail to load symbol: %s", dlerror());
85 if (desc->load() == FALSE) {
86 dbg("false return from load(). skip this plugin");
93 p = tcore_plugin_new(s, desc, filename, handle);
94 tcore_server_add_plugin(s, p);
96 dbg("plugin(%s) added", filename);
101 list = tcore_server_ref_plugins(s);
102 for (; list; list = list->next) {
107 desc = (struct tcore_plugin_define_desc *)tcore_plugin_get_description(p);
114 if (!desc->init(p)) {
115 dbg("plugin(%s) init failed.", tcore_plugin_get_filename(p));
122 static void usage(const char *name)
124 printf("Usage: %s [OPTION]... [PLUGIN_PATH]\n", name);
126 printf(" -T, --testload\t run with plugin load test mode and exit\n");
127 printf(" -h, --help\t\t display this help and exit\n");
131 static void on_signal_usr1(int signo)
136 monitor_server_state(_server);
139 int main(int argc, char *argv[])
141 struct sigaction sigact_usr1;
143 int flag_test_load=0;
146 struct option options[] = {
148 { "testload", 0, &flag_test_load, 1 },
151 char *plugin_path = "/usr/lib/telephony/plugins/";
153 sigact_usr1.sa_handler = on_signal_usr1;
154 sigemptyset(&sigact_usr1.sa_mask);
155 sigaddset(&sigact_usr1.sa_mask, SIGUSR1);
156 sigact_usr1.sa_flags = 0;
158 if (sigaction(SIGUSR1, &sigact_usr1, NULL) < 0) {
159 warn("sigaction(SIGUSR1) failed.");
164 opt = getopt_long(argc, argv, "hT", options, &opt_index);
191 plugin_path = argv[optind];
194 dbg("plugin_path: [%s]", plugin_path);
195 dbg("flag[test_load]: %d", flag_test_load);
200 s = tcore_server_new();
202 err("server_new failed.");
207 if (!load_plugins(s, plugin_path, flag_test_load)) {
214 if (tcore_server_run(s) == FALSE) {
215 err("server_run failed.");
225 tcore_server_free(s);