• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cooperate_server.h"
17 
18 #include "cooperate_params.h"
19 #include "devicestatus_define.h"
20 
21 namespace OHOS {
22 namespace Msdp {
23 namespace DeviceStatus {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateServer" };
26 } // namespace
27 
CooperateServer(IContext * context)28 CooperateServer::CooperateServer(IContext *context)
29     : context_(context)
30 {}
31 
Enable(CallingContext & context,MessageParcel & data,MessageParcel & reply)32 int32_t CooperateServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
33 {
34     CALL_DEBUG_ENTER;
35     CHKPR(context_, RET_ERR);
36     ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
37     CHKPR(cooperate, RET_ERR);
38     cooperate->Enable(context.pid);
39     return RET_OK;
40 }
41 
Disable(CallingContext & context,MessageParcel & data,MessageParcel & reply)42 int32_t CooperateServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply)
43 {
44     CALL_DEBUG_ENTER;
45     CHKPR(context_, RET_ERR);
46     ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
47     CHKPR(cooperate, RET_ERR);
48     cooperate->Disable(context.pid);
49     context_->GetPluginManager().UnloadCooperate();
50     return RET_OK;
51 }
52 
Start(CallingContext & context,MessageParcel & data,MessageParcel & reply)53 int32_t CooperateServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply)
54 {
55     CALL_DEBUG_ENTER;
56     StartCooperateParam param;
57     if (!param.Unmarshalling(data)) {
58         FI_HILOGE("StartCooperateParam::Unmarshalling fail");
59         return RET_ERR;
60     }
61     CHKPR(context_, RET_ERR);
62     ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
63     CHKPR(cooperate, RET_ERR);
64     return cooperate->Start(context.pid, param.userData, param.remoteNetworkId, param.startDeviceId);
65 }
66 
Stop(CallingContext & context,MessageParcel & data,MessageParcel & reply)67 int32_t CooperateServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply)
68 {
69     CALL_DEBUG_ENTER;
70     StopCooperateParam param;
71     if (!param.Unmarshalling(data)) {
72         FI_HILOGE("StopCooperateParam::Unmarshalling fail");
73         return RET_ERR;
74     }
75     CHKPR(context_, RET_ERR);
76     ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
77     CHKPR(cooperate, RET_ERR);
78     return cooperate->Stop(context.pid, param.userData, param.isUnchained);
79 }
80 
AddWatch(CallingContext & context,uint32_t id,MessageParcel & data,MessageParcel & reply)81 int32_t CooperateServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
82 {
83     CALL_DEBUG_ENTER;
84     switch (id) {
85         case CooperateRequestID::REGISTER_LISTENER: {
86             CHKPR(context_, RET_ERR);
87             ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
88             CHKPR(cooperate, RET_ERR);
89             return cooperate->RegisterListener(context.pid);
90         }
91         case CooperateRequestID::REGISTER_HOTAREA_LISTENER: {
92             CHKPR(context_, RET_ERR);
93             ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
94             CHKPR(cooperate, RET_ERR);
95             return cooperate->RegisterHotAreaListener(context.pid);
96         }
97         default: {
98             FI_HILOGE("Unexpected request ID (%{public}u)", id);
99             return RET_ERR;
100         }
101     }
102 }
103 
RemoveWatch(CallingContext & context,uint32_t id,MessageParcel & data,MessageParcel & reply)104 int32_t CooperateServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
105 {
106     CALL_DEBUG_ENTER;
107     switch (id) {
108         case CooperateRequestID::UNREGISTER_LISTENER: {
109             CHKPR(context_, RET_ERR);
110             ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
111             CHKPR(cooperate, RET_ERR);
112             return cooperate->UnregisterListener(context.pid);
113         }
114         case CooperateRequestID::UNREGISTER_HOTAREA_LISTENER: {
115             CHKPR(context_, RET_ERR);
116             ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
117             CHKPR(cooperate, RET_ERR);
118             return cooperate->UnregisterHotAreaListener(context.pid);
119         }
120         default: {
121             FI_HILOGE("Unexpected request ID (%{public}u)", id);
122             return RET_ERR;
123         }
124     }
125 }
126 
SetParam(CallingContext & context,uint32_t id,MessageParcel & data,MessageParcel & reply)127 int32_t CooperateServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
128 {
129     CALL_DEBUG_ENTER;
130     return RET_ERR;
131 }
132 
GetParam(CallingContext & context,uint32_t id,MessageParcel & data,MessageParcel & reply)133 int32_t CooperateServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
134 {
135     CALL_DEBUG_ENTER;
136     switch (id) {
137         case CooperateRequestID::GET_COOPERATE_STATE: {
138             GetCooperateStateParam param;
139             if (!param.Unmarshalling(data)) {
140                 FI_HILOGE("GetCooperateStateParam::Unmarshalling fail");
141                 return RET_ERR;
142             }
143             CHKPR(context_, RET_ERR);
144             ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
145             CHKPR(cooperate, RET_ERR);
146             return cooperate->GetCooperateState(context.pid, param.userData, param.networkId);
147         }
148         default: {
149             FI_HILOGE("Unexpected request ID (%{public}u)", id);
150             return RET_ERR;
151         }
152     }
153 }
154 
Control(CallingContext & context,uint32_t id,MessageParcel & data,MessageParcel & reply)155 int32_t CooperateServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
156 {
157     CALL_DEBUG_ENTER;
158     return RET_ERR;
159 }
160 } // namespace DeviceStatus
161 } // namespace Msdp
162 } // namespace OHOS