• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device 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 ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility'
17import IdlWeatherServiceStub from '../MainAbility/data/IIdlWeatherServiceTS/idl_weather_service_stub'
18import { updateWeatherCallback } from "../MainAbility/data/IIdlWeatherServiceTS/i_idl_weather_service"
19import { getUpdateTemperature } from '../mock/RequestData'
20import Logger from '../util/Logger'
21
22class WeatherServiceStub extends IdlWeatherServiceStub {
23  constructor(des) {
24    super(des)
25  }
26
27  updateWeather(data: number, callback: updateWeatherCallback): void {
28    let temperature = getUpdateTemperature()
29    callback(0, temperature)
30    Logger.info(`testIntTransaction: temperature: ${temperature}`)
31  }
32}
33
34export default class ServiceExtAbility extends ServiceExtension {
35  onCreate(want) {
36    Logger.info(`onCreate, want: ${want.abilityName}`)
37  }
38
39  onRequest(want, startId) {
40    Logger.info(`onRequest, want: ${want.abilityName}`)
41  }
42
43  onConnect(want) {
44    Logger.info(`onConnect , want: ${want.abilityName}`)
45    return new WeatherServiceStub("weather service stub")
46  }
47
48  onDisconnect(want) {
49    Logger.info(`onDisconnect, want: ${want.abilityName}`)
50  }
51
52  onDestroy() {
53    Logger.info(`onDestroy`)
54  }
55}