/home/aconway/svn/qpid/cpp/src/qpid/client/IncomingMessage.h

00001 #ifndef _IncomingMessage_
00002 #define _IncomingMessage_
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/sys/Monitor.h"
00025 #include <map>
00026 #include <queue>
00027 #include <vector>
00028 #include <boost/variant.hpp>
00029 
00030 namespace qpid {
00031 namespace client {
00032 
00033 class Message;
00034 
00044 class IncomingMessage {
00045   public:
00047     struct Reference {
00048         std::string data;
00049         std::vector<Message> messages;
00050     };
00051 
00053     class Destination {
00054       public:
00055         virtual ~Destination();
00056 
00058         virtual void message(const Message&) = 0;
00059 
00061         virtual void empty() = 0;
00062     };
00063 
00064 
00066     class WaitableDestination : public Destination
00067     {
00068       public:
00069         WaitableDestination();
00070         void message(const Message& msg);        
00071         void empty();
00073         bool wait(Message& msgOut);
00074         void shutdown();
00075 
00076       private:
00077         struct Empty {};
00078         typedef boost::variant<Message,Empty> Item;
00079         sys::Monitor monitor;
00080         std::queue<Item> queue;
00081         bool shutdownFlag;
00082     };
00083  
00084 
00085 
00087     void openReference(const std::string& name);
00088 
00090     void appendReference(const std::string& name,
00091                          const std::string& data);
00092 
00096     Message&  createMessage(const std::string& destination,
00097                             const std::string& reference);
00098 
00102     Reference& getReference(const std::string& name);
00103     
00107     void closeReference(const std::string& name);
00108 
00113     void addDestination(std::string name, Destination&);
00114 
00116     void removeDestination(std::string name);
00117 
00119     Destination& getDestination(const std::string& name);
00120   private:
00121 
00122     typedef std::map<std::string, Reference> ReferenceMap;
00123     typedef std::map<std::string, Destination*> DestinationMap;
00124     
00125     Reference& getRefUnlocked(const std::string& name);
00126     Destination& getDestUnlocked(const std::string& name);
00127 
00128     mutable sys::Mutex lock;
00129     ReferenceMap references;
00130     DestinationMap destinations;
00131 };
00132 
00133 }}
00134 
00135 
00136 #endif

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7