/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/CompletionTracker.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 
00022 #include <list>
00023 #include <boost/function.hpp>
00024 #include "qpid/framing/amqp_framing.h"
00025 #include "qpid/framing/SequenceNumber.h"
00026 #include "qpid/sys/Mutex.h"
00027 
00028 #ifndef _CompletionTracker_
00029 #define _CompletionTracker_
00030 
00031 namespace qpid {
00032 namespace client {
00033 
00034 class CompletionTracker
00035 {
00036 public:
00037     typedef boost::function<void()> CompletionListener;    
00038     typedef boost::function<void(const std::string&)> ResultListener;
00039 
00040     CompletionTracker();
00041     CompletionTracker(const framing::SequenceNumber& mark);
00042     void completed(const framing::SequenceNumber& mark);
00043     void received(const framing::SequenceNumber& id, const std::string& result);
00044     void listenForCompletion(const framing::SequenceNumber& point, CompletionListener l);
00045     void listenForResult(const framing::SequenceNumber& point, ResultListener l);
00046     void close();
00047 
00048 private:
00049     struct Record 
00050     {
00051         framing::SequenceNumber id; 
00052         CompletionListener f;
00053         ResultListener g;        
00054 
00055         Record(const framing::SequenceNumber& _id, CompletionListener l) : id(_id), f(l) {}
00056         Record(const framing::SequenceNumber& _id, ResultListener l) : id(_id), g(l) {}
00057         void completed();
00058         void received(const std::string& result);
00059 
00060     };
00061 
00062     typedef std::list<Record> Listeners;
00063     bool closed;
00064     
00065     sys::Mutex lock;
00066     framing::SequenceNumber mark;
00067     Listeners listeners;
00068 
00069     bool add(const Record& r);
00070     Listeners::iterator seek(const framing::SequenceNumber&);
00071 };
00072 
00073 }
00074 }
00075 
00076 
00077 #endif

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7