From b77019ea048947bdaf983295e7246a8dd8dc53d2 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 4 Mar 2013 21:08:17 +0000 Subject: 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 --- cpp/src/qpid/broker/Selector.cpp | 82 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 cpp/src/qpid/broker/Selector.cpp (limited to 'cpp/src/qpid/broker/Selector.cpp') 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 + +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 NULL_SELECTOR = boost::shared_ptr(); +} + +boost::shared_ptr returnSelector(const string& e) +{ + if (e.empty()) return NULL_SELECTOR; + return boost::make_shared(e); +} + + +}} -- cgit v1.2.1