Ejemplo n.º 1
0
void ObservableLooper::_handleRemoveObserver(
    BMessage*								message) {

//	PRINT(("ObservableLooper::_handleRemoveObserver():\n"
//		"  %ld targets\n", CountTargets()));
    BMessage reply;

    BMessenger observer;
    status_t err = message->FindMessenger(
                       "observer", &observer);
    if(err < B_OK) {
        PRINT((
                  "* ObservableLooper::_handleRemoveObserver(): no observer specified!\n"));
        // send reply? +++++
        return;
    }

    // at this point, a reply of some sort will be sent
    reply.AddMessenger("target", BMessenger(this));
    reply.AddMessenger("observer", observer);

    int32 index = IndexOfTarget(observer.Target(0));
    if(index == -1) {
        reply.what = M_BAD_OBSERVER;
    }
    else {
        RemoveTarget(index);
        reply.what = M_OBSERVER_REMOVED;
    }

    message->SendReply(&reply);

    // call hook
    observerRemoved(observer);

    // time to shut down?
    if(m_quitting && !CountTargets()) {
        releaseComplete();
        BLooper::Quit();
    }
}
Ejemplo n.º 2
0
void ObservableHandler::_handleRemoveObserver(
	BMessage*								message) {

#if DEBUG
	BLooper* l = Looper();
	ASSERT(l);
	ASSERT(l->IsLocked());
#endif
	BMessage reply;

	BMessenger observer;
	status_t err = message->FindMessenger(
		"observer", &observer);
	if(err < B_OK) {
		PRINT((
			"* ObservableHandler::_handleRemoveObserver(): no observer specified!\n"));
		// send reply? +++++
		return;
	}

	int32 index = IndexOfTarget(observer.Target(0));
	if(index == -1) {
		reply.what = M_BAD_OBSERVER;
		
		reply.AddMessenger("target", BMessenger(this));
		reply.AddMessenger("observer", observer);
		message->SendReply(&reply);
		return;
	}
	
	// valid observer given; remove it & call notification hook
	RemoveTarget(index);
	observerRemoved(observer);
	
	// time to shut down?
	if(m_released && !CountTargets()) {
		releaseComplete();
		delete this; // BOOM!
	}
}