Example #1
0
void Activator::ServiceChanged(const ServiceEvent event) {
	// MutexLocker lock(&m_mutex);
	if (event.GetType() == ServiceEvent::REGISTERED) {
		if (!this->ref) {
			// Get a reference to the service object.
			this->ref = event.GetServiceReference();
			this->axService = this->context->GetService(this->ref);
		}
	}
	// If an Autexousious service was unregistered, see if it
	// was the one we were using. If so, unget the service
	// and try to query to get another one.
	else if (event.GetType() == ServiceEvent::UNREGISTERING) {
		if (event.GetServiceReference() == this->ref) {
			// Unget service object and null references.
			this->context->UngetService(this->ref);
			this->ref = 0;
			this->axService = NULL;

			// Query to see if we can get another service.
			std::vector<ServiceReference<sl::ax::engine::AutexousiousService> > refs;
			try {
				refs = this->context->GetServiceReferences<sl::ax::engine::AutexousiousService>();
			} catch (const std::invalid_argument& e) {
				std::cout << e.what() << std::endl;
			}

			if (!refs.empty()) {
				// Get a reference to the first service object.
				this->ref = refs.front();
				this->axService = this->context->GetService(this->ref);
			}
		}
	}
}