bool message_queue::send(message::ptr msg, bool waitforanswer)
{
	msg->needsanswer = waitforanswer;
	msg->result = false;
	message* msg_addr = msg.get();
	mutex_locker oml(mymutex);
	bool e = myqueue.empty();
	myqueue.push_back(msg.release());
	msginqueue = true;
	if (e) {
		emptycondvar.signal();
	}
	if (waitforanswer) {
		while (true) {
			ackcondvar.wait(mymutex);
			// check if this message has been acknowledged
			for (std::list<message*>::iterator it = ackqueue.begin(); it != ackqueue.end(); ) {
				if (*it == msg_addr) {
					// found it, return result, delete and unqueue message
					bool result = (*it)->result;
					delete *it;
					ackqueue.erase(it);
					return result;
				}
			}
		}
	}
	return true;
}
std::list<message*> message_queue::receive(bool wait)
{
	std::list<message*> result;
	mutex_locker oml(mymutex);
	if (myqueue.empty()) {
		if (wait && !abortwait) {
			emptycondvar.wait(mymutex);
		} else {
			// no need to wait, so clear abort signal
			abortwait = false;
			msginqueue = false;
			return result;
		}
	}

	abortwait = false;

	// if we woke up and queue is still empty, we received a wakeup signal
	// so result either is empty or contains the full queue after this line
	myqueue.swap(result);

	// any way, there are now no messages in the queue. return messages or empty list.
	msginqueue = false;
	return result;
}
void message_queue::wakeup_receiver()
{
	// set a special flag to avoid another thread to enter the wait() command
	// if this signal comes while the other thread tests wether to enter wait state
	mutex_locker oml(mymutex);
	abortwait = true;
	emptycondvar.signal();
}
void message_queue::acknowledge(message* msg)
{
	if (!msg)
		throw error("acknowledge without message called");
	bool needsanswer = msg->needsanswer;
	mutex_locker oml(mymutex);
	if (needsanswer) {
		ackqueue.push_back(msg);
		ackcondvar.signal();
	} else {
		delete msg;
	}
}
void AutomaticGainControl_i::configure(const CF::Properties& props) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration)
{
    static int init = 0;

    CORBA::Float simple_temp;

    DEBUG(3, AutomaticGainControl, "configure() invoked")

    DEBUG(3, AutomaticGainControl, "props length : " << props.length())

    if (init == 0) {
        if ( props.length() <= 0 ) {
            std::cout << "AutomaticGainControl: configure called with invalid props.length() - " << props.length() << std::endl;
            return;
        }

        propertySet.length(props.length());
        for (unsigned int i=0; i < props.length(); i++) {
            propertySet[i].id = CORBA::string_dup(props[i].id);
            propertySet[i].value = props[i].value;
        }
        init++;
    }

    for (unsigned int i=0; i < props.length(); i++) {
        std::cout << "Property Id : " << props[i].id << std::endl;
        if (strcmp(props[i].id, "DCE:aaf97fa0-d184-4d88-9954-3a1334c73d6d") == 0) {
            // energy_lo
            props[i].value >>= simple_temp;
            omni_mutex_lock oml(accessPrivateData);
            energy_lo = simple_temp;
            // Update value of this property in propertySet also
            for (unsigned int j=0; j < propertySet.length(); j++ ) {
                if ( strcmp(propertySet[j].id, props[i].id) == 0 ) {
                    propertySet[j].value = props[i].value;
                    break;
                }
            }
            DEBUG(3, AutomaticGainControl, "prop (energy_lo): " << simple_temp)

        } else if (strcmp(props[i].id, "DCE:346e17c9-6678-483a-bffb-1909c64bddc0") == 0) {