• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "domain_rpc_service_proxy.h"
17 #include "common/common_macro.h"
18 #include "common/sharing_log.h"
19 #include "ipc_msg_decoder.h"
20 #include "ipc_msg_encoder.h"
21 namespace OHOS {
22 namespace Sharing {
23 
DomainRpcServiceProxy(const sptr<IRemoteObject> & impl)24 DomainRpcServiceProxy::DomainRpcServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IDomainRpcService>(impl)
25 {
26     SHARING_LOGD("trace.");
27 }
28 
SetListenerObject(const sptr<IRemoteObject> & object)29 int32_t DomainRpcServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
30 {
31     SHARING_LOGD("trace.");
32     MessageParcel data;
33     MessageParcel reply;
34     MessageOption option;
35     RETURN_INVALID_IF_NULL(object);
36     (void)data.WriteRemoteObject(object);
37 
38     int error = Remote()->SendRequest(DomainServiceMsg::SET_LISTENER_OBJ, data, reply, option);
39     if (error != ERR_NONE) {
40         SHARING_LOGE("set listener object failed: %{public}d.", error);
41         return error;
42     }
43 
44     return reply.ReadInt32();
45 }
46 
GetSubSystemAbility(int32_t type)47 sptr<IRemoteObject> DomainRpcServiceProxy::GetSubSystemAbility(int32_t type)
48 {
49     SHARING_LOGD("trace.");
50     MessageParcel data;
51     MessageParcel reply;
52     MessageOption option;
53 
54     data.WriteInt32(type);
55 
56     int error = Remote()->SendRequest(DomainServiceMsg::GET_SUBSYSTEM, data, reply, option);
57     if (error != ERR_NONE) {
58         SHARING_LOGE("create sub proxy failed, error: %{public}d.", error);
59         return nullptr;
60     }
61 
62     return reply.ReadRemoteObject();
63 }
64 
DoRpcCommand(std::shared_ptr<BaseDomainMsg> msg,std::shared_ptr<BaseDomainMsg> replyMsg)65 int32_t DomainRpcServiceProxy::DoRpcCommand(std::shared_ptr<BaseDomainMsg> msg, std::shared_ptr<BaseDomainMsg> replyMsg)
66 {
67     SHARING_LOGD("trace.");
68     MessageParcel data;
69     MessageParcel reply;
70     MessageOption option = {MessageOption::TF_ASYNC, MessageOption::TF_WAIT_TIME};
71     IpcMsgEncoder::GetInstance().DomainMsgEncode(data, msg);
72 
73     int error = Remote()->SendRequest(DomainServiceMsg::DOMAIN_MSG, data, reply, option);
74     if (error != ERR_NONE) {
75         SHARING_LOGE("do ipc command failed %{public}d.", error);
76         return error;
77     }
78 
79     return reply.ReadInt32();
80 }
81 
82 } // namespace Sharing
83 } // namespace OHOS
84