summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/qpid/client/amqp0_10/IncomingMessages.h
blob: f6a291bc68e58317a8818fe7eb4fa5d7a22986b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef QPID_CLIENT_AMQP0_10_INCOMINGMESSAGES_H
#define QPID_CLIENT_AMQP0_10_INCOMINGMESSAGES_H

/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */
#include <string>
#include <boost/shared_ptr.hpp>
#include "qpid/client/AsyncSession.h"
#include "qpid/framing/SequenceSet.h"
#include "qpid/sys/BlockingQueue.h"
#include "qpid/sys/Time.h"
#include "qpid/client/amqp0_10/AcceptTracker.h"

namespace qpid {

namespace framing{
class FrameSet;
}

namespace messaging {
class Message;
}

namespace client {
namespace amqp0_10 {

/**
 * Queue of incoming messages.
 */
class IncomingMessages
{
  public:
    typedef boost::shared_ptr<qpid::framing::FrameSet> FrameSetPtr;
    class MessageTransfer
    {
      public:
        const std::string& getDestination();
        void retrieve(qpid::messaging::Message* message);
      private:
        FrameSetPtr content;
        IncomingMessages& parent;

        MessageTransfer(FrameSetPtr, IncomingMessages&);
      friend class IncomingMessages;
    };

    struct Handler
    {
        virtual ~Handler() {}
        virtual bool accept(MessageTransfer& transfer) = 0;
    };

    void setSession(qpid::client::AsyncSession session);
    bool get(Handler& handler, qpid::sys::Duration timeout);
    bool getNextDestination(std::string& destination, qpid::sys::Duration timeout);
    void accept();
    void accept(qpid::framing::SequenceNumber id);
    void releaseAll();
    void releasePending(const std::string& destination);

    uint32_t pendingAccept();
    uint32_t pendingAccept(const std::string& destination);

    uint32_t available();
    uint32_t available(const std::string& destination);
  private:
    typedef std::deque<FrameSetPtr> FrameSetQueue;

    sys::Mutex lock;
    qpid::client::AsyncSession session;
    boost::shared_ptr< sys::BlockingQueue<FrameSetPtr> > incoming;
    FrameSetQueue received;
    AcceptTracker acceptTracker;

    bool process(Handler*, qpid::sys::Duration);
    bool wait(qpid::sys::Duration);
    void retrieve(FrameSetPtr, qpid::messaging::Message*);

};
}}} // namespace qpid::client::amqp0_10

#endif  /*!QPID_CLIENT_AMQP0_10_INCOMINGMESSAGES_H*/