@@ -572,8 +572,8 @@ ReturnCode ContextImpl::InitApiConfig(Config* api_config) {
572572
573573ReturnCode ContextImpl::InitGlobalConfig (Config* config, Context* context) {
574574 // Init server connector plugin
575- Config* plugin_config = config->GetSubConfig (" serverConnector" );
576- Plugin* plugin = NULL ;
575+ ScopedPtr< Config> plugin_config ( config->GetSubConfig (" serverConnector" ) );
576+ Plugin* plugin = NULL ;
577577 std::string protocol =
578578 plugin_config->GetStringOrDefault (" protocol" , kPluginDefaultServerConnector );
579579 PluginManager::Instance ().GetPlugin (protocol, kPluginServerConnector , plugin);
@@ -582,11 +582,9 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
582582 POLARIS_LOG (LOG_ERROR,
583583 " Plugin factory register with name[%s] and type[%s] return error instance" ,
584584 protocol.c_str (), PluginTypeToString (kPluginServerConnector ));
585- delete plugin_config;
586585 return kReturnPluginError ;
587586 }
588- ReturnCode ret = server_connector_->Init (plugin_config, context);
589- delete plugin_config;
587+ ReturnCode ret = server_connector_->Init (plugin_config.Get (), context);
590588 if (ret != kReturnOk ) {
591589 return ret;
592590 }
@@ -607,7 +605,7 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
607605 }
608606
609607 // Init stat reporter
610- plugin_config = config->GetSubConfig (" statReporter" );
608+ plugin_config. Reset ( config->GetSubConfig (" statReporter" ) );
611609 plugin = NULL ;
612610 std::string plugin_name = plugin_config->GetStringOrDefault (" name" , kPluginDefaultStatReporter );
613611 PluginManager::Instance ().GetPlugin (plugin_name, kPluginStatReporter , plugin);
@@ -616,30 +614,45 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
616614 POLARIS_LOG (LOG_ERROR,
617615 " Plugin factory register with name[%s] and type[%s] return error instance" ,
618616 plugin_name.c_str (), PluginTypeToString (kPluginStatReporter ));
619- delete plugin_config;
620617 return kReturnPluginError ;
621618 }
622- ret = stat_reporter_->Init (plugin_config, context);
623- delete plugin_config;
619+ ret = stat_reporter_->Init (plugin_config.Get (), context);
624620 if (ret != kReturnOk ) {
625621 return ret;
626622 }
627623
628624 // Init alert reporter
629- plugin_config = config->GetSubConfig (" alertReporter" );
630- plugin = NULL ;
631- plugin_name = plugin_config->GetStringOrDefault (" name" , kPluginDefaultAlertReporter );
625+ plugin_config. Reset ( config->GetSubConfig (" alertReporter" ) );
626+ plugin = NULL ;
627+ plugin_name = plugin_config->GetStringOrDefault (" name" , kPluginDefaultAlertReporter );
632628 PluginManager::Instance ().GetPlugin (plugin_name, kPluginAlertReporter , plugin);
633629 alert_reporter_ = dynamic_cast <AlertReporter*>(plugin);
634630 if (alert_reporter_ == NULL ) {
635631 POLARIS_LOG (LOG_ERROR,
636632 " Plugin factory register with name[%s] and type[%s] return error instance" ,
637633 plugin_name.c_str (), PluginTypeToString (kPluginAlertReporter ));
638- delete plugin_config;
639634 return kReturnPluginError ;
640635 }
641- ret = alert_reporter_->Init (plugin_config, context);
642- delete plugin_config;
636+ ret = alert_reporter_->Init (plugin_config.Get (), context);
637+ if (ret != kReturnOk ) {
638+ return ret;
639+ }
640+
641+ // Init server metric
642+ plugin_config.Reset (config->GetSubConfig (" serverMetric" ));
643+ plugin = NULL ;
644+ plugin_name = plugin_config->GetStringOrDefault (" name" , " " );
645+ if (!plugin_name.empty ()) {
646+ PluginManager::Instance ().GetPlugin (plugin_name, kPluginServerMetric , plugin);
647+ server_metric_.Set (dynamic_cast <ServerMetric*>(plugin));
648+ if (server_metric_.IsNull ()) {
649+ POLARIS_LOG (LOG_ERROR,
650+ " Plugin factory register with name[%s] and type[%s] return error instance" ,
651+ plugin_name.c_str (), PluginTypeToString (kPluginServerMetric ));
652+ return kReturnPluginError ;
653+ }
654+ ret = server_metric_->Init (plugin_config.Get (), context);
655+ }
643656 return ret;
644657}
645658
0 commit comments