提交 b39f0033 编写于 作者: T TeslaZhao

fix bad code style by clang-format

上级 57fc2a09
......@@ -23,18 +23,20 @@ namespace paddle_serving {
namespace predictor {
//////////////// DECLARE INTERFACE ////////////////
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
FactoryDerive<D, B>* factory = new (std::nothrow) FactoryDerive<D, B>();\
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", #D); \
RAW_LOG(FATAL, err_str); \
return -1; \
} \
return 0; \
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
FactoryDerive<D, B>* factory = new (std::nothrow) FactoryDerive<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", \
#D); \
RAW_LOG(FATAL, err_str); \
return -1; \
} \
return 0; \
}
#define PDS_STR_CAT(a, b) PDS_STR_CAT_I(a, b)
......@@ -58,8 +60,11 @@ namespace predictor {
::baidu::paddle_serving::predictor::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(FATAL, err_str); \
return; \
} \
......@@ -76,13 +81,21 @@ namespace predictor {
if (factory == NULL || \
::baidu::paddle_serving::predictor::FactoryPool<B>::instance() \
.register_factory(N, factory) != 0) { \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag: %s in macro!", \
#D, \
#B, \
N); \
RAW_LOG(FATAL, err_str); \
return; \
} \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Succ regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Succ regist factory: %s->%s, tag: %s in macro!", \
#D, \
#B, \
N); \
RAW_LOG(WARNING, err_str); \
return; \
}
......@@ -115,8 +128,10 @@ class FactoryPool {
typename std::map<std::string, FactoryBase<B>*>::iterator it =
_pool.find(tag);
if (it != _pool.end()) {
snprintf(err_str, ERROR_STRING_LEN - 1,
"Insert duplicate with tag: %s", tag.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Insert duplicate with tag: %s",
tag.c_str());
RAW_LOG(FATAL, err_str);
return -1;
}
......@@ -124,15 +139,19 @@ class FactoryPool {
std::pair<typename std::map<std::string, FactoryBase<B>*>::iterator, bool>
r = _pool.insert(std::make_pair(tag, factory));
if (!r.second) {
snprintf(err_str, ERROR_STRING_LEN - 1,
"Failed insert new factory with: %s", tag.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Failed insert new factory with: %s",
tag.c_str());
RAW_LOG(FATAL, err_str);
return -1;
}
snprintf(err_str, ERROR_STRING_LEN - 1,
"Succ insert one factory, tag: %s, base type %s", tag.c_str(),
typeid(B).name());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Succ insert one factory, tag: %s, base type %s",
tag.c_str(),
typeid(B).name());
RAW_LOG(INFO, err_str);
return 0;
}
......@@ -142,9 +161,11 @@ class FactoryPool {
_pool.find(tag);
if (it == _pool.end() || it->second == NULL) {
char err_str[ERROR_STRING_LEN];
snprintf(err_str, ERROR_STRING_LEN - 1,
"Not found factory pool, tag: %s, pool size %u", tag.c_str(),
_pool.size());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Not found factory pool, tag: %s, pool size %u",
tag.c_str(),
_pool.size());
RAW_LOG(FATAL, err_str);
return NULL;
}
......
......@@ -63,8 +63,8 @@ class OpRepository {
void regist_op(std::string op_type) {
_repository[op_type] = &OpFactory<OP_TYPE>::instance();
char err_str[ERROR_STRING_LEN];
snprintf(err_str, ERROR_STRING_LEN - 1, "Succ regist op: %s",
op_type.c_str());
snprintf(
err_str, ERROR_STRING_LEN - 1, "Succ regist op: %s", op_type.c_str());
RAW_LOG(INFO, err_str);
}
......
......@@ -21,23 +21,27 @@ namespace baidu {
namespace paddle_serving {
namespace predictor {
#define REGIST_FORMAT_SERVICE(svr_name, svr) \
do { \
char err_str[ERROR_STRING_LEN]; \
int ret = \
::baidu::paddle_serving::predictor::FormatServiceManager::instance() \
.regist_service(svr_name, svr); \
if (ret != 0) { \
snprintf(err_str, ERROR_STRING_LEN - 1, "Failed regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(ERROR, err_str); \
} else { \
snprintf(err_str, ERROR_STRING_LEN - 1, "Success regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(INFO, err_str); \
} \
#define REGIST_FORMAT_SERVICE(svr_name, svr) \
do { \
char err_str[ERROR_STRING_LEN]; \
int ret = \
::baidu::paddle_serving::predictor::FormatServiceManager::instance() \
.regist_service(svr_name, svr); \
if (ret != 0) { \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(ERROR, err_str); \
} else { \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Success regist service[%s][%s]", \
svr_name.c_str(), \
typeid(svr).name()); \
RAW_LOG(INFO, err_str); \
} \
} while (0)
class FormatServiceManager {
......@@ -47,9 +51,11 @@ class FormatServiceManager {
int regist_service(const std::string& svr_name, Service* svr) {
char err_str[ERROR_STRING_LEN];
if (_service_map.find(svr_name) != _service_map.end()) {
snprintf(err_str, ERROR_STRING_LEN - 1, "Service[%s][%s] already exist!",
svr_name.c_str(),
typeid(svr).name());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Service[%s][%s] already exist!",
svr_name.c_str(),
typeid(svr).name());
RAW_LOG(ERROR, err_str);
return -1;
}
......@@ -57,15 +63,19 @@ class FormatServiceManager {
std::pair<boost::unordered_map<std::string, Service*>::iterator, bool> ret;
ret = _service_map.insert(std::make_pair(svr_name, svr));
if (ret.second == false) {
snprintf(err_str, ERROR_STRING_LEN - 1, "Service[%s][%s] insert failed!",
svr_name.c_str(),
typeid(svr).name());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Service[%s][%s] insert failed!",
svr_name.c_str(),
typeid(svr).name());
RAW_LOG(ERROR, err_str);
return -1;
}
snprintf(err_str, ERROR_STRING_LEN - 1, "Service[%s] insert successfully!",
svr_name.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Service[%s] insert successfully!",
svr_name.c_str());
RAW_LOG(INFO, err_str);
return 0;
}
......@@ -74,8 +84,10 @@ class FormatServiceManager {
char err_str[ERROR_STRING_LEN];
boost::unordered_map<std::string, Service*>::iterator res;
if ((res = _service_map.find(svr_name)) == _service_map.end()) {
snprintf(err_str, ERROR_STRING_LEN - 1,
"Service[%s] not found in service manager!", svr_name.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Service[%s] not found in service manager!",
svr_name.c_str());
RAW_LOG(WARNING, err_str);
return NULL;
}
......
......@@ -50,8 +50,8 @@ class WeightedRandomRender : public EndpointRouterBase {
Factory<WeightedRandomRender, EndpointRouterBase>* factory =
new (std::nothrow) Factory<WeightedRandomRender, EndpointRouterBase>();
if (factory == NULL) {
RAW_LOG(ERROR,
"Failed regist factory: WeightedRandomRender->EndpointRouterBase \
RAW_LOG(ERROR,
"Failed regist factory: WeightedRandomRender->EndpointRouterBase \
in macro!");
return -1;
}
......@@ -62,7 +62,8 @@ class WeightedRandomRender : public EndpointRouterBase {
// together.
if (FactoryPool<EndpointRouterBase>::instance().register_factory(
"WeightedRandomRender", factory) != 0) {
RAW_LOG(INFO, "Factory has been registed: \
RAW_LOG(INFO,
"Factory has been registed: \
WeightedRandomRender->EndpointRouterBase.");
}
......
......@@ -29,31 +29,36 @@ namespace brpc = baidu::rpc;
#define ERROR_STRING_LEN 10240
#define INLINE_REGIST_OBJECT(D, B, E) \
do { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(#D, factory) != 0) {\
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
RAW_LOG(ERROR, err_str); \
return E; \
} \
#define INLINE_REGIST_OBJECT(D, B, E) \
do { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(ERROR, err_str); \
return E; \
} \
} while (0)
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", #D); \
RAW_LOG(ERROR, err_str); \
return -1; \
} \
return 0; \
#define DECLARE_FACTORY_OBJECT(D, B) \
static int regist(const std::string& tag) { \
Factory<D, B>* factory = new (std::nothrow) Factory<D, B>(); \
if (factory == NULL || \
FactoryPool<B>::instance().register_factory(tag, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s in macro!", \
#D); \
RAW_LOG(ERROR, err_str); \
return -1; \
} \
return 0; \
}
#define PDS_STR_CAT(a, b) PDS_STR_CAT_I(a, b)
......@@ -65,39 +70,46 @@ namespace brpc = baidu::rpc;
D::regist(#D); \
}
#define REGIST_FACTORY_OBJECT_IMPL(D, B) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>();\
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", #D, #B); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
#define REGIST_FACTORY_OBJECT_IMPL(D, B) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(#D, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s in macro!", \
#D, \
#B); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_FACTORY_OBJECT_IMPL_WITH_TAG(D, B, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>();\
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag %s in macro!", #D, #B, T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_FACTORY_OBJECT_IMPL_WITH_TAG(D, B, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory<D, B>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory<D, B>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool<B>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->%s, tag %s in macro!", \
#D, \
#B, \
T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
#define REGIST_ABTEST_OBJECT(D) \
REGIST_FACTORY_OBJECT_IMPL( \
......@@ -107,26 +119,29 @@ namespace brpc = baidu::rpc;
REGIST_FACTORY_OBJECT_IMPL_WITH_TAG( \
D, ::baidu::paddle_serving::sdk_cpp::ABTestRouterBase, T)
#define REGIST_STUB_OBJECT_WITH_TAG(D, C, R, I, O, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool< \
::baidu::paddle_serving::sdk_cpp::Stub>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->Stub, tag: %s in macro!", #D, T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
#define REGIST_STUB_OBJECT_WITH_TAG(D, C, R, I, O, T) \
__attribute__((constructor)) static void PDS_STR_CAT(GlobalRegistObject, \
__LINE__)(void) { \
::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>* factory = \
new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \
::baidu::paddle_serving::sdk_cpp::StubImpl<D, C, R, I, O>, \
::baidu::paddle_serving::sdk_cpp::Stub>(); \
if (factory == NULL || \
::baidu::paddle_serving::sdk_cpp::FactoryPool< \
::baidu::paddle_serving::sdk_cpp::Stub>::instance() \
.register_factory(T, factory) != 0) { \
char err_str[ERROR_STRING_LEN]; \
snprintf(err_str, \
ERROR_STRING_LEN - 1, \
"Failed regist factory: %s->Stub, tag: %s in macro!", \
#D, \
T); \
RAW_LOG(ERROR, err_str); \
return; \
} \
return; \
}
class Stub;
......@@ -161,8 +176,10 @@ class FactoryPool {
_pool.find(tag);
if (it != _pool.end()) {
char err_str[ERROR_STRING_LEN];
snprintf(err_str, ERROR_STRING_LEN - 1,
"Insert duplicate with tag: %s", tag.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Insert duplicate with tag: %s",
tag.c_str());
RAW_LOG(ERROR, err_str);
return -1;
}
......@@ -171,8 +188,10 @@ class FactoryPool {
r = _pool.insert(std::make_pair(tag, factory));
if (!r.second) {
char err_str[ERROR_STRING_LEN];
snprintf(err_str, ERROR_STRING_LEN - 1,
"Failed insert new factory with: %s", tag.c_str());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Failed insert new factory with: %s",
tag.c_str());
RAW_LOG(ERROR, err_str);
return -1;
}
......@@ -185,9 +204,11 @@ class FactoryPool {
_pool.find(tag);
if (it == _pool.end() || it->second == NULL) {
char err_str[ERROR_STRING_LEN];
snprintf(err_str, ERROR_STRING_LEN - 1,
"Not found factory pool, tag: %s, pool size: %u",
tag.c_str(), _pool.size());
snprintf(err_str,
ERROR_STRING_LEN - 1,
"Not found factory pool, tag: %s, pool size: %u",
tag.c_str(),
_pool.size());
RAW_LOG(ERROR, err_str);
return NULL;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册