divert_init.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id divert_init.c,v 1.5.6.2 2001/01/24 22:18:17 kai Exp $
  2.  *
  3.  * Module init for DSS1 diversion services for i4l.
  4.  *
  5.  * Copyright 1999       by Werner Cornelius (werner@isdn4linux.de)
  6.  * 
  7.  * This software may be used and distributed according to the terms
  8.  * of the GNU General Public License, incorporated herein by reference.
  9.  *
  10.  */
  11. #include <linux/module.h>
  12. #include <linux/version.h>
  13. #include <linux/init.h>
  14. #include "isdn_divert.h"
  15. MODULE_DESCRIPTION("ISDN4Linux: Call diversion support");
  16. MODULE_AUTHOR("Werner Cornelius");
  17. MODULE_LICENSE("GPL");
  18. /********************/
  19. /* needed externals */
  20. /********************/
  21. extern int printk(const char *fmt,...);
  22. /****************************************/
  23. /* structure containing interface to hl */
  24. /****************************************/
  25. isdn_divert_if divert_if =
  26.   { DIVERT_IF_MAGIC,  /* magic value */
  27.     DIVERT_CMD_REG,   /* register cmd */
  28.     ll_callback,      /* callback routine from ll */
  29.     NULL,             /* command still not specified */
  30.     NULL,             /* drv_to_name */
  31.     NULL,             /* name_to_drv */
  32.   };
  33. /*************************/
  34. /* Module interface code */
  35. /* no cmd line parms     */
  36. /*************************/
  37. static int __init divert_init(void)
  38. { int i;
  39.   if (divert_dev_init())
  40.    { printk(KERN_WARNING "dss1_divert: cannot install device, not loadedn");
  41.      return(-EIO);
  42.    }
  43.   if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR)
  44.    { divert_dev_deinit();
  45.      printk(KERN_WARNING "dss1_divert: error %d registering module, not loadedn",i);
  46.      return(-EIO);
  47.    } 
  48. #if (LINUX_VERSION_CODE < 0x020111)
  49.   register_symtab(0);
  50. #endif
  51.   printk(KERN_INFO "dss1_divert module successfully installedn");
  52.   return(0);
  53. }
  54. /**********************/
  55. /* Module deinit code */
  56. /**********************/
  57. static void __exit divert_exit(void)
  58. { unsigned long flags;
  59.   int i;
  60.   save_flags(flags);
  61.   cli();
  62.   divert_if.cmd = DIVERT_CMD_REL; /* release */
  63.   if ((i = DIVERT_REG_NAME(&divert_if)) != DIVERT_NO_ERR)
  64.    { printk(KERN_WARNING "dss1_divert: error %d releasing modulen",i);
  65.      restore_flags(flags);
  66.      return;
  67.    } 
  68.   if (divert_dev_deinit()) 
  69.    { printk(KERN_WARNING "dss1_divert: device busy, remove cancelledn");
  70.      restore_flags(flags);
  71.      return;
  72.    }
  73.   restore_flags(flags);
  74.   deleterule(-1); /* delete all rules and free mem */
  75.   deleteprocs();
  76.   printk(KERN_INFO "dss1_divert module successfully removed n");
  77. }
  78. module_init(divert_init);
  79. module_exit(divert_exit);