因为项目的原因需要使用Apache 模块开发(Apache + C++),现在总结如下:
modules.c文件结构-->modules.so
-
module AP_MODULE_DECLARE_DATA get_service_module;
-
-
配置文件的内存结构
-
typedef struct
-
{
-
const char* dataFolder;
-
}Service_Conf_Rec;
-
-
static void *create_services_config(apr_pool_t *p, char* d)
-
{
-
Service_Conf_Rec *conf = (Service_Conf_Rec *)apr_pcalloc(p, sizeof(*conf));
-
if(conf == NULL) return NULL;
-
return conf;
-
}
-
-
//读取DataFolder的参数的具体函数
-
static const char * readDataFolder(cmd_parms *cmd, void *mconfig, const char*name)
-
{
-
Service_Conf_Rec *conf = (Service_Conf_Rec*)mconfig;
-
conf->dataFolder = apr_pstrdup(cmd->pool, name);
-
return NULL;
-
}
-
-
static const command_rec services_conf[] =
-
{
-
AP_INIT_TAKE1("DataFolder", readDataFolder, NULL, OR_FILEINFO, "invalid data folder"),
-
{NULL}
-
};
-
-
-
module AP_MODULE_DECLARE_DATA get_service_module = {
-
STANDARD20_MODULE_STUFF,
-
create_services_config, /* create per-dir config structures */
-
NULL, /* merge per-dir config structures */
-
NULL, /* create per-server config structures */
-
NULL, /* merge per-server config structures */
-
services_conf, /* table of config file commands */
-
get_service_register_hooks /* register hooks */
-
};
-
-
static void get_service_register_hooks(apr_pool_t *p)
-
{
-
ap_hook_handler(get_service_handler, NULL, NULL, APR_HOOK_MIDDLE);
-
}
-
-
static int get_service_handler(request_rec *r)
-
{
-
Service_Conf_Rec *conf = ap_get_module_config(r->per_dir_config, &get_service_module) ;
-
C函数调用
-
//读取配置文件
-
//对请求进行处理-->调用ServiceApi.cpp中的函数(dlopen-->call service.so function)
-
}
ServiceApi.cpp
-->service.so
-
#ifndef _SERVICESAPI_H
-
#define _SERVICESAPI_H
-
-
#ifdef __cplusplus
-
extern "C" {
-
-
void Services_Init(...);
-
void Services_Finish(...);
-
#ifdef __cplusplus
-
}
-
#endif
-
-
#endif
阅读(4108) | 评论(0) | 转发(1) |