From 8ddd83cf0a9613b52112a5b469fed066d428c495 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Fri, 11 Feb 2011 04:13:51 +0000 Subject: QPID-3046 - Added an example in C++ for receiving events git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1069672 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/bindings/qmf2/examples/cpp/Makefile.am | 4 +- cpp/bindings/qmf2/examples/cpp/print_events.cpp | 64 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 cpp/bindings/qmf2/examples/cpp/print_events.cpp diff --git a/cpp/bindings/qmf2/examples/cpp/Makefile.am b/cpp/bindings/qmf2/examples/cpp/Makefile.am index 9c3bd615d6..84207d43c4 100644 --- a/cpp/bindings/qmf2/examples/cpp/Makefile.am +++ b/cpp/bindings/qmf2/examples/cpp/Makefile.am @@ -21,7 +21,7 @@ INCLUDE = -I$(top_srcdir)/include AM_CPPFLAGS = $(INCLUDE) -noinst_PROGRAMS=agent list_agents +noinst_PROGRAMS=agent list_agents print_events agent_SOURCES=agent.cpp agent_LDADD=$(top_builddir)/src/libqmf2.la @@ -29,3 +29,5 @@ agent_LDADD=$(top_builddir)/src/libqmf2.la list_agents_SOURCES=list_agents.cpp list_agents_LDADD=$(top_builddir)/src/libqmf2.la +print_events_SOURCES=print_events.cpp +print_events_LDADD=$(top_builddir)/src/libqmf2.la diff --git a/cpp/bindings/qmf2/examples/cpp/print_events.cpp b/cpp/bindings/qmf2/examples/cpp/print_events.cpp new file mode 100644 index 0000000000..9883a19962 --- /dev/null +++ b/cpp/bindings/qmf2/examples/cpp/print_events.cpp @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace qmf; +using qpid::types::Variant; +using qpid::messaging::Duration; + +int main(int argc, char** argv) +{ + string url("localhost"); + string connectionOptions; + string sessionOptions; + + if (argc > 1) + url = argv[1]; + if (argc > 2) + connectionOptions = argv[2]; + if (argc > 3) + sessionOptions = argv[3]; + + qpid::messaging::Connection connection(url, connectionOptions); + connection.open(); + + ConsoleSession session(connection, sessionOptions); + session.open(); + + while (true) { + ConsoleEvent event; + if (session.nextEvent(event)) { + if (event.getType() == CONSOLE_EVENT) { + const Data& data(event.getData(0)); + cout << "Event: timestamp=" << event.getTimestamp() << " severity=" << + event.getSeverity() << " content=" << data.getProperties() << endl; + } + } + } +} + -- cgit v1.2.1