00001 #ifndef QPID_FRAMING_INVOKER_H
00002 #define QPID_FRAMING_INVOKER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 }}
00085
00086 #endif