!443 service适配4.1版本

Merge pull request !443 from 胡瑞涛/master
This commit is contained in:
openharmony_ci 2024-07-19 09:10:46 +00:00 committed by Gitee
commit 8dac4e65a1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 309 additions and 53 deletions

View File

@ -12,7 +12,7 @@
│ ├── ... # 其它文档
│ ├── src
│ │ ├── ...
│ │ ├── cml # 脚手架源码
│ │ ├── cli # 脚手架源码
│ │ | ├── h2sa/src # 工具源码
│ │ | | ├── src
│ │ | | | ├── tools # 公共模块代码,包括消息体校验、文件读写、正则表达式转换等

View File

@ -16,7 +16,6 @@
#define TEST_H
namespace OHOS {
namespace Example {
/**
* @brief service服务IPC调用接口
* @ServiceClass
@ -25,6 +24,5 @@ namespace OHOS {
public:
int testFunc(int v1, int v2, bool v3);
};
} // namespace Example
} // namespace OHOS
#endif // TEST_H

View File

@ -68,7 +68,7 @@ node main.js -f test.h
-l, 日志级别0-3默认为1
-o,生成框架代码输入到指定路径下;
-s,指定serviceID。
-v,指定版本3.2和4.1默认版本为3.2
6.输出testservice文件夹其中的文件如下所示
![](./docs/figures/h2sa_outRes.png)

View File

@ -28,8 +28,8 @@ function parseFileAll(hFilePath) {
// call exe file (for real runtime)
let sysInfo = os.platform();
let execPath = path.dirname(process.execPath);
let exeFile = sysInfo === 'win32' ? path.join(execPath, 'header_parser.exe') :
path.join(execPath, 'header_parser');
let exeFile = sysInfo === 'win32' ? path.join(execPath, 'header_parser.exe') :
path.join(execPath, 'header_parser');
cmd = exeFile + ' ' + hFilePath;
}
@ -97,7 +97,7 @@ function createClassInfo(parseClassInfo) {
'namespace': [],
'properties': [],
'functions': [],
'extends':[]
'extends': []
};
classInfo.name = parseClassInfo.name;
classInfo.namespace = parseClassInfo.namespace.split('::');
@ -155,7 +155,9 @@ function doAnalyze(hFilePath, cmdParam) {
'includes': [],
'using': [],
'serviceId': (cmdParam.serviceId === null || cmdParam.serviceId === undefined) ?
'9002' : cmdParam.serviceId,
'9002' : cmdParam.serviceId,
'versionTag': (cmdParam.versionTag === null || cmdParam.versionTag === undefined) ?
'3.2' : cmdParam.versionTag,
'rawContent': parseResult.rawContent
};
@ -168,4 +170,4 @@ function doAnalyze(hFilePath, cmdParam) {
module.exports = {
doAnalyze
};
};

View File

@ -39,6 +39,7 @@ public:
} // namespace OHOS
#endif // I_[marcoName]_SERVICE_H
`;
let proxyHTemplate = `#ifndef [marcoName]_PROXY_H
#define [marcoName]_PROXY_H
#include "message_parcel.h"
@ -150,6 +151,7 @@ void [className]DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
} // namespace [serviceName]
} // namespace OHOS
`;
let proxyFuncTemplate = `[retType] [className]Proxy::[funcName]([params])
{
int retCode;
@ -255,11 +257,14 @@ void [className]Service::OnStop()
let serviceFuncImplTemplate = `[retType] [className]Service::[funcName]([params])
{
[retType] ret;
[retType] ret = [initRetvalue];
// TODO: Invoke the business implementation
ret = [paramsName];
printf("service [paramsName]= %i", ret);
return ret;
}
`;
let clientCppTemplate = `#include "[proxyHInclude]"
#include "ipc_skeleton.h"
#include "system_ability_definition.h"
@ -296,8 +301,11 @@ int main(int argc, char *argv[])
{
auto proxy = getRemoteProxy();
// TODO: Invoke remote method by proxy
[clientFuncParaMessage]
int res = 99;
[clientFuncInvoke]
printf("get res = %i", res);
[clientFuncParaLogMessage]
IPCSkeleton::JoinWorkThread();
return 0;
}`;
@ -334,7 +342,7 @@ ohos_shared_library("[lowServiceName]service") {
}
ohos_executable("[lowServiceName]client") {
sources = [
sources = [
"//[lowServiceName]service/src/[iServiceCppFile]",
"//[lowServiceName]service/src/[proxyCppFile]",
"//[lowServiceName]service/src/[clientCppFile]"
@ -361,6 +369,58 @@ ohos_executable("[lowServiceName]client") {
}
`;
let buildGnTemplate41 = `import("//build/ohos.gni")
ohos_shared_library("[lowServiceName]service") {
sources = [
"//[lowServiceName]service/src/[iServiceCppFile]",
"//[lowServiceName]service/src/[stubCppFile]",
"//[lowServiceName]service/src/[serviceCppFile]"
]
include_dirs = [
"//[lowServiceName]service/include",
"//[lowServiceName]service/interface",
"//commonlibrary/c_utils/base/include",
"//base/startup/init/interfaces/innerkits/include/syspara"
]
external_deps = [
"hilog:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"c_utils:utils",
]
part_name = "[lowServiceName]service_part"
subsystem_name = "[lowServiceName]service"
}
ohos_executable("[lowServiceName]client") {
sources = [
"//[lowServiceName]service/src/[iServiceCppFile]",
"//[lowServiceName]service/src/[proxyCppFile]",
"//[lowServiceName]service/src/[clientCppFile]"
]
include_dirs = [
"//[lowServiceName]service/include",
"//[lowServiceName]service/interface",
"//commonlibrary/c_utils/base/include"
]
external_deps = [
"hilog:libhilog",
"ipc:ipc_core",
"samgr:samgr_proxy",
"c_utils:utils",
]
part_name = "[lowServiceName]service_part"
subsystem_name = "[lowServiceName]service"
}
`;
let bundleJsonTemplate = `{
"name": "@ohos/[lowServiceName]service",
"description": "system ability framework test",
@ -408,11 +468,67 @@ let bundleJsonTemplate = `{
}
}`;
let bundleJsonTemplate41 = `{
"name": "@ohos/[lowServiceName]service_part",
"description": "system ability framework test",
"homePage": "https://gitee.com/",
"version": "4.1",
"license": "Apache License 2.0",
"repository": "",
"publishAs": "code-segment",
"segment": {
"destPath": "[lowServiceName]service"
},
"dirs": {},
"scripts": {},
"component": {
"name": "[lowServiceName]service_part",
"subsystem": "[lowServiceName]service",
"adapted_system_type": [
"standard"
],
"rom": "2048KB",
"ram": "~4096KB",
"deps": {
"components": [
"hilog",
"ipc",
"samgr",
"c_utils",
"safwk"
],
"third_party": [ "libxml2" ]
},
"build": {
"sub_component": [
"//[lowServiceName]service:[lowServiceName]service",
"//[lowServiceName]service/sa_profile:[lowServiceName]service_sa_profile",
"//[lowServiceName]service:[lowServiceName]client",
"//[lowServiceName]service/etc:[lowServiceName]_service_init"
],
"inner_kits": [
],
"test": [
]
}
}
}`;
let profileGnTemplate = `import("//build/ohos.gni")
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("[lowServiceName]service_sa_profile") {
sources = [ "[serviceId].xml" ]
part_name = "[lowServiceName]service_part"
}
`;
let profileGnTemplate41 = `import("//build/ohos.gni")
import("//build/ohos/sa_profile/sa_profile.gni")
ohos_sa_profile("[lowServiceName]service_sa_profile") {
sources = [ "[serviceId].json" ]
part_name = "[lowServiceName]service_part"
}
@ -431,6 +547,20 @@ let profileXmlTemplate = `<?xml version="1.0" encoding="utf-8"?>
</info>
`;
let profileJsonTemplate = `{
"process":"[lowServiceName]service_sa",
"systemability":[
{
"name":[serviceId],
"libpath":"lib[lowServiceName]service.z.so",
"run-on-create":false,
"auto-restart":true,
"distributed":false,
"dump-level":1
}
]
}`;
let serviceCfgTemplate = `{
"services" : [{
"name" : "[lowServiceName]service",
@ -442,6 +572,17 @@ let serviceCfgTemplate = `{
}
`;
let serviceCfgTemplate41 = `{
"services" : [{
"name" : "[lowServiceName]service",
"path" : ["/system/bin/sa_main", "/system/profile/[lowServiceName]service_sa.json"],
"uid" : "system",
"gid" : ["system", "shell"]
}
]
}
`;
let serviceCfgGnTemplate = `import("//build/ohos.gni")
ohos_prebuilt_etc("[lowServiceName]_service_init") {
@ -468,10 +609,15 @@ module.exports = {
serviceFuncImplTemplate,
clientCppTemplate,
buildGnTemplate,
buildGnTemplate41,
bundleJsonTemplate,
bundleJsonTemplate41,
profileGnTemplate,
profileGnTemplate41,
profileXmlTemplate,
profileJsonTemplate,
serviceCfgTemplate,
serviceCfgTemplate41,
serviceCfgGnTemplate,
iServiceCppTemplate
};
};

View File

@ -16,13 +16,15 @@
const { NapiLog } = require('../tools/NapiLog');
const { replaceAll, getTab } = require('../tools/tool');
const re = require('../tools/re');
const { iServiceHTemplate, proxyHTemplate, stubHTemplate, serviceHTemplate, proxyCppTemplate,
proxyFuncTemplate, stubCppTemplate, stubInnerFuncTemplate, serviceCppTemplate, serviceFuncImplTemplate,
clientCppTemplate, buildGnTemplate, bundleJsonTemplate, profileGnTemplate, profileXmlTemplate, serviceCfgTemplate,
serviceCfgGnTemplate, iServiceCppTemplate } = require('./fileTemplate');
const { DATA_W_MAP, DATA_R_MAP, VECTOR_W_MAP, VECTOR_R_MAP, getParcelType, AllParseFileList, MarshallInfo,
ProcessingClassList} = require('../tools/common');
const { iServiceHTemplate, proxyHTemplate, stubHTemplate, serviceHTemplate, proxyCppTemplate, proxyFuncTemplate,
stubCppTemplate, stubInnerFuncTemplate, serviceCppTemplate, serviceFuncImplTemplate, clientCppTemplate, buildGnTemplate,
buildGnTemplate41, bundleJsonTemplate, bundleJsonTemplate41, profileGnTemplate, profileGnTemplate41, profileJsonTemplate,
profileXmlTemplate, serviceCfgTemplate, serviceCfgTemplate41, serviceCfgGnTemplate, iServiceCppTemplate } = require('./fileTemplate');
const { DATA_W_MAP, DATA_R_MAP, VECTOR_W_MAP, VECTOR_R_MAP, getParcelType, AllParseFileList, MarshallInfo,
ProcessingClassList } = require('../tools/common');
const numericTypes = ['short', 'int', 'long', 'long long', 'float', 'double'];
const boolType = ['bool'];
const charType = ['char', 'string'];
let rootHFileSrc = ''; // .h文件的源码
let dependSrcList = []; //在.h文件中定义并被接口使用到的class/struct类定义源码集合(接口没用到的class定义就不需要了)
let marshallFuncList = []; // class类的消息序列化方法代码集合
@ -40,6 +42,7 @@ let fileContent = {
'bundleJsonFile': {},
'profileGnFile': {},
'profileXmlFile': {},
'profileJsonFile': {},
'serviceCfgFile': {},
'serviceCfgGnFile': {},
'iServiceCppFile': {},
@ -70,22 +73,70 @@ function getFuncParamStr(params) {
return paramStr;
}
function getClientFuncParamStr(params) {
let paramStr = '';
for (let i = 0; i < params.length; ++i) {
paramStr += (i === 0) ? '' : ', ';
paramStr += params[i].name;
}
return paramStr;
}
function genClientMsgFunc(funcList) {
let initParavalue = '';
let initParamessage = '';
for (var n = 0; n < funcList.params.length; ++n) {
if (numericTypes.includes(funcList.params[n].type)) {
// 数值类型初始化为0
initParavalue = '1';
initParamessage += ' int ' + funcList.params[n].name + ' = ' + initParavalue + ';\r\n';
funcList.params[n].name;
} else if (boolType.includes(funcList.params[n].type)) {
// 布尔类型初始化为true
initParavalue = 'true';
initParamessage += ' bool ' + funcList.params[n].name + ' = ' + initParavalue + ';\r\n';
} else if (charType.includes(funcList.params[n].type)) {
// 字符类型初始化为空字符''
initParavalue = '';
initParamessage += ' string ' + funcList.params[n].name + ' = ' + initParavalue + ';\r\n';
} else {
// 对于其他类型,这里可以根据需要进行处理
initRetvalue = 'nullptr'; // 假设是指针类型或其他复杂类型
}
}
return initParamessage;
}
function genClientLogFunc(funcList) {
let initParaLog = '';
for (let n = 0; n < funcList.params.length; ++n) {
if (numericTypes.includes(funcList.params[n].type)) {
// 数值类型初始化为0
initParaLog += ' printf("client %s = %i",%s);\r\n'.format(funcList.params[n].name, funcList.params[n].name);
} else {
// 对于其他类型,这里可以根据需要进行处理
}
}
return initParaLog;
}
/**
* 获取class类型在原始.h文件中的定义源码段
* @param className 待查找的class名称(可以是struct)
* @param rawContent .h文件源码
* @returns class类型在原始.h文件中的定义源码段
*/
function getClassSrc(className, rawContent) {
function getClassSrc(className, rawContent) {
let beginPos = rawContent.indexOf(className);
if ( beginPos < 0) {
if (beginPos < 0) {
NapiLog.logError('Warning: Can not find definition of ' + className);
return null;
}
let firstBracesPos = rawContent.indexOf('{', beginPos); // class后面第一个{的位置
let firstSemiPos = rawContent.indexOf(';', beginPos); // class后面第一个分号的位置
if ( (firstBracesPos < 0) || (firstSemiPos < firstBracesPos)) {
if ((firstBracesPos < 0) || (firstSemiPos < firstBracesPos)) {
// class定义后面找不到{}或先找到了结束符分号视为该class没有相关的实现代码
NapiLog.logError('Warning: Can not find implementation of ' + className);
return null;
@ -107,7 +158,7 @@ function getFuncParamStr(params) {
NapiLog.logError('Warning: The braces of %s do not match.'.format(className));
return null;
}
let classSrc = rawContent.substring(beginPos, endPos);
return classSrc;
}
@ -150,8 +201,8 @@ function findGetSet(propName, classInfo) {
}
if (findGet && findSet) {
// get和set方法必须同时具备成员对象属性才能序列化/反序列化,缺一不可。
result = {'name': propName, 'getName': getName, 'setName': setName};
}
result = { 'name': propName, 'getName': getName, 'setName': setName };
}
return result;
}
@ -166,7 +217,7 @@ function privatePropMashall(parcelName, objName, classInfo, marshallInfo) {
} else {
NapiLog.logError(
'Warning: Can not find get/set method of %s.%s, the property will be ignored in remote request.'
.format(classInfo.name, properties[i].name));
.format(classInfo.name, properties[i].name));
}
}
let writePropStr = '';
@ -250,25 +301,25 @@ function createMarshallInfo(classInfo) {
// 为了marshall方法的入参能同时支持左值引用marshall(xx.obj)和右值引用marshall(xx.getObj()),这里采用万能引用模板来实现
newMarshall.marshallFuncH = replaceAll(
'\ntemplate<typename T> // T should be [className]& or [className]&&', '[className]', classInfo.name);
newMarshall.marshallFuncH +=
newMarshall.marshallFuncH +=
'\n%s bool %s(MessageParcel& data, T&& %s) {[publicMarshall][privateMarshall]\n return true;\n}\n'
.format('__attribute__((unused)) static', newMarshall.marshallFuncName, objName);
newMarshall.unmarshallFuncH =
.format('__attribute__((unused)) static', newMarshall.marshallFuncName, objName);
newMarshall.unmarshallFuncH =
'\n%s bool %s(MessageParcel& data, %s& %s) {[publicUnmarshall][privateUnmarshall]\n return true;\n}\n'
.format('__attribute__((unused)) static', newMarshall.unmarshallFuncName, classInfo.name, objName);
.format('__attribute__((unused)) static', newMarshall.unmarshallFuncName, classInfo.name, objName);
let marshallInfo = {
'className': classInfo.name,
'marshallFuncs': newMarshall
};
// 这里必须先将class放入处理列表中以免后续的属性代码生成过程中再次遇到该class类型造成无限循环嵌套。
ProcessingClassList.push(marshallInfo);
ProcessingClassList.push(marshallInfo);
// 继续生成属性代码
publicPropMashall('data', objName, classInfo, newMarshall);
privatePropMashall('data', objName, classInfo, newMarshall);
marshallFuncList.push(marshallInfo);
marshallFuncList.push(marshallInfo);
return newMarshall;
}
@ -302,7 +353,7 @@ function genClassWriteString(objName, parcelName, marshallInfo, classInfo) {
* @param marshallInfo class对应的打包函数(没有为null)
* @param classInfo class结构信息
*/
function genClassReadString(destObj, parcelName, marshallInfo, classInfo) {
function genClassReadString(destObj, parcelName, marshallInfo, classInfo) {
let marshall = marshallInfo;
if (!marshall) {
marshall = createMarshallInfo(classInfo);
@ -327,7 +378,7 @@ function genClassWriteString(objName, parcelName, marshallInfo, classInfo) {
* @param matchs vector类型的正则匹配结果
* @returns 生成的vector变量序列化打包代码段
*/
function genVectorWrite(vectorName, parcelName, vecType, matchs) {
function genVectorWrite(vectorName, parcelName, vecType, matchs) {
let rawType = re.getReg(vecType, matchs.regs[2]);
let parcelType = getParcelType(rawType);
let wFunc = VECTOR_W_MAP.get(parcelType);
@ -378,7 +429,7 @@ function genWrite(srcName, parcelName, vType) {
* @param matchs vector类型的正则匹配结果
* @returns 生成的vector变量反序列化读取码段
*/
function genVectorRead(parcelName, vectorName, vecType, matchs) {
function genVectorRead(parcelName, vectorName, vecType, matchs) {
let rawType = re.getReg(vecType, matchs.regs[2]);
let parcelType = getParcelType(rawType);
let rFunc = VECTOR_R_MAP.get(parcelType);
@ -417,7 +468,7 @@ function genRead(parcelName, destObj) {
// 从parcel data中读取基本类型变量
let result = destObj.setFunc ? '%s(%s.%s());'.format(destObj.setFunc, parcelName, rFunc)
: '%s = %s.%s();'.format(destObj.name, parcelName, rFunc);
: '%s = %s.%s();'.format(destObj.name, parcelName, rFunc);
return result;
}
@ -470,7 +521,7 @@ function genStubInnerFunc(funcInfo, className) {
readDataStr += '\n' + tab;
innerParamStr += ' ,';
}
//将remote请求中的参数值读取到内部参数变量中
readDataStr += '%s %s;'.format(param.type, innerParamName); // 定义内部参数变量
let destObj = {
@ -500,9 +551,37 @@ function genStubInnerFunc(funcInfo, className) {
function genServiceFunc(funcInfo, className, paramStr) {
let serviceFunc = replaceAll(serviceFuncImplTemplate, '[retType]', funcInfo.retType);
// 根据类型初始化返回值
let initRetvalue;
let paramsName = '';
if (numericTypes.includes(funcInfo.retType)) {
// 数值类型初始化为0
initRetvalue = '0';
} else if (boolType.includes(funcInfo.retType)) {
// 布尔类型初始化为true
initRetvalue = 'true';
} else if (charType.includes(funcInfo.retType)) {
// 字符类型初始化为空字符''
initRetvalue = '';
} else {
// 对于其他类型,这里可以根据需要进行处理
initRetvalue = 'nullptr'; // 假设是指针类型或其他复杂类型
}
for (var n = 0; n < funcInfo.params.length; ++n) {
if (numericTypes.includes(funcInfo.params[n].type)) {
// 数值添加
paramsName += (n === 0) ? '' : '+ ';
paramsName += funcInfo.params[n].name + ' ';
} else {
// 对于其他类型,这里可以根据需要进行处理
}
}
serviceFunc = replaceAll(serviceFunc, '[initRetvalue]', initRetvalue);
serviceFunc = replaceAll(serviceFunc, '[className]', className);
serviceFunc = replaceAll(serviceFunc, '[funcName]', funcInfo.name);
serviceFunc = replaceAll(serviceFunc, '[params]', paramStr);
serviceFunc = replaceAll(serviceFunc, '[paramsName]', paramsName);
return serviceFunc;
}
@ -518,6 +597,8 @@ function genFunctions(classInfo, files) {
files.stubCpp = replaceAll(files.stubCpp, '[innerFuncImpl]', res.stubInnerFuncCpp);
files.serviceCpp = replaceAll(files.serviceCpp, '[serviceFuncImpl]', res.serviceFuncCpp);
files.clientCpp = replaceAll(files.clientCpp, '[clientFuncInvoke]', res.clientFuncCpp);
files.clientCpp = replaceAll(files.clientCpp, '[clientFuncParaMessage]', res.clientFuncMessage);
files.clientCpp = replaceAll(files.clientCpp, '[clientFuncParaLogMessage]', res.clientFuncLogMessage);
}
function genFilesByTemplate(upperServiceName, lowServiceName, rootInfo) {
@ -534,18 +615,27 @@ function genFilesByTemplate(upperServiceName, lowServiceName, rootInfo) {
files.iServiceCpp = iServiceCppTemplate;
// 按模板生成资源配置文件内容框架
files.buildGn = replaceAll(buildGnTemplate, '[lowServiceName]', lowServiceName);
if (rootInfo.versionTag === '4.1') {
files.buildGn = replaceAll(buildGnTemplate41, '[lowServiceName]', lowServiceName);
files.bundleJson = replaceAll(bundleJsonTemplate41, '[lowServiceName]', lowServiceName);
files.profileJson = replaceAll(profileJsonTemplate, '[lowServiceName]', lowServiceName);
files.profileJson = replaceAll(files.profileJson, '[serviceId]', rootInfo.serviceId);
files.profileGn = replaceAll(profileGnTemplate41, '[lowServiceName]', lowServiceName);
files.serviceCfg = replaceAll(serviceCfgTemplate41, '[lowServiceName]', lowServiceName);
} else {
files.buildGn = replaceAll(buildGnTemplate, '[lowServiceName]', lowServiceName);
files.bundleJson = replaceAll(bundleJsonTemplate, '[lowServiceName]', lowServiceName);
files.profileXml = replaceAll(profileXmlTemplate, '[lowServiceName]', lowServiceName);
files.profileXml = replaceAll(files.profileXml, '[serviceId]', rootInfo.serviceId);
files.profileGn = replaceAll(profileGnTemplate, '[lowServiceName]', lowServiceName);
files.serviceCfg = replaceAll(serviceCfgTemplate, '[lowServiceName]', lowServiceName);
}
files.buildGn = replaceAll(files.buildGn, '[stubCppFile]', fileContent.stubCppFile.name);
files.buildGn = replaceAll(files.buildGn, '[serviceCppFile]', fileContent.serviceCppFile.name);
files.buildGn = replaceAll(files.buildGn, '[proxyCppFile]', fileContent.proxyCppFile.name);
files.buildGn = replaceAll(files.buildGn, '[clientCppFile]', fileContent.clientCppFile.name);
files.buildGn = replaceAll(files.buildGn, '[iServiceCppFile]', fileContent.iServiceCppFile.name);
files.bundleJson = replaceAll(bundleJsonTemplate, '[lowServiceName]', lowServiceName);
files.profileGn = replaceAll(profileGnTemplate, '[lowServiceName]', lowServiceName);
files.profileGn = replaceAll(files.profileGn, '[serviceId]', rootInfo.serviceId);
files.profileXml = replaceAll(profileXmlTemplate, '[lowServiceName]', lowServiceName);
files.profileXml = replaceAll(files.profileXml, '[serviceId]', rootInfo.serviceId);
files.serviceCfg = replaceAll(serviceCfgTemplate, '[lowServiceName]', lowServiceName);
files.serviceGnCfg = replaceAll(serviceCfgGnTemplate, '[lowServiceName]', lowServiceName);
return files;
}
@ -600,7 +690,11 @@ function genFileNames(lowServiceName, rootInfo) {
fileContent.buildGnFile.name = 'BUILD.gn';
fileContent.bundleJsonFile.name = 'bundle.json';
fileContent.profileGnFile.name = 'BUILD.gn';
fileContent.profileXmlFile.name = rootInfo.serviceId + '.xml';
if (rootInfo.versionTag === '4.1') {
fileContent.profileJsonFile.name = rootInfo.serviceId + '.json';
} else {
fileContent.profileXmlFile.name = rootInfo.serviceId + '.xml';
}
fileContent.serviceCfgFile.name = '%s_service.cfg'.format(lowServiceName);
fileContent.serviceCfgGnFile.name = 'BUILD.gn';
fileContent.iServiceCppFile.name = 'i_%s_service.cpp'.format(lowServiceName);
@ -618,7 +712,9 @@ function genFunctionCode(classInfo) {
genResult.stubInnerFuncCpp = ''; // stub.cpp 的inner方法实现
genResult.serviceFuncCpp = ''; // service.cpp的方法实现
genResult.clientFuncCpp = ''; // client.cpp 的inner方法定义
genResult.clientFuncParaLen = ''; // client.cpp中参数的个数
genResult.clientFuncMessage = ''; // client.cpp中参数的初始化
genResult.clientFuncLogMessage = ''; //client.cpp 中的打印信息
let enumTab = getTab(2);
let funcTab = getTab(1);
for (var i = 0; i < funcList.length; ++i) {
@ -627,6 +723,7 @@ function genFunctionCode(classInfo) {
genResult.funcEnumStr += funcList[i].funcEnum;
let paramStr = getFuncParamStr(funcList[i].params);
let clientParamStr = getClientFuncParamStr(funcList[i].params);
genResult.iServiceFuncH += (i === 0) ? '' : '\n' + funcTab;
genResult.iServiceFuncH += 'virtual %s %s(%s) = 0;'.format(funcList[i].retType, funcList[i].name, paramStr);
@ -634,7 +731,7 @@ function genFunctionCode(classInfo) {
genResult.proxyFuncH += '%s %s(%s) override;'.format(funcList[i].retType, funcList[i].name, paramStr);
genResult.stubInnerFuncH += (i === 0) ? '' : '\n' + funcTab;
genResult.stubInnerFuncH +=
genResult.stubInnerFuncH +=
'ErrCode %sInner(MessageParcel &data, MessageParcel &reply);'.format(funcList[i].name);
genResult.proxyFuncCpp += genProxyFunc(funcList[i], classInfo.name, paramStr);
@ -646,8 +743,12 @@ function genFunctionCode(classInfo) {
genResult.stubInnerFuncCpp += genStubInnerFunc(funcList[i], classInfo.name);
genResult.serviceFuncCpp += genServiceFunc(funcList[i], classInfo.name, paramStr);
genResult.clientFuncParaLen += '%s'.format(funcList[i].params.length);
genResult.clientFuncMessage += genClientMsgFunc(funcList[i]);
genResult.clientFuncLogMessage += genClientLogFunc(funcList[i]);
genResult.clientFuncCpp += (i === 0) ? '' : '\n' + funcTab;
genResult.clientFuncCpp += '// proxy->%s(%s);'.format(funcList[i].name, paramStr);
genResult.clientFuncCpp += 'res = proxy->%s(%s);'.format(funcList[i].name, clientParamStr);
}
return genResult;
}
@ -714,7 +815,11 @@ function doGenerate(rootInfo) {
fileContent.buildGnFile.content = files.buildGn;
fileContent.bundleJsonFile.content = files.bundleJson;
fileContent.profileGnFile.content = files.profileGn;
fileContent.profileXmlFile.content = files.profileXml;
if (rootInfo.versionTag === '4.1') {
fileContent.profileJsonFile.content = files.profileJson;
} else {
fileContent.profileXmlFile.content = files.profileXml;
}
fileContent.serviceCfgFile.content = files.serviceCfg;
fileContent.serviceCfgGnFile.content = files.serviceGnCfg;
fileContent.iServiceCppFile.content = files.iServiceCpp;
@ -723,4 +828,4 @@ function doGenerate(rootInfo) {
module.exports = {
doGenerate
};
};

View File

@ -27,7 +27,8 @@ let ops = stdio.getopt({
'filename': { key: 'f', args: 1, description: '.h file', default: '' },
'out': { key: 'o', args: 1, description: 'output directory', default: '.' },
'loglevel': { key: 'l', args: 1, description: 'Log Level: 0~3', default: '1' },
'serviceId': { key: 's', args: 1, description: 'service register id: 9000~16777214', default: '9000' }
'serviceId': { key: 's', args: 1, description: 'service register id: 9000~16777214', default: '9000' },
'versionTag': { key: 'v', args: 1, description: 'version tag: 4.1 / 3.2', default: '3.2' }
});
NapiLog.init(ops.loglevel, path.join('' + ops.out, 'napi_gen.log'));
@ -113,14 +114,18 @@ function genServiceFile(fileName) {
createFolder(srcPath);
// 4. 生成代码保存为文件
wirte2Disk(fileContent.serviceCfgFile, etcPath);
wirte2Disk(fileContent.serviceCfgGnFile, etcPath);
wirte2Disk(fileContent.proxyHFile, includePath);
wirte2Disk(fileContent.stubHFile, includePath);
if (ops.versionTag === '4.1') {
wirte2Disk(fileContent.profileJsonFile, profilePath);
} else {
wirte2Disk(fileContent.profileXmlFile, profilePath);
}
wirte2Disk(fileContent.serviceCfgFile, etcPath);
wirte2Disk(fileContent.serviceHFile, includePath);
wirte2Disk(fileContent.iServiceHFile, interfacePath);
wirte2Disk(fileContent.profileGnFile, profilePath);
wirte2Disk(fileContent.profileXmlFile, profilePath);
wirte2Disk(fileContent.proxyCppFile, srcPath);
wirte2Disk(fileContent.stubCppFile, srcPath);
wirte2Disk(fileContent.serviceCppFile, srcPath);