It will be modified to load only the necessary providers on demand.
Change-Id: I81f622c42dd3ae5d0615feb2aa1592006e67c6f0
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
cynara-creds-gdbus
cynara-client
cynara-session
- context-provider
+ libcontext-server
+ context
)
# Common Options
/usr/include
/usr/include/glib-2.0
)
-ADD_DEFINITIONS(-O2 -Wall -fPIC -fdata-sections -ffunction-sections -fvisibility=hidden)
-SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -Wl,--as-needed -Wl,--gc-section -Wl,--print-gc-section")
+ADD_DEFINITIONS(-O2 -Wall -fPIC -fPIE -fdata-sections -ffunction-sections -fvisibility=hidden)
+ADD_DEFINITIONS(-DLOG_TAG="CONTEXT")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIC -pie -Wl,--as-needed -Wl,--gc-section -Wl,--print-gc-section")
# Building Daemon
pkg_check_modules(daemon_pkg REQUIRED ${DEPS})
-SET(DAEMON_EXTRA_CFLAGS -fPIE)
FOREACH(flag ${daemon_pkg_CFLAGS})
- SET(DAEMON_EXTRA_CFLAGS "${DAEMON_EXTRA_CFLAGS} ${flag}")
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
ENDFOREACH(flag)
ADD_EXECUTABLE(${target} ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${daemon_pkg_LDFLAGS} -pie)
-SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_FLAGS ${DAEMON_EXTRA_CFLAGS})
-SET_TARGET_PROPERTIES(${target} PROPERTIES COMPILE_DEFINITIONS "LOG_TAG=\"CONTEXT\"")
+TARGET_LINK_LIBRARIES(${target} ${daemon_pkg_LDFLAGS} -ldl)
# Installing Daemon
INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_BINDIR})
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(cynara-session)
+BuildRequires: pkgconfig(libcontext-server)
BuildRequires: pkgconfig(context)
-BuildRequires: pkgconfig(context-provider)
+Requires: context-provider
Requires(preun): /usr/bin/systemctl
Requires(post): /usr/bin/systemctl
#include "ContextManager.h"
#include "trigger/TemplateManager.h"
-/* Context Providers */
-#include <internal/DeviceContextProvider.h>
-#include <internal/StatisticsContextProvider.h>
-#include <internal/PlaceContextProvider.h>
-#include <internal/CustomContextProvider.h>
-
using namespace ctx;
struct TriggerItemFormat {
bool ContextManager::init()
{
- bool ret;
-
- ret = initDeviceContextProvider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: DeviceContextProvider");
-
- ret = initStatisticsContextProvider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: StatisticsContextProvider");
-
- ret = initPlaceContextProvider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: PlaceContextProvider");
-
-// ret = initCustomContextProvider();
-// IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: CustomContextProvider");
-
- __initialized = true;
+ __initialized = __providerLoader.loadAll();
return true;
}
#include <map>
#include <IContextManager.h>
+#include "ProviderLoader.h"
namespace ctx {
bool __initialized;
std::map<std::string, ProviderHandler*> __providerHandleMap;
+ ProviderLoader __providerLoader;
friend class Server;
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlfcn.h>
+#include <dirent.h>
+#include <set>
+#include <Types.h>
+#include <ContextProvider.h>
+#include "ProviderLoader.h"
+
+#define PROVIDER_SO_PATH "/usr/lib/context"
+
+using namespace ctx;
+
+typedef bool (*create_t)();
+
+static bool getSharedObjectPaths(const char *dirPath, std::set<std::string> &soNames)
+{
+ DIR *dir = NULL;
+ struct dirent dirEntry;
+ struct dirent *result;
+ int error;
+
+ dir = opendir(dirPath);
+ IF_FAIL_RETURN_TAG(dir, false, _E, "Failed to open '%s'", dirPath);
+
+ while (true) {
+ error = readdir_r(dir, &dirEntry, &result);
+
+ if (error != 0)
+ continue;
+
+ if (result == NULL)
+ break;
+
+ if (dirEntry.d_type != DT_REG)
+ continue;
+
+ soNames.insert(dirEntry.d_name);
+ }
+
+ closedir(dir);
+ return true;
+}
+
+ProviderLoader::ProviderLoader()
+{
+}
+
+ProviderLoader::~ProviderLoader()
+{
+ __unload();
+}
+
+ContextProvider* ProviderLoader::load(const char *subject)
+{
+ /* TODO: Implement */
+ return NULL;
+}
+
+ContextProvider* ProviderLoader::__load(const char *soPath, const char *subject)
+{
+ _I("Load '%s' from '%s'", subject, soPath);
+
+ void *soHandle = dlopen(soPath, RTLD_LAZY | RTLD_GLOBAL);
+ IF_FAIL_RETURN_TAG(soHandle, NULL, _E, "%s", dlerror());
+
+ create_t create = reinterpret_cast<create_t>(dlsym(soHandle, "create"));
+ if (!create) {
+ _E("%s", dlerror());
+ dlclose(soHandle);
+ return NULL;
+ }
+
+ /* TODO: Update this part for dynamic loading */
+ create();
+
+ return NULL;
+}
+
+void ProviderLoader::__unload()
+{
+ /* TODO: Implement */
+}
+
+bool ProviderLoader::loadAll()
+{
+ /* TODO: Remove this function. This is a temporary solution. */
+ std::set<std::string> soNames;
+ std::string soPath;
+
+ if (!getSharedObjectPaths(PROVIDER_SO_PATH, soNames)) {
+ return false;
+ }
+
+ for (std::set<std::string>::iterator it = soNames.begin(); it != soNames.end(); ++it) {
+ soPath = PROVIDER_SO_PATH;
+ soPath = soPath + "/" + (*it);
+ __load(soPath.c_str(), NULL);
+ }
+
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTEXT_PROVIDER_LOADER_H_
+#define _CONTEXT_PROVIDER_LOADER_H_
+
+namespace ctx {
+
+ class ContextProvider;
+
+ class ProviderLoader {
+ public:
+ ProviderLoader();
+ ~ProviderLoader();
+
+ ContextProvider* load(const char *subject);
+ bool loadAll();
+
+ private:
+ ContextProvider* __load(const char *soPath, const char *subject);
+ void __unload();
+ };
+
+}
+
+#endif /* _CONTEXT_PROVIDER_LOADER_H_ */