Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / CpluffAdapter.cpp
index 3acd2f5..e2b3d68 100644 (file)
@@ -28,14 +28,14 @@ using namespace OIC;
 
 CpluffAdapter *CpluffAdapter::s_pinstance;
 
-CpluffAdapter::CpluffAdapter()
+CpluffAdapter::CpluffAdapter(void *args)
 {
     m_status = cp_init();
     m_context = cp_create_context(&m_status);
     m_cp_plugins = nullptr;
     m_plugin = nullptr;
 
-    config = Config::Getinstance();
+    config = Config::Getinstance(args);
     std::string pluginpath = config->getPluginPath();
     if (pluginpath != "")
     {
@@ -194,24 +194,9 @@ int CpluffAdapter::loadPluginInfoToManager(const std::string path)
         }
         if (plugin_compare_flag)
         {
-            //Auto plugin detection is disabled
-            /*
-            try
-            {
-                boost::thread *t = new boost::thread(boost::bind(&CpluffAdapter::observePluginPath,
-                                                     //this, (void *)path.c_str()));
-                                                     this, (void *)m_cp_plugins[i]->plugin_path));
-                m_thread_g.add_thread(t);
-            }
-            catch (...)
-            {
-                printf("thread throw exception\n");
-            }
-            */
             m_plugins.push_back(*plugin);
             delete(plugin);
         }
-        //printf("plugin size = %d\n",m_plugins.size());
     }
 
     return TRUE;
@@ -219,7 +204,6 @@ int CpluffAdapter::loadPluginInfoToManager(const std::string path)
 
 int CpluffAdapter::registerPlugin(const std::string path)
 {
-    //printf("CpluffAdapter register\n");
     int flag = FALSE;
 
     if (path == "")
@@ -238,7 +222,6 @@ int CpluffAdapter::registerPlugin(const std::string path)
 
 int CpluffAdapter::registerAllPlugin(const std::string path)
 {
-    //printf("CpluffAdapter register\n");
     int flag = FALSE;
     if (path == "")
     {
@@ -316,7 +299,8 @@ std::vector<Plugin> *CpluffAdapter::findPlugins(const std::string key, const std
 
     for (unsigned int i = 0; i < m_plugins.size(); i++)
     {
-        if (!m_plugins[i].getValueByAttribute(key).compare(value))
+        std::string attributeValue = m_plugins[i].getValueByAttribute(key);
+        if (!attributeValue.empty() && !attributeValue.compare(value))
         {
             re_plugins->push_back(m_plugins[i]);
         }
@@ -324,6 +308,7 @@ std::vector<Plugin> *CpluffAdapter::findPlugins(const std::string key, const std
 
     return re_plugins;
 }
+
 /*
 Plugin *CpluffAdapter::getPlugin(const std::string plugID)
 {
@@ -338,6 +323,7 @@ Plugin *CpluffAdapter::getPlugin(const std::string plugID)
     return nullptr;
 }
 */
+
 bool CpluffAdapter::getFileList(File_list &list, const std::string strDir)
 {
     struct stat statinfo;
@@ -445,21 +431,14 @@ void CpluffAdapter::printPluginList()
 
 int CpluffAdapter::start(Plugin *const plugin, void *const arg)
 {
-    //printf("start\n");
     std::string id;
     cp_status_t status;
-    cp_context_t *ctx;
 
     id = plugin->getID();
     for (unsigned int i = 0 ; i < m_plugins.size(); i++)
     {
         if (*plugin == m_plugins[i])
         {
-            ctx = cpi_new_context((cp_plugin_t *)hnode_get(hash_lookup(m_context->env->plugins, id.c_str())),
-                                  m_context->env, &status);
-            //cp_define_symbol(ctx, "START_ARGUMENT", arg);
-            //printf("start ocplatform address : %x\n", arg);
-
             if ((status = cp_start_plugin(m_context, (char *)id.c_str()) ) != CP_OK)
             {
                 printf("API function CpluffAdapter::start() faild with error code.\n");
@@ -510,18 +489,17 @@ bool CpluffAdapter::isStarted(Plugin *plugin)
     }
     return FALSE;
 }
-//Auto plugin detection is disabled
+
+// Auto plugin detection is disabled
 /*
 void CpluffAdapter::observePluginPath(void *str)
 {
-    //printf("start observePluginPath\n");
     int length;
     int i = 0;
     int fd;
     int wd;
     char *str1 = (char *)str;
     std::string original_path(str1);
-    //printf("Directory is %s\n",(char*)str1));
     char buffer[BUF_LEN];
 
     fd = inotify_init();
@@ -546,7 +524,6 @@ void CpluffAdapter::observePluginPath(void *str)
             printf("observePluginPath read\n");
         }
         std::string filepath = original_path;
-        //printf("filepath = %s\n",filepath.c_str());
         while ( i < length )
         {
             if (i < (signed)(BUF_LEN  - ( sizeof( struct inotify_event) + 16)) && i > -1)
@@ -559,12 +536,8 @@ void CpluffAdapter::observePluginPath(void *str)
                 }
                 else
                 {
-                    //filepath += "/";
-                    //filepath += std::string(event->name);
                     std::vector<Plugin> *resource_plugin = findPlugins("Path", filepath.c_str()); //add foldername
 
-                    //printf("plugin size is %d\n",resource_plugin->size());
-                    //printf("plugin file path is %s\n",resource_plugin->());
                     if (resource_plugin->size() == 1)
                     {
                         unregisterPlugin(&(resource_plugin->at(0)));
@@ -576,8 +549,6 @@ void CpluffAdapter::observePluginPath(void *str)
                     delete(resource_plugin);
                     resource_plugin = nullptr;
                 }
-                //printf("observePluginPath path = %s \n",str1);
-                //printf("observePluginPath directory name = %s \n",event->name);
                 i += EVENT_SIZE + event->len;
             }
         }
@@ -586,9 +557,9 @@ void CpluffAdapter::observePluginPath(void *str)
     }
     ( void ) inotify_rm_watch( fd, wd );
     ( void ) close( fd );
-    //printf("observePluginPath end\n");
 }
 */
+
 const std::string CpluffAdapter::getState(const std::string plugID)
 {
     return state_to_string(cp_get_plugin_state(m_context, plugID.c_str()));