1 /*
2 * Copyright (c) 2021 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 "rs_render_service_proxy.h"
17
18 #include <message_option.h>
19 #include <message_parcel.h>
20 #include <platform/common/rs_log.h>
21
22 namespace OHOS {
23 namespace Rosen {
24
RSRenderServiceProxy(const sptr<IRemoteObject> & impl)25 RSRenderServiceProxy::RSRenderServiceProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<RSIRenderService>(impl) {}
26
CreateConnection(const sptr<RSIConnectionToken> & token)27 sptr<RSIRenderServiceConnection> RSRenderServiceProxy::CreateConnection(const sptr<RSIConnectionToken>& token)
28 {
29 if (token == nullptr) {
30 ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): token is null.");
31 return nullptr;
32 }
33
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option;
37 option.SetFlags(MessageOption::TF_SYNC);
38 if (!data.WriteInterfaceToken(RSIRenderService::GetDescriptor())) {
39 ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): WriteInterfaceToken failed.");
40 return nullptr;
41 }
42
43 data.WriteRemoteObject(token->AsObject());
44 uint32_t code = static_cast<uint32_t>(RSIRenderServiceInterfaceCode::CREATE_CONNECTION);
45 int32_t err = Remote()->SendRequest(code, data, reply, option);
46 if (err != NO_ERROR) {
47 ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): SendRequest failed, err is %{public}d.", err);
48 return nullptr;
49 }
50
51 auto remoteObj = reply.ReadRemoteObject();
52 if (remoteObj == nullptr || !remoteObj->IsProxyObject()) {
53 ROSEN_LOGE("RSRenderServiceProxy::CreateConnection(): Reply is not valid.");
54 return nullptr;
55 }
56
57 return iface_cast<RSIRenderServiceConnection>(remoteObj);
58 }
59 } // namespace Rosen
60 } // namespace OHOS
61