-
Notifications
You must be signed in to change notification settings - Fork 0
/
RouterRegistry-impl.h
42 lines (37 loc) · 1.55 KB
/
RouterRegistry-impl.h
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <stdexcept>
#include <folly/Conv.h>
#include "mcrouter/lib/network/gen/MemcacheRouterInfo.h"
#include "mcrouter/lib/network/gen/MemcacheServer.h"
/**
* Finds the proper carbon api according to 'routerName', and calls 'func'
* templated by the corresponding RouterInfo and RequestHandler.
*
* 'func' must be a function template, like the following:
*
* template <class RouterInfo, template <class> class RequestHandler>
* void myFunc(...) {
* // ...
* }
*
*
* @param routerName Name of the router (e.g. Memcache).
* @param func The function template that will be called.
*/
#define CALL_BY_ROUTER_NAME(routerName, func, ...) \
do { \
if ((routerName) == facebook::memcache::MemcacheRouterInfo::name) { \
func< \
facebook::memcache::MemcacheRouterInfo, \
facebook::memcache::MemcacheRequestHandler>(__VA_ARGS__); \
} else { \
throw std::invalid_argument( \
folly::to<std::string>("Invalid router name: ", (routerName))); \
} \
} while (false);