• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "input_device_cooperate_state_free.h"
17 
18 #include "device_cooperate_softbus_adapter.h"
19 #include "input_device_cooperate_sm.h"
20 #include "input_device_cooperate_util.h"
21 
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceCooperateStateFree"};
26 } // namespace
27 
StartInputDeviceCooperate(const std::string & remoteNetworkId,int32_t startInputDeviceId)28 int32_t InputDeviceCooperateStateFree::StartInputDeviceCooperate(
29     const std::string &remoteNetworkId, int32_t startInputDeviceId)
30 {
31     CALL_INFO_TRACE;
32     if (remoteNetworkId.empty()) {
33         MMI_HILOGE("RemoteNetworkId is empty");
34         return static_cast<int32_t>(CooperationMessage::COOPERATION_DEVICE_ERROR);
35     }
36     std::string localNetworkId = GetLocalDeviceId();
37     if (localNetworkId.empty() || remoteNetworkId == localNetworkId) {
38         MMI_HILOGE("Input Parameters error");
39         return static_cast<int32_t>(CooperationMessage::COOPERATION_DEVICE_ERROR);
40     }
41     int32_t ret = DevCooperateSoftbusAdapter->StartRemoteCooperate(localNetworkId, remoteNetworkId);
42     if (ret != RET_OK) {
43         MMI_HILOGE("Start input device cooperate fail");
44         return static_cast<int32_t>(CooperationMessage::COOPERATE_FAIL);
45     }
46     std::string taskName = "process_start_task";
47     std::function<void()> handleProcessStartFunc =
48         std::bind(&InputDeviceCooperateStateFree::ProcessStart, this, remoteNetworkId, startInputDeviceId);
49     CHKPR(eventHandler_, RET_ERR);
50     eventHandler_->ProxyPostTask(handleProcessStartFunc, taskName, 0);
51     return RET_OK;
52 }
53 
ProcessStart(const std::string & remoteNetworkId,int32_t startInputDeviceId)54 int32_t InputDeviceCooperateStateFree::ProcessStart(const std::string &remoteNetworkId, int32_t startInputDeviceId)
55 {
56     CALL_DEBUG_ENTER;
57     return PrepareAndStart(remoteNetworkId, startInputDeviceId);
58 }
59 } // namespace MMI
60 } // namespace OHOS
61