1、现在有两个内核模块函数分别为:
EXPORT_SYMBOL()作用是,导出本模块函数给“其他模块函数使用”
(1)、calculate.c内核模块
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
int add_integar(int a,int b)
{
return a+b;
}
int sub_integar(int a,int b)
{
return a-b;
}
static int __init sym_init()
{
return 0;
}
static void __exit sym_exit()
{
}
module_init(sym_init);
module_exit(sym_exit);
/* EXPORT_SYMBOL(add_integar); */
/* EXPORT_SYMBOL(sub_integar); */
(2)、hello.c内核模块
#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("David Xie");
MODULE_DESCRIPTION("Hello World Module");
MODULE_ALIAS("a simplest module");
extern int add_integar(int a,int b);
extern int sub_integar(int a,int b);
static int __init hello_init()
{
int res = add_integar(1,2); // “ hello.c内核模块” 引用 “calculate.c内核模块”
return 0;
}
static void __exit hello_exit()
{
int res = sub_integar(2,1); //
}
module_init(hello_init);
module_exit(hello_exit);
说明:使用cat /proc/kallsyms | grep add_integar 查看导出文件
kallsyms文件中“记录所有输出到系统中的函数”,供其他模块调用
2、Makefile 文件如下ifneq ($(KERNELRELEASE),)
obj-m := hello.o calculate.o
else
KDIR := /lib/modules/2.6.18-53.el5/build
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif
看到有同学提问, 自己试炼了一把, 只为实现标签页效果, 未作细化和完善工作.
路过的同学多多指教
--------------------------------------------------------------
a.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <label>btn <input id="aa" type="button" onclick="location='http://www.google.com'" name="Submit" value="提交" /> </label> <a id="bb" href=/blog_article/"http_/www.baidu.com">ahref</a>/index.html <br /> <label>btn <input id="aa" type="button" onclick="" name="Submit" value="提交" /> </label> <a href=/blog_article/"http_/so.com" target="_blank">so</a> </body> </html>
单元文件
unit Unit11; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleCtrls, SHDocVw, StdCtrls, ComCtrls, ExtCtrls; type TForm11 = class(TForm) pgc1: TPageControl; procedure FormCreate(Sender: TObject); private function NewWindow(const URL : string = '') : TWebBrowser; procedure MyBeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool); procedure MyNewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool); { Private declarations } public { Public declarations } end; var Form11: TForm11; implementation {$R *.dfm} function TForm11.NewWindow(const URL : string = '') : TWebBrowser; var aTab : TTabSheet; begin aTab := TTabSheet.Create(pgc1); aTab.PageControl := pgc1; aTab.Caption := 'tab' + IntToStr(pgc1.PageCount); pgc1.ActivePage := aTab; aTab.Align := alClient; result := TWebBrowser.Create(self); aTab.InsertControl(result); result.Align := alClient; result.OnBeforeNavigate2 := MyBeforeNavigate2; result.OnNewWindow2 := MyNewWindow2; if URL <> '' then result.Navigate(url); end; procedure TForm11.FormCreate(Sender: TObject); begin NewWindow(ExtractFilePath(Application.ExeName)+'a.html'); end; procedure TForm11.MyNewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool); begin //新链接事件处理 ppDisp := NewWindow().DefaultInterface; end; procedure TForm11.MyBeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool); begin //Todo 事务处理 end; end.
界面文件
object Form11: TForm11 Left = 0 Top = 0 Caption = 'Form11' ClientHeight = 461 ClientWidth = 769 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object pgc1: TPageControl Left = 0 Top = 0 Width = 769 Height = 461 Align = alClient TabOrder = 0 ExplicitTop = 56 ExplicitHeight = 405 end end
开始还以为是uri匹配的不对,后来查阅文档才明白,Grails的过滤器只对controller有效,对静态资源无能为力(包括网站的各种图标)
解决办法,回归原本
1. 在src/java或src/groovy下创建一个过滤器,可以让它什么都不做
package myoa
import javax.servlet.*
class StaticFilter implements Filter {
@Override
void init(FilterConfig filterConfig) {
println('StaticFilter init')
}
@Override
void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
println('StaticFilter doFilter')
}
@Override
void destroy() {
println('StaticFilter destroy')
}
}
2. 创建配置文件
grails install-templates
编辑之
src/templates/war/web.xml
<filter>
<filter-name>staticFilters</filter-name>
<filter-class>myoa.StaticFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>staticFilters</filter-name>
<url-pattern>/file-store/*</url-pattern>
</filter-mapping>
这样就做好了一个最简单的静态资源过滤器,uri在file-store文件夹的所有资源将被禁止访问。
3. 再进一步,可以完善这个doFilter功能,其实这就是Grails的过滤器的本质。 这里倒是有了个小心得,越本质的东西,看起来复杂,理解起来容易(好比是Servlet);封装过的东西,用起来简单,理解起来困难(好比是Grails)。所以要两者兼顾,先实用主义,把东西先做出来,然后慢慢体会最本质的东西,好歹现在都是open source的,看源码比看文档来得更透彻。
void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) {
println('StaticFilter doFilter')
HttpServletRequest request = (HttpServletRequest) servletRequest
HttpServletResponse response = (HttpServletResponse) servletResponse
HttpSession session = request.getSession(false) //若存在会话则返回该会话,否则返回NULL
if (session?.getAttribute('loginUser')) {
chain.doFilter(servletRequest, servletResponse);//放行。让其走到下个链或目标资源中
} else {
println('please login')
response.sendRedirect(request.getContextPath() + "/user/login")
}
}
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—