Esempio n. 1
0
void Subscriber::OnMessage(Safir::Dob::MessageProxy messageProxy)
{
    DoseStressTest::RootMessagePtr rootMsg =
        boost::static_pointer_cast<DoseStressTest::RootMessage>(messageProxy.GetMessage());

    switch (rootMsg->GetTypeId())
    {
    case DoseStressTest::MessageWithAckLarge::ClassTypeId:
        {
            m_receivedWithAckLargeStat->Tick();

            if (rootMsg->SequenceNumber().GetVal() != m_lastSequenceNumberWithAckLarge + 1)
            {
                //tick up number of lost messages
                m_missedWithAckLargeStat->Tick(rootMsg->SequenceNumber().GetVal() - m_lastSequenceNumberWithAckLarge);
            }
            m_lastSequenceNumberWithAckLarge = rootMsg->SequenceNumber().GetVal();
        }
        break;

    case DoseStressTest::MessageWithAck::ClassTypeId:
        {
            m_receivedWithAckStat->Tick();

            if (rootMsg->SequenceNumber().GetVal() != m_lastSequenceNumberWithAck + 1)
            {
                //tick up number of lost messages
                m_missedWithAckStat->Tick(rootMsg->SequenceNumber().GetVal() - m_lastSequenceNumberWithAck);
            }
            m_lastSequenceNumberWithAck = rootMsg->SequenceNumber().GetVal();
        }
        break;

    case DoseStressTest::MessageWithoutAckLarge::ClassTypeId:
        {
            m_receivedWithoutAckLargeStat->Tick();

            if (rootMsg->SequenceNumber().GetVal() != m_lastSequenceNumberWithoutAckLarge + 1)
            {
                //tick up number of lost messages
                m_missedWithoutAckLargeStat->Tick(rootMsg->SequenceNumber().GetVal() - m_lastSequenceNumberWithoutAckLarge);
            }
            m_lastSequenceNumberWithoutAckLarge = rootMsg->SequenceNumber().GetVal();
        }
        break;

    case DoseStressTest::MessageWithoutAck::ClassTypeId:
        {
            m_receivedWithoutAckStat->Tick();

            if (rootMsg->SequenceNumber().GetVal() != m_lastSequenceNumberWithoutAck + 1)
            {
                //tick up number of lost messages
                m_missedWithoutAckStat->Tick(rootMsg->SequenceNumber().GetVal() - m_lastSequenceNumberWithoutAck);
            }
            m_lastSequenceNumberWithoutAck = rootMsg->SequenceNumber().GetVal();
        }
        break;

    }
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
void BackdoorKeeper::OnMessage(const Safir::Dob::MessageProxy messageProxy)
{
    try
    {
        const boost::wregex::flag_type regExpFlags = boost::regex::perl | boost::regex::icase;

        const Safir::Dob::MessagePtr message = messageProxy.GetMessage();

        const Safir::Application::BackdoorCommandPtr cmd =
                boost::dynamic_pointer_cast<Safir::Application::BackdoorCommand>(message);

        if (cmd == NULL)
        {
            // Unexpected message
            return;   // *** RETURN ***
        }

        if (!cmd->NodeName().IsNull())
        {
            if (!boost::regex_search(Safir::Dob::ThisNodeParameters::Name(),
                                     boost::wregex(cmd->NodeName().GetVal(), regExpFlags)))
            {
                // Node name doesn't match
                return;  // *** RETURN ***
            }
        }

        Safir::Dob::ConnectionAspectMisc connectionAspectMisc(m_connection);
        if (!cmd->ConnectionName().IsNull())
        {
            if (!boost::regex_search(connectionAspectMisc.GetConnectionName(),
                                     boost::wregex(cmd->ConnectionName().GetVal(), regExpFlags)))
            {
                // Connection name doesn't match
                return;  // *** RETURN ***
            }
        }

        if (cmd->Command().IsNull())
        {
            // No command given
            return;  // *** RETURN ***
        }

        // Ok, it seems that this PI-command is for this application

        std::vector<std::wstring> cmdTokens;

        const wchar_t* delimiters = L" \t\n\r";
        Tokenize(cmd->Command().GetVal(), cmdTokens, delimiters);

        if (!cmdTokens.empty())
        {
            if (cmdTokens[0] == pingCmd)
            {
                // It's a 'ping' command. Answer to it without bothering
                // the subclass implementator.

                std::wostringstream ostr;
                ostr << "Ping reply from "
                     << connectionAspectMisc.GetConnectionName()
                     <<  " on node "
                     << Safir::Dob::ThisNodeParameters::Name();

                Safir::Logging::SendSystemLog(Safir::Logging::Debug,
                                              ostr.str());

                return; // *** RETURN ***
            }
            else if (cmdTokens[0] == helpCmd)
            {
                // Get help text from subclass implementator.
                Safir::Logging::SendSystemLog(Safir::Logging::Debug,
                                              m_backdoor->GetHelpText());

                return; // *** RETURN ***
            }
        }

        // Let the subclass handle the command
        m_backdoor->HandleCommand(cmdTokens);
    }
    catch (boost::bad_expression& /* e*/ )
    {
        // An invalid regular expression was used, skip this command
        return;  // *** RETURN ***
    }
}