mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-30 11:11:06 +00:00
Modified gn file and add new cooperate file
Signed-off-by: baoshubei <baoshubei@huawei.com> Change-Id: I6db5058e098928e6c015f2e9e0b87d0272493b23
This commit is contained in:
parent
a68432dc6c
commit
0ea09c6127
4
BUILD.gn
4
BUILD.gn
@ -30,12 +30,12 @@ group("devicestatus_service_group") {
|
||||
|
||||
group("intention_group") {
|
||||
deps = [
|
||||
"${device_status_root_path}/intention/cooperate/server:intention_cooperate",
|
||||
"${device_status_root_path}/intention/data:cooperate_params",
|
||||
"${device_status_root_path}/intention/data:drag_params",
|
||||
"${device_status_root_path}/intention/drag/server:intention_drag",
|
||||
"${device_status_root_path}/intention/frameworks/client:intention_client",
|
||||
"${device_status_root_path}/intention/ipc:intention_ipc",
|
||||
"${device_status_root_path}/intention/plugins/cooperate:intention_cooperate",
|
||||
"${device_status_root_path}/intention/plugins/drag:intention_drag",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:plugin_manager",
|
||||
"${device_status_root_path}/intention/scheduler/task_scheduler:task_scheduler",
|
||||
"${device_status_root_path}/intention/scheduler/timer_manager:timer_manager",
|
||||
|
76
intention/cooperate/server/BUILD.gn
Executable file
76
intention/cooperate/server/BUILD.gn
Executable file
@ -0,0 +1,76 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("../../../device_status.gni")
|
||||
|
||||
config("cooperate_public_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("intention_cooperate") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${intention_root_path}/data/cooperate/include",
|
||||
"${intention_root_path}/data/include",
|
||||
"${intention_root_path}/interfaces/include",
|
||||
"${device_status_root_path}/utils/ipc/include",
|
||||
"${intention_root_path}/data/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/cooperate.cpp",
|
||||
"src/cooperate_manager.cpp",
|
||||
"src/cooperate_device_manager.cpp",
|
||||
"src/cooperate_event_handler.cpp",
|
||||
"src/cooperate_event_manager.cpp",
|
||||
"src/cooperate_sm.cpp",
|
||||
"src/cooperate_softbus_adapter.cpp",
|
||||
"src/cooperate_state_free.cpp",
|
||||
"src/cooperate_state_in.cpp",
|
||||
"src/cooperate_state_out.cpp",
|
||||
"src/cooperate_util.cpp",
|
||||
"src/device_profile_adapter.cpp",
|
||||
"src/distributed_input_adapter.cpp",
|
||||
"src/i_cooperate_state.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":cooperate_public_config" ]
|
||||
|
||||
defines = device_status_default_defines
|
||||
|
||||
deps = [
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"${device_status_utils_path}:devicestatus_util",
|
||||
"//third_party/cJSON:cjson",
|
||||
"//third_party/openssl:libcrypto_shared",
|
||||
"${intention_root_path}/data:cooperate_params",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"input:libmmi-client",
|
||||
"device_info_manager:distributed_device_profile_client",
|
||||
"device_manager:devicemanagersdk",
|
||||
"distributed_input:libdinput_sdk",
|
||||
"dsoftbus:softbus_client",
|
||||
"eventhandler:libeventhandler",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_single",
|
||||
"window_manager:libdm",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
part_name = "${device_status_part_name}"
|
||||
}
|
48
intention/cooperate/server/include/cooperate.h
Normal file
48
intention/cooperate/server/include/cooperate.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_H
|
||||
#define COOPERATE_H
|
||||
|
||||
#include "i_context.h"
|
||||
#include "i_plugin.h"
|
||||
#include "cooperate_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class Cooperate : public IPlugin {
|
||||
public:
|
||||
Cooperate(IContext *context);
|
||||
virtual ~Cooperate() = default;
|
||||
|
||||
int32_t Enable(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Disable(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Start(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t Stop(CallingContext &context, Parcel &data, Parcel &reply);
|
||||
int32_t AddWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t RemoveWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t SetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t GetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
int32_t Control(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply);
|
||||
|
||||
private:
|
||||
IContext *context_ { nullptr };
|
||||
CooperateManager cooperateMgr_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_H
|
217
intention/cooperate/server/include/cooperate_sm.h
Normal file
217
intention/cooperate/server/include/cooperate_sm.h
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef COOPERATE_SM_H
|
||||
#define COOPERATE_SM_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "singleton.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "device_manager_callback.h"
|
||||
#include "distributed_input_adapter.h"
|
||||
#include "dm_device_info.h"
|
||||
#include "input_manager.h"
|
||||
#include "i_cooperate_state.h"
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "i_input_event_filter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
static constexpr int32_t SUBSTR_NETWORKID_LEN = 6;
|
||||
enum class CooperateState {
|
||||
STATE_FREE = 0,
|
||||
STATE_IN = 1,
|
||||
STATE_OUT = 2
|
||||
};
|
||||
|
||||
enum class CooperateMsg {
|
||||
COOPERATE_ON_SUCCESS = 0,
|
||||
COOPERATE_ON_FAIL = 1,
|
||||
COOPERATE_OFF_SUCCESS = 2,
|
||||
COOPERATE_OFF_FAIL = 3,
|
||||
COOPERATE_START = 4,
|
||||
COOPERATE_START_SUCCESS = 5,
|
||||
COOPERATE_START_FAIL = 6,
|
||||
COOPERATE_STOP = 7,
|
||||
COOPERATE_STOP_SUCCESS = 8,
|
||||
COOPERATE_STOP_FAIL = 9,
|
||||
COOPERATE_NULL = 10
|
||||
};
|
||||
|
||||
enum class CooStateChangeType {
|
||||
STATE_NONE = -1,
|
||||
STATE_FREE_TO_IN = 0,
|
||||
STATE_FREE_TO_OUT = 1,
|
||||
STATE_IN_TO_FREE = 2,
|
||||
STATE_OUT_TO_FREE = 3
|
||||
};
|
||||
|
||||
struct PointerFilter : public MMI::IInputEventFilter {
|
||||
bool OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inline void UpdateCurrentFilterId(int32_t filterId)
|
||||
{
|
||||
filterId_ = filterId;
|
||||
}
|
||||
bool OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
private:
|
||||
mutable int32_t filterId_ { -1 };
|
||||
};
|
||||
|
||||
class CooperateSM final {
|
||||
DECLARE_DELAYED_SINGLETON(CooperateSM);
|
||||
|
||||
class DeviceInitCallBack : public DistributedHardware::DmInitCallback {
|
||||
void OnRemoteDied() override;
|
||||
};
|
||||
|
||||
class DmDeviceStateCallback : public DistributedHardware::DeviceStateCallback {
|
||||
void OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) override;
|
||||
void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override;
|
||||
void OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) override;
|
||||
void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) override;
|
||||
};
|
||||
|
||||
class InterceptorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
};
|
||||
|
||||
class MonitorConsumer : public MMI::IInputEventConsumer {
|
||||
public:
|
||||
explicit MonitorConsumer(std::function<void (std::shared_ptr<MMI::PointerEvent>)> cb) : callback_(cb) {}
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
private:
|
||||
std::function<void (std::shared_ptr<MMI::PointerEvent>)> callback_ { nullptr };
|
||||
};
|
||||
|
||||
public:
|
||||
void SetAbsolutionLocation(double xPercent, double yPercent);
|
||||
DISALLOW_COPY_AND_MOVE(CooperateSM);
|
||||
void Init();
|
||||
void OnSessionLost(SessionPtr session);
|
||||
void PrepareCooperate();
|
||||
void UnprepareCooperate();
|
||||
int32_t ActivateCooperate(const std::string &remoteNetworkId, int32_t startDeviceId);
|
||||
int32_t DeactivateCooperate(bool isUnchained);
|
||||
int32_t GetCooperateState(const std::string &deviceId);
|
||||
void StartRemoteCooperate(const std::string &remoteNetworkId, bool buttonIsPressed);
|
||||
void StartPointerEventFilter();
|
||||
void StartRemoteCooperateResult(bool isSuccess,
|
||||
const std::string &startDeviceDhid, int32_t xPercent, int32_t yPercent);
|
||||
void StopRemoteCooperate(bool isUnchained);
|
||||
void StopRemoteCooperateResult(bool isSuccess);
|
||||
void StartCooperateOtherResult(const std::string &remoteNetworkId);
|
||||
void UpdateState(CooperateState state);
|
||||
void UpdatePreparedDevices(const std::string &remoteNetworkId, const std::string &originNetworkId);
|
||||
std::pair<std::string, std::string> GetPreparedDevices() const;
|
||||
CooperateState GetCurrentCooperateState() const;
|
||||
void OnCooperateChanged(const std::string &networkId, bool isOpen);
|
||||
void OnKeyboardOnline(const std::string &dhid);
|
||||
void OnPointerOffline(const std::string &dhid, const std::vector<std::string> &keyboards);
|
||||
void OnKeyboardOffline(const std::string &dhid);
|
||||
bool InitDeviceManager();
|
||||
void OnDeviceOnline(const std::string &networkId);
|
||||
void OnDeviceOffline(const std::string &networkId);
|
||||
void OnStartFinish(bool isSuccess, const std::string &remoteNetworkId, int32_t startDeviceId);
|
||||
void OnStopFinish(bool isSuccess, const std::string &remoteNetworkId);
|
||||
bool IsStarting() const;
|
||||
bool IsStopping() const;
|
||||
void Reset(const std::string &networkId);
|
||||
void Dump(int32_t fd);
|
||||
std::string GetDeviceCooperateState(CooperateState value) const;
|
||||
void UpdateLastPointerEventCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
std::shared_ptr<MMI::PointerEvent> GetLastPointerEvent() const;
|
||||
void RemoveMonitor();
|
||||
void RemoveInterceptor();
|
||||
bool IsNeedFilterOut(const std::string &deviceId, const std::shared_ptr<MMI::KeyEvent> keyEvent);
|
||||
void RegisterStateChange(CooStateChangeType type,
|
||||
std::function<void(CooperateState, CooperateState)> callback);
|
||||
bool UnchainCooperate(const std::string &localNetworkId, const std::string &remoteNetworkId);
|
||||
void SetUnchainStatus(bool isUnchained);
|
||||
void NotifyChainRemoved();
|
||||
void NotifyUnchainedResult(const std::string &remoteNetworkId, bool isSuccess);
|
||||
void SetSinkNetworkId(const std::string &sinkNetworkId);
|
||||
void RegisterRemoteNetworkId(std::function<void(std::string)> callback);
|
||||
void RegisterMouseLocation(std::function<void(int32_t, int32_t)> callback);
|
||||
void RegisterNotifyDragCancel(std::function<void(void)> callback);
|
||||
void OnInterceptorInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
|
||||
void OnInterceptorInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
void OnMonitorInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
void OnSoftbusSessionClosed(const std::string &NetworkId);
|
||||
|
||||
private:
|
||||
void Reset(bool adjustAbsolutionLocation = false);
|
||||
void OnCloseCooperate(const std::string &networkId, bool isLocal);
|
||||
void NotifyRemoteStartFail(const std::string &remoteNetworkId);
|
||||
void NotifyRemoteStartSuccess(const std::string &remoteNetworkId, const std::string &startDeviceDhid);
|
||||
void NotifyRemoteStopFinish(bool isSuccess, const std::string &remoteNetworkId);
|
||||
bool UpdateMouseLocation();
|
||||
void StateChangedNotify(CooperateState oldState, CooperateState newState);
|
||||
void ChangeNotify(CooStateChangeType type, CooperateState oldState, CooperateState newState);
|
||||
void NotifyRemoteNetworkId(const std::string &remoteNetworkId);
|
||||
void NotifyMouseLocation(int32_t x, int32_t y);
|
||||
void SetPointerVisible();
|
||||
void OnPostInterceptorKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
|
||||
void OnPostInterceptorPointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
void OnPostMonitorInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
|
||||
void OnReset(const std::string &NetworkId);
|
||||
std::shared_ptr<ICooperateState> GetCurrentState();
|
||||
void RegisterSessionCallback();
|
||||
|
||||
private:
|
||||
std::pair<std::string, std::string> preparedNetworkId_;
|
||||
std::string startDeviceDhid_;
|
||||
std::string remoteNetworkId_;
|
||||
std::string sinkNetworkId_;
|
||||
bool isUnchained_ { false };
|
||||
CooperateState currentState_ { CooperateState::STATE_FREE };
|
||||
std::shared_ptr<DistributedHardware::DmInitCallback> initCallback_ { nullptr };
|
||||
std::shared_ptr<DistributedHardware::DeviceStateCallback> stateCallback_ { nullptr };
|
||||
std::vector<std::string> onlineDevice_;
|
||||
mutable std::mutex mutex_;
|
||||
std::atomic<bool> isStarting_ { false };
|
||||
std::atomic<bool> isStopping_ { false };
|
||||
std::pair<int32_t, int32_t> mouseLocation_ { std::make_pair(0, 0) };
|
||||
std::shared_ptr<MMI::PointerEvent> lastPointerEvent_ { nullptr };
|
||||
int32_t displayX_ { -1 };
|
||||
int32_t displayY_ { -1 };
|
||||
int32_t interceptorId_ { -1 };
|
||||
int32_t monitorId_ { -1 };
|
||||
int32_t filterId_ { -1 };
|
||||
std::map<CooStateChangeType, std::function<void(CooperateState, CooperateState)>> stateChangedCallbacks_;
|
||||
std::function<void(std::string)> remoteNetworkIdCallback_;
|
||||
std::function<void(int32_t, int32_t)> mouseLocationCallback_;
|
||||
std::function<void(void)> notifyDragCancelCallback_;
|
||||
std::map<CooperateState, std::shared_ptr<ICooperateState>> cooperateStates_;
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner_ { nullptr };
|
||||
std::shared_ptr<CooperateEventHandler> eventHandler_ { nullptr };
|
||||
};
|
||||
|
||||
#define DIS_HARDWARE DistributedHardware::DeviceManager::GetInstance()
|
||||
#define COOR_SM OHOS::DelayedSingleton<CooperateSM>::GetInstance()
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_SM_H
|
132
intention/cooperate/server/src/cooperate.cpp
Normal file
132
intention/cooperate/server/src/cooperate.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "cooperate.h"
|
||||
|
||||
#include "cooperate_params.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "Cooperate" };
|
||||
} // namespace
|
||||
|
||||
Cooperate::Cooperate(IContext *context)
|
||||
: context_(context)
|
||||
{}
|
||||
|
||||
int32_t Cooperate::Enable(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
{
|
||||
cooperateMgr_.PrepareCooperate();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Disable(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
{
|
||||
cooperateMgr_.UnprepareCooperate();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Start(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
{
|
||||
CHKPR(context_, RET_ERR);
|
||||
StartCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.ActivateCooperate(context.session, param.userData, param.remoteNetworkId, param.startDeviceId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Activate cooperate failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Stop(CallingContext &context, Parcel &data, Parcel &reply)
|
||||
{
|
||||
StopCooperateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.DeactivateCooperate(context.session, param.userData, param.isUnchained);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Deactivate cooperate failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::AddWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
int32_t ret = cooperateMgr_.RegisterCooperateListener(context.session);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Register cooperate listener failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::RemoveWatch(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
int32_t ret = cooperateMgr_.UnregisterCooperateListener(context.session);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Unregister cooperate listener failed, ret:%{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::SetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t Cooperate::GetParam(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
GetCooperateStateParam param;
|
||||
if (!param.Unmarshalling(data)) {
|
||||
FI_HILOGE("Failed to unmarshalling param");
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t ret = cooperateMgr_.GetCooperateState(context.session, param.userData, param.deviceId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Get cooperate state failed");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Control(CallingContext &context, uint32_t id, Parcel &data, Parcel &reply)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
extern "C" IPlugin* CreateInstance(IContext *context)
|
||||
{
|
||||
CHKPP(context);
|
||||
return new (std::nothrow) Cooperate(context);
|
||||
}
|
||||
|
||||
extern "C" void DestroyInstance(IPlugin *instance)
|
||||
{
|
||||
if (instance != nullptr) {
|
||||
delete instance;
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
1181
intention/cooperate/server/src/cooperate_sm.cpp
Normal file
1181
intention/cooperate/server/src/cooperate_sm.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,7 @@
|
||||
#include "i_plugin_manager.h"
|
||||
#include "i_task_scheduler.h"
|
||||
#include "i_timer_manager.h"
|
||||
#include "i_device_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -31,6 +32,7 @@ public:
|
||||
virtual ITaskScheduler& GetTaskScheduler() = 0;
|
||||
virtual ITimerManager& GetTimerManager() = 0;
|
||||
virtual IPluginManager& GetPluginManager() = 0;
|
||||
virtual IDeviceManager& GetDeviceManager() = 0;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
63
intention/data/include/i_device.h
Normal file
63
intention/data/include/i_device.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_DEVICE_H
|
||||
#define I_DEVICE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IDevice {
|
||||
public:
|
||||
enum KeyboardType {
|
||||
KEYBOARD_TYPE_NONE,
|
||||
KEYBOARD_TYPE_UNKNOWN,
|
||||
KEYBOARD_TYPE_ALPHABETICKEYBOARD,
|
||||
KEYBOARD_TYPE_DIGITALKEYBOARD,
|
||||
KEYBOARD_TYPE_HANDWRITINGPEN,
|
||||
KEYBOARD_TYPE_REMOTECONTROL,
|
||||
KEYBOARD_TYPE_MAX
|
||||
};
|
||||
|
||||
public:
|
||||
IDevice() = default;
|
||||
virtual ~IDevice() = default;
|
||||
|
||||
virtual int32_t Open() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void SetDevPath(const std::string &devPath) = 0;
|
||||
virtual void SetSysPath(const std::string &sysPath) = 0;
|
||||
|
||||
virtual int32_t GetId() const = 0;
|
||||
virtual std::string GetDevPath() const = 0;
|
||||
virtual std::string GetSysPath() const = 0;
|
||||
virtual std::string GetName() const = 0;
|
||||
virtual int32_t GetBus() const = 0;
|
||||
virtual int32_t GetVersion() const = 0;
|
||||
virtual int32_t GetProduct() const = 0;
|
||||
virtual int32_t GetVendor() const = 0;
|
||||
virtual std::string GetPhys() const = 0;
|
||||
virtual std::string GetUniq() const = 0;
|
||||
virtual KeyboardType GetKeyboardType() const = 0;
|
||||
virtual bool IsPointerDevice() const = 0;
|
||||
virtual bool IsKeyboard() const = 0;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // I_DEVICE_H
|
41
intention/data/include/i_device_manager.h
Normal file
41
intention/data/include/i_device_manager.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_DEVICE_MANAGER_H
|
||||
#define I_DEVICE_MANAGER_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "i_device.h"
|
||||
#include "i_device_observer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IDeviceManager {
|
||||
public:
|
||||
IDeviceManager() = default;
|
||||
virtual ~IDeviceManager() = default;
|
||||
virtual std::shared_ptr<IDevice> GetDevice(int32_t id) const = 0;
|
||||
virtual int32_t AddDeviceObserver(std::weak_ptr<IDeviceObserver> observer) = 0;
|
||||
virtual void RemoveDeviceObserver(std::weak_ptr<IDeviceObserver> observer) = 0;
|
||||
virtual void RetriggerHotplug(std::weak_ptr<IDeviceObserver> observer) = 0;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // I_DEVICE_MANAGER_H
|
47
intention/data/include/i_device_observer.h
Normal file
47
intention/data/include/i_device_observer.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_DEVICE_OBSERVER_H
|
||||
#define I_DEVICE_OBSERVER_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "i_device.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IDeviceObserver {
|
||||
public:
|
||||
IDeviceObserver() = default;
|
||||
virtual ~IDeviceObserver() = default;
|
||||
|
||||
virtual void OnDeviceAdded(std::shared_ptr<IDevice>) = 0;
|
||||
virtual void OnDeviceRemoved(std::shared_ptr<IDevice>) = 0;
|
||||
};
|
||||
|
||||
inline bool operator<(std::weak_ptr<IDeviceObserver> ptr1, std::weak_ptr<IDeviceObserver> ptr2)
|
||||
{
|
||||
return (ptr1.lock() < ptr2.lock());
|
||||
}
|
||||
|
||||
inline bool operator==(const std::weak_ptr<IDeviceObserver> ptr1, std::nullptr_t) noexcept
|
||||
{
|
||||
return (ptr1.lock() == nullptr);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // I_DEVICE_OBSERVER_H
|
35
intention/data/include/i_epoll_event_source.h
Normal file
35
intention/data/include/i_epoll_event_source.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef I_EPOLL_EVENT_SOURCE_H
|
||||
#define I_EPOLL_EVENT_SOURCE_H
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IEpollEventSource {
|
||||
public:
|
||||
IEpollEventSource() = default;
|
||||
virtual ~IEpollEventSource() = default;
|
||||
|
||||
virtual int32_t GetFd() const = 0;
|
||||
virtual void Dispatch(const struct epoll_event &ev) = 0;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // I_EPOLL_EVENT_SOURCE_H
|
@ -22,7 +22,7 @@
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
inline constexpr std::string_view COOPERATE { "cooperate" };
|
||||
inline constexpr std::string_view COOPERATE_NAME { "cooperate" };
|
||||
inline constexpr std::string_view DRAG_TYPE { "drag" };
|
||||
inline const std::string DEV_INPUT_PATH { "/dev/input/" };
|
||||
inline constexpr std::string_view CALL_FUNCTION { "napi_call_function" };
|
||||
|
Loading…
Reference in New Issue
Block a user