diff --git a/core/predictor/framework/factory.h b/core/predictor/framework/factory.h index 826b1134c1310cce97812d5d9840b40297ec67a3..fde95eaa1565c8d0f4fca7f846c7c8a49b383163 100644 --- a/core/predictor/framework/factory.h +++ b/core/predictor/framework/factory.h @@ -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* factory = new (std::nothrow) FactoryDerive();\ - if (factory == NULL || \ - FactoryPool::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* factory = new (std::nothrow) FactoryDerive(); \ + if (factory == NULL || \ + FactoryPool::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::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::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*>::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*>::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; } diff --git a/core/predictor/framework/op_repository.h b/core/predictor/framework/op_repository.h index dcd0b13438c9d040336922c03dbbfe2c9dbccf8d..bf3b2327cd4a1f0af83c98a5bfe529c37ceb403e 100644 --- a/core/predictor/framework/op_repository.h +++ b/core/predictor/framework/op_repository.h @@ -63,8 +63,8 @@ class OpRepository { void regist_op(std::string op_type) { _repository[op_type] = &OpFactory::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); } diff --git a/core/predictor/framework/service_manager.h b/core/predictor/framework/service_manager.h index a12f13cd67ffde9cad810c7755900f224cd0c07f..b6b301dd3dc88dc064e0b17739fa059f3366f023 100644 --- a/core/predictor/framework/service_manager.h +++ b/core/predictor/framework/service_manager.h @@ -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::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::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; } diff --git a/core/sdk-cpp/include/abtest.h b/core/sdk-cpp/include/abtest.h index 53be4dffece35b2cd5886fd94ab60da58db464bd..a4275fcf52413bb85bcca1fcb470ea2360fdf174 100644 --- a/core/sdk-cpp/include/abtest.h +++ b/core/sdk-cpp/include/abtest.h @@ -50,8 +50,8 @@ class WeightedRandomRender : public EndpointRouterBase { Factory* factory = new (std::nothrow) Factory(); 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::instance().register_factory( "WeightedRandomRender", factory) != 0) { - RAW_LOG(INFO, "Factory has been registed: \ + RAW_LOG(INFO, + "Factory has been registed: \ WeightedRandomRender->EndpointRouterBase."); } diff --git a/core/sdk-cpp/include/factory.h b/core/sdk-cpp/include/factory.h index 86935b936d1a81c130501b386656e8eb5a4247b7..89c8aae3ef6bd7b296a8a953f2db88786b501352 100644 --- a/core/sdk-cpp/include/factory.h +++ b/core/sdk-cpp/include/factory.h @@ -29,31 +29,36 @@ namespace brpc = baidu::rpc; #define ERROR_STRING_LEN 10240 -#define INLINE_REGIST_OBJECT(D, B, E) \ - do { \ - Factory* factory = new (std::nothrow) Factory(); \ - if (factory == NULL || \ - FactoryPool::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* factory = new (std::nothrow) Factory(); \ + if (factory == NULL || \ + FactoryPool::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* factory = new (std::nothrow) Factory(); \ - if (factory == NULL || \ - FactoryPool::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* factory = new (std::nothrow) Factory(); \ + if (factory == NULL || \ + FactoryPool::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* factory = \ - new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory();\ - if (factory == NULL || \ - ::baidu::paddle_serving::sdk_cpp::FactoryPool::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* factory = \ + new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory(); \ + if (factory == NULL || \ + ::baidu::paddle_serving::sdk_cpp::FactoryPool::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* factory = \ - new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory();\ - if (factory == NULL || \ - ::baidu::paddle_serving::sdk_cpp::FactoryPool::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* factory = \ + new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory(); \ + if (factory == NULL || \ + ::baidu::paddle_serving::sdk_cpp::FactoryPool::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, \ - ::baidu::paddle_serving::sdk_cpp::Stub>* factory = \ - new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \ - ::baidu::paddle_serving::sdk_cpp::StubImpl, \ - ::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, \ + ::baidu::paddle_serving::sdk_cpp::Stub>* factory = \ + new (::std::nothrow)::baidu::paddle_serving::sdk_cpp::Factory< \ + ::baidu::paddle_serving::sdk_cpp::StubImpl, \ + ::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; }