• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2024 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*/
15import * as vscode from 'vscode';
16import * as path from 'path';
17import { IModel } from "./imodel";
18import { parseHeaderFile } from '../parse/parsec';
19import { GenInfo } from '../gen/datatype';
20import { genDtsFile } from '../gen/gendts';
21import { GEN_COMPLETE, HDF_FRAMEWORK, NAPI_FRAMEWORK, PARSE_COMPLETE, SA_FRAMEWORK } from '../common/constants';
22import { Logger } from "../common/log";
23import {
24  EVENT_ERROR,
25  EVENT_INFORMATION,
26  EVENT_PROGRESS,
27  EVENT_WARNING
28} from '../common/eventtype';
29import { generateFuncTestCase } from '../gen/gentest';
30import { H2hdfMod } from './h2hdfmod';
31import { H2saMod } from './h2samod';
32import { Dts2cppMod } from './dts2cppmod';
33
34export class WelcomeMod extends IModel {
35  name: string;
36  versionTag: string = '4.1';
37  serviceId: string = '19000';
38  genType: string = HDF_FRAMEWORK;
39
40  private static instance: WelcomeMod;
41  constructor() {
42    super();
43    this.name = 'welcomemod';
44  }
45
46  static getInstance(): IModel {
47    if (!WelcomeMod.instance) {
48      WelcomeMod.instance = new WelcomeMod();
49    }
50    return WelcomeMod.instance;
51  }
52
53  setVersionTag(version: string) {
54    this.versionTag = version;
55  }
56
57  setServiceId(id: string) {
58    this.serviceId = id;
59  }
60
61  setGenType(value: string) {
62    this.genType = value;
63  }
64
65  init(uri: vscode.Uri): void {
66    this.uri = uri;
67  }
68
69  async doStart(): Promise<void> {
70    try {
71      if (this.uri) {
72        switch (this.genType) {
73          case NAPI_FRAMEWORK:
74            {
75              let dts2cppmod = Dts2cppMod.getInstance() as Dts2cppMod;
76              dts2cppmod.init(this.uri);
77              dts2cppmod.callbacks = this.callbacks;
78              dts2cppmod.doStart();
79            }
80            // generateDtscpp(this.uri.fsPath);
81            break;
82          case SA_FRAMEWORK:
83            {
84              let samod = H2saMod.getInstance() as H2saMod;
85              samod.init(this.uri);
86              samod.callbacks = this.callbacks;
87              samod.setServiceId(this.serviceId);
88              samod.setVersionTag(this.versionTag);
89              samod.doStart();
90            }
91            // generateSa(this.uri.fsPath, this.versionTag, this.serviceId);
92            break;
93          case HDF_FRAMEWORK:
94            let hdfmod = H2hdfMod.getInstance() as H2hdfMod;
95              hdfmod.init(this.uri);
96              hdfmod.callbacks = this.callbacks;
97              hdfmod.setServiceId(this.serviceId);
98              hdfmod.setVersionTag(this.versionTag);
99              hdfmod.doStart();
100            // generateHdf(this.uri.fsPath, this.versionTag);
101            break;
102          default:
103            Logger.getInstance().error('unknown gen type: ' + this.genType);
104            break;
105        }
106      } else {
107        Logger.getInstance().error('parse header file error with undefine uri.');
108      }
109    } catch (e) {
110      let errmsg = 'parse header file error: ' + JSON.stringify(e);
111      Logger.getInstance().error(errmsg);
112      this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
113    }
114  }
115
116  async doStop(): Promise<void> {
117    throw new Error("Method not implemented.");
118  }
119
120  async doPause(): Promise<void> {
121    throw new Error("Method not implemented.");
122  }
123
124  async doResume(): Promise<void> {
125    throw new Error("Method not implemented.");
126  }
127}