Ejemplo n.º 1
0
void ServiceRegistration::SetProperties(const ServiceProperties& props)
{
  if (!d) throw std::logic_error("ServiceRegistration object invalid");

  MutexLocker lock(d->eventLock);

  ServiceListeners::ServiceListenerEntries before;
  // TBD, optimize the locking of services
  {
    //MutexLocker lock2(d->module->coreCtx->globalFwLock);

    if (d->available)
    {
      // NYI! Optimize the MODIFIED_ENDMATCH code
      int old_rank = 0;
      int new_rank = 0;

      std::list<std::string> classes;
      {
        MutexLocker lock3(d->propsLock);

        Any any = d->properties[ServiceConstants::SERVICE_RANKING()];
        if (any.Type() == typeid(int)) old_rank = any_cast<int>(any);

        d->module->coreCtx->listeners.GetMatchingServiceListeners(d->reference, before, false);
        classes = ref_any_cast<std::list<std::string> >(d->properties[ServiceConstants::OBJECTCLASS()]);
        long int sid = any_cast<long int>(d->properties[ServiceConstants::SERVICE_ID()]);
        d->properties = ServiceRegistry::CreateServiceProperties(props, classes, sid);

        any = d->properties[ServiceConstants::SERVICE_RANKING()];
        if (any.Type() == typeid(int)) new_rank = any_cast<int>(any);
      }

      if (old_rank != new_rank)
      {
        d->module->coreCtx->services.UpdateServiceRegistrationOrder(*this, classes);
      }
    }
    else
    {
      throw std::logic_error("Service is unregistered");
    }
  }
  ServiceListeners::ServiceListenerEntries matchingListeners;
  d->module->coreCtx->listeners.GetMatchingServiceListeners(d->reference, matchingListeners);
  d->module->coreCtx->listeners.ServiceChanged(matchingListeners,
                                               ServiceEvent(ServiceEvent::MODIFIED, d->reference),
                                               before);

  d->module->coreCtx->listeners.ServiceChanged(before,
                                               ServiceEvent(ServiceEvent::MODIFIED_ENDMATCH, d->reference));
}
Ejemplo n.º 2
0
DWORD MIDIStreamer::PlayerLoop()
{
	HANDLE events[2] = { BufferDoneEvent, ExitEvent };
	int res;

	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);

	for (;;)
	{
		switch (WaitForMultipleObjects(2, events, FALSE, INFINITE))
		{
		case WAIT_OBJECT_0:
			if (0 != (res = ServiceEvent()))
			{
				return res;
			}
			break;

		case WAIT_OBJECT_0 + 1:
			return 0;

		default:
			// Should not happen.
			return MMSYSERR_ERROR;
		}
	}
}
Ejemplo n.º 3
0
ServiceRegistration ServiceRegistry::RegisterService(ModulePrivate* module,
                                                     const std::list<std::string>& classes,
                                                     itk::LightObject* service,
                                                     const ServiceProperties& properties)
{
  if (service == 0)
  {
    throw std::invalid_argument("Can't register 0 as a service");
  }

  // Check if service implements claimed classes and that they exist.
  for (std::list<std::string>::const_iterator i = classes.begin();
       i != classes.end(); ++i)
  {
    if (i->empty())
    {
      throw std::invalid_argument("Can't register as null class");
    }

    if (!(dynamic_cast<ServiceFactory*>(service)))
    {
      if (!CheckServiceClass(service, *i))
      {
        std::string msg;
        std::stringstream ss(msg);
        ss << "Service class " << service->GetNameOfClass() << " is not an instance of "
               << (*i) << ". Maybe you forgot to export the RTTI information for the interface.";
        throw std::invalid_argument(msg);
      }
    }
  }

  ServiceRegistration res(module, service,
                          CreateServiceProperties(properties, classes));
  {
    MutexLocker lock(mutex);
    services.insert(std::make_pair(res, classes));
    serviceRegistrations.push_back(res);
    for (std::list<std::string>::const_iterator i = classes.begin();
         i != classes.end(); ++i)
    {
      std::list<ServiceRegistration>& s = classServices[*i];
      std::list<ServiceRegistration>::iterator ip =
          std::lower_bound(s.begin(), s.end(), res, ServiceRegistrationComparator());
      s.insert(ip, res);
    }
  }

  ServiceReference r = res.GetReference();
  ServiceListeners::ServiceListenerEntries listeners;
  module->coreCtx->listeners.GetMatchingServiceListeners(r, listeners);
  module->coreCtx->listeners.ServiceChanged(listeners,
                                            ServiceEvent(ServiceEvent::REGISTERED, r));
  return res;
}
Ejemplo n.º 4
0
void ServiceRegistration::Unregister()
{
  if (!d) throw std::logic_error("ServiceRegistration object invalid");

  if (d->unregistering) return; // Silently ignore redundant unregistration.
  {
    MutexLocker lock(d->eventLock);
    if (d->unregistering) return;
    d->unregistering = true;

    if (d->available)
    {
      if (d->module)
      {
        d->module->coreCtx->services.RemoveServiceRegistration(*this);
      }
    }
    else
    {
      throw std::logic_error("Service is unregistered");
    }
  }

  if (d->module)
  {
    ServiceListeners::ServiceListenerEntries listeners;
    d->module->coreCtx->listeners.GetMatchingServiceListeners(d->reference, listeners);
     d->module->coreCtx->listeners.ServiceChanged(
         listeners,
         ServiceEvent(ServiceEvent::UNREGISTERING, d->reference));
  }

  {
    MutexLocker lock(d->eventLock);
    {
      MutexLocker lock2(d->propsLock);
      d->available = false;
      #ifdef US_ENABLE_SERVICE_FACTORY_SUPPORT
      if (d->module)
      {
        ServiceRegistrationPrivate::ModuleToServicesMap::const_iterator end = d->serviceInstances.end();
        for (ServiceRegistrationPrivate::ModuleToServicesMap::const_iterator i = d->serviceInstances.begin();
             i != end; ++i)
        {
          US_BASECLASS_NAME* obj = i->second;
          try
          {
            // NYI, don't call inside lock
            dynamic_cast<ServiceFactory*>(d->service)->UngetService(i->first,
                                                                    *this,
                                                                    obj);
          }
          catch (const std::exception& /*ue*/)
          {
            US_WARN << "ServiceFactory UngetService implementation threw an exception";
          }
        }
      }
      #endif
      d->module = 0;
      d->dependents.clear();
      d->service = 0;
      d->serviceInstances.clear();
      // increment the reference count, since "d->reference" was used originally
      // to keep d alive.
      d->ref.Ref();
      d->reference = 0;
      d->unregistering = false;
    }
  }
}
Ejemplo n.º 5
0
/*****************************************************************************
 * CAudioFilterFactory::HandleInterrupt()
 *****************************************************************************
 *//*!
 * @brief
 */
VOID
CAudioFilterFactory::
HandleInterrupt
(
	IN		AUDIO_INTERRUPT_ORIGINATOR	Originator,
	IN		UCHAR						OriginatorID,
	IN		PVOID						InterruptFilter
)
{
	switch (Originator)
	{
		case AUDIO_INTERRUPT_ORIGINATOR_AC_TERMINAL:
		{
			ULONG PinCount = m_AudioFilterDescriptor.PinCount();

			for (ULONG i=0; i<PinCount; i++)
			{
				PFILTER_PIN_DESCRIPTOR Pin = m_AudioFilterDescriptor.FindFilterPin(i);

				if (Pin && Pin->TerminalID() == OriginatorID)
				{
					ServiceEvent(InterruptFilter, (GUID*)&KSEVENTSETID_AudioControlChange, KSEVENT_CONTROL_CHANGE, TRUE, Pin->PinId(), FALSE, ULONG(-1));
					break;
				}
			}
		}
		break;

		case AUDIO_INTERRUPT_ORIGINATOR_AC_UNIT:
		{
			ULONG NodeCount = m_AudioFilterDescriptor.NodeCount();

			for (ULONG i=0; i<NodeCount; i++)
			{
				PNODE_DESCRIPTOR Node = m_AudioFilterDescriptor.FindNode(i);

				if (Node && Node->UnitID() == OriginatorID)
				{
					ServiceEvent(InterruptFilter, (GUID*)&KSEVENTSETID_AudioControlChange, KSEVENT_CONTROL_CHANGE, FALSE, ULONG(-1), TRUE, Node->NodeId());
					break;
				}
			}
		}
		break;

		case AUDIO_INTERRUPT_ORIGINATOR_AC_FUNCTION:
		{
			ServiceEvent(InterruptFilter, (GUID*)&KSEVENTSETID_AudioControlChange, KSEVENT_CONTROL_CHANGE, FALSE, ULONG(-1), FALSE, ULONG(-1));
		}
		break;

		case AUDIO_INTERRUPT_ORIGINATOR_AS_INTERFACE:
		{
			//TODO:
		}
		break;

		case AUDIO_INTERRUPT_ORIGINATOR_AS_ENDPOINT:
		{
			//TODO:
		}
		break;

		default:
		{
		}
		break;
	}
}