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>
26 #include <tzplatform_config.h>
29 #include "livebox-cpp.h"
30 #include "livebox-impl.h"
34 const char *CModule::m_sModulePath = tzplatform_mkpath(TZ_USER_LIVE,"%s/libexec/liblive-%s.so");
35 struct dlist *CModule::m_pModuleList = NULL;
37 CModule *CModule::Load(const char *pkgname)
44 tmp = strdup(pkgname);
46 ErrPrint("Memory: %s\n", strerror(errno));
51 inst = new CModule(tmp);
58 module_path = livebox_service_libexec(pkgname);
65 inst->m_pHandle = dlopen(module_path, RTLD_LOCAL | RTLD_NOW | RTLD_DEEPBIND);
68 if (!inst->m_pHandle) {
69 ErrPrint("dlopen: %s\n", dlerror());
75 inst->m_fNew = (void *(*)(void))dlsym(inst->m_pHandle, "livebox_new");
77 ErrPrint("symbol: livebox_new is not found: %s\n", dlerror());
78 dlclose(inst->m_pHandle);
84 inst->m_fNeedToCreate = (int (*)(const char *, const char *))dlsym(inst->m_pHandle, "livebox_need_to_create");
85 if (!inst->m_fNeedToCreate) {
86 DbgPrint("%s has no livebox_need_to_create\n", pkgname);
89 inst->m_fInitialize = (int (*)(const char *))dlsym(inst->m_pHandle, "livebox_initialize");
90 if (!inst->m_fInitialize) {
91 DbgPrint("%s has no livebox_initialize\n", pkgname);
93 ret = inst->m_fInitialize(pkgname);
95 ErrPrint("livebox_finalize(%s) returns %d\n", pkgname, ret);
96 dlclose(inst->m_pHandle);
103 inst->m_fFinalize = (int (*)(void))dlsym(inst->m_pHandle, "livebox_finalize");
104 if (!inst->m_fFinalize) {
105 DbgPrint("%s has no livebox_finalize\n", pkgname);
108 m_pModuleList = dlist_append(m_pModuleList, inst);
112 int CModule::Unload(void)
116 l = dlist_find_data(m_pModuleList, this);
117 m_pModuleList = dlist_remove(m_pModuleList, l);
122 DbgPrint("livebox_finalize of %s returns %d\n", m_sPkgname, ret);
128 return LB_STATUS_SUCCESS;
131 int CModule::Create(const char *filename, const char *content, const char *cluster, const char *category)
135 inst = (CLiveBoxImpl *)m_fNew();
138 ret = inst->Create(filename, content, cluster, category);
144 m_pList = dlist_append(m_pList, inst);
148 return LB_STATUS_ERROR_FAULT;
151 int CModule::Destroy(CLiveBoxImpl *inst)
155 l = dlist_find_data(m_pList, inst);
157 return LB_STATUS_ERROR_NOT_EXIST;
160 m_pList = dlist_remove(m_pList, l);
162 return LB_STATUS_SUCCESS;
165 CLiveBoxImpl *CModule::FindLiveBox(const char *filename)
171 dlist_foreach(m_pList, l, item) {
172 box = (CLiveBoxImpl *)item;
173 if (!strcmp(filename, box->Filename())) {
181 int CModule::NeedToCreate(const char *cluster, const char *category)
183 if (!m_fNeedToCreate) {
187 return m_fNeedToCreate(cluster, category);
190 CModule *CModule::FindModule(const char *pkgname)
196 dlist_foreach(m_pModuleList, l, item) {
197 module = (CModule *)item;
198 if (!strcmp(pkgname, module->PackageName())) {