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_stub.h"
17 #include "securec.h"
18 #include "intell_voice_log.h"
19
20 #define LOG_TAG "IntellVoiceEngineStub"
21
22 namespace OHOS {
23 namespace IntellVoiceEngine {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)24 int32_t IntellVoiceEngineStub::OnRemoteRequest(uint32_t code,
25 MessageParcel &data, MessageParcel &reply, MessageOption &option)
26 {
27 if (data.ReadInterfaceToken() != IIntellVoiceEngine::GetDescriptor()) {
28 INTELL_VOICE_LOG_ERROR("token mismatch");
29 return -1;
30 }
31
32 int32_t ret = 0;
33
34 switch (code) {
35 case INTELL_VOICE_ENGINE_SET_CALLBACK:
36 object = data.ReadRemoteObject();
37 SetCallback(object);
38 break;
39 case INTELL_VOICE_ENGINE_ATTACH:
40 info.wakeupPhrase = data.ReadString();
41 info.isPcmFromExternal = data.ReadBool();
42 info.minBufSize = data.ReadInt32();
43 info.sampleChannels = data.ReadInt32();
44 info.bitsPerSample = data.ReadInt32();
45 info.sampleRate = data.ReadInt32();
46 ret = Attach(info);
47 break;
48 case INTELL_VOICE_ENGINE_DETACH:
49 ret = Detach();
50 break;
51 case INTELL_VOICE_ENGINE_SET_PARAMETER:
52 ret = SetParameter(data.ReadString());
53 break;
54 case INTELL_VOICE_ENGINE_GET_PARAMETER:
55 str = GetParameter(data.ReadString());
56 reply.WriteString(str);
57 break;
58 case INTELL_VOICE_ENGINE_START:
59 ret = Start(data.ReadBool());
60 break;
61 case INTELL_VOICE_ENGINE_STOP:
62 ret = Stop();
63 break;
64 case INTELL_VOICE_ENGINE_WRITE_AUDIO:
65 size = data.ReadInt32();
66 buffer = data.ReadBuffer(size);
67 ret = WriteAudio(buffer, size);
68 break;
69 default:
70 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
71 break;
72 }
73
74 return ret;
75 }
76 }
77 }