• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15
16import * as fs from 'fs';
17import { FuncObj, HdfRootInfo } from "../datatype";
18import { replaceAll } from '../../common/tool';
19import { getServiceFuncParamStr } from './genservicehfile';
20import { hdiServiceFuncTemplate } from '../../template/func_template';
21
22export function doGenServiceCppFile(rootInfo: HdfRootInfo, fileContent: string): string {
23  let hdiServiceFuncCpp = '';
24  let funcList: FuncObj[] = rootInfo.funcs;
25  let upperName = rootInfo.driverName.substring(0, 1).toLocaleUpperCase();
26  let marcoName = upperName + rootInfo.driverName.substring(1, rootInfo.driverName.length);
27  for (let i = 0; i < funcList.length; ++i) {
28    // xxx_interface_service.cpp的实现
29    let paramStr = getServiceFuncParamStr(funcList[i]);
30    let serviceCppContent = replaceAll(hdiServiceFuncTemplate, '[functionName]', funcList[i].name);
31    serviceCppContent = replaceAll(serviceCppContent, '[marcoName]', marcoName);
32    hdiServiceFuncCpp = replaceAll(serviceCppContent, '[params]', paramStr);
33  }
34  fileContent = replaceAll(fileContent, '[driverName]', rootInfo.driverName);
35  fileContent = replaceAll(fileContent, '[marcoName]', marcoName);
36  fileContent = replaceAll(fileContent, '[serviceFuncListImpl]', hdiServiceFuncCpp);
37  return fileContent;
38}
39
40export function genServiceCppFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
41  fileContent = doGenServiceCppFile(rootInfo, fileContent);
42  fs.writeFileSync(filePath, fileContent);
43}