예제 #1
0
void ListenerAdapter::polkit_qt_listener_initiate_authentication(PolkitAgentListener  *listener,
        const gchar          *action_id,
        const gchar          *message,
        const gchar          *icon_name,
        PolkitDetails        *details,
        const gchar          *cookie,
        GList                *identities,
        GCancellable         *cancellable,
        GSimpleAsyncResult *result)
{
    qDebug() << "polkit_qt_listener_initiate_authentication callback for " << listener;

    PolkitQt1::Identity::List idents;
    PolkitQt1::Details dets(details);

    Listener *list = findListener(listener);

    for (GList *identity = g_list_first(identities); identity != NULL; identity = g_list_next(identity)) {
         idents.append(PolkitQt1::Identity((PolkitIdentity *)identity->data));
    }

    list->initiateAuthentication(QString::fromUtf8(action_id),
                                 QString::fromUtf8(message),
                                 QString::fromUtf8(icon_name),
                                 dets,
                                 QString::fromUtf8(cookie),
                                 idents,
                                 new AsyncResult(result));
}
예제 #2
0
SoundContext::SoundContext(const Misc::ConfigurationFileSection& configFileSection,VruiState* sVruiState)
    :vruiState(sVruiState),
#ifdef VRUI_USE_OPENAL
     alDevice(0),alContext(0),
#endif
     contextData(0),
     listener(findListener(configFileSection.retrieveString("./listenerName").c_str()))
{
#ifdef VRUI_USE_OPENAL
    /* Open the OpenAL device: */
    std::string alDeviceName=configFileSection.retrieveValue<std::string>("./deviceName","Default");
    alDevice=alcOpenDevice(alDeviceName!="Default"?alDeviceName.c_str():0);
    if(alDevice==0)
        Misc::throwStdErr("SoundContext::SoundContext: Could not open OpenAL sound device %s",alDeviceName.c_str());

    /* Create an OpenAL context: */
    alContext=alcCreateContext(alDevice,0);
    if(alContext==0)
    {
        alcCloseDevice(alDevice);
        Misc::throwStdErr("SoundContext::SoundContext: Could not create OpenAL context for sound device %s",alDeviceName.c_str());
    }
#endif

    /* Create an AL context data object: */
    contextData=new ALContextData(101);

    /* Initialize the sound context's OpenAL context: */
    makeCurrent();

    /* Initialize application sound state: */
    if(vruiState->perSoundInitFunction!=0)
        vruiState->perSoundInitFunction(*contextData,vruiState->perSoundInitFunctionData);
}
예제 #3
0
void ListenerAdapter::cancelled_cb(PolkitAgentListener *listener)
{
    qDebug() << "cancelled_cb for " << listener;

    Listener *list = findListener(listener);

    list->cancelAuthentication();
}
예제 #4
0
파일: ws_api.cpp 프로젝트: nonolith/connect
bool StreamingDevice::processMessage(ClientConn& client, string& cmd, JSONNode& n){
	if (cmd == "listen"){
		cancelListen(findListener(&client, jsonIntProp(n, "id")));
		addListener(makeStreamListener(this, &client, n));
	
	}else if (cmd == "cancelListen"){
		cancelListen(findListener(&client, jsonIntProp(n, "id")));
	
	}else if (cmd == "configure"){
		int      mode =       jsonIntProp(n,   "mode");
		unsigned samples =    jsonIntProp(n,   "samples");
		double    sampleTime = jsonFloatProp(n, "sampleTime");
		bool     continuous = jsonBoolProp(n,  "continuous", false);
		bool     raw =        jsonBoolProp(n,  "raw", false);
		configure(mode, sampleTime, samples, continuous, raw);
	
	}else if (cmd == "startCapture"){
		start_capture();
	
	}else if (cmd == "pauseCapture"){
		pause_capture();
	
	}else if (cmd == "set"){
		Channel *channel = channelById(jsonStringProp(n, "channel"));
		if (!channel) throw ErrorStringException("Channel not found");
		setOutput(channel, makeSource(n));
		
	}else if (cmd == "setGain"){
		Channel *channel = channelById(jsonStringProp(n, "channel"));
		if (!channel) throw ErrorStringException("Channel not found");
		Stream *stream = findStream(
				jsonStringProp(n, "channel"),
				jsonStringProp(n, "stream"));

		double gain = jsonFloatProp(n, "gain", 1);
		
		setGain(channel, stream, gain);
	}else if (cmd == "setCurrentLimit"){
		unsigned limit = jsonFloatProp(n, "currentLimit");
		setCurrentLimit(limit);
	}else{
		return false;
	}
	return true;
}
예제 #5
0
static bool removeListenerFromVector(EventListenerVector& listeners, EventListener& listener, bool useCapture)
{
    size_t indexOfRemovedListener = findListener(listeners, listener, useCapture);
    if (UNLIKELY(indexOfRemovedListener == notFound))
        return false;

    listeners[indexOfRemovedListener]->markAsRemoved();
    listeners.remove(indexOfRemovedListener);
    return true;
}
예제 #6
0
// ----------------------------------------------------------------------------
//
bool SpotifyEngine::unregisterEventListener( IPlayerEventCallback* listener )
{
    CSingleLock lock( &m_event_lock, TRUE );

    auto it = findListener( listener );
    if ( it == m_event_listeners.end() )
        return false;

    m_event_listeners.erase( it );
    return true;
}
예제 #7
0
// ----------------------------------------------------------------------------
//
bool SpotifyEngine::registerEventListener( IPlayerEventCallback* listener )
{
    CSingleLock lock( &m_event_lock, TRUE );

    if ( findListener( listener ) != m_event_listeners.end() )
        return false;

    m_event_listeners.push_back( listener );

    return true;
}
예제 #8
0
void EventListenerMap::replace(const AtomicString& eventType, EventListener& oldListener, Ref<EventListener>&& newListener, const RegisteredEventListener::Options& options)
{
    assertNoActiveIterators();

    auto* listeners = find(eventType);
    ASSERT(listeners);
    size_t index = findListener(*listeners, oldListener, options.capture);
    ASSERT(index != notFound);
    auto& registeredListener = listeners->at(index);
    registeredListener->markAsRemoved();
    registeredListener = RegisteredEventListener::create(WTFMove(newListener), options);
}
예제 #9
0
bool EventListenerMap::add(const AtomicString& eventType, Ref<EventListener>&& listener, const RegisteredEventListener::Options& options)
{
    assertNoActiveIterators();

    if (auto* listeners = find(eventType)) {
        if (findListener(*listeners, listener, options.capture) != notFound)
            return false; // Duplicate listener.
        listeners->append(RegisteredEventListener::create(WTFMove(listener), options));
        return true;
    }

    auto listeners = std::make_unique<EventListenerVector>();
    listeners->uncheckedAppend(RegisteredEventListener::create(WTFMove(listener), options));
    m_entries.append({ eventType, WTFMove(listeners) });
    return true;
}
예제 #10
0
bool ossimListenerManager::addListener(ossimListener* listener)
{
   if(theFireEventFlag)
   {
      theDelayedAdd.push_back(listener);
   }
   else
   {
      
      if(!findListener(listener))
      {
         theListenerList.push_back(listener);
      }
   }
   
   return true;
}
예제 #11
0
void
LocalConnection_as::update()
{
    // Check whether local connection is disabled(!): brilliant choice of
    // function name.
    if (rcfile.getLocalConnection()) {
        log_security("Attempting to write to disabled LocalConnection!");
        movie_root& mr = getRoot(owner());
        mr.removeAdvanceCallback(this);
        return;
    }

    // No-op if already attached. Nothing to do if it fails, but we
    // should probably stop trying.
    if (!_shm.attach()) {
        log_error("Failed to attach shared memory segment");
        return;
    }

    // We need the lock to prevent simultaneous reads/writes from other
    // processes.
    SharedMem::Lock lock(_shm);
    if (!lock.locked()) {
        log_debug("Failed to get shm lock");
        return;
    }

    SharedMem::iterator ptr = _shm.begin();
    
    // First check timestamp data.

    // These are not network byte order by default, but not sure about 
    // host byte order.
    const boost::uint32_t timestamp = readLong(ptr + 8);
    const boost::uint32_t size = readLong(ptr + 12);

    // As long as there is a timestamp in the shared memory, we mustn't
    // write anything.
    //
    // We check if this is data we are listening for. If it is, read it and
    // mark for overwriting.
    //
    // If not, we keep checking until the data has been overwritten by
    // another listener or until it's expired. If it's expired, we
    // mark for overwriting.
    if (timestamp) {

        // Start after 16-byte header.
        const boost::uint8_t* b = ptr + 16;

        // End at reported size of AMF sequence.
        const boost::uint8_t* end = b + size;

        amf::Reader rd(b, end, getGlobal(owner()));
        as_value a;

        // Get the connection name. That's all we need to remove expired
        // data.
        if (!rd(a)) {
            log_error("Invalid connection name data");
            return;
        }
        const std::string& connection = a.to_string();

        // Now check if data we wrote has expired. There's no really
        // reliable way of checking that we genuinely wrote it.
        if (_lastTime == timestamp) {
            
            const size_t timeout = 4 * 1000;

            VM& vm = getVM(owner());
            const boost::uint32_t timeNow = getTimestamp(vm);

            if (timeNow - timestamp > timeout) {
                log_debug("Data %s expired at %s. Removing its target "
                        "as a listener", timestamp, timeNow);
                removeListener(connection, _shm);
                markRead(_shm);
                _lastTime = 0;
            }
        }

        // If we are listening and the data is for us, get the rest of it
        // and call the method.
        if (_connected && connection == _domain + ":" + _name) {
            executeAMFFunction(owner(), rd);
            // Zero the timestamp bytes to signal that the shared memory
            // can be written again.
            markRead(_shm);
        }
        else {
            // The data has not expired and we didn't read it. Leave it
            // alone until it's expired or someone else has read it.
            return;
        }
    }

    // If we have no data to send, there's nothing more to do.
    if (_queue.empty()) {
        // ...except remove the callback if we aren't listening for anything.
        if (!_connected) {
            movie_root& mr = getRoot(owner());
            mr.removeAdvanceCallback(this);
        }
        return;
    }

    // Get the first buffer.
    boost::shared_ptr<ConnectionData> cd = _queue.front();
    _queue.pop_front();

    // If the correct listener isn't there, iterate until we find one or
    // there aren't any left.
    while (!findListener(_domain + ":" + cd->name, _shm)) {
        if (_queue.empty()) {
            // Make sure we send the empty header later.
            cd->ts = 0;
            break;
        }
        cd = _queue.front();
        _queue.pop_front();
    }

    // Yes, there is data to send.
    const char i[] = { 1, 0, 0, 0, 1, 0, 0, 0 };
    std::copy(i, i + arraySize(i), ptr);

    SimpleBuffer& buf = cd->data;

    SharedMem::iterator tmp = ptr + 8;
    writeLong(tmp, cd->ts);
    writeLong(tmp, cd->ts ? buf.size() : 0);
    std::copy(buf.data(), buf.data() + buf.size(), tmp);

    // Note the timestamp of our last send. We will keep calling update()
    // until the data has expired or been read.
    _lastTime = cd->ts;

}
예제 #12
0
SoundContext::SoundContext(const Misc::ConfigurationFileSection& configFileSection,VruiState* sVruiState)
	:vruiState(sVruiState),
	 #if ALSUPPORT_CONFIG_HAVE_OPENAL
	 alDevice(0),alContext(0),
	 #endif
	 contextData(0),
	 listener(findListener(configFileSection.retrieveString("./listenerName").c_str())),
	 speedOfSound(float(getMeterFactor())*343.0f),
	 dopplerFactor(1.0f),
	 distanceAttenuationModel(CONSTANT)
	{
	/* Set sound context parameters from configuration file: */
	speedOfSound=configFileSection.retrieveValue<float>("./speedOfSound",speedOfSound);
	dopplerFactor=configFileSection.retrieveValue<float>("./dopplerFactor",dopplerFactor);
	distanceAttenuationModel=configFileSection.retrieveValue<DistanceAttenuationModel>("./distanceAttenuationModel",distanceAttenuationModel);
	
	#if ALSUPPORT_CONFIG_HAVE_OPENAL
	/* Open the OpenAL device: */
	std::string alDeviceName=configFileSection.retrieveValue<std::string>("./deviceName","Default");
	alDevice=alcOpenDevice(alDeviceName!="Default"?alDeviceName.c_str():0);
	if(alDevice==0)
		Misc::throwStdErr("SoundContext::SoundContext: Could not open OpenAL sound device \"%s\"",alDeviceName.c_str());
	
	/* Create a list of context attributes: */
	ALCint alContextAttributes[9];
	ALCint* attPtr=alContextAttributes;
	if(configFileSection.hasTag("./mixerFrequency"))
		{
		*(attPtr++)=ALC_FREQUENCY;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./mixerFrequency");
		}
	if(configFileSection.hasTag("./refreshFrequency"))
		{
		*(attPtr++)=ALC_REFRESH;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./refreshFrequency");
		}
	if(configFileSection.hasTag("./numMonoSources"))
		{
		*(attPtr++)=ALC_MONO_SOURCES;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./numMonoSources");
		}
	if(configFileSection.hasTag("./numStereoSources"))
		{
		*(attPtr++)=ALC_STEREO_SOURCES;
		*(attPtr++)=configFileSection.retrieveValue<ALCint>("./numStereoSources");
		}
	*(attPtr++)=ALC_INVALID;
	
	/* Create an OpenAL context: */
	alContext=alcCreateContext(alDevice,alContextAttributes);
	if(alContext==0)
		{
		alcCloseDevice(alDevice);
		Misc::throwStdErr("SoundContext::SoundContext: Could not create OpenAL context for sound device %s",alDeviceName.c_str());
		}
	#endif
	
	/* Create an AL context data object: */
	contextData=new ALContextData(101);
	
	/* Initialize the sound context's OpenAL context: */
	makeCurrent();
	
	#if ALSUPPORT_CONFIG_HAVE_OPENAL
	/* Set global OpenAL parameters: */
	alSpeedOfSound(speedOfSound);
	alDopplerFactor(dopplerFactor);
	switch(distanceAttenuationModel)
		{
		case CONSTANT:
			alDistanceModel(AL_NONE);
			break;
		
		case INVERSE:
			alDistanceModel(AL_INVERSE_DISTANCE);
			break;
		
		case INVERSE_CLAMPED:
			alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
			break;
		
		case LINEAR:
			alDistanceModel(AL_LINEAR_DISTANCE);
			break;
		
		case LINEAR_CLAMPED:
			alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
			break;
		
		case EXPONENTIAL:
			alDistanceModel(AL_EXPONENT_DISTANCE);
			break;
		
		case EXPONENTIAL_CLAMPED:
			alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED);
			break;
		}
	#endif
	}