Java模块名如何取,Java本机接口方法和模块名称的命名约定吗?

I am able to follow a jni tutorial just fine. But when I change the method name, I run into trouble. Is there a naming convention I need to follow? The tutorial used HelloJNI as the module name, and library name. I used "useaaacom".

I got great feedback on this and i am making progress. I have a related question; let me know if I should create another post for it. I like to build on this app, which runs at this point. How do I call functions from a device driver? I have the header file, and the driver is loaded into my image. By "how" I mean, do I need to have a copy of the header file in my project? This device driver is vendor implemented, i.e. it is not part of AOSP. I do have a copy of it since I downloaded the entire open source project and built it. So what I am asking is what do I need in my apk for the app to call the functions which are part of an active device driver?

Let me know if I should explain any part of it more, or I need to post the header file or ....

I already verified that I can open a device driver with the following lines of code:

#include

#include

#include

#include

#include

#include

int main(int argc, char **argv)

{

/* Our file descriptor */

int fd;

int rc = 0;

char *rd_buf[16];

printf("%s: entered\n", argv[0]);

/* Open the device */

fd = open("/dev/hello1", O_RDWR);

if ( fd == -1 ) {

perror("open failed");

rc = fd;

exit(-1);

}

printf("%s: open: successful\n", argv[0]);

/* Issue a read */

rc = read(fd, rd_buf, 0);

if ( rc == -1 ) {

perror("read failed");

close(fd);

exit(-1);

}

printf("%s: read: returning %d bytes!\n", argv[0], rc);

close(fd);

return 0;

}

I think I need to add the above code to my jni folder in the form of a .c source file, and call the functions in my device driver header file from this file? You may have noticed that the above code is for a test device driver called "hello1". I am gonna change the name to my targeted device driver.

解决方案

Dynamic linkers resolve entries based on their names. A native method name is concatenated from the following components:

the prefix Java_

a mangled fully-qualified class name

an underscore (_) separator

a mangled method name

for overloaded native methods, two underscores (__) followed by the mangled argument signature

So if you have the following:

package com.foo.bar;

class Baz {

public native void Grill(int i);

}

Then the corresponding C function should be:

JNIEXPORT void JNICALL Java_com_foo_bar_Baz_Grill(JNIEnv *env, jobject thiz, jint i);

If you have an underscore in the Java method name:

public native void A_Grill(int i);

Then the C function would be:

JNIEXPORT void JNICALL Java_com_foo_bar_Baz_A_1Grill(JNIEnv *env, jobject thiz, jint i);

The _1 escape sequence matches the _ in A_Grill.

1. 模块命名、数据库表命名、域模型命名、各分层的类/方法命名、页面的命名模块命名: a. 包命名:com.project_name.module_name.action/service/dao/ws; service的实现都置于com.project_name.module_name.service.impl下; b. 接口命名遵守XxxxService,接口实现遵守XxxxServiceImpl; 2. 包的设计、页面的层次结构设计(jsp/css/js等文件的结构); 3. log、异常(声明式异常)的约定设计; 4. 链接、按钮、表单提交的统一方式;通用式Ajax调用与页面跳转统一模型; 5. 响应一个请求的分层结构约定,列举几个示例(常规调用、Ajax调用、WebService调用、提供WebService暴露、硬件设备接口调用); 6. 验证代码质量的约定,如JUnit、EMMA、FindBugs、CheckStyle、PMD的使用;Hudson持续集成需注意的; 7. 压力测试、防内存泄漏测试; 基础CSS:标签的各种状态的样式;表格单双行的样式; 开发一个Action请求的响应: 前置条件:该Action涉及的Entity及EntityName.hbm.xml已经准备好。 步骤: a. 前端页面触发Action的请求; 统一采用全路径请求,URL格式: 1> basePath/web/moduleName/*_ *.action {1}  EntityName,{2}  ActionMethodName 2> basePath/web/moduleName/gotoXxx.action (无需调用Service,直接跳转) 包括jQuery的Ajax方式和非Ajax方式; 包括表单提交; 参数设值的方式: 1> URL参数: basePath/web/moduleName/*_*.action?entity.propertyName=paramValue&paramName=paramValue 2> 或 另外,对于表单的提交,前后台都必须做数据校验,SWDF已提供了此能力,进行简单的配置即可,前台直接提供类似以下代码即可,点此查看前端校验详细规则说明。 前端校验示例; 后台数据校验,点此查看校验详细说明. b. 配置struts-moduleName.xml; 直接跳转示例; 调用Service示例; c. 开发对应的{EntityName}Action类; 该类必须继承com.hikvision.swdf.xx.BaseAction,该Action类有一个关键属性entity,即泛型Entity类的一个实体,该属性默认填充好了请求提交过来的entity对应参数(即entity.propertyName); d. 开发Service接口和Service接口实现,并在Action中通过set方法注入该Service; 接口文件:UserService 接口实现:UserServiceImpl 注入Service e. 开发DAO,DAO继承com.hikvision.xxx.HibernateBaseDAO; 示例 f. 配置applicationContext-*.xml; 配置DAO bean、Service Bean、Action Bean及注入的配置; g. 测试; 备注: 1. Action建议统一遵守通配符的约定,basePath/web/moduleName/*_ *.action {1}  EntityName,{2}  ActionMethodName 2. 统一命名规则:接口类似UserService,接口实现类型UserServiceImpl;(IUserService和UserServiceImpl) 开发一个Action调用关联应用提供的WebService 前置条件:该WebService?WSDL可正常获取 步骤: a. 配置applicationContext-wsclient.xml; Spring管理第三方WebService实例bean Jaxws-client配置代码 b. 生成第三方WebService接口文件;(提供系统自动生成) 自动生成代码 c. 页面调用Action请求,Action中注入WebService实例bean; Action对应方法直接调用第三方WebService的相关方法; d. 测试; 备注: 1. 步骤b,接口文件必须同包同类置于src目录下; 开发一个Action调用关联应用开放的HTTP请求 步骤: 1. 页面调用Action请求; 2. Action类相应方法使用封装好的HttpClient相关工具类,准备好HTTP请求的相关参数header参数和body参数并以xml的方式提交HTTP请求; 3. 解析该HTTP请求返回值(XML或JSON); 4. 响应结果; 5. 测试; 备注: 开发一个需要对第三方应用发布的WebService 步骤: a. 开发WebService接口,@WebService进行注解该接口; b. 开发WebService接口实现类,@WebService注解该实现类,并制定endpointInterface; c. 配置applicationContext-ws.xml d. 测试 备注: 开发一个需要对第三方应用发布的RESTful Service 步骤: a. 开发RS接口,提供如下Annotation; b. 开发RS接口实现,并提供如下Annotation; c. 配置applicationContext-rs.xml 备注: 所有Annotation的涵义解释如下:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值