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 != "")
{
}
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;
int CpluffAdapter::registerPlugin(const std::string path)
{
- //printf("CpluffAdapter register\n");
int flag = FALSE;
if (path == "")
int CpluffAdapter::registerAllPlugin(const std::string path)
{
- //printf("CpluffAdapter register\n");
int flag = FALSE;
if (path == "")
{
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]);
}
return re_plugins;
}
+
/*
Plugin *CpluffAdapter::getPlugin(const std::string plugID)
{
return nullptr;
}
*/
+
bool CpluffAdapter::getFileList(File_list &list, const std::string strDir)
{
struct stat statinfo;
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");
}
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();
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)
}
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)));
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;
}
}
}
( 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()));