我目前正在编写一个firebreath C ++ NPAPI插件,我试图从插件中调用boost :: thread。我正在构建它的平台是Ubuntu Linux 13.04。这是类声明和相关成员函数实现的框架:
class EmulatorLaunchPluginAPI : public FB::JSAPIAuto
{
public:
EmulatorLaunchPluginAPI(const EmulatorLaunchPluginPtr& plugin,
const FB::BrowserHostPtr& host):m_plugin(plugin), m_host(host)
{
registerMethod("launch_emulator",
make_method(this, &EmulatorLaunchPluginAPI::launch_emulator));
registerMethod("launch_emulator_thread",
make_method(this, &EmulatorLaunchPluginAPI::launch_emulator_thread));
}
virtual ~EmulatorLaunchPluginAPI() {};
EmulatorLaunchPluginPtr getPlugin()
{
EmulatorLaunchPluginPtr plugin(m_plugin.lock());
if (!plugin) {
throw FB::script_error("The plugin is invalid");
}
return plugin;
}
bool launch_emulator(const std::string& ,const FB::JSObjectPtr& )
{
emt(boost::bind(//boost::type<void>(),
&EmulatorLaunchPluginAPI::launch_emulator_thread,
this,
cmd,
callback));
return true;
}
void launch_emulator_thread(const std::string& , const FB::JSObjectPtr& )
{
//thread body logic here
int result = 0;
result = invoke_command(cmd);
//callback to the browser
callback->InvokeAsync("", FB::variant_list_of(shared_from_this())(result));
}
private:
int invoke_command(const std::string& )
{
int res = system("/usr/bin/firefox");
return res;
}
EmulatorLaunchPluginWeakPtr m_plugin;
FB::BrowserHostPtr m_host;
boost::thread emt;
};
I am getting the following compile error for the code fragmented highlighted above:
[54%]构建CXX对象项目/ EmulatorLaunchPlugin / CMakeFiles / EmulatorLaunchPlugin.dir / EmulatorLaunchPluginAPI.cpp.o /home/ajay/Downloads/firebreath-FireBreath-c335f5b/projects/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp:在成员函数'bool EmulatorLaunchPluginAPI :: launch_emulator(const string&amp;,const JSObjectPtr&amp;)'中: /home/ajay/Downloads/firebreath-FireBreath-c335f5b/projects/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp:94:30:错误:无法调用'(boost :: thread)(boost :: _ bi :: bind_t&amp;,const boost :: shared_ptr&amp;&gt;,boost :: _ bi :: list3,boost :: _ bi :: value&gt;,boost :: _ bi :: value&gt;&gt;&gt;)' make [2]: * [projects / EmulatorLaunchPlugin / CMakeFiles / EmulatorLaunchPlugin.dir / EmulatorLaunchPluginAPI.cpp.o]错误1 make [1]: [projects / EmulatorLaunchPlugin / CMakeFiles / EmulatorLaunchPlugin.dir / all]错误2 make:* * [all]错误2
我是Boost Libraries的新手,我确实尝试了解boost :: bind的工作原理,但我无法解决此错误。有人可以帮我理解编译器的行为吗?
此致 阿贾伊
答案 0 :(得分:0)
我仍然没有清楚地看到错误消息(特别是我对shared_ptr
w / o模板类型和悬挂>
之后感到困惑),但我仍然看到代码中的一些错误:
launch_emulator
使用此代码无法观察到的smth。例如名为cmd
和callback
的smth。使用我的心灵感应,我猜错过了功能参数名称(我是否正确?)
该类包含未初始化 boost::thread
实例 - 您必须在ctor中初始化它,因为此类没有复制ctor或assign运算符(对于C ++ 11模式,它有移动构造函数/ assign )
在launch_emulator
operator()
为boost::thread
实例调用{{1}}。这个类没有这样的成员...所以我想你实际上有关这个事实的缩短错误信息......
答案 1 :(得分:0)
尝试将行更改为:
emt = boost::thread(&EmulatorLaunchPluginAPI::launch_emulator_thread, this, cmd, callback));