-
Notifications
You must be signed in to change notification settings - Fork 74
/
finder_messenger.cc
132 lines (111 loc) · 3.52 KB
/
finder_messenger.cc
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
// vim:set sts=4 ts=8:
// Copyright (c) 2001-2009 XORP, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License, Version
// 2.1, June 1999 as published by the Free Software Foundation.
// Redistribution and/or modification of this program under the terms of
// any other version of the GNU Lesser General Public License is not
// permitted.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
// see the GNU Lesser General Public License, Version 2.1, a copy of
// which can be found in the XORP LICENSE.lgpl file.
//
// XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net
#include "finder_module.h"
#include "finder_messenger.hh"
#include "libxorp/debug.h"
#include "libxorp/xlog.h"
FinderMessengerBase::FinderMessengerBase(EventLoop& e,
FinderMessengerManager* fmm,
XrlCmdMap& cmds)
: _eventloop(e), _manager(fmm), _cmds(cmds)
{
// _manager.messenger_birth_event(this);
debug_msg("Constructor for %p\n", this);
}
FinderMessengerBase::~FinderMessengerBase()
{
// _manager.messenger_death_event(this);
debug_msg("Destructor for %p\n", this);
}
bool
FinderMessengerBase::dispatch_xrl_response(uint32_t seqno,
const XrlError& xe,
XrlArgs* args)
{
SeqNoResponseMap::iterator i = _expected_responses.find(seqno);
if (_expected_responses.end() == i) {
debug_msg("Attempting to make response for invalid seqno\n");
return false;
}
SendCallback scb = i->second.scb;
_expected_responses.erase(i);
scb->dispatch(xe, args);
return true;
}
bool
FinderMessengerBase::store_xrl_response(uint32_t seqno,
const SendCallback& scb)
{
SeqNoResponseMap::const_iterator ci = _expected_responses.find(seqno);
if (_expected_responses.end() != ci)
return false; // A callback appears to be registered with seqno
_expected_responses.insert(
SeqNoResponseMap::value_type(seqno, ResponseState(seqno, scb, this))
);
return true;
}
void
FinderMessengerBase::response_timeout(uint32_t seqno)
{
// Assert that response existed to be dispatched: it shouldn't be able
// to timeout otherwise.
XLOG_ASSERT(dispatch_xrl_response(seqno, XrlError::REPLY_TIMED_OUT(), 0));
}
void
FinderMessengerBase::dispatch_xrl(uint32_t seqno, const Xrl& xrl)
{
const XrlCmdEntry* ce = command_map().get_handler(xrl.command());
if (0 == ce) {
reply(seqno, XrlError::NO_SUCH_METHOD(), 0);
return;
}
// Announce we're about to dispatch an xrl
if (manager())
manager()->messenger_active_event(this);
#ifdef XORP_ENABLE_ASYNC_SERVER
ce->dispatch(xrl.args(),
callback(this, &FinderMessengerBase::dispatch_xrl_cb, seqno));
#else
XrlArgs reply_args;
XrlError e = ce->dispatch(xrl.args(), &reply_args);
if (XrlCmdError::OKAY() == e) {
reply(seqno, e, &reply_args);
} else {
reply(seqno, e, 0);
}
#endif
// Announce we've dispatched xrl
if (manager())
manager()->messenger_inactive_event(this);
}
#ifdef XORP_ENABLE_ASYNC_SERVER
void
FinderMessengerBase::dispatch_xrl_cb(const XrlCmdError &e,
const XrlArgs *reply_args,
uint32_t seqno)
{
reply(seqno, e, XrlCmdError::OKAY() == e ? reply_args : NULL);
}
#endif
void
FinderMessengerBase::unhook_manager()
{
_manager = 0;
}