/home/aconway/svn/qpid/cpp/src/qpid/broker/Reference.h

00001 #ifndef _broker_Reference_h
00002 #define _broker_Reference_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 
00022 #include <string>
00023 #include <vector>
00024 #include <map>
00025 #include <boost/shared_ptr.hpp>
00026 #include <boost/range.hpp>
00027 
00028 namespace qpid {
00029 
00030 namespace framing {
00031 class MessageAppendBody;
00032 }
00033 
00034 namespace broker {
00035 
00036 class MessageMessage;
00037 class ReferenceRegistry;
00038 
00039 // FIXME aconway 2007-03-27: Merge with client::IncomingMessage
00040 // to common reference handling code.
00041 
00052 class Reference
00053 {
00054   public:
00055     typedef std::string Id;
00056     typedef boost::shared_ptr<Reference> shared_ptr;
00057     typedef boost::shared_ptr<MessageMessage> MessagePtr;
00058     typedef std::vector<MessagePtr> Messages;
00059     typedef boost::shared_ptr<framing::MessageAppendBody> AppendPtr;
00060     typedef std::vector<AppendPtr> Appends;
00061 
00062     Reference(const Id& id_=Id(), ReferenceRegistry* reg=0)
00063         : id(id_), size(0), registry(reg) {}
00064     
00065     const std::string& getId() const { return id; }
00066     uint64_t getSize() const { return size; }
00067 
00069     void addMessage(MessagePtr message) { messages.push_back(message); }
00070 
00072     void append(AppendPtr ptr);
00073 
00075     void close();
00076 
00077     const Appends& getAppends() const { return appends; }
00078     const Messages& getMessages() const { return messages; }
00079     
00080   private:
00081     Id id;
00082     uint64_t size;
00083     ReferenceRegistry* registry;
00084     Messages messages;
00085     Appends appends;
00086 };
00087 
00088 
00095 class ReferenceRegistry {
00096   public:
00097     ReferenceRegistry() {};
00098     Reference::shared_ptr open(const Reference::Id& id);
00099     Reference::shared_ptr get(const Reference::Id& id);
00100 
00101   private:
00102     typedef std::map<Reference::Id, Reference::shared_ptr> ReferenceMap;
00103     ReferenceMap references;
00104 
00105     // Reference calls references.erase().
00106     friend class Reference;
00107 };
00108 
00109 
00110 }} // namespace qpid::broker
00111 
00112 
00113 
00114 #endif  

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