1 /*
2 * Copyright (c) 2023 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
16 #include "intell_voice_engine_callback_stub.h"
17 #include "intell_voice_log.h"
18
19 #define LOG_TAG "IntellVoiceEngineCallbackStub"
20
21 using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
22
23 namespace OHOS {
24 namespace IntellVoiceEngine {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int IntellVoiceEngineCallbackStub::OnRemoteRequest(
26 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
27 {
28 INTELL_VOICE_LOG_INFO("OnRemoteRequest");
29 if (data.ReadInterfaceToken() != IIntelligentVoiceEngineCallback::GetDescriptor()) {
30 INTELL_VOICE_LOG_ERROR("ReadInterfaceToken failed");
31 return -1;
32 }
33 IIntelligentVoiceEngineCallback::Code msgCode = static_cast<IIntelligentVoiceEngineCallback::Code>(code);
34 switch (msgCode) {
35 case ON_INTELL_VOICE_ENGINE_EVENT: {
36 OnIntellVoiceEngineEventInner(data);
37 reply.WriteInt32(0);
38 break;
39 }
40 default: {
41 INTELL_VOICE_LOG_WARN("invalid msgCode:%{public}d", msgCode);
42 reply.WriteInt32(-1);
43 break;
44 }
45 }
46 return 0;
47 }
48
OnIntellVoiceEngineEventInner(MessageParcel & data)49 void IntellVoiceEngineCallbackStub::OnIntellVoiceEngineEventInner(MessageParcel &data)
50 {
51 IntellVoiceEngineCallBackEvent event = {
52 .msgId = static_cast<IntellVoiceEngineMessageType>(data.ReadInt32()),
53 .result = static_cast<IntellVoiceEngineErrors>(data.ReadInt32()),
54 .info = data.ReadString(),
55 };
56 OnIntellVoiceEngineEvent(event);
57 }
58 }
59 }