summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/broker/Selector.cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2013-03-04 21:08:17 +0000
committerAndrew Stitcher <astitcher@apache.org>2013-03-04 21:08:17 +0000
commitb77019ea048947bdaf983295e7246a8dd8dc53d2 (patch)
tree461900ca2b53c7ed5fc02e733466b2b7569f3c97 /cpp/src/qpid/broker/Selector.cpp
parent221259deec8b45854d03926b68a6ffa4928fbb3b (diff)
downloadqpid-python-b77019ea048947bdaf983295e7246a8dd8dc53d2.tar.gz
QPID-4558: Selectors for C++ broker
- Add support to 0-10 protocol codepaths in client messaging library and the broker to transmit a selector when subscribing to a queue - This is specified by using a link property qpid.selector in the queue address. - The selector is actually transmitted under 0-10 as an user vlaue named qpid.selector in the arguments table of the subscription. - Added simple selector framework to broker. - Added in infrastructure for selector evaluation -- Put in place a trivial (but real) selector: The expression specifies a message property and returns true if it is present. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1452522 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/Selector.cpp')
-rw-r--r--cpp/src/qpid/broker/Selector.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/cpp/src/qpid/broker/Selector.cpp b/cpp/src/qpid/broker/Selector.cpp
new file mode 100644
index 0000000000..805bcdbba1
--- /dev/null
+++ b/cpp/src/qpid/broker/Selector.cpp
@@ -0,0 +1,82 @@
+/*
+ *
+ * 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/broker/Selector.h"
+
+#include "qpid/broker/Message.h"
+
+#include <boost/make_shared.hpp>
+
+namespace qpid {
+namespace broker {
+
+using std::string;
+
+Selector::Selector(const string& e) :
+ expression(e)
+{
+}
+
+Selector::~Selector()
+{
+}
+
+bool Selector::eval(const SelectorEnv& env)
+{
+ // Simple test - return true if expression is a non-empty property
+ return env.present(expression);
+}
+
+bool Selector::filter(const Message& msg)
+{
+ return eval(MessageSelectorEnv(msg));
+}
+
+MessageSelectorEnv::MessageSelectorEnv(const Message& m) :
+ msg(m)
+{
+}
+
+bool MessageSelectorEnv::present(const string& identifier) const
+{
+ // If the value we get is void then most likely the property wasn't present
+ return !msg.getProperty(identifier).isVoid();
+}
+
+string MessageSelectorEnv::value(const string& identifier) const
+{
+ // Just return property as string
+ return msg.getPropertyAsString(identifier);
+}
+
+
+namespace {
+const boost::shared_ptr<Selector> NULL_SELECTOR = boost::shared_ptr<Selector>();
+}
+
+boost::shared_ptr<Selector> returnSelector(const string& e)
+{
+ if (e.empty()) return NULL_SELECTOR;
+ return boost::make_shared<Selector>(e);
+}
+
+
+}}