15 #include <boost/static_assert.hpp>
28 CalloutManager::CalloutManager(
int num_libraries)
30 current_hook_(-1), current_library_(-1),
31 hook_vector_(
ServerHooks::getServerHooks().getCount()),
32 library_handle_(this), pre_library_handle_(this, 0),
33 post_library_handle_(this, INT_MAX), num_libraries_(num_libraries)
35 if (num_libraries < 0) {
37 "CalloutManager must be >= 0");
47 CalloutManager::checkLibraryIndex(
int library_index)
const {
48 if (((library_index >= -1) && (library_index <= num_libraries_)) ||
49 (library_index == INT_MAX)) {
53 isc_throw(NoSuchLibrary,
"library index " << library_index <<
54 " is not valid for the number of loaded libraries (" <<
55 num_libraries_ <<
")");
64 .arg(current_library_).arg(name);
67 checkLibraryIndex(current_library_);
70 ensureHookLibsVectorSize();
74 int hook_index = server_hooks_.
getIndex(name);
79 for (CalloutVector::iterator i = hook_vector_[hook_index].begin();
80 i != hook_vector_[hook_index].end(); ++i) {
81 if (i->first > current_library_) {
84 hook_vector_[hook_index].insert(i, make_pair(current_library_,
93 hook_vector_[hook_index].push_back(make_pair(current_library_, callout));
101 if ((hook_index < 0) || (hook_index >= hook_vector_.size())) {
103 " is not valid for the list of registered hooks");
107 return (!hook_vector_[hook_index].empty());
147 current_hook_ = hook_index;
154 CalloutVector callouts(hook_vector_[hook_index]);
162 .arg(server_hooks_.
getName(current_hook_));
165 for (CalloutVector::const_iterator i = callouts.begin();
166 i != callouts.end(); ++i) {
170 current_library_ = i->first;
175 int status = (*i->second)(callout_handle);
179 HOOKS_CALLOUT_CALLED).arg(current_library_)
180 .arg(server_hooks_.
getName(current_hook_))
185 .arg(current_library_)
186 .arg(server_hooks_.
getName(current_hook_))
190 }
catch (
const std::exception& e) {
196 .arg(current_library_)
197 .arg(server_hooks_.
getName(current_hook_))
208 .arg(server_hooks_.
getName(current_hook_))
214 current_library_ = -1;
237 checkLibraryIndex(current_library_);
240 ensureHookLibsVectorSize();
244 int hook_index = server_hooks_.
getIndex(name);
247 if (hook_index >= hook_vector_.size()) {
253 CalloutEntry target(current_library_, callout);
258 size_t initial_size = hook_vector_[hook_index].size();
269 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
270 hook_vector_[hook_index].end(),
271 bind1st(equal_to<CalloutEntry>(),
273 hook_vector_[hook_index].end());
276 bool removed = initial_size != hook_vector_[hook_index].size();
279 HOOKS_CALLOUT_DEREGISTERED).arg(current_library_).arg(name);
291 ensureHookLibsVectorSize();
295 int hook_index = server_hooks_.
getIndex(name);
299 CalloutEntry target(current_library_,
static_cast<CalloutPtr>(0));
304 size_t initial_size = hook_vector_[hook_index].size();
307 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
308 hook_vector_[hook_index].end(),
309 bind1st(CalloutLibraryEqual(),
311 hook_vector_[hook_index].end());
314 bool removed = initial_size != hook_vector_[hook_index].size();
317 HOOKS_ALL_CALLOUTS_DEREGISTERED).arg(current_library_)
328 ensureHookLibsVectorSize();
332 if (hook_index < 0) {
340 hook_vector_.resize(server_hooks_.
getCount());
345 CalloutManager::ensureHookLibsVectorSize() {
347 if (hooks.
getCount() > hook_vector_.size()) {
349 hook_vector_.resize(hooks.
getCount());