Exemplo n.º 1
0
void JSAPIImpl::FireEvent(const std::string& eventName, const std::vector<variant>& args)
{
    if (!m_valid)   // When invalidated, do nothing more
        return;

    {
        JSAPIImplPtr self(shared_from_this());
        boost::recursive_mutex::scoped_lock _l(m_proxyMutex);
        ProxyList::iterator proxyIt = m_proxies.begin();
        while (proxyIt != m_proxies.end()) {
            JSAPIImplPtr proxy(proxyIt->lock());
            if (!proxy) {
                // Since you can't use a shared_ptr in a destructor, there
                // is no way for the proxy object to let us know when it goes
                // away; thus when we find them, we remove them for efficiency
                proxyIt = m_proxies.erase(proxyIt);
                continue;
            }

            VariantList newArgs = proxyProcessList(args, self, proxy);

            proxy->FireEvent(eventName, newArgs);
            ++proxyIt;
        }
    }

    try {
        fireAsyncEvent(eventName, args);
    } catch (const FB::script_error&) {
        // a script_error can be fired during shutdown when this is called
        // from another thread; this should not be an error
    }
}
Exemplo n.º 2
0
void JSAPIImpl::unregisterProxy( const JSAPIImplPtr& ptr ) const
{
    boost::recursive_mutex::scoped_lock _l(m_proxyMutex);
    for (ProxyList::iterator it = m_proxies.begin(); it != m_proxies.end(); ++it) {
        JSAPIPtr cur(it->lock());
        if (!cur || ptr == cur)
            it = m_proxies.erase(it);
    }
}
Exemplo n.º 3
0
void JSAPIImpl::FireJSEvent( const std::string& eventName, const VariantMap &members, const VariantList &arguments )
{
    if (!m_valid)   // When invalidated, do nothing more
        return;

    {
        JSAPIImplPtr self(shared_from_this());
        boost::recursive_mutex::scoped_lock _l(m_proxyMutex);
        ProxyList::iterator proxyIt = m_proxies.begin();
        while (proxyIt != m_proxies.end()) {
            JSAPIImplPtr proxy(proxyIt->lock());
            if (!proxy) {
                // Since you can't use a shared_ptr in a destructor, there
                // is no way for the proxy object to let us know when it goes
                // away; thus when we find them, we remove them for efficiency
                proxyIt = m_proxies.erase(proxyIt);
                continue;
            }

            VariantList newArgs = proxyProcessList(arguments, self, proxy);
            VariantMap newMap = proxyProcessMap(members, self, proxy);

            proxy->FireJSEvent(eventName, newMap, newArgs);
            proxyIt++;
        }
    }

    VariantList args;
    args.push_back(CreateEvent(shared_from_this(), eventName, members, arguments));

    {
        boost::recursive_mutex::scoped_lock _l(m_eventMutex);
        EventContextMap::iterator it(m_eventMap.begin());
        while (it != m_eventMap.end()) {
            std::pair<EventMultiMap::iterator, EventMultiMap::iterator> range = it->second.equal_range(eventName);
            for (EventMultiMap::const_iterator eventIt = range.first; eventIt != range.second; eventIt++) {
                eventIt->second->InvokeAsync("", args);
            }
            ++it;
        }
    }

    // Some events are registered as a jsapi object with a method of the same name as the event
    {
        boost::recursive_mutex::scoped_lock _l(m_eventMutex);
        EventIfaceContextMap::iterator it(m_evtIfaces.begin());
        while (it != m_evtIfaces.end()) {
            for (EventIFaceMap::const_iterator ifaceIt = it->second.begin(); ifaceIt != it->second.end(); ifaceIt++) {
                ifaceIt->second->InvokeAsync(eventName, args);
            }
        }
    }
}