Question

I am currently writing a firebreath C++ NPAPI plugin, and i an trying to invoke a boost::thread from inside the plugin. The platform i am building it is Ubuntu Linux 13.04. Here is the skeleton of the class declaration and relevant member function implementations:

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%] Building CXX object projects/EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir/EmulatorLaunchPluginAPI.cpp.o /home/ajay/Downloads/firebreath-FireBreath-c335f5b/projects/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp: In member function ‘bool EmulatorLaunchPluginAPI::launch_emulator(const string&, const JSObjectPtr&)’: /home/ajay/Downloads/firebreath-FireBreath-c335f5b/projects/EmulatorLaunchPlugin/EmulatorLaunchPluginAPI.cpp:94:30: error: no match for call to ‘(boost::thread) (boost::_bi::bind_t&, const boost::shared_ptr&>, boost::_bi::list3, boost::_bi::value >, boost::_bi::value > > >)’ make[2]: * [projects/EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir/EmulatorLaunchPluginAPI.cpp.o] Error 1 make[1]: [projects/EmulatorLaunchPlugin/CMakeFiles/EmulatorLaunchPlugin.dir/all] Error 2 make: ** [all] Error 2

I am new to Boost Libraries, and i did try to understand how boost::bind works, but i could not resolve this error. Can someone please help me understand the compiler's behavior?

Regards, Ajay

Was it helpful?

Solution

Try changing the line to:

emt = boost::thread(&EmulatorLaunchPluginAPI::launch_emulator_thread, this, cmd, callback));

OTHER TIPS

I still do not see the error message clearly (particularly I'm confused by shared_ptr w/o a template type and dangling > after it), but I see some errors in your code anyway:

  1. launch_emulator uses smth that is not observable by this code. for example smth named cmd and callback. using my telepathy, I guess missed function parameter names (am I correct?)

  2. the class contains uninitialized boost::thread instance -- you have to initialize it in ctor, because this class do not have a copy ctor or assign operator (for C++11 mode it have move constructor/assign)

  3. in launch_emulator you call operator() for boost::thread instance. this class do not have such member... so I suppose your shortened error message about this fact actually...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top