Пример #1
0
bool Notification::serviceAvailable(NotificationType type)
{
    if (type < 0 || type >= END_OF_TYPE)
        return false;
    NotificationService *service = notify_service[type];
    if (!service)
        return false;
    return service->serviceAvailable();
}
status_t
NotificationManager::RemoveListener(const char* serviceName,
	const KMessage* eventSpecifier, NotificationListener& listener)
{
	MutexLocker locker(fLock);
	NotificationService* service = _ServiceFor(serviceName);
	if (service == NULL)
		return B_NAME_NOT_FOUND;

	BReference<NotificationService> reference(service);
	locker.Unlock();

	return service->RemoveListener(eventSpecifier, listener);
}
status_t
NotificationManager::RegisterService(NotificationService& service)
{
	MutexLocker _(fLock);

	if (_ServiceFor(service.Name()))
		return B_NAME_IN_USE;

	status_t status = fServiceHash.Insert(&service);
	if (status == B_OK)
		service.AcquireReference();

	return status;
}
void
NotificationManager::UnregisterService(NotificationService& service)
{
	MutexLocker _(fLock);
	fServiceHash.Remove(&service);
	service.ReleaseReference();
}
Пример #5
0
void
SystemProfiler::EventOccurred(NotificationService& service,
	const KMessage* event)
{
	int32 eventCode;
	if (event->FindInt32("event", &eventCode) != B_OK)
		return;

	if (strcmp(service.Name(), "teams") == 0) {
		Team* team = (Team*)event->GetPointer("teamStruct", NULL);
		if (team == NULL)
			return;

		switch (eventCode) {
			case TEAM_ADDED:
				if (fTeamNotificationsEnabled)
					_TeamAdded(team);
				break;

			case TEAM_REMOVED:
				if (team->id == fTeam) {
					// The profiling team is gone -- uninstall the profiler!
					InterruptsSpinLocker locker(sProfilerLock);
					if (sProfiler != this)
						return;

					sProfiler = NULL;
					locker.Unlock();

					ReleaseReference();
					return;
				}

				// When we're still doing the initial team list scan, we are
				// also interested in removals that happened to teams we have
				// already seen.
				if (fTeamNotificationsEnabled
					|| team->serial_number <= fLastTeamAddedSerialNumber) {
					_TeamRemoved(team);
				}
				break;

			case TEAM_EXEC:
				if (fTeamNotificationsEnabled)
					_TeamExec(team);
				break;
		}
	} else if (strcmp(service.Name(), "threads") == 0) {
		Thread* thread = (Thread*)event->GetPointer("threadStruct", NULL);
		if (thread == NULL)
			return;

		switch (eventCode) {
			case THREAD_ADDED:
				if (fThreadNotificationsEnabled)
					_ThreadAdded(thread);
				break;

			case THREAD_REMOVED:
				// When we're still doing the initial thread list scan, we are
				// also interested in removals that happened to threads we have
				// already seen.
				if (fThreadNotificationsEnabled
					|| thread->serial_number <= fLastThreadAddedSerialNumber) {
					_ThreadRemoved(thread);
				}
				break;
		}
	} else if (strcmp(service.Name(), "images") == 0) {
		if (!fImageNotificationsEnabled)
			return;

		struct image* image = (struct image*)event->GetPointer(
			"imageStruct", NULL);
		if (image == NULL)
			return;

		switch (eventCode) {
			case IMAGE_ADDED:
				_ImageAdded(image);
				break;

			case IMAGE_REMOVED:
				_ImageRemoved(image);
				break;
		}
	} else if (strcmp(service.Name(), "I/O") == 0) {
		if (!fIONotificationsEnabled)
			return;

		IOScheduler* scheduler = (IOScheduler*)event->GetPointer("scheduler",
			NULL);
		if (scheduler == NULL)
			return;

		IORequest* request = (IORequest*)event->GetPointer("request", NULL);
		IOOperation* operation = (IOOperation*)event->GetPointer("operation",
			NULL);

		switch (eventCode) {
			case IO_SCHEDULER_ADDED:
				_IOSchedulerAdded(scheduler);
				break;

			case IO_SCHEDULER_REMOVED:
				_IOSchedulerRemoved(scheduler);
				break;

			case IO_SCHEDULER_REQUEST_SCHEDULED:
				_IORequestScheduled(scheduler, request);
				break;

			case IO_SCHEDULER_REQUEST_FINISHED:
				_IORequestFinished(scheduler, request);
				break;

			case IO_SCHEDULER_OPERATION_STARTED:
				_IOOperationStarted(scheduler, request, operation);
				break;

			case IO_SCHEDULER_OPERATION_FINISHED:
				_IOOperationFinished(scheduler, request, operation);
				break;
		}
	}

	_MaybeNotifyProfilerThread();
}