Add library file list loader & statis trigger template loader 35/67235/4
authorMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 26 Apr 2016 02:55:20 +0000 (11:55 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 26 Apr 2016 04:26:36 +0000 (13:26 +0900)
Change-Id: I69796755f74e443d83b4a633614832706c8c2c0f
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
packaging/context-service.spec
src/ContextManager.cpp
src/ProviderLoader.cpp
src/ProviderLoader.h
src/trigger/TemplateManager.cpp

index f9e2e8d7f83ace67b36ca0fa3982aac456a699e1..5495f55f85efc9ac2ccf7b20c6dff2a1d9e4c908 100644 (file)
@@ -30,6 +30,7 @@ BuildRequires: pkgconfig(cynara-session)
 
 BuildRequires: pkgconfig(libcontext-server)
 BuildRequires: pkgconfig(context)
+BuildRequires: context-provider-devel
 Requires: context-provider
 
 Requires(preun): /usr/bin/systemctl
index 39b0ded8e4dd962b520602f82c4e41d431ae0b2e..75478a84cd992ba0372d4b39dee235452f5b561b 100644 (file)
@@ -61,6 +61,7 @@ ContextManager::ContextManager() :
        __initialized(false)
 {
        ContextProvider::__setContextManager(this);
+       __providerLoader.init();
 }
 
 ContextManager::~ContextManager()
index b8c5bf600882a7e503cbda19c32afc31b6e22745..c48a99267dc7849b7e60fe3a4f416846d9cfef13 100644 (file)
  */
 
 #include <dlfcn.h>
-#include <dirent.h>
 #include <set>
 #include <Types.h>
 #include <ContextProvider.h>
+#include <ProviderList.h>
 #include "ProviderLoader.h"
 
-#define PROVIDER_SO_PATH "/usr/lib/context"
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
 
 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;
-}
+std::map<const char*, const char*, CompareSubjectName> ProviderLoader::__providerLibMap;
 
 ProviderLoader::ProviderLoader()
 {
@@ -99,18 +72,45 @@ void ProviderLoader::__unload()
 bool ProviderLoader::loadAll()
 {
        /* TODO: Remove this function. This is a temporary solution. */
-       std::set<std::string> soNames;
-       std::string soPath;
+       std::set<std::string> soPaths;
 
-       if (!getSharedObjectPaths(PROVIDER_SO_PATH, soNames)) {
-               return false;
+       for (auto it : __providerLibMap) {
+               std::string path = LIB_DIRECTORY;
+               path = path + LIB_PREFIX + it.second + LIB_EXTENSION;
+               soPaths.insert(path);
        }
 
-       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);
+       for (std::set<std::string>::iterator it = soPaths.begin(); it != soPaths.end(); ++it) {
+               __load((*it).c_str(), NULL);
        }
 
        return true;
 }
+
+bool ProviderLoader::init()
+{
+       int size = ARRAY_SIZE(subjectLibraryList);
+
+       for (int i = 0; i < size; ++i) {
+               __providerLibMap[subjectLibraryList[i].subject] = subjectLibraryList[i].library;
+       }
+
+       return true;
+}
+
+bool ProviderLoader::popTriggerTemplate(std::string &subject, int &operation, Json &attribute, Json &option)
+{
+       static int i = 0;
+       static int size = ARRAY_SIZE(triggerTemplateList);
+
+       if (i == size)
+               return false;
+
+       subject = triggerTemplateList[i].subject;
+       operation = triggerTemplateList[i].operation;
+       attribute = triggerTemplateList[i].attribute;
+       option = triggerTemplateList[i].option;
+
+       ++i;
+       return true;
+}
index fedca2545562a0494ba1f79a6e40a16bb71bc4b7..7623b8963b98f933bb95ae1fee7527755b066bbe 100644 (file)
 #ifndef _CONTEXT_PROVIDER_LOADER_H_
 #define _CONTEXT_PROVIDER_LOADER_H_
 
+#include <map>
+
 namespace ctx {
 
        class ContextProvider;
 
+       struct CompareSubjectName {
+               bool operator()(const char *left, const char *right) const {
+                       const char *pl = left;
+                       const char *pr = right;
+                       while (pl != NULL && pr != NULL) {
+                               if (*pl < *pr)
+                                       return true;
+                               if (*pl > *pr)
+                                       return false;
+                               ++pl;
+                               ++pr;
+                       }
+                       return false;
+               }
+       };
+
        class ProviderLoader {
        public:
                ProviderLoader();
@@ -29,9 +47,14 @@ namespace ctx {
                ContextProvider* load(const char *subject);
                bool loadAll();
 
+               static bool init();
+               static bool popTriggerTemplate(std::string &subject, int &operation, Json &attribute, Json &option);
+
        private:
                ContextProvider* __load(const char *soPath, const char *subject);
                void __unload();
+
+               static std::map<const char*, const char*, CompareSubjectName> __providerLibMap;
        };
 
 }
index 51dcb6cc69b66aad45703ac7079e0bd364024768..b33e10a23805a2fd93790496a3188245e0994a0f 100644 (file)
@@ -96,10 +96,11 @@ void TemplateManager::applyTemplates()
        Json attributes;
        Json options;
        std::string owner;
-       bool unregister;
+       //bool unregister;
        std::string query;
        query.clear();
 
+       /*
        while(__contextMgr->popTriggerItem(subject, operation, attributes, options, owner, unregister)) {
                if (unregister) {
                        unregisterTemplate(subject);
@@ -107,6 +108,12 @@ void TemplateManager::applyTemplates()
                        registerTemplate(subject, operation, attributes, options, owner);
                }
        }
+       */
+
+       /* FIXME */
+       while (ProviderLoader::popTriggerTemplate(subject, operation, attributes, options)) {
+               registerTemplate(subject, operation, attributes, options, "");
+       }
 }
 
 void TemplateManager::registerTemplate(std::string subject, int operation, Json attributes, Json options, std::string owner)