You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2013/12/20 03:01:57 UTC
svn commit: r1552476 - in /qpid/trunk/qpid/cpp: examples/messaging/drain.cpp
examples/messaging/spout.cpp include/qpid/messaging/Message_ostream.h
src/CMakeLists.txt src/qpid/messaging/Message_ostream.cpp
Author: aconway
Date: Fri Dec 20 02:01:56 2013
New Revision: 1552476
URL: http://svn.apache.org/r1552476
Log:
NO-JIRA: Added ostream operator for qpid::Messaging::Message
Added:
qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h (with props)
qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp (with props)
Modified:
qpid/trunk/qpid/cpp/examples/messaging/drain.cpp
qpid/trunk/qpid/cpp/examples/messaging/spout.cpp
qpid/trunk/qpid/cpp/src/CMakeLists.txt
Modified: qpid/trunk/qpid/cpp/examples/messaging/drain.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/drain.cpp?rev=1552476&r1=1552475&r2=1552476&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/drain.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/drain.cpp Fri Dec 20 02:01:56 2013
@@ -21,6 +21,7 @@
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Message_ostream.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Session.h>
@@ -92,17 +93,7 @@ int main(int argc, char** argv)
int i = 0;
while (receiver.fetch(message, timeout)) {
- std::cout << "Message(properties=" << message.getProperties();
- if (!message.getSubject().empty()) {
- std::cout << ", subject='" << message.getSubject() << "'";
- }
- std::cout << ", content='";
- if (message.getContentType() == "amqp/map") {
- std::cout << message.getContentObject().asMap();
- } else {
- std::cout << message.getContentObject();
- }
- std::cout << "')" << std::endl;
+ std::cout << message << std::endl;
session.acknowledge();
if (count && (++i == count))
break;
Modified: qpid/trunk/qpid/cpp/examples/messaging/spout.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/spout.cpp?rev=1552476&r1=1552475&r2=1552476&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/spout.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/spout.cpp Fri Dec 20 02:01:56 2013
@@ -22,6 +22,7 @@
#include <qpid/messaging/Address.h>
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
+#include <qpid/messaging/Message_ostream.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Session.h>
#include <qpid/types/Variant.h>
@@ -51,6 +52,7 @@ struct Options : OptionParser
string_vector entries;
std::string content;
std::string connectionOptions;
+ bool print;
Options()
: OptionParser("Usage: spout [OPTIONS] ADDRESS", "Send messages to the specified address"),
@@ -69,6 +71,7 @@ struct Options : OptionParser
add("map,M", entries, "specify entry for map content");
add("content", content, "specify textual content");
add("connection-options", connectionOptions, "connection options string in the form {name1:value1, name2:value2}");
+ add("print", print, "print each message sent");
}
static bool nameval(const std::string& in, std::string& name, std::string& value)
@@ -137,7 +140,6 @@ struct Options : OptionParser
}
};
-
int main(int argc, char** argv)
{
Options options;
@@ -170,6 +172,7 @@ int main(int argc, char** argv)
std::stringstream spoutid;
spoutid << id << ":" << count;
message.getProperties()["spout-id"] = spoutid.str();
+ if (options.print) std::cout << message << std::endl;
sender.send(message);
}
session.sync();
Added: qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h?rev=1552476&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h (added)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h Fri Dec 20 02:01:56 2013
@@ -0,0 +1,34 @@
+#ifndef QPID_MESSAGING_MESSAGE_OSTREAM_H
+#define QPID_MESSAGING_MESSAGE_OSTREAM_H
+
+/*
+ *
+ * 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 "Message.h"
+#include <iosfwd>
+
+namespace qpid {
+namespace messaging {
+
+QPID_MESSAGING_EXTERN std::ostream& operator<<(std::ostream&, const Message&);
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_MESSAGE_OSTREAM_H*/
Propchange: qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/include/qpid/messaging/Message_ostream.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: qpid/trunk/qpid/cpp/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/CMakeLists.txt?rev=1552476&r1=1552475&r2=1552476&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/src/CMakeLists.txt Fri Dec 20 02:01:56 2013
@@ -1064,6 +1064,7 @@ set (qpidmessaging_SOURCES
qpid/messaging/ConnectionOptions.cpp
qpid/messaging/MessageImpl.h
qpid/messaging/MessageImpl.cpp
+ qpid/messaging/Message_ostream.cpp
qpid/messaging/ProtocolRegistry.cpp
qpid/messaging/amqp/EncodedMessage.h
qpid/messaging/amqp/EncodedMessage.cpp
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp?rev=1552476&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp Fri Dec 20 02:01:56 2013
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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 "qpid/messaging/Message_ostream.h"
+#include <ostream>
+
+namespace qpid {
+namespace messaging {
+
+using namespace std;
+ostream& operator<<(ostream& o, const Message& message) {
+ o << "Message(properties=" << message.getProperties();
+ if (!message.getSubject().empty()) {
+ o << ", subject='" << message.getSubject() << "'";
+ }
+ if (!message.getContentObject().isVoid()) {
+ o << ", content='";
+ if (message.getContentType() == "amqp/map") {
+ o << message.getContentObject().asMap();
+ } else {
+ o << message.getContentObject();
+ }
+ }
+ o << "')";
+ return o;
+}
+
+}} // namespace qpid::messaging
Propchange: qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/messaging/Message_ostream.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org