aboutsummaryrefslogtreecommitdiffstats
path: root/messagebus/src/vespa/messagebus/callstack.cpp
blob: 63d3dabbe48abddc2200196ad4827041e3895b31 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "callstack.h"
#include "message.h"
#include "reply.h"
#include "idiscardhandler.h"
#include <cassert>

namespace mbus {

void
CallStack::discard()
{
    while (!_stack.empty()) {
        const Frame &frame = _stack.back();
        if (frame.discardHandler != nullptr) {
            frame.discardHandler->handleDiscard(frame.ctx);
        }
        _stack.pop_back();
    }
}

CallStack::~CallStack() = default;

IReplyHandler &
CallStack::pop(Reply &reply)
{
    assert(!_stack.empty());
    const Frame &frame = _stack.back();
    IReplyHandler *handler = frame.replyHandler;
    reply.setContext(frame.ctx);
    _stack.pop_back();
    return *handler;
}

} // namespace mbus