• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 
16 #include "multimodal_input_connect_proxy.h"
17 #include "message_option.h"
18 #include "mmi_log.h"
19 #include "multimodal_input_connect_def_parcel.h"
20 #include "multimodal_input_connect_define.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "MultimodalInputConnectProxy" };
27 }
28 
29 // 获取其他设备注册的SA的Proxy
MultimodalInputConnectProxy(const sptr<IRemoteObject> & impl)30 MultimodalInputConnectProxy::MultimodalInputConnectProxy(const sptr<IRemoteObject> &impl) :
31     IRemoteProxy<IMultimodalInputConnect>(impl)
32 {
33     MMI_LOGI("MultimodalInputConnectProxy()");
34 }
35 
~MultimodalInputConnectProxy()36 MultimodalInputConnectProxy::~MultimodalInputConnectProxy()
37 {
38     MMI_LOGI("~MultimodalInputConnectProxy()");
39 }
40 
AllocSocketFd(const std::string & programName,const int32_t moduleType,int32_t & socketFd)41 int32_t MultimodalInputConnectProxy::AllocSocketFd(const std::string &programName,
42     const int32_t moduleType, int32_t &socketFd)
43 {
44     MMI_LOGD("enter");
45     MessageParcel data;
46     MessageParcel reply;
47     MessageOption option; // (MessageOption::TF_ASYNC);
48 
49     if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) {
50         MMI_LOGE("Failed to write descriptor");
51         return ERR_INVALID_VALUE;
52     }
53 
54     ConnectReqParcel req;
55     req.data.moduleId = moduleType;
56     req.data.clientName = programName;
57     if (!data.WriteParcelable(&req)) {
58         MMI_LOGE("Failed to write programName");
59         return ERR_INVALID_VALUE;
60     }
61 
62     int32_t requestResult = Remote()->SendRequest(ALLOC_SOCKET_FD, data, reply, option);
63     if (requestResult != NO_ERROR) {
64         MMI_LOGE("send request fail, result:%{public}d", requestResult);
65         return RET_ERR;
66     }
67 
68     MMI_LOGD("have recieve message from server");
69 
70     int32_t result = reply.ReadInt32();
71     MMI_LOGD("result:%{public}d", result);
72     if (result != RET_OK) {
73         MMI_LOGE("responce return error:%{public}d", result);
74         return RET_ERR;
75     }
76     socketFd = reply.ReadFileDescriptor();
77     MMI_LOGD("socketFd:%{public}d", socketFd);
78     MMI_LOGD("leave");
79     return RET_OK;
80 }
81 
AddInputEventFilter(sptr<IEventFilter> filter)82 int32_t MultimodalInputConnectProxy::AddInputEventFilter(sptr<IEventFilter> filter)
83 {
84     MMI_LOGD("enter");
85     MessageParcel data;
86     MessageParcel reply;
87     MessageOption option;
88 
89     if (!data.WriteInterfaceToken(MultimodalInputConnectProxy::GetDescriptor())) {
90         MMI_LOGE("Failed to write descriptor");
91         return ERR_INVALID_VALUE;
92     }
93 
94     if (!data.WriteRemoteObject(filter->AsObject().GetRefPtr())) {
95         MMI_LOGE("Failed to write filter");
96         return ERR_INVALID_VALUE;
97     }
98 
99     int32_t requestResult = Remote()->SendRequest(SET_EVENT_POINTER_FILTER, data, reply, option);
100     if (requestResult != NO_ERROR) {
101         MMI_LOGE("send request fail, result:%{public}d", requestResult);
102         return RET_ERR;
103     }
104 
105     int32_t result = reply.ReadInt32();
106     if (result != RET_OK) {
107         MMI_LOGE("responce return error:%{public}d", result);
108     }
109     MMI_LOGD("leave");
110     return result;
111 }
112 } // namespace MMI
113 } // namespace OHOS
114