Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef QPID_FRAMING_INVOKER_H 00002 #define QPID_FRAMING_INVOKER_H 00003 00004 /* 00005 * 00006 * Licensed to the Apache Software Foundation (ASF) under one 00007 * or more contributor license agreements. See the NOTICE file 00008 * distributed with this work for additional information 00009 * regarding copyright ownership. The ASF licenses this file 00010 * to you under the Apache License, Version 2.0 (the 00011 * "License"); you may not use this file except in compliance 00012 * with the License. You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, 00017 * software distributed under the License is distributed on an 00018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00019 * KIND, either express or implied. See the License for the 00020 * specific language governing permissions and limitations 00021 * under the License. 00022 * 00023 */ 00024 #include "qpid/framing/AMQMethodBody.h" 00025 #include "qpid/framing/MethodBodyDefaultVisitor.h" 00026 #include "qpid/framing/StructHelper.h" 00027 00028 #include <boost/optional.hpp> 00029 00030 namespace qpid { 00031 namespace framing { 00032 00033 class AMQMethodBody; 00034 00038 class Invoker: public MethodBodyDefaultVisitor, protected StructHelper 00039 { 00040 public: 00041 struct Result { 00042 public: 00043 Result() : handled(false) {} 00044 const std::string& getResult() const { return result; } 00045 bool hasResult() const { return !result.empty(); } 00046 bool wasHandled() const { return handled; } 00047 operator bool() const { return handled; } 00048 00049 std::string result; 00050 bool handled; 00051 }; 00052 00053 void defaultVisit(const AMQMethodBody&) {} 00054 Result getResult() const { return result; } 00055 00056 protected: 00057 Result result; 00058 }; 00059 00064 template <class Invocable> 00065 Invoker::Result invoke(Invocable& target, const AMQMethodBody& body) { 00066 typename Invocable::Invoker invoker(target); 00067 body.accept(invoker); 00068 return invoker.getResult(); 00069 } 00070 00075 template <class Invocable> 00076 Invoker::Result invoke(Invocable& target, const AMQBody& body) { 00077 typename Invocable::Invoker invoker(target); 00078 const AMQMethodBody* method = body.getMethod(); 00079 if (method) 00080 method->accept(invoker); 00081 return invoker.getResult(); 00082 } 00083 00084 }} // namespace qpid::framing 00085 00086 #endif