コード例 #1
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::setCapacity(boost::shared_ptr<ReceiverContext> receiver, uint32_t capacity)
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    receiver->setCapacity(capacity);
    pn_link_flow((pn_link_t*) receiver->receiver, receiver->getCapacity());
    wakeupDriver();
}
コード例 #2
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::close()
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    if (state != CONNECTED) return;
    if (!(pn_connection_state(connection) & PN_LOCAL_CLOSED)) {
        for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); ++i) {
            //wait for outstanding sends to settle
            while (!i->second->settled()) {
                QPID_LOG(debug, "Waiting for sends to settle before closing");
                wait();//wait until message has been confirmed
            }


            if (!(pn_session_state(i->second->session) & PN_LOCAL_CLOSED)) {
                pn_session_close(i->second->session);
            }
        }
        pn_connection_close(connection);
        wakeupDriver();
        //wait for close to be confirmed by peer?
        while (!(pn_connection_state(connection) & PN_REMOTE_CLOSED)) {
            wait();
        }
        sessions.clear();
    }
    transport->close();
    while (state != DISCONNECTED) {
        lock.wait();
    }
}
コード例 #3
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::acknowledge(boost::shared_ptr<SessionContext> ssn, qpid::messaging::Message* message, bool cumulative)
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    if (message) {
        ssn->acknowledge(MessageImplAccess::get(*message).getInternalId(), cumulative);
    } else {
        ssn->acknowledge();
    }
    wakeupDriver();
}
コード例 #4
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
bool ConnectionContext::fetch(boost::shared_ptr<SessionContext> ssn, boost::shared_ptr<ReceiverContext> lnk, qpid::messaging::Message& message, qpid::messaging::Duration timeout)
{
    {
        qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
        if (!lnk->capacity) {
            pn_link_flow(lnk->receiver, 1);
            wakeupDriver();
        }
    }
    if (get(ssn, lnk, message, timeout)) {
        qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
        if (lnk->capacity) {
            pn_link_flow(lnk->receiver, 1);//TODO: is this the right approach?
            wakeupDriver();
        }
        return true;
    } else {
        {
            qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
            pn_link_drain(lnk->receiver, 0);
            wakeupDriver();
            while (pn_link_credit(lnk->receiver) && !pn_link_queued(lnk->receiver)) {
                QPID_LOG(debug, "Waiting for message or for credit to be drained: credit=" << pn_link_credit(lnk->receiver) << ", queued=" << pn_link_queued(lnk->receiver));
                wait();
            }
            if (lnk->capacity && pn_link_queued(lnk->receiver) == 0) {
                pn_link_flow(lnk->receiver, lnk->capacity);
            }
        }
        if (get(ssn, lnk, message, qpid::messaging::Duration::IMMEDIATE)) {
            qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
            if (lnk->capacity) {
                pn_link_flow(lnk->receiver, 1);
                wakeupDriver();
            }
            return true;
        } else {
            return false;
        }
    }
}
コード例 #5
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::attach(pn_session_t* /*session*/, pn_link_t* link, int credit)
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    QPID_LOG(debug, "Attaching link " << link << ", state=" << pn_link_state(link));
    pn_link_open(link);
    QPID_LOG(debug, "Link attached " << link << ", state=" << pn_link_state(link));
    if (credit) pn_link_flow(link, credit);
    wakeupDriver();
    while (pn_link_state(link) & PN_REMOTE_UNINIT) {
        QPID_LOG(debug, "waiting for confirmation of link attach for " << link << ", state=" << pn_link_state(link));
        wait();
    }
}
コード例 #6
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::send(boost::shared_ptr<SenderContext> snd, const qpid::messaging::Message& message, bool sync)
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    SenderContext::Delivery* delivery(0);
    while (!(delivery = snd->send(message))) {
        QPID_LOG(debug, "Waiting for capacity...");
        wait();//wait for capacity
    }
    wakeupDriver();
    if (sync) {
        while (!delivery->accepted()) {
            QPID_LOG(debug, "Waiting for confirmation...");
            wait();//wait until message has been confirmed
        }
    }
}
コード例 #7
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
boost::shared_ptr<SessionContext> ConnectionContext::newSession(bool transactional, const std::string& n)
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    if (transactional) throw qpid::messaging::MessagingException("Transactions not yet supported");
    std::string name = n.empty() ? qpid::framing::Uuid(true).str() : n;
    SessionMap::const_iterator i = sessions.find(name);
    if (i == sessions.end()) {
        boost::shared_ptr<SessionContext> s(new SessionContext(connection));
        s->session = pn_session(connection);
        pn_session_open(s->session);
        sessions[name] = s;
        wakeupDriver();
        while (pn_session_state(s->session) & PN_REMOTE_UNINIT) {
            wait();
        }
        return s;
    } else {
        throw qpid::messaging::KeyError(std::string("Session already exists: ") + name);
    }

}
コード例 #8
0
ファイル: platform_sanbot_a.c プロジェクト: BHFaction/SanBot
// TODO: Implement!
int platformInit ( void )
{
	uint8_t i = 0;
	int checksum = 0;

	//Low level init: Clock and Interrupt controller
	NVIC_PriorityGroupConfig ( NVIC_PriorityGroup_4 );

	// Disable the jtag gpio
	GPIO_PinRemapConfig ( GPIO_Remap_SWJ_JTAGDisable, ENABLE );

	ledInit();

	ledSet ( 0, 0 );
	ledSet ( 1, 0 );
	ledSet ( 2, 0 );

	delay_ms ( 500 );
	ledSet ( 0, 1 );
	delay_ms ( 500 );
	ledSet ( 1, 1 );
	delay_ms ( 500 );
	ledSet ( 2, 1 );

	delay_ms ( 500 );

	uartInit();

	DEBUG_PRINT ( "Too young too simple, sometimes naive.\n" );
	DEBUG_PRINT ( "I'm a journalist from Hongkong.\n" );
	DEBUG_PRINT ( "I could run very fast.\n" );
	DEBUG_PRINT ( "------------------------------\n" );

	DEBUG_PRINT ( "uart init successfully.\n" );

	ledSet ( 0, 0 );

	// adcInit();

	DEBUG_PRINT ( "test motor.\n" );

	timInit();

	DEBUG_PRINT ( "waking up driver.\n" );

	wakeupDriver();

	timSetPulse ( TIM2, 3, 0 );
	timSetPulse ( TIM3, 3, 0 );
	timSetPulse ( TIM4, 3, 0 );
	timSetPulse ( TIM2, 4, 0 );
	timSetPulse ( TIM3, 4, 0 );
	timSetPulse ( TIM4, 4, 0 );

	delay_ms ( 500 );

	timSetPulse ( TIM2, 4, 500 );
	timSetPulse ( TIM3, 4, 500 );
	timSetPulse ( TIM4, 4, 500 );

	delay_ms ( 500 );

	timSetPulse ( TIM2, 3, 0 );
	timSetPulse ( TIM3, 3, 0 );
	timSetPulse ( TIM4, 3, 0 );
	timSetPulse ( TIM2, 4, 0 );
	timSetPulse ( TIM3, 4, 0 );
	timSetPulse ( TIM4, 4, 0 );

	delay_ms ( 500 );

	timSetPulse ( TIM2, 3, 500 );
	timSetPulse ( TIM3, 3, 500 );
	timSetPulse ( TIM4, 3, 500 );

	delay_ms ( 500 );

	timSetPulse ( TIM2, 3, 0 );
	timSetPulse ( TIM3, 3, 0 );
	timSetPulse ( TIM4, 3, 0 );
	timSetPulse ( TIM2, 4, 0 );
	timSetPulse ( TIM3, 4, 0 );
	timSetPulse ( TIM4, 4, 0 );

	ledSet ( 1, 0 );

	delay_ms ( 200 );

	nrf24l01Init();

	i = nrf24l01ConnectCheck();

	nrf24l01SetAddress();
	// i = nrf24l01ConnectCheck();

	if ( i == 1 )
	{
		checksum --;
		ledSet ( 2, 0 );
	}

	delay_ms ( 1000 );

	// mpu9150Init();
	// i = mpu9150Status();

	// if(!i)
	// {
	//  checksum --;
	//  ledSet(1, 0);
	// }

	if ( checksum > 0 )
	{
		delay_ms ( 1000 );

		timSetPulse ( TIM2, 3, 0 );
		timSetPulse ( TIM3, 3, 0 );
		timSetPulse ( TIM4, 3, 0 );
		timSetPulse ( TIM2, 4, 0 );
		timSetPulse ( TIM3, 4, 0 );
		timSetPulse ( TIM4, 4, 0 );
		// timSetPulse(TIM2, 4, 999);
		// timSetPulse(TIM3, 4, 999);
		// timSetPulse(TIM4, 4, 999);

		while ( 1 )
		{

			ledSet ( 0, 1 );
			ledSet ( 1, 1 );
			ledSet ( 2, 1 );
			delay_ms ( 100 );
			ledSet ( 0, 0 );
			ledSet ( 1, 0 );
			ledSet ( 2, 0 );
			delay_ms ( 100 );
		}
	}

	ledSet ( 0, 0 );
	ledSet ( 1, 0 );
	ledSet ( 2, 0 );

	delay_ms ( 500 );

	ledSet ( 0, 1 );
	ledSet ( 1, 1 );
	ledSet ( 2, 1 );

	delay_ms ( 500 );

	ledSet ( 0, 0 );
	ledSet ( 1, 0 );
	ledSet ( 2, 0 );

	return 0;
}
コード例 #9
0
ファイル: ConnectionContext.cpp プロジェクト: ncdc/qpid
void ConnectionContext::activateOutput()
{
    qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock);
    wakeupDriver();
}