2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <livebox-service.h>
27 #include "livebox-cpp.h"
28 #include "livebox-impl.h"
32 const char *CModule::m_sModulePath = "/opt/usr/live/%s/libexec/liblive-%s.so";
33 struct dlist *CModule::m_pModuleList = NULL;
35 CModule *CModule::Load(const char *pkgname)
42 tmp = strdup(pkgname);
44 ErrPrint("Memory: %s\n", strerror(errno));
49 inst = new CModule(tmp);
56 module_path = livebox_service_libexec(pkgname);
63 inst->m_pHandle = dlopen(module_path, RTLD_LOCAL | RTLD_NOW | RTLD_DEEPBIND);
66 if (!inst->m_pHandle) {
67 ErrPrint("dlopen: %s\n", dlerror());
73 inst->m_fNew = (void *(*)(void))dlsym(inst->m_pHandle, "livebox_new");
75 ErrPrint("symbol: livebox_new is not found: %s\n", dlerror());
76 dlclose(inst->m_pHandle);
82 inst->m_fNeedToCreate = (int (*)(const char *, const char *))dlsym(inst->m_pHandle, "livebox_need_to_create");
83 if (!inst->m_fNeedToCreate)
84 DbgPrint("%s has no livebox_need_to_create\n", pkgname);
86 inst->m_fInitialize = (int (*)(const char *))dlsym(inst->m_pHandle, "livebox_initialize");
87 if (!inst->m_fInitialize) {
88 DbgPrint("%s has no livebox_initialize\n", pkgname);
90 ret = inst->m_fInitialize(pkgname);
92 ErrPrint("livebox_finalize(%s) returns %d\n", pkgname, ret);
93 dlclose(inst->m_pHandle);
100 inst->m_fFinalize = (int (*)(void))dlsym(inst->m_pHandle, "livebox_finalize");
101 if (!inst->m_fFinalize)
102 DbgPrint("%s has no livebox_finalize\n", pkgname);
104 m_pModuleList = dlist_append(m_pModuleList, inst);
108 int CModule::Unload(void)
112 l = dlist_find_data(m_pModuleList, this);
113 m_pModuleList = dlist_remove(m_pModuleList, l);
118 DbgPrint("livebox_finalize of %s returns %d\n", m_sPkgname, ret);
127 int CModule::Create(const char *filename, const char *content, const char *cluster, const char *category)
131 inst = (CLiveBoxImpl *)m_fNew();
134 ret = inst->Create(filename, content, cluster, category);
140 m_pList = dlist_append(m_pList, inst);
147 int CModule::Destroy(CLiveBoxImpl *inst)
151 l = dlist_find_data(m_pList, inst);
155 m_pList = dlist_remove(m_pList, l);
160 CLiveBoxImpl *CModule::FindLiveBox(const char *filename)
166 dlist_foreach(m_pList, l, item) {
167 box = (CLiveBoxImpl *)item;
168 if (!strcmp(filename, box->Filename()))
175 int CModule::NeedToCreate(const char *cluster, const char *category)
177 if (!m_fNeedToCreate)
180 return m_fNeedToCreate(cluster, category);
183 CModule *CModule::FindModule(const char *pkgname)
189 dlist_foreach(m_pModuleList, l, item) {
190 module = (CModule *)item;
191 if (!strcmp(pkgname, module->PackageName())) {