• 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 rpc from '@ohos.rpc'
17import { updateWeatherCallback } from './i_idl_weather_service'
18import IIdlWeatherService from './i_idl_weather_service'
19import Logger from '../../../util/Logger'
20
21export default class IdlWeatherServiceProxy implements IIdlWeatherService {
22  constructor(proxy) {
23    this.proxy = proxy
24  }
25
26  updateWeather(data: number, callback: updateWeatherCallback): void {
27    let _option = new rpc.MessageOption(0)
28    let _data = new rpc.MessageParcel()
29    let _reply = new rpc.MessageParcel()
30    _data.writeInt(data)
31    this.proxy.sendRequest(IdlWeatherServiceProxy.COMMAND_UPDATE_WEATHER, _data, _reply, _option).then(function (result) {
32      if (result.errCode === 0) {
33        let _errCode = result.reply.readInt()
34        if (_errCode != 0) {
35          let _returnValue = undefined
36          callback(_errCode, _returnValue)
37          return
38        }
39        let _returnValue = result.reply.readInt()
40        callback(_errCode, _returnValue)
41      } else {
42        Logger.error("sendRequest failed, errCode: " + result.errCode)
43      }
44    })
45  }
46
47  static readonly COMMAND_UPDATE_WEATHER = 1
48  private proxy
49}
50
51