Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1466690
  • 博文数量: 218
  • 博客积分: 6394
  • 博客等级: 准将
  • 技术积分: 2563
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-08 15:33
个人简介

持之以恒

文章分类

全部博文(218)

文章存档

2013年(8)

2012年(2)

2011年(21)

2010年(55)

2009年(116)

2008年(16)

分类: 服务器与存储

2013-11-04 21:46:02

因为项目的原因需要使用Apache 模块开发(Apache + C++),现在总结如下:
modules.c文件结构-->modules.so

点击(此处)折叠或打开

  1. module AP_MODULE_DECLARE_DATA get_service_module;

  2. 配置文件的内存结构
  3. typedef struct
  4. {
  5.     const char* dataFolder;
  6. }Service_Conf_Rec;

  7. static void *create_services_config(apr_pool_t *p, char* d)
  8. {
  9.     Service_Conf_Rec *conf = (Service_Conf_Rec *)apr_pcalloc(p, sizeof(*conf));
  10.     if(conf == NULL) return NULL;
  11.     return conf;
  12. }
  13. //读取DataFolder的参数的具体函数
  14. static const char * readDataFolder(cmd_parms *cmd, void *mconfig, const char*name)
  15. {
  16.     Service_Conf_Rec *conf = (Service_Conf_Rec*)mconfig;
  17.     conf->dataFolder = apr_pstrdup(cmd->pool, name);
  18.     return NULL;
  19. }

  20. static const command_rec services_conf[] =
  21. {
  22.     AP_INIT_TAKE1("DataFolder", readDataFolder, NULL, OR_FILEINFO, "invalid data folder"),
  23.     {NULL}
  24. };


  25. module AP_MODULE_DECLARE_DATA get_service_module = {
  26.     STANDARD20_MODULE_STUFF,
  27.     create_services_config, /* create per-dir config structures */
  28.     NULL, /* merge per-dir config structures */
  29.     NULL, /* create per-server config structures */
  30.     NULL, /* merge per-server config structures */
  31.     services_conf, /* table of config file commands */
  32.     get_service_register_hooks /* register hooks */
  33. };

  34. static void get_service_register_hooks(apr_pool_t *p)
  35. {
  36.     ap_hook_handler(get_service_handler, NULL, NULL, APR_HOOK_MIDDLE);
  37. }

  38. static int get_service_handler(request_rec *r)
  39. {
  40.     Service_Conf_Rec *conf = ap_get_module_config(r->per_dir_config, &get_service_module) ;
  41. C函数调用
  42.     //读取配置文件
  43.     //对请求进行处理-->调用ServiceApi.cpp中的函数(dlopen-->call service.so function)
  44. }

ServiceApi.cpp-->service.so

点击(此处)折叠或打开

  1. #ifndef _SERVICESAPI_H
  2. #define _SERVICESAPI_H

  3. #ifdef __cplusplus
  4. extern "C" {

  5. void Services_Init(...);
  6. void Services_Finish(...);
  7. #ifdef __cplusplus
  8. }
  9. #endif

  10. #endif



阅读(4044) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~