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_stub.h"
17
18 #include <iremote_proxy.h>
19
20 namespace OHOS {
21 namespace Rosen {
22 class RSConnectionTokenProxy : public IRemoteProxy<RSIConnectionToken> {
23 public:
RSConnectionTokenProxy(const sptr<IRemoteObject> & impl)24 explicit RSConnectionTokenProxy(const sptr<IRemoteObject>& impl)
25 : IRemoteProxy<RSIConnectionToken>(impl) {}
26 virtual ~RSConnectionTokenProxy() noexcept = default;
27
28 private:
29 static inline BrokerDelegator<RSConnectionTokenProxy> delegator_;
30 };
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int RSRenderServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
33 {
34 int ret = ERR_NONE;
35 switch (code) {
36 case CREATE_CONNECTION: {
37 auto interfaceToken = data.ReadInterfaceToken();
38 if (interfaceToken != RSIRenderService::GetDescriptor()) {
39 ret = ERR_INVALID_STATE;
40 break;
41 }
42
43 auto remoteObj = data.ReadRemoteObject();
44 if (remoteObj == nullptr) {
45 ret = ERR_NULL_OBJECT;
46 break;
47 }
48
49 if (!remoteObj->IsProxyObject()) {
50 ret = ERR_UNKNOWN_OBJECT;
51 break;
52 }
53
54 auto token = iface_cast<RSIConnectionToken>(remoteObj);
55 auto newConn = CreateConnection(token);
56 reply.WriteRemoteObject(newConn->AsObject());
57 break;
58 }
59 default: {
60 ret = ERR_UNKNOWN_TRANSACTION;
61 break;
62 }
63 }
64
65 return ret;
66 }
67 } // namespace Rosen
68 } // namespace OHOS
69