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_service_proxy.h"
17 #include "intell_voice_log.h"
18
19 #define LOG_TAG "IntellVoiceServiceProxy"
20 namespace OHOS {
21 namespace IntellVoiceEngine {
CreateIntellVoiceEngine(IntellVoiceEngineType type,sptr<IIntellVoiceEngine> & inst)22 int32_t IntellVoiceServiceProxy::CreateIntellVoiceEngine(IntellVoiceEngineType type, sptr<IIntellVoiceEngine> &inst)
23 {
24 MessageParcel data;
25 MessageParcel reply;
26 MessageOption option;
27
28 data.WriteInterfaceToken(IIntellVoiceService::GetDescriptor());
29 data.WriteInt32(static_cast<int>(type));
30
31 Remote()->SendRequest(HDI_INTELL_VOICE_SERVICE_CREATE_ENGINE, data, reply, option);
32
33 sptr<IRemoteObject> remote = reply.ReadRemoteObject();
34 if (remote == nullptr) {
35 INTELL_VOICE_LOG_ERROR("Create engine failed, engine is null");
36 return -1;
37 }
38 inst = iface_cast<IIntellVoiceEngine>(remote);
39
40 return 0;
41 }
42
ReleaseIntellVoiceEngine(IntellVoiceEngineType type)43 int32_t IntellVoiceServiceProxy::ReleaseIntellVoiceEngine(IntellVoiceEngineType type)
44 {
45 MessageParcel data;
46 MessageParcel reply;
47 MessageOption option;
48
49 data.WriteInterfaceToken(IIntellVoiceService::GetDescriptor());
50 data.WriteInt32(type);
51
52 Remote()->SendRequest(HDI_INTELL_VOICE_SERVICE_RELEASE_ENGINE, data, reply, option);
53 return reply.ReadInt32();
54 }
55 }
56 }
57