插件开发技术说明(7)---读插件配置

来源:互联网 发布:深圳网络安防培训学校 编辑:程序博客网 时间:2024/03/28 17:25

1.插件配置

每个插件**可以**有私有的配置文件,文件名与插件同名,扩展名为:conf.

如ad插件的配置文件ad.conf内容如下:

<?xml version="1.0" encoding="gb2312" standalone="yes"?><config><dbc>yoopa</dbc>  <!--广告图片文件目录 -->  <ad_pic_file_path>file_home\Ad</ad_pic_file_path></config>


2.实现示例

配置文件读取在插件的ReadPrivateConfig中实现.
示例代码如下: 

int CAdService::ReadPrivateConfig() {parent::ReadPrivateConfig();if (config_->Open(cf_.c_str())) {ACE_ERROR_RETURN((LM_ERROR,"open config file %s failure.\n",cf_.c_str()),-1);}INode *root = config_->GetChildNodes()->GetChildNodes("config")->GetChildNode(0);INode *node,*attr;node = root->GetChildNodes()->GetChildNodes("ad_pic_file_path")->GetChildNode(0);ad_pic_file_path_ = (string)*node; ad_pic_file_path_ = RegularPath(ad_pic_file_path_); ///< 规格化路径if (_access(ad_pic_file_path_.c_str(),0)) ///< 如果目录不存在则创建CreateMultDir(ad_pic_file_path_.c_str());config_->Close();return 0;}

3.读文件目录配置

.不确定用户配置的文件路径是否以分隔符('/'或'\')结束,需要使用RegularPath函数转换.
.当目录不存在时是否自动创建由应用设计决定,创建多级目录可用CreateMultDir函数.

代码如上.

这2个函数定义在:stdfile.h

LS_API string RegularPath(string path, bool tail_added=true) ;/// tail_added:是否在尾部增加'\\'或'/'LS_API int CreateMultDir(string path);


 

0 0