2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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>
25 #include <livebox-errno.h>
28 #include "livebox-cpp.h"
29 #include "livebox-impl.h"
33 const char *CModule::m_sModulePath = "/opt/usr/live/%s/libexec/liblive-%s.so";
34 struct dlist *CModule::m_pModuleList = NULL;
36 CModule *CModule::Load(const char *pkgname)
43 tmp = strdup(pkgname);
45 ErrPrint("Memory: %s\n", strerror(errno));
50 inst = new CModule(tmp);
57 module_path = livebox_service_libexec(pkgname);
64 inst->m_pHandle = dlopen(module_path, RTLD_LOCAL | RTLD_NOW | RTLD_DEEPBIND);
67 if (!inst->m_pHandle) {
68 ErrPrint("dlopen: %s\n", dlerror());
74 inst->m_fNew = (void *(*)(void))dlsym(inst->m_pHandle, "livebox_new");
76 ErrPrint("symbol: livebox_new is not found: %s\n", dlerror());
77 dlclose(inst->m_pHandle);
83 inst->m_fNeedToCreate = (int (*)(const char *, const char *))dlsym(inst->m_pHandle, "livebox_need_to_create");
84 if (!inst->m_fNeedToCreate) {
85 DbgPrint("%s has no livebox_need_to_create\n", pkgname);
88 inst->m_fInitialize = (int (*)(const char *))dlsym(inst->m_pHandle, "livebox_initialize");
89 if (!inst->m_fInitialize) {
90 DbgPrint("%s has no livebox_initialize\n", pkgname);
92 ret = inst->m_fInitialize(pkgname);
94 ErrPrint("livebox_finalize(%s) returns %d\n", pkgname, ret);
95 dlclose(inst->m_pHandle);
102 inst->m_fFinalize = (int (*)(void))dlsym(inst->m_pHandle, "livebox_finalize");
103 if (!inst->m_fFinalize) {
104 DbgPrint("%s has no livebox_finalize\n", pkgname);
107 m_pModuleList = dlist_append(m_pModuleList, inst);
111 int CModule::Unload(void)
115 l = dlist_find_data(m_pModuleList, this);
116 m_pModuleList = dlist_remove(m_pModuleList, l);
121 DbgPrint("livebox_finalize of %s returns %d\n", m_sPkgname, ret);
127 return LB_STATUS_SUCCESS;
130 int CModule::Create(const char *filename, const char *content, const char *cluster, const char *category)
134 inst = (CLiveBoxImpl *)m_fNew();
137 ret = inst->Create(filename, content, cluster, category);
143 m_pList = dlist_append(m_pList, inst);
147 return LB_STATUS_ERROR_FAULT;
150 int CModule::Destroy(CLiveBoxImpl *inst)
154 l = dlist_find_data(m_pList, inst);
156 return LB_STATUS_ERROR_NOT_EXIST;
159 m_pList = dlist_remove(m_pList, l);
161 return LB_STATUS_SUCCESS;
164 CLiveBoxImpl *CModule::FindLiveBox(const char *filename)
170 dlist_foreach(m_pList, l, item) {
171 box = (CLiveBoxImpl *)item;
172 if (!strcmp(filename, box->Filename())) {
180 int CModule::NeedToCreate(const char *cluster, const char *category)
182 if (!m_fNeedToCreate) {
186 return m_fNeedToCreate(cluster, category);
189 CModule *CModule::FindModule(const char *pkgname)
195 dlist_foreach(m_pModuleList, l, item) {
196 module = (CModule *)item;
197 if (!strcmp(pkgname, module->PackageName())) {