mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-27 09:41:43 +00:00
Merge branch 'master' of https://gitee.com/openharmony/msdp_device_status into dfx
Change-Id: I472242b049439e53e8a2b80db6dba7e61b546b80
This commit is contained in:
commit
831c756f01
@ -173,7 +173,7 @@ void CoordinationManagerImpl::OnCoordinationMessageEvent(int32_t userData,
|
||||
CHKPV(event);
|
||||
event(networkId, msg);
|
||||
FI_HILOGD("Coordination msg event callback, userData:%{public}d, networkId:%{public}s",
|
||||
userData, AnonyNetworkId(networkId).c_str());
|
||||
userData, GetAnonyString(networkId).c_str());
|
||||
}
|
||||
|
||||
void CoordinationManagerImpl::OnCoordinationStateEvent(int32_t userData, bool state)
|
||||
|
@ -322,7 +322,7 @@ int32_t DSoftbusAdapterImpl::OpenSessionLocked(const std::string &networkId)
|
||||
char peerName[DEVICE_NAME_SIZE_MAX] { SERVER_SESSION_NAME };
|
||||
char peerNetworkId[PKG_NAME_SIZE_MAX] {};
|
||||
if (strcpy_s(peerNetworkId, sizeof(peerNetworkId), networkId.c_str()) != EOK) {
|
||||
FI_HILOGE("Invalid peerNetworkId:%{public}s", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGE("Invalid peerNetworkId:%{public}s", GetAnonyString(networkId).c_str());
|
||||
return RET_ERR;
|
||||
}
|
||||
char pkgName[PKG_NAME_SIZE_MAX] { FI_PKG_NAME };
|
||||
|
@ -39,8 +39,11 @@ ohos_shared_library("intention_cooperate") {
|
||||
"src/cooperate_out.cpp",
|
||||
"src/dsoftbus_handler.cpp",
|
||||
"src/event_manager.cpp",
|
||||
"src/hot_area.cpp",
|
||||
"src/i_cooperate_state.cpp",
|
||||
"src/input_device_manager.cpp",
|
||||
"src/input_event_transmission/input_event_builder.cpp",
|
||||
"src/input_event_transmission/input_event_interceptor.cpp",
|
||||
"src/input_event_transmission/input_event_serialization.cpp",
|
||||
"src/state_machine.cpp",
|
||||
]
|
||||
|
||||
@ -56,17 +59,15 @@ ohos_shared_library("intention_cooperate") {
|
||||
"${device_status_root_path}/intention/prototype:intention_prototype",
|
||||
"${device_status_root_path}/utils/common:devicestatus_util",
|
||||
"${device_status_root_path}/utils/ipc:devicestatus_ipc",
|
||||
"//third_party/openssl:libcrypto_shared",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"dsoftbus:softbus_client",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image_native",
|
||||
"input:libmmi-client",
|
||||
"ipc:ipc_single",
|
||||
"window_manager:libdm",
|
||||
"window_manager:libwmutil_base",
|
||||
]
|
||||
|
||||
subsystem_name = "${device_status_subsystem_name}"
|
||||
|
@ -31,7 +31,7 @@ namespace Cooperate {
|
||||
class Cooperate final : public ICooperate {
|
||||
public:
|
||||
Cooperate(IContext *env);
|
||||
~Cooperate() = default;
|
||||
~Cooperate();
|
||||
DISALLOW_COPY_AND_MOVE(Cooperate);
|
||||
|
||||
int32_t RegisterListener(int32_t pid) override;
|
||||
@ -39,8 +39,8 @@ public:
|
||||
int32_t RegisterHotAreaListener(int32_t pid) override;
|
||||
int32_t UnregisterHotAreaListener(int32_t pid) override;
|
||||
|
||||
int32_t Enable(int32_t pid) override;
|
||||
int32_t Disable(int32_t pid) override;
|
||||
int32_t Enable(int32_t pid, int32_t userData) override;
|
||||
int32_t Disable(int32_t pid, int32_t userData) override;
|
||||
int32_t Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId) override;
|
||||
int32_t Stop(int32_t pid, int32_t userData, bool isUnchained) override;
|
||||
|
||||
@ -56,13 +56,12 @@ private:
|
||||
Context context_;
|
||||
StateMachine sm_;
|
||||
std::mutex lock_;
|
||||
bool workerStarted_ { false };
|
||||
std::thread worker_;
|
||||
std::atomic_bool running_ { false };
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
Channel<CooperateEvent>::Receiver receiver_;
|
||||
};
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // COOPERATE_H
|
||||
#endif // COOPERATE_H
|
||||
|
@ -16,17 +16,17 @@
|
||||
#ifndef COOPERATE_CONTEXT_H
|
||||
#define COOPERATE_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "cooperate_events.h"
|
||||
#include "ddm_adapter.h"
|
||||
#include "ddp_adapter.h"
|
||||
#include "dsoftbus_handler.h"
|
||||
#include "event_manager.h"
|
||||
#include "input_device_manager.h"
|
||||
#include "hot_area.h"
|
||||
#include "input_event_transmission/input_event_builder.h"
|
||||
#include "input_event_transmission/input_event_interceptor.h"
|
||||
#include "i_context.h"
|
||||
#include "i_ddm_adapter.h"
|
||||
#include "i_ddp_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -43,44 +43,48 @@ public:
|
||||
void Disable();
|
||||
|
||||
Channel<CooperateEvent>::Sender Sender() const;
|
||||
std::string Origin() const;
|
||||
std::string Local() const;
|
||||
std::string Peer() const;
|
||||
std::string StartDeviceDhid() const;
|
||||
int32_t StartDeviceId() const;
|
||||
std::vector<std::string> CooperateDhids() const;
|
||||
Coordinate CursorPosition() const;
|
||||
NormalizedCoordinate NormalizedCursorPosition() const;
|
||||
|
||||
bool IsLocal(const std::string &networkId) const;
|
||||
bool IsPeer(const std::string &networkId) const;
|
||||
|
||||
void EnableCooperate(const EnableCooperateEvent &event);
|
||||
void DisableCooperate(const DisableCooperateEvent &event);
|
||||
void StartCooperate(const StartCooperateEvent &event);
|
||||
void RemoteStart(const DSoftbusStartCooperate &event);
|
||||
void RemoteStartSuccess(const DSoftbusStartCooperateFinished &event);
|
||||
void RelayCooperate(const DSoftbusRelayCooperate &event);
|
||||
void OnPointerEvent(const InputPointerEvent &event);
|
||||
|
||||
std::shared_ptr<InputDeviceManager> devMgr_;
|
||||
std::shared_ptr<IDDMAdapter> ddm_;
|
||||
std::shared_ptr<IDDPAdapter> ddp_;
|
||||
std::shared_ptr<DSoftbusHandler> dsoftbus_;
|
||||
DDMAdapter ddm_;
|
||||
DDPAdapter ddp_;
|
||||
DSoftbusHandler dsoftbus_;
|
||||
EventManager eventMgr_;
|
||||
HotArea hotArea_;
|
||||
InputEventBuilder inputEventBuilder_;
|
||||
InputEventInterceptor inputEventInterceptor_;
|
||||
|
||||
private:
|
||||
int32_t EnableDevMgr();
|
||||
void DisableDevMgr();
|
||||
int32_t EnableDSoftbus();
|
||||
void DisableDSoftbus();
|
||||
int32_t EnableDDM();
|
||||
void DisableDDM();
|
||||
int32_t EnableDDP();
|
||||
void DisableDDP();
|
||||
void SetCursorPosition(const DSoftbusStartCooperateFinished &event);
|
||||
int32_t EnableDevMgr();
|
||||
void DisableDevMgr();
|
||||
void SetCursorPosition(const Coordinate &cursorPos);
|
||||
void ResetCursorPosition();
|
||||
|
||||
IContext *env_ { nullptr };
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
std::string originNetworkId_;
|
||||
std::string remoteNetworkId_;
|
||||
std::string startDeviceDhid_;
|
||||
int32_t startDeviceId_ { -1 };
|
||||
Coordinate cursorPos_ {};
|
||||
std::shared_ptr<IBoardObserver> boardObserver_;
|
||||
std::shared_ptr<IDeviceProfileObserver> dpObserver_;
|
||||
std::shared_ptr<IDeviceObserver> hotplugObserver_;
|
||||
};
|
||||
|
||||
inline Channel<CooperateEvent>::Sender Context::Sender() const
|
||||
@ -88,9 +92,9 @@ inline Channel<CooperateEvent>::Sender Context::Sender() const
|
||||
return sender_;
|
||||
}
|
||||
|
||||
inline std::string Context::Origin() const
|
||||
inline std::string Context::Local() const
|
||||
{
|
||||
return originNetworkId_;
|
||||
return DSoftbusHandler::GetLocalNetworkId();
|
||||
}
|
||||
|
||||
inline std::string Context::Peer() const
|
||||
@ -98,26 +102,21 @@ inline std::string Context::Peer() const
|
||||
return remoteNetworkId_;
|
||||
}
|
||||
|
||||
inline std::string Context::StartDeviceDhid() const
|
||||
{
|
||||
return startDeviceDhid_;
|
||||
}
|
||||
|
||||
inline int32_t Context::StartDeviceId() const
|
||||
{
|
||||
return startDeviceId_;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> Context::CooperateDhids() const
|
||||
{
|
||||
return devMgr_->GetCooperateDhids(startDeviceId_);
|
||||
}
|
||||
|
||||
inline Coordinate Context::CursorPosition() const
|
||||
{
|
||||
return cursorPos_;
|
||||
}
|
||||
|
||||
inline bool Context::IsLocal(const std::string &networkId) const
|
||||
{
|
||||
return (networkId == DSoftbusHandler::GetLocalNetworkId());
|
||||
}
|
||||
|
||||
inline bool Context::IsPeer(const std::string &networkId) const
|
||||
{
|
||||
return (networkId == remoteNetworkId_);
|
||||
|
@ -33,7 +33,6 @@ enum CooperateState : size_t {
|
||||
enum class CooperateEventType {
|
||||
NOOP,
|
||||
QUIT,
|
||||
UPDATE_STATE,
|
||||
REGISTER_LISTENER,
|
||||
UNREGISTER_LISTENER,
|
||||
REGISTER_HOTAREA_LISTENER,
|
||||
@ -48,19 +47,32 @@ enum class CooperateEventType {
|
||||
DDM_BOARD_ONLINE,
|
||||
DDM_BOARD_OFFLINE,
|
||||
DDP_COOPERATE_SWITCH_CHANGED,
|
||||
INPUT_PLUG_KEYBOARD,
|
||||
INPUT_UNPLUG_KEYBOARD,
|
||||
INPUT_UNPLUG_POINTER,
|
||||
INPUT_POINTER_MOVE,
|
||||
DINPUT_PREPARE_RESULT,
|
||||
DINPUT_START_RESULT,
|
||||
DINPUT_SESSION_CLOSED,
|
||||
DINPUT_STOP_RESULT,
|
||||
INPUT_HOTPLUG_EVENT,
|
||||
INPUT_POINTER_EVENT,
|
||||
DSOFTBUS_SESSION_OPEND,
|
||||
DSOFTBUS_SESSION_CLOSED,
|
||||
DSOFTBUS_START_COOPERATE,
|
||||
DSOFTBUS_START_COOPERATE_RESPONSE,
|
||||
DSOFTBUS_START_COOPERATE_FINISHED,
|
||||
DSOFTBUS_COME_BACK,
|
||||
DSOFTBUS_STOP_COOPERATE,
|
||||
DSOFTBUS_STOP_COOPERATE_FINISHED,
|
||||
DSOFTBUS_RELAY_COOPERATE,
|
||||
DSOFTBUS_RELAY_COOPERATE_RESPONSE,
|
||||
DSOFTBUS_RELAY_COOPERATE_FINISHED,
|
||||
};
|
||||
|
||||
struct Coordinate {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
using NormalizedCoordinate = Coordinate;
|
||||
|
||||
struct Rectangle {
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
};
|
||||
|
||||
struct UpdateStateEvent {
|
||||
@ -69,6 +81,7 @@ struct UpdateStateEvent {
|
||||
|
||||
struct RegisterListenerEvent {
|
||||
int32_t pid;
|
||||
int32_t userData;
|
||||
};
|
||||
|
||||
using UnregisterListenerEvent = RegisterListenerEvent;
|
||||
@ -102,55 +115,49 @@ struct DumpEvent {
|
||||
|
||||
struct DDMBoardOnlineEvent {
|
||||
std::string networkId;
|
||||
};
|
||||
|
||||
using DDMBoardOfflineEvent = DDMBoardOnlineEvent;
|
||||
|
||||
struct DDPCooperateSwitchChanged {
|
||||
std::string networkId;
|
||||
bool status;
|
||||
};
|
||||
|
||||
struct InputHotplugEvent {
|
||||
std::string dhid;
|
||||
};
|
||||
|
||||
struct DInputPrepareResult {
|
||||
std::string remoteNetworkId;
|
||||
std::string originNetworkId;
|
||||
int32_t startDeviceId;
|
||||
bool success;
|
||||
};
|
||||
|
||||
struct DInputStopResult {
|
||||
std::string originNetworkId;
|
||||
int32_t startDeviceId;
|
||||
bool success;
|
||||
};
|
||||
|
||||
using DInputStartResult = DInputPrepareResult;
|
||||
|
||||
struct DSoftbusSessionClosed {
|
||||
std::string networkId;
|
||||
};
|
||||
|
||||
using DSoftbusStartCooperate = DSoftbusSessionClosed;
|
||||
|
||||
struct DSoftbusStartCooperateResponse {
|
||||
std::string networkId;
|
||||
bool normal;
|
||||
};
|
||||
|
||||
struct Coordinate {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
using DDMBoardOfflineEvent = DDMBoardOnlineEvent;
|
||||
using DDPCooperateSwitchChanged = DDMBoardOnlineEvent;
|
||||
|
||||
enum class InputHotplugType {
|
||||
PLUG,
|
||||
UNPLUG,
|
||||
};
|
||||
|
||||
struct InputHotplugEvent {
|
||||
int32_t deviceId;
|
||||
InputHotplugType type;
|
||||
};
|
||||
|
||||
struct InputPointerEvent {
|
||||
int32_t deviceId;
|
||||
int32_t pointerAction;
|
||||
int32_t sourceType;
|
||||
Coordinate position;
|
||||
};
|
||||
|
||||
using DSoftbusSessionOpened = DDMBoardOnlineEvent;
|
||||
using DSoftbusSessionClosed = DDMBoardOnlineEvent;
|
||||
using DSoftbusStartCooperate = DDMBoardOnlineEvent;
|
||||
using DSoftbusStartCooperateResponse = DDMBoardOnlineEvent;
|
||||
|
||||
struct DSoftbusStartCooperateFinished {
|
||||
std::string networkId;
|
||||
std::string startDeviceDhid;
|
||||
std::string originNetworkId;
|
||||
bool success;
|
||||
Coordinate cursorPos;
|
||||
NormalizedCoordinate cursorPos;
|
||||
};
|
||||
|
||||
using DSoftbusComeBack = DSoftbusStartCooperateFinished;
|
||||
using DSoftbusStopCooperate = DDMBoardOnlineEvent;
|
||||
using DSoftbusStopCooperateFinished = DDMBoardOnlineEvent;
|
||||
|
||||
struct DSoftbusRelayCooperate {
|
||||
std::string networkId;
|
||||
std::string targetNetworkId;
|
||||
bool normal;
|
||||
};
|
||||
|
||||
struct CooperateEvent {
|
||||
@ -170,15 +177,16 @@ struct CooperateEvent {
|
||||
GetCooperateStateEvent,
|
||||
DumpEvent,
|
||||
DDMBoardOnlineEvent,
|
||||
DDPCooperateSwitchChanged,
|
||||
DInputPrepareResult,
|
||||
DInputStopResult,
|
||||
InputHotplugEvent,
|
||||
DSoftbusSessionClosed,
|
||||
DSoftbusStartCooperateResponse,
|
||||
DSoftbusStartCooperateFinished
|
||||
InputPointerEvent,
|
||||
DSoftbusStartCooperateFinished,
|
||||
DSoftbusRelayCooperate
|
||||
> event;
|
||||
};
|
||||
|
||||
inline constexpr int32_t DEFAULT_TIMEOUT { 3000 };
|
||||
inline constexpr int32_t REPEAT_ONCE { 1 };
|
||||
inline constexpr int32_t DEFAULT_COOLING_TIME { 100 };
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
@ -32,7 +31,14 @@ namespace DeviceStatus {
|
||||
namespace Cooperate {
|
||||
class EventManager final {
|
||||
public:
|
||||
enum EventType { LISTENER, ENABLE, START, STOP, STATE };
|
||||
enum EventType {
|
||||
LISTENER,
|
||||
ENABLE,
|
||||
START,
|
||||
STOP,
|
||||
STATE,
|
||||
};
|
||||
|
||||
struct EventInfo {
|
||||
EventType type { LISTENER };
|
||||
MessageId msgId { MessageId::INVALID };
|
||||
@ -47,28 +53,29 @@ public:
|
||||
~EventManager() = default;
|
||||
DISALLOW_COPY_AND_MOVE(EventManager);
|
||||
|
||||
void RegisterListener(const RegisterListenerEvent &event);
|
||||
void UnregisterListener(const UnregisterListenerEvent &event);
|
||||
void EnableCooperate(const EnableCooperateEvent &event);
|
||||
void DisableCooperate(const DisableCooperateEvent &event);
|
||||
void StartCooperate(const StartCooperateEvent &event);
|
||||
void StartCooperateFinish(const DSoftbusStartCooperateFinished &event);
|
||||
void RemoteStart(const DSoftbusStartCooperate &event);
|
||||
void RemoteStartFinish(const DSoftbusStartCooperateFinished &event);
|
||||
|
||||
void AddCooperateEvent(std::shared_ptr<EventInfo> event);
|
||||
void RemoveCooperateEvent(std::shared_ptr<EventInfo> event);
|
||||
int32_t OnCooperateMessage(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnEnable(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnStart(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnStop(CoordinationMessage msg, const std::string &networkId = "");
|
||||
void OnGetCrossingSwitchState(bool state);
|
||||
void OnErrorMessage(EventType type, CoordinationMessage msg);
|
||||
void StopCooperate(const StopCooperateEvent &event);
|
||||
void StopCooperateFinish(const DSoftbusStopCooperateFinished &event);
|
||||
void RemoteStop(const DSoftbusStopCooperate &event);
|
||||
void RemoteStopFinish(const DSoftbusStopCooperateFinished &event);
|
||||
void OnProfileChanged(const DDPCooperateSwitchChanged &event);
|
||||
void OnSoftbusSessionClosed(const DSoftbusSessionClosed &event);
|
||||
|
||||
private:
|
||||
void OnCooperateMessage(CoordinationMessage msg, const std::string &networkId);
|
||||
void NotifyCooperateMessage(int32_t pid, MessageId msgId, int32_t userData,
|
||||
const std::string &networkId, CoordinationMessage msg);
|
||||
void NotifyCooperateState(int32_t pid, MessageId msgId, int32_t userData, bool state);
|
||||
|
||||
private:
|
||||
IContext *env_ { nullptr };
|
||||
std::mutex lock_;
|
||||
std::list<std::shared_ptr<EventInfo>> listeners_;
|
||||
std::map<EventType, std::shared_ptr<EventInfo>> calls_ {
|
||||
{ EventType::ENABLE, nullptr },
|
||||
|
@ -36,12 +36,12 @@ public:
|
||||
static int32_t NetPacketToSwitchEvent(NetPacket &pkt, std::shared_ptr<MMI::SwitchEvent> key);
|
||||
static int32_t Marshalling(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
|
||||
static int32_t Unmarshalling(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt);
|
||||
static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
|
||||
static int32_t MarshallingEnhanceData(std::shared_ptr<MMI::KeyEvent> event, NetPacket &pkt);
|
||||
static int32_t UnmarshallingEnhanceData(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> event);
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
private:
|
||||
static int32_t SerializeInputEvent(std::shared_ptr<MMI::InputEvent> event, NetPacket &pkt);
|
||||
static int32_t DeserializeInputEvent(NetPacket &pkt, std::shared_ptr<MMI::InputEvent> event);
|
||||
@ -61,14 +61,14 @@ private:
|
||||
static int32_t DeserializeBuffer(NetPacket &pkt, std::shared_ptr<MMI::PointerEvent> event);
|
||||
static void ReadFunctionKeys(NetPacket &pkt, std::shared_ptr<MMI::KeyEvent> key);
|
||||
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
static constexpr uint32_t MAX_HMAC_SIZE = 64;
|
||||
struct SecCompPointEvent {
|
||||
double touchX;
|
||||
double touchY;
|
||||
uint64_t timeStamp;
|
||||
};
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
};
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
|
@ -18,14 +18,13 @@
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
#include "cooperate_context.h"
|
||||
#include "i_cooperate_state.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace Cooperate {
|
||||
class StateMachine final {
|
||||
class StateMachine final : public IStateMachine {
|
||||
public:
|
||||
StateMachine(IContext *env);
|
||||
~StateMachine() = default;
|
||||
@ -34,15 +33,34 @@ public:
|
||||
void OnEvent(Context &context, const CooperateEvent &event);
|
||||
|
||||
private:
|
||||
void UpdateState(Context &context, const CooperateEvent &event);
|
||||
void TransiteTo(Context &context, CooperateState state) override;
|
||||
void AddHandler(CooperateEventType event, void (StateMachine::*handler)(Context&, const CooperateEvent&));
|
||||
void OnQuit(Context &context);
|
||||
void RegisterListener(Context &context, const CooperateEvent &event);
|
||||
void UnregisterListener(Context &context, const CooperateEvent &event);
|
||||
void RegisterHotAreaListener(Context &context, const CooperateEvent &event);
|
||||
void UnregisterHotAreaListener(Context &context, const CooperateEvent &event);
|
||||
void EnableCooperate(Context &context, const CooperateEvent &event);
|
||||
void DisableCooperate(Context &context, const CooperateEvent &event);
|
||||
void GetCooperateState(Context &context, const CooperateEvent &event);
|
||||
void OnBoardOnline(Context &context, const CooperateEvent &event);
|
||||
void OnBoardOffline(Context &context, const CooperateEvent &event);
|
||||
void OnProfileChanged(Context &context, const CooperateEvent &event);
|
||||
void OnPointerEvent(Context &context, const CooperateEvent &event);
|
||||
void OnSoftbusSessionClosed(Context &context, const CooperateEvent &event);
|
||||
void Transfer(Context &context, const CooperateEvent &event);
|
||||
void AddSessionObserver(Context &context, const EnableCooperateEvent &event);
|
||||
void RemoveSessionObserver(Context &context, const DisableCooperateEvent &event);
|
||||
void AddMonitor(Context &context);
|
||||
void RemoveMonitor(Context &context);
|
||||
void RemoveWatches(Context &context);
|
||||
|
||||
IContext *env_ { nullptr };
|
||||
std::map<CooperateEventType, std::function<void(Context&, const CooperateEvent&)>> handlers_;
|
||||
size_t current_ { COOPERATE_STATE_FREE };
|
||||
std::array<std::shared_ptr<ICooperateState>, N_COOPERATE_STATES> states_;
|
||||
std::set<std::string> onlineBoards_;
|
||||
int32_t monitorId_ { -1 };
|
||||
};
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
|
@ -34,10 +34,16 @@ Cooperate::Cooperate(IContext *env)
|
||||
context_.Enable();
|
||||
}
|
||||
|
||||
Cooperate::~Cooperate()
|
||||
{
|
||||
StopWorker();
|
||||
context_.Disable();
|
||||
}
|
||||
|
||||
int32_t Cooperate::RegisterListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::REGISTER_LISTENER,
|
||||
RegisterListenerEvent {
|
||||
.pid = pid
|
||||
@ -48,7 +54,7 @@ int32_t Cooperate::RegisterListener(int32_t pid)
|
||||
int32_t Cooperate::UnregisterListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::UNREGISTER_LISTENER,
|
||||
UnregisterListenerEvent {
|
||||
.pid = pid
|
||||
@ -59,7 +65,7 @@ int32_t Cooperate::UnregisterListener(int32_t pid)
|
||||
int32_t Cooperate::RegisterHotAreaListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::REGISTER_HOTAREA_LISTENER,
|
||||
RegisterHotareaListenerEvent {
|
||||
.pid = pid
|
||||
@ -70,7 +76,7 @@ int32_t Cooperate::RegisterHotAreaListener(int32_t pid)
|
||||
int32_t Cooperate::UnregisterHotAreaListener(int32_t pid)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::UNREGISTER_HOTAREA_LISTENER,
|
||||
UnregisterHotareaListenerEvent {
|
||||
.pid = pid
|
||||
@ -78,25 +84,27 @@ int32_t Cooperate::UnregisterHotAreaListener(int32_t pid)
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Enable(int32_t pid)
|
||||
int32_t Cooperate::Enable(int32_t pid, int32_t userData)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
StartWorker();
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::ENABLE,
|
||||
EnableCooperateEvent {
|
||||
.pid = pid
|
||||
.pid = pid,
|
||||
.userData = userData,
|
||||
}));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t Cooperate::Disable(int32_t pid)
|
||||
int32_t Cooperate::Disable(int32_t pid, int32_t userData)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::DISABLE,
|
||||
DisableCooperateEvent {
|
||||
.pid = pid
|
||||
.pid = pid,
|
||||
.userData = userData,
|
||||
}));
|
||||
StopWorker();
|
||||
return RET_OK;
|
||||
@ -105,7 +113,7 @@ int32_t Cooperate::Disable(int32_t pid)
|
||||
int32_t Cooperate::Start(int32_t pid, int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::START,
|
||||
StartCooperateEvent {
|
||||
.pid = pid,
|
||||
@ -119,7 +127,7 @@ int32_t Cooperate::Start(int32_t pid, int32_t userData, const std::string &remot
|
||||
int32_t Cooperate::Stop(int32_t pid, int32_t userData, bool isUnchained)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::STOP,
|
||||
StopCooperateEvent {
|
||||
.pid = pid,
|
||||
@ -132,7 +140,7 @@ int32_t Cooperate::Stop(int32_t pid, int32_t userData, bool isUnchained)
|
||||
int32_t Cooperate::GetCooperateState(int32_t pid, int32_t userData, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::GET_COOPERATE_STATE,
|
||||
GetCooperateStateEvent {
|
||||
.pid = pid,
|
||||
@ -145,7 +153,7 @@ int32_t Cooperate::GetCooperateState(int32_t pid, int32_t userData, const std::s
|
||||
void Cooperate::Dump(int32_t fd)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
sender_.Send(CooperateEvent(
|
||||
context_.Sender().Send(CooperateEvent(
|
||||
CooperateEventType::DUMP,
|
||||
DumpEvent {
|
||||
.fd = fd
|
||||
@ -154,18 +162,21 @@ void Cooperate::Dump(int32_t fd)
|
||||
|
||||
void Cooperate::Loop()
|
||||
{
|
||||
running_.store(true);
|
||||
while (running_.load()) {
|
||||
CALL_DEBUG_ENTER;
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
CooperateEvent event = receiver_.Receive();
|
||||
switch (event.type) {
|
||||
case CooperateEventType::NOOP : {
|
||||
case CooperateEventType::NOOP: {
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::QUIT : {
|
||||
running_.store(false);
|
||||
case CooperateEventType::QUIT: {
|
||||
FI_HILOGI("Skip out of loop");
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
default: {
|
||||
sm_.OnEvent(context_, event);
|
||||
break;
|
||||
}
|
||||
@ -175,16 +186,24 @@ void Cooperate::Loop()
|
||||
|
||||
void Cooperate::StartWorker()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard guard(lock_);
|
||||
worker_ = std::thread(std::bind(&Cooperate::Loop, this));
|
||||
if (!workerStarted_) {
|
||||
workerStarted_ = true;
|
||||
worker_ = std::thread(std::bind(&Cooperate::Loop, this));
|
||||
}
|
||||
}
|
||||
|
||||
void Cooperate::StopWorker()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard guard(lock_);
|
||||
sender_.Send(CooperateEvent(CooperateEventType::QUIT));
|
||||
if (worker_.joinable()) {
|
||||
worker_.join();
|
||||
if (workerStarted_) {
|
||||
context_.Sender().Send(CooperateEvent(CooperateEventType::QUIT));
|
||||
if (worker_.joinable()) {
|
||||
worker_.join();
|
||||
}
|
||||
workerStarted_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,13 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "display_manager.h"
|
||||
|
||||
#include "ddm_adapter.h"
|
||||
#include "ddp_adapter.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "display_manager.h"
|
||||
#include "dsoftbus_handler.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -28,7 +31,8 @@ namespace DeviceStatus {
|
||||
namespace Cooperate {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "CooperateContext" };
|
||||
const std::string COOPERATE_SWITCH { "COOPERATE_SWITCH" };
|
||||
const std::string COOPERATE_SWITCH { "currentStatus" };
|
||||
constexpr double PERCENT { 100.0 };
|
||||
} // namespace
|
||||
|
||||
class BoardObserver final : public IBoardObserver {
|
||||
@ -39,6 +43,7 @@ public:
|
||||
|
||||
void OnBoardOnline(const std::string &networkId) override
|
||||
{
|
||||
FI_HILOGD("\'%{public}s\' is online", Utility::Anonymize(networkId));
|
||||
sender_.Send(CooperateEvent(
|
||||
CooperateEventType::DDM_BOARD_ONLINE,
|
||||
DDMBoardOnlineEvent {
|
||||
@ -48,6 +53,7 @@ public:
|
||||
|
||||
void OnBoardOffline(const std::string &networkId) override
|
||||
{
|
||||
FI_HILOGD("\'%{public}s\' is offline", Utility::Anonymize(networkId));
|
||||
sender_.Send(CooperateEvent(
|
||||
CooperateEventType::DDM_BOARD_OFFLINE,
|
||||
DDMBoardOfflineEvent {
|
||||
@ -61,7 +67,7 @@ private:
|
||||
|
||||
class DeviceProfileObserver final : public IDeviceProfileObserver {
|
||||
public:
|
||||
DeviceProfileObserver(std::shared_ptr<IDDPAdapter> ddp, Channel<CooperateEvent>::Sender sender)
|
||||
DeviceProfileObserver(DDPAdapter &ddp, Channel<CooperateEvent>::Sender sender)
|
||||
: ddp_(ddp), sender_(sender) {}
|
||||
|
||||
~DeviceProfileObserver() = default;
|
||||
@ -70,142 +76,211 @@ public:
|
||||
void OnProfileChanged(const std::string &networkId) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<IDDPAdapter> ddp_;
|
||||
DDPAdapter &ddp_;
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
};
|
||||
|
||||
void DeviceProfileObserver::OnProfileChanged(const std::string &networkId)
|
||||
{
|
||||
std::shared_ptr<IDDPAdapter> ddp = ddp_.lock();
|
||||
CHKPV(ddp);
|
||||
FI_HILOGI("Profile of \'%{public}s\' has changed", Utility::Anonymize(networkId));
|
||||
bool switchStatus = false;
|
||||
|
||||
int32_t ret = ddp->GetProperty(networkId, COOPERATE_SWITCH, switchStatus);
|
||||
int32_t ret = ddp_.GetProperty(networkId, COOPERATE_SWITCH, switchStatus);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to query switch status of \'%{public}s\'", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGE("Failed to query switch status of \'%{public}s\'", Utility::Anonymize(networkId));
|
||||
return;
|
||||
}
|
||||
FI_HILOGI("Profile of \'%{public}s\', switch status:%{public}d", Utility::Anonymize(networkId), switchStatus);
|
||||
sender_.Send(CooperateEvent(
|
||||
CooperateEventType::DDP_COOPERATE_SWITCH_CHANGED,
|
||||
DDPCooperateSwitchChanged {
|
||||
.networkId = networkId,
|
||||
.status = switchStatus,
|
||||
.normal = switchStatus,
|
||||
}));
|
||||
}
|
||||
|
||||
class HotplugObserver final : public IDeviceObserver {
|
||||
public:
|
||||
explicit HotplugObserver(Channel<CooperateEvent>::Sender sender) : sender_(sender) {}
|
||||
~HotplugObserver() = default;
|
||||
|
||||
void OnDeviceAdded(std::shared_ptr<IDevice> dev) override;
|
||||
void OnDeviceRemoved(std::shared_ptr<IDevice> dev) override;
|
||||
|
||||
private:
|
||||
Channel<CooperateEvent>::Sender sender_;
|
||||
};
|
||||
|
||||
void HotplugObserver::OnDeviceAdded(std::shared_ptr<IDevice> dev)
|
||||
{
|
||||
CHKPV(dev);
|
||||
sender_.Send(CooperateEvent(
|
||||
CooperateEventType::INPUT_HOTPLUG_EVENT,
|
||||
InputHotplugEvent {
|
||||
.deviceId = dev->GetId(),
|
||||
.type = InputHotplugType::PLUG,
|
||||
}));
|
||||
}
|
||||
|
||||
void HotplugObserver::OnDeviceRemoved(std::shared_ptr<IDevice> dev)
|
||||
{
|
||||
CHKPV(dev);
|
||||
sender_.Send(CooperateEvent(
|
||||
CooperateEventType::INPUT_HOTPLUG_EVENT,
|
||||
InputHotplugEvent {
|
||||
.deviceId = dev->GetId(),
|
||||
.type = InputHotplugType::UNPLUG,
|
||||
}));
|
||||
}
|
||||
|
||||
Context::Context(IContext *env)
|
||||
: eventMgr_(env)
|
||||
{
|
||||
devMgr_ = std::make_shared<InputDeviceManager>(env);
|
||||
ddm_ = std::make_shared<DDMAdapter>();
|
||||
ddp_ = std::make_shared<DDPAdapter>();
|
||||
dsoftbus_ = std::make_shared<DSoftbusHandler>();
|
||||
}
|
||||
: dsoftbus_(env), eventMgr_(env), hotArea_(env),
|
||||
inputEventBuilder_(env), inputEventInterceptor_(env), env_(env)
|
||||
{}
|
||||
|
||||
void Context::AttachSender(Channel<CooperateEvent>::Sender sender)
|
||||
{
|
||||
sender_ = sender;
|
||||
devMgr_->AttachSender(sender);
|
||||
dsoftbus_->AttachSender(sender);
|
||||
dsoftbus_.AttachSender(sender);
|
||||
}
|
||||
|
||||
void Context::Enable()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
EnableDevMgr();
|
||||
EnableDSoftbus();
|
||||
EnableDDM();
|
||||
EnableDDP();
|
||||
EnableDevMgr();
|
||||
}
|
||||
|
||||
void Context::Disable()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DisableDevMgr();
|
||||
DisableDDP();
|
||||
DisableDDM();
|
||||
DisableDSoftbus();
|
||||
DisableDevMgr();
|
||||
}
|
||||
|
||||
int32_t Context::EnableDevMgr()
|
||||
{
|
||||
devMgr_->Enable();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void Context::DisableDevMgr()
|
||||
{
|
||||
devMgr_->Disable();
|
||||
}
|
||||
|
||||
int32_t Context::EnableDSoftbus()
|
||||
{
|
||||
return dsoftbus_->Enable();
|
||||
}
|
||||
|
||||
void Context::DisableDSoftbus()
|
||||
{
|
||||
dsoftbus_->Disable();
|
||||
}
|
||||
|
||||
int32_t Context::EnableDDM()
|
||||
{
|
||||
boardObserver_ = std::make_shared<BoardObserver>(sender_);
|
||||
ddm_->AddBoardObserver(boardObserver_);
|
||||
return ddm_->Enable();
|
||||
ddm_.AddBoardObserver(boardObserver_);
|
||||
return ddm_.Enable();
|
||||
}
|
||||
|
||||
void Context::DisableDDM()
|
||||
{
|
||||
ddm_->Disable();
|
||||
ddm_->RemoveBoardObserver(boardObserver_);
|
||||
ddm_.Disable();
|
||||
ddm_.RemoveBoardObserver(boardObserver_);
|
||||
boardObserver_.reset();
|
||||
}
|
||||
|
||||
int32_t Context::EnableDDP()
|
||||
{
|
||||
dpObserver_ = std::make_shared<DeviceProfileObserver>(ddp_, sender_);
|
||||
ddp_->AddObserver(dpObserver_);
|
||||
ddp_.AddObserver(dpObserver_);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void Context::DisableDDP()
|
||||
{
|
||||
ddp_->RemoveObserver(dpObserver_);
|
||||
ddp_.RemoveObserver(dpObserver_);
|
||||
dpObserver_.reset();
|
||||
}
|
||||
|
||||
int32_t Context::EnableDevMgr()
|
||||
{
|
||||
hotplugObserver_ = std::make_shared<HotplugObserver>(sender_);
|
||||
env_->GetDeviceManager().AddDeviceObserver(hotplugObserver_);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void Context::DisableDevMgr()
|
||||
{
|
||||
env_->GetDeviceManager().RemoveDeviceObserver(hotplugObserver_);
|
||||
hotplugObserver_.reset();
|
||||
}
|
||||
|
||||
NormalizedCoordinate Context::NormalizedCursorPosition() const
|
||||
{
|
||||
auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
if (display == nullptr) {
|
||||
FI_HILOGE("No default display");
|
||||
return cursorPos_;
|
||||
}
|
||||
Rectangle displayRect {
|
||||
.width = display->GetWidth(),
|
||||
.height = display->GetHeight(),
|
||||
};
|
||||
if ((displayRect.width <= 0) || (displayRect.height <= 0)) {
|
||||
FI_HILOGE("Invalid display information");
|
||||
return cursorPos_;
|
||||
}
|
||||
return NormalizedCoordinate {
|
||||
.x = static_cast<int32_t>(cursorPos_.x * PERCENT / displayRect.width),
|
||||
.y = static_cast<int32_t>(cursorPos_.y * PERCENT / displayRect.height),
|
||||
};
|
||||
}
|
||||
|
||||
void Context::EnableCooperate(const EnableCooperateEvent &event)
|
||||
{
|
||||
int32_t ret = ddp_.SetProperty(COOPERATE_SWITCH, true);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to update switch status");
|
||||
}
|
||||
}
|
||||
|
||||
void Context::DisableCooperate(const DisableCooperateEvent &event)
|
||||
{
|
||||
int32_t ret = ddp_.SetProperty(COOPERATE_SWITCH, false);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to update switch status");
|
||||
}
|
||||
}
|
||||
|
||||
void Context::StartCooperate(const StartCooperateEvent &event)
|
||||
{
|
||||
remoteNetworkId_ = event.remoteNetworkId;
|
||||
startDeviceId_ = event.startDeviceId;
|
||||
startDeviceDhid_ = devMgr_->GetDhid(startDeviceId_);
|
||||
originNetworkId_ = devMgr_->GetOriginNetworkId(startDeviceId_);
|
||||
}
|
||||
|
||||
void Context::RemoteStart(const DSoftbusStartCooperate &event)
|
||||
void Context::OnPointerEvent(const InputPointerEvent &event)
|
||||
{
|
||||
remoteNetworkId_ = event.networkId;
|
||||
if ((event.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) &&
|
||||
(event.pointerAction == MMI::PointerEvent::POINTER_ACTION_MOVE)) {
|
||||
cursorPos_ = event.position;
|
||||
}
|
||||
}
|
||||
|
||||
void Context::RemoteStartSuccess(const DSoftbusStartCooperateFinished &event)
|
||||
{
|
||||
startDeviceDhid_ = event.startDeviceDhid;
|
||||
originNetworkId_ = devMgr_->GetOriginNetworkId(startDeviceDhid_);
|
||||
SetCursorPosition(event);
|
||||
remoteNetworkId_ = event.originNetworkId;
|
||||
SetCursorPosition(event.cursorPos);
|
||||
}
|
||||
|
||||
void Context::SetCursorPosition(const DSoftbusStartCooperateFinished &event)
|
||||
void Context::RelayCooperate(const DSoftbusRelayCooperate &event)
|
||||
{
|
||||
constexpr double PERCENT { 100.0 };
|
||||
double xPercent = (PERCENT - std::clamp<double>(event.cursorPos.x, 0.0, PERCENT)) / PERCENT;
|
||||
double yPercent = std::clamp<double>(event.cursorPos.y, 0.0, PERCENT) / PERCENT;
|
||||
remoteNetworkId_ = event.targetNetworkId;
|
||||
}
|
||||
|
||||
void Context::SetCursorPosition(const Coordinate &cursorPos)
|
||||
{
|
||||
double xPercent = (PERCENT - std::clamp<double>(cursorPos.x, 0.0, PERCENT)) / PERCENT;
|
||||
double yPercent = std::clamp<double>(cursorPos.y, 0.0, PERCENT) / PERCENT;
|
||||
|
||||
auto display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
CHKPV(display);
|
||||
cursorPos_.x = static_cast<int32_t>(xPercent * display->GetWidth());
|
||||
cursorPos_.y = static_cast<int32_t>(yPercent * display->GetHeight());
|
||||
MMI::InputManager::GetInstance()->SetPointerLocation(cursorPos_.x, cursorPos_.y);
|
||||
env_->GetInput().SetPointerLocation(cursorPos_.x, cursorPos_.y);
|
||||
}
|
||||
|
||||
void Context::ResetCursorPosition()
|
||||
{
|
||||
constexpr Coordinate defaultCursorPos {
|
||||
.x = 50,
|
||||
.y = 50,
|
||||
};
|
||||
SetCursorPosition(defaultCursorPos);
|
||||
}
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
|
@ -189,7 +189,7 @@ void CooperateFree::ContactRemote::OnProgress(Context &context, const CooperateE
|
||||
const std::string remoteNetworkId = context.Peer();
|
||||
int32_t ret = context.dsoftbus_->OpenSession(remoteNetworkId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to connect to \'%{public}s\'", AnonyNetworkId(remoteNetworkId).c_str());
|
||||
FI_HILOGE("Failed to connect to \'%{public}s\'", GetAnonyString(remoteNetworkId).c_str());
|
||||
OnReset(context, event);
|
||||
return;
|
||||
}
|
||||
@ -198,7 +198,7 @@ void CooperateFree::ContactRemote::OnProgress(Context &context, const CooperateE
|
||||
};
|
||||
ret = context.dsoftbus_->StartCooperate(remoteNetworkId, request);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to contact with \'%{public}s\'", AnonyNetworkId(remoteNetworkId).c_str());
|
||||
FI_HILOGE("Failed to contact with \'%{public}s\'", GetAnonyString(remoteNetworkId).c_str());
|
||||
OnReset(context, event);
|
||||
return;
|
||||
}
|
||||
@ -463,7 +463,7 @@ void CooperateFree::RemoteStart::OnProgress(Context &context, const CooperateEve
|
||||
};
|
||||
int32_t ret = context.dsoftbus_->StartCooperateResponse(req.networkId, resp);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to answer \'%{public}s\'", AnonyNetworkId(req.networkId).c_str());
|
||||
FI_HILOGE("Failed to answer \'%{public}s\'", GetAnonyString(req.networkId).c_str());
|
||||
OnReset(context, event);
|
||||
return;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ void CooperateOut::RemoteStart::OnProgress(Context &context, const CooperateEven
|
||||
};
|
||||
int32_t ret = context.dsoftbus_->StartCooperateResponse(req.networkId, resp);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to answer \'%{public}s\'", AnonyNetworkId(req.networkId).c_str());
|
||||
FI_HILOGE("Failed to answer \'%{public}s\'", GetAnonyString(req.networkId).c_str());
|
||||
OnReset(context, event);
|
||||
return;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "event_manager.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -29,123 +30,145 @@ EventManager::EventManager(IContext *env)
|
||||
: env_(env)
|
||||
{}
|
||||
|
||||
void EventManager::RegisterListener(const RegisterListenerEvent &event)
|
||||
{
|
||||
std::shared_ptr<EventInfo> eventInfo = std::make_shared<EventInfo>();
|
||||
eventInfo->type = EventType::LISTENER;
|
||||
eventInfo->msgId = MessageId::COORDINATION_ADD_LISTENER;
|
||||
eventInfo->pid = event.pid;
|
||||
|
||||
FI_HILOGI("Add cooperate listener (%{public}d)", eventInfo->pid);
|
||||
auto iter = std::find_if(listeners_.begin(), listeners_.end(),
|
||||
[eventInfo](const auto &item) {
|
||||
return ((item != nullptr) && (item->pid == eventInfo->pid));
|
||||
});
|
||||
if (iter != listeners_.end()) {
|
||||
*iter = eventInfo;
|
||||
} else {
|
||||
listeners_.emplace_back(eventInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::UnregisterListener(const UnregisterListenerEvent &event)
|
||||
{
|
||||
FI_HILOGI("Remove cooperate listener (%{public}d)", event.pid);
|
||||
listeners_.erase(std::remove_if(listeners_.begin(), listeners_.end(),
|
||||
[pid = event.pid](const auto &item) {
|
||||
return ((item == nullptr) || (item->pid == pid));
|
||||
}), listeners_.end());
|
||||
}
|
||||
|
||||
void EventManager::EnableCooperate(const EnableCooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::string networkId;
|
||||
NotifyCooperateMessage(event.pid, MessageId::COORDINATION_MESSAGE,
|
||||
event.userData, networkId, CoordinationMessage::PREPARE);
|
||||
}
|
||||
|
||||
void EventManager::DisableCooperate(const DisableCooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::string networkId;
|
||||
NotifyCooperateMessage(event.pid, MessageId::COORDINATION_MESSAGE,
|
||||
event.userData, networkId, CoordinationMessage::UNPREPARE);
|
||||
}
|
||||
|
||||
void EventManager::StartCooperate(const StartCooperateEvent &event)
|
||||
{
|
||||
std::shared_ptr<EventInfo> evInfo = std::make_shared<EventInfo>();
|
||||
evInfo->type = EventType::START;
|
||||
evInfo->msgId = MessageId::COORDINATION_MESSAGE;
|
||||
evInfo->pid = event.pid;
|
||||
evInfo->userData = event.userData;
|
||||
evInfo->networkId = event.remoteNetworkId;
|
||||
calls_[EventType::START] = evInfo;
|
||||
CALL_DEBUG_ENTER;
|
||||
std::shared_ptr<EventInfo> eventInfo = std::make_shared<EventInfo>();
|
||||
eventInfo->type = EventType::START;
|
||||
eventInfo->msgId = MessageId::COORDINATION_MESSAGE;
|
||||
eventInfo->pid = event.pid;
|
||||
eventInfo->networkId = event.remoteNetworkId;
|
||||
eventInfo->userData = event.userData;
|
||||
calls_[EventType::START] = eventInfo;
|
||||
}
|
||||
|
||||
void EventManager::StartCooperateFinish(const DSoftbusStartCooperateFinished &event)
|
||||
{}
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::shared_ptr<EventInfo> eventInfo = calls_[EventType::START];
|
||||
CHKPV(eventInfo);
|
||||
CoordinationMessage msg = (event.success ?
|
||||
CoordinationMessage::ACTIVATE_SUCCESS :
|
||||
CoordinationMessage::ACTIVATE_FAIL);
|
||||
NotifyCooperateMessage(eventInfo->pid, eventInfo->msgId, eventInfo->userData, eventInfo->networkId, msg);
|
||||
calls_[EventType::START] = nullptr;
|
||||
}
|
||||
|
||||
void EventManager::RemoteStart(const DSoftbusStartCooperate &event)
|
||||
{}
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
OnCooperateMessage(CoordinationMessage::ACTIVATE, event.networkId);
|
||||
}
|
||||
|
||||
void EventManager::RemoteStartFinish(const DSoftbusStartCooperateFinished &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CoordinationMessage msg { event.success ?
|
||||
CoordinationMessage::ACTIVATE_SUCCESS :
|
||||
CoordinationMessage::ACTIVATE_FAIL };
|
||||
OnCooperateMessage(msg, event.networkId);
|
||||
}
|
||||
|
||||
void EventManager::AddCooperateEvent(std::shared_ptr<EventInfo> event)
|
||||
void EventManager::StopCooperate(const StopCooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
CHKPV(event);
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
if (event->type == EventType::LISTENER) {
|
||||
auto it = std::find_if(listeners_.begin(), listeners_.end(),
|
||||
[event] (const auto &info) {
|
||||
return ((info != nullptr) && (info->pid == event->pid));
|
||||
});
|
||||
if (it != listeners_.end()) {
|
||||
*it = event;
|
||||
} else {
|
||||
listeners_.emplace_back(event);
|
||||
}
|
||||
} else {
|
||||
calls_[event->type] = event;
|
||||
}
|
||||
std::shared_ptr<EventInfo> eventInfo = std::make_shared<EventInfo>();
|
||||
eventInfo->type = EventType::STOP;
|
||||
eventInfo->msgId = MessageId::COORDINATION_MESSAGE;
|
||||
eventInfo->pid = event.pid;
|
||||
eventInfo->userData = event.userData;
|
||||
calls_[EventType::STOP] = eventInfo;
|
||||
}
|
||||
|
||||
void EventManager::RemoveCooperateEvent(std::shared_ptr<EventInfo> event)
|
||||
void EventManager::StopCooperateFinish(const DSoftbusStopCooperateFinished &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
CHKPV(event);
|
||||
for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
|
||||
if ((*it)->pid == event->pid) {
|
||||
listeners_.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t EventManager::OnCooperateMessage(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
|
||||
std::shared_ptr<EventInfo> listener = *it;
|
||||
CHKPC(listener);
|
||||
NotifyCooperateMessage(listener->pid, listener->msgId, listener->userData, networkId, msg);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void EventManager::OnEnable(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<EventInfo> call = calls_[EventType::ENABLE];
|
||||
CHKPV(call);
|
||||
NotifyCooperateMessage(call->pid, call->msgId, call->userData, networkId, msg);
|
||||
calls_[EventType::ENABLE] = nullptr;
|
||||
}
|
||||
|
||||
void EventManager::OnStart(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<EventInfo> call = calls_[EventType::START];
|
||||
CHKPV(call);
|
||||
NotifyCooperateMessage(call->pid, call->msgId, call->userData, networkId, msg);
|
||||
calls_[EventType::START] = nullptr;
|
||||
}
|
||||
|
||||
void EventManager::OnStop(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<EventInfo> call = calls_[EventType::STOP];
|
||||
CHKPV(call);
|
||||
NotifyCooperateMessage(call->pid, call->msgId, call->userData, networkId, msg);
|
||||
std::shared_ptr<EventInfo> eventInfo = calls_[EventType::STOP];
|
||||
CHKPV(eventInfo);
|
||||
CoordinationMessage msg = (event.normal ?
|
||||
CoordinationMessage::DEACTIVATE_SUCCESS :
|
||||
CoordinationMessage::DEACTIVATE_FAIL);
|
||||
NotifyCooperateMessage(eventInfo->pid, eventInfo->msgId, eventInfo->userData, eventInfo->networkId, msg);
|
||||
calls_[EventType::STOP] = nullptr;
|
||||
}
|
||||
|
||||
void EventManager::OnGetCrossingSwitchState(bool state)
|
||||
void EventManager::RemoteStop(const DSoftbusStopCooperate &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<EventInfo> call = calls_[EventType::STATE];
|
||||
CHKPV(call);
|
||||
NotifyCooperateState(call->pid, call->msgId, call->userData, state);
|
||||
calls_[EventType::STATE] = nullptr;
|
||||
}
|
||||
|
||||
void EventManager::OnErrorMessage(EventType type, CoordinationMessage msg)
|
||||
void EventManager::RemoteStopFinish(const DSoftbusStopCooperateFinished &event)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(lock_);
|
||||
std::shared_ptr<EventInfo> call = calls_[type];
|
||||
CHKPV(call);
|
||||
NotifyCooperateMessage(call->pid, call->msgId, call->userData, "", msg);
|
||||
calls_[type] = nullptr;
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void EventManager::OnProfileChanged(const DDPCooperateSwitchChanged &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
FI_HILOGI("Switch status of \'%{public}s\' has changed to %{public}d",
|
||||
Utility::Anonymize(event.networkId), event.normal);
|
||||
CoordinationMessage msg = (event.normal ? CoordinationMessage::PREPARE : CoordinationMessage::UNPREPARE);
|
||||
OnCooperateMessage(msg, event.networkId);
|
||||
}
|
||||
|
||||
void EventManager::OnSoftbusSessionClosed(const DSoftbusSessionClosed &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
}
|
||||
|
||||
void EventManager::OnCooperateMessage(CoordinationMessage msg, const std::string &networkId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
for (auto iter = listeners_.begin(); iter != listeners_.end(); ++iter) {
|
||||
std::shared_ptr<EventInfo> listener = *iter;
|
||||
CHKPC(listener);
|
||||
FI_HILOGD("Notify cooperate listener (%{public}d, %{public}d)", listener->pid, listener->msgId);
|
||||
NotifyCooperateMessage(listener->pid, listener->msgId, listener->userData, networkId, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void EventManager::NotifyCooperateMessage(int32_t pid, MessageId msgId, int32_t userData,
|
||||
|
@ -16,9 +16,9 @@
|
||||
#include "input_event_transmission/input_event_serialization.h"
|
||||
|
||||
#include "extra_data.h"
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
#include "sec_comp_enhance_kit.h"
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
@ -529,7 +529,7 @@ int32_t InputEventSerialization::Unmarshalling(NetPacket &pkt, std::shared_ptr<M
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#ifdef OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
int32_t InputEventSerialization::MarshallingEnhanceData(std::shared_ptr<MMI::PointerEvent> event, NetPacket &pkt)
|
||||
{
|
||||
CHKPR(event, ERROR_NULL_POINTER);
|
||||
@ -651,7 +651,7 @@ int32_t InputEventSerialization::UnmarshallingEnhanceData(NetPacket &pkt, std::s
|
||||
event->SetEnhanceData(enhanceData);
|
||||
return RET_OK;
|
||||
}
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
|
||||
#endif // OHOS_BUILD_ENABLE_SECURITY_PART
|
||||
} // namespace Cooperate
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
#include "state_machine.h"
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
#include "cooperate_free.h"
|
||||
#include "cooperate_in.h"
|
||||
#include "cooperate_out.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -30,66 +30,109 @@ constexpr HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "StateMachine"
|
||||
} // namespace
|
||||
|
||||
StateMachine::StateMachine(IContext *env)
|
||||
: env_(env)
|
||||
{
|
||||
states_[COOPERATE_STATE_FREE] = std::make_shared<CooperateFree>(env);
|
||||
states_[COOPERATE_STATE_OUT] = std::make_shared<CooperateOut>(env);
|
||||
states_[COOPERATE_STATE_IN] = std::make_shared<CooperateIn>(env);
|
||||
states_[COOPERATE_STATE_FREE] = std::make_shared<CooperateFree>(*this, env);
|
||||
states_[COOPERATE_STATE_OUT] = std::make_shared<CooperateOut>(*this, env);
|
||||
states_[COOPERATE_STATE_IN] = std::make_shared<CooperateIn>(*this, env);
|
||||
|
||||
AddHandler(CooperateEventType::REGISTER_LISTENER, &StateMachine::RegisterListener);
|
||||
AddHandler(CooperateEventType::UNREGISTER_LISTENER, &StateMachine::UnregisterListener);
|
||||
AddHandler(CooperateEventType::REGISTER_HOTAREA_LISTENER, &StateMachine::RegisterHotAreaListener);
|
||||
AddHandler(CooperateEventType::UNREGISTER_HOTAREA_LISTENER, &StateMachine::UnregisterHotAreaListener);
|
||||
AddHandler(CooperateEventType::ENABLE, &StateMachine::EnableCooperate);
|
||||
AddHandler(CooperateEventType::DISABLE, &StateMachine::DisableCooperate);
|
||||
AddHandler(CooperateEventType::GET_COOPERATE_STATE, &StateMachine::GetCooperateState);
|
||||
AddHandler(CooperateEventType::DDM_BOARD_ONLINE, &StateMachine::OnBoardOnline);
|
||||
AddHandler(CooperateEventType::DDM_BOARD_OFFLINE, &StateMachine::OnBoardOffline);
|
||||
AddHandler(CooperateEventType::DDP_COOPERATE_SWITCH_CHANGED, &StateMachine::OnProfileChanged);
|
||||
AddHandler(CooperateEventType::INPUT_POINTER_EVENT, &StateMachine::OnPointerEvent);
|
||||
AddHandler(CooperateEventType::DSOFTBUS_SESSION_CLOSED, &StateMachine::OnSoftbusSessionClosed);
|
||||
}
|
||||
|
||||
void StateMachine::OnEvent(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
switch (event.type) {
|
||||
case CooperateEventType::UPDATE_STATE: {
|
||||
UpdateState(context, event);
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::ENABLE: {
|
||||
EnableCooperate(context, event);
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::DISABLE: {
|
||||
DisableCooperate(context, event);
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::DDM_BOARD_ONLINE: {
|
||||
OnBoardOnline(context, event);
|
||||
break;
|
||||
}
|
||||
case CooperateEventType::DDM_BOARD_OFFLINE: {
|
||||
OnBoardOffline(context, event);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
states_[current_]->OnEvent(context, event);
|
||||
break;
|
||||
}
|
||||
if (auto iter = handlers_.find(event.type); iter != handlers_.end()) {
|
||||
iter->second(context, event);
|
||||
} else {
|
||||
Transfer(context, event);
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::UpdateState(Context &context, const CooperateEvent &event)
|
||||
void StateMachine::TransiteTo(Context &context, CooperateState state)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
UpdateStateEvent updateEvent = std::get<UpdateStateEvent>(event.event);
|
||||
|
||||
if ((updateEvent.current >= COOPERATE_STATE_FREE) &&
|
||||
(updateEvent.current < N_COOPERATE_STATES) &&
|
||||
(updateEvent.current != current_)) {
|
||||
if ((state >= COOPERATE_STATE_FREE) &&
|
||||
(state < N_COOPERATE_STATES) &&
|
||||
(state != current_)) {
|
||||
states_[current_]->OnLeaveState(context);
|
||||
current_ = updateEvent.current;
|
||||
current_ = state;
|
||||
states_[current_]->OnEnterState(context);
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::AddHandler(CooperateEventType event,
|
||||
void (StateMachine::*handler)(Context&, const CooperateEvent&))
|
||||
{
|
||||
handlers_.emplace(event, std::bind(handler, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
void StateMachine::OnQuit(Context &context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
RemoveWatches(context);
|
||||
RemoveMonitor(context);
|
||||
}
|
||||
|
||||
void StateMachine::RegisterListener(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
RegisterListenerEvent notice = std::get<RegisterListenerEvent>(event.event);
|
||||
context.eventMgr_.RegisterListener(notice);
|
||||
}
|
||||
|
||||
void StateMachine::UnregisterListener(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
UnregisterListenerEvent notice = std::get<UnregisterListenerEvent>(event.event);
|
||||
context.eventMgr_.UnregisterListener(notice);
|
||||
}
|
||||
|
||||
void StateMachine::RegisterHotAreaListener(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
RegisterHotareaListenerEvent notice = std::get<RegisterHotareaListenerEvent>(event.event);
|
||||
context.hotArea_.AddListener(notice);
|
||||
}
|
||||
|
||||
void StateMachine::UnregisterHotAreaListener(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
UnregisterHotareaListenerEvent notice = std::get<UnregisterHotareaListenerEvent>(event.event);
|
||||
context.hotArea_.RemoveListener(notice);
|
||||
}
|
||||
|
||||
void StateMachine::EnableCooperate(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
EnableCooperateEvent enableEvent = std::get<EnableCooperateEvent>(event.event);
|
||||
context.EnableCooperate(enableEvent);
|
||||
context.eventMgr_.EnableCooperate(enableEvent);
|
||||
context.hotArea_.EnableCooperate(enableEvent);
|
||||
AddSessionObserver(context, enableEvent);
|
||||
AddMonitor(context);
|
||||
Transfer(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::DisableCooperate(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DisableCooperateEvent disableEvent = std::get<DisableCooperateEvent>(event.event);
|
||||
context.DisableCooperate(disableEvent);
|
||||
context.eventMgr_.DisableCooperate(disableEvent);
|
||||
RemoveSessionObserver(context, disableEvent);
|
||||
RemoveMonitor(context);
|
||||
Transfer(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::GetCooperateState(Context &context, const CooperateEvent &event)
|
||||
{}
|
||||
|
||||
void StateMachine::OnBoardOnline(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
@ -97,7 +140,9 @@ void StateMachine::OnBoardOnline(Context &context, const CooperateEvent &event)
|
||||
|
||||
auto ret = onlineBoards_.insert(onlineEvent.networkId);
|
||||
if (ret.second) {
|
||||
context.ddp_->AddWatch(onlineEvent.networkId);
|
||||
FI_HILOGD("Watch \'%{public}s\'", Utility::Anonymize(onlineEvent.networkId));
|
||||
context.ddp_.AddWatch(onlineEvent.networkId);
|
||||
Transfer(context, event);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,7 +153,108 @@ void StateMachine::OnBoardOffline(Context &context, const CooperateEvent &event)
|
||||
|
||||
if (auto iter = onlineBoards_.find(offlineEvent.networkId); iter != onlineBoards_.end()) {
|
||||
onlineBoards_.erase(iter);
|
||||
context.ddp_->RemoveWatch(offlineEvent.networkId);
|
||||
FI_HILOGD("Remove watch \'%{public}s\'", Utility::Anonymize(offlineEvent.networkId));
|
||||
context.ddp_.RemoveWatch(offlineEvent.networkId);
|
||||
Transfer(context, event);
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::OnProfileChanged(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DDPCooperateSwitchChanged notice = std::get<DDPCooperateSwitchChanged>(event.event);
|
||||
context.eventMgr_.OnProfileChanged(notice);
|
||||
Transfer(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::OnPointerEvent(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
InputPointerEvent pointerEvent = std::get<InputPointerEvent>(event.event);
|
||||
context.OnPointerEvent(pointerEvent);
|
||||
Transfer(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::OnSoftbusSessionClosed(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DSoftbusSessionClosed notice = std::get<DSoftbusSessionClosed>(event.event);
|
||||
context.eventMgr_.OnSoftbusSessionClosed(notice);
|
||||
Transfer(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::Transfer(Context &context, const CooperateEvent &event)
|
||||
{
|
||||
states_[current_]->OnEvent(context, event);
|
||||
}
|
||||
|
||||
void StateMachine::AddSessionObserver(Context &context, const EnableCooperateEvent &event)
|
||||
{
|
||||
env_->GetSocketSessionManager().AddSessionDeletedCallback(
|
||||
event.pid,
|
||||
[sender = context.Sender()](SocketSessionPtr session) mutable {
|
||||
CHKPV(session);
|
||||
FI_HILOGI("Disconnected with AssociateAssistant(%{public}d)", session->GetPid());
|
||||
sender.Send(CooperateEvent(CooperateEventType::APP_CLOSED));
|
||||
});
|
||||
}
|
||||
|
||||
void StateMachine::RemoveSessionObserver(Context &context, const DisableCooperateEvent &event)
|
||||
{
|
||||
env_->GetSocketSessionManager().RemoveSessionDeletedCallback(event.pid);
|
||||
}
|
||||
|
||||
void StateMachine::AddMonitor(Context &context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (monitorId_ >= 0) {
|
||||
return;
|
||||
}
|
||||
monitorId_ = env_->GetInput().AddMonitor(
|
||||
[sender = context.Sender(), &hotArea = context.hotArea_](
|
||||
std::shared_ptr<MMI::PointerEvent> pointerEvent) mutable {
|
||||
hotArea.ProcessData(pointerEvent);
|
||||
|
||||
MMI::PointerEvent::PointerItem pointerItem;
|
||||
if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
|
||||
FI_HILOGE("Corrupted pointer event");
|
||||
return;
|
||||
}
|
||||
sender.Send(CooperateEvent(
|
||||
CooperateEventType::INPUT_POINTER_EVENT,
|
||||
InputPointerEvent {
|
||||
.deviceId = pointerEvent->GetDeviceId(),
|
||||
.pointerAction = pointerEvent->GetPointerAction(),
|
||||
.sourceType = pointerEvent->GetSourceType(),
|
||||
.position = Coordinate {
|
||||
.x = pointerItem.GetDisplayX(),
|
||||
.y = pointerItem.GetDisplayY(),
|
||||
}
|
||||
}));
|
||||
});
|
||||
if (monitorId_ < 0) {
|
||||
FI_HILOGE("MMI::Add Monitor fail");
|
||||
}
|
||||
}
|
||||
|
||||
void StateMachine::RemoveMonitor(Context &context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
if (monitorId_ < 0) {
|
||||
return;
|
||||
}
|
||||
env_->GetInput().RemoveMonitor(monitorId_);
|
||||
monitorId_ = -1;
|
||||
}
|
||||
|
||||
void StateMachine::RemoveWatches(Context &context)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
for (auto iter = onlineBoards_.begin();
|
||||
iter != onlineBoards_.end(); iter = onlineBoards_.begin()) {
|
||||
FI_HILOGD("Remove watch \'%{public}s\'", Utility::Anonymize(*iter));
|
||||
context.ddp_.RemoveWatch(*iter);
|
||||
onlineBoards_.erase(iter);
|
||||
}
|
||||
}
|
||||
} // namespace Cooperate
|
||||
|
@ -46,15 +46,14 @@ public:
|
||||
int32_t UpdateShadowPic(ITunnelClient &tunnel, const ShadowInfo &shadowInfo);
|
||||
int32_t GetDragTargetPid(ITunnelClient &tunnel);
|
||||
int32_t GetUdKey(ITunnelClient &tunnel, std::string &udKey);
|
||||
int32_t GetShadowOffset(ITunnelClient &tunnel,
|
||||
int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height);
|
||||
int32_t GetShadowOffset(ITunnelClient &tunnel, ShadowOffset &shadowOffset);
|
||||
int32_t GetDragData(ITunnelClient &tunnel, DragData &dragData);
|
||||
int32_t UpdatePreviewStyle(ITunnelClient &tunnel, const PreviewStyle &previewStyle);
|
||||
int32_t UpdatePreviewStyleWithAnimation(ITunnelClient &tunnel,
|
||||
const PreviewStyle &previewStyle, const PreviewAnimation &animation);
|
||||
int32_t GetDragSummary(ITunnelClient &tunnel, std::map<std::string, int64_t> &summarys);
|
||||
int32_t GetDragState(ITunnelClient &tunnel, DragState &dragState);
|
||||
int32_t EnterTextEditorArea(ITunnelClient &tunnel, bool enable);
|
||||
int32_t EnableUpperCenterMode(ITunnelClient &tunnel, bool enable);
|
||||
int32_t GetDragAction(ITunnelClient &tunnel, DragAction &dragAction);
|
||||
int32_t GetExtraInfo(ITunnelClient &tunnel, std::string &extraInfo);
|
||||
int32_t AddPrivilege(ITunnelClient &tunnel);
|
||||
|
@ -181,8 +181,7 @@ int32_t DragClient::GetUdKey(ITunnelClient &tunnel, std::string &udKey)
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t DragClient::GetShadowOffset(ITunnelClient &tunnel,
|
||||
int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
|
||||
int32_t DragClient::GetShadowOffset(ITunnelClient &tunnel, ShadowOffset &shadowOffset)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
@ -221,7 +220,7 @@ int32_t DragClient::GetDragState(ITunnelClient &tunnel, DragState &dragState)
|
||||
return RET_ERR;
|
||||
}
|
||||
|
||||
int32_t DragClient::EnterTextEditorArea(ITunnelClient &tunnel, bool enable)
|
||||
int32_t DragClient::EnableUpperCenterMode(ITunnelClient &tunnel, bool enable)
|
||||
{
|
||||
return RET_ERR;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
int32_t AddSubscriptListener(SubscriptListenerPtr listener);
|
||||
int32_t RemoveSubscriptListener(SubscriptListenerPtr listener);
|
||||
int32_t SetDragWindowVisible(bool visible, bool isForce = false);
|
||||
int32_t GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height);
|
||||
int32_t GetShadowOffset(ShadowOffset &shadowOffset);
|
||||
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
|
||||
int32_t GetDragData(DragData &dragData);
|
||||
int32_t GetDragState(DragState &dragState);
|
||||
@ -68,7 +68,7 @@ public:
|
||||
int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
|
||||
int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
|
||||
int32_t GetDragSummary(std::map<std::string, int64_t> &summarys);
|
||||
int32_t EnterTextEditorArea(bool enable);
|
||||
int32_t EnableUpperCenterMode(bool enable);
|
||||
int32_t GetDragAction(DragAction &dragAction);
|
||||
int32_t GetExtraInfo(std::string &extraInfo);
|
||||
int32_t AddPrivilege();
|
||||
|
@ -258,10 +258,10 @@ int32_t IntentionManager::SetDragWindowVisible(bool visible, bool isForce)
|
||||
return drag_.SetDragWindowVisible(*tunnel_, visible, isForce);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
|
||||
int32_t IntentionManager::GetShadowOffset(ShadowOffset &shadowOffset)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return drag_.GetShadowOffset(*tunnel_, offsetX, offsetY, width, height);
|
||||
return drag_.GetShadowOffset(*tunnel_, shadowOffset);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
|
||||
@ -340,7 +340,7 @@ int32_t IntentionManager::GetDragSummary(std::map<std::string, int64_t> &summary
|
||||
return drag_.GetDragSummary(*tunnel_, summarys);
|
||||
}
|
||||
|
||||
int32_t IntentionManager::EnterTextEditorArea(bool enable)
|
||||
int32_t IntentionManager::EnableUpperCenterMode(bool enable)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
return drag_.EnableUpperCenterMode(*tunnel_, enable);
|
||||
|
@ -24,7 +24,7 @@ namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "IntentionService" };
|
||||
constexpr HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "IntentionService" };
|
||||
} // namespace
|
||||
|
||||
IntentionService::IntentionService(IContext *context)
|
||||
|
@ -250,7 +250,7 @@ void FusionDeviceProfileAdapter::SaveSubscribeInfos(const std::string &deviceId,
|
||||
if (callback == nullptr) {
|
||||
subscribeInfos.clear();
|
||||
FI_HILOGE("Find callback for device %{public}s failed, and the given callback is nullptr",
|
||||
AnonyNetworkId(deviceId).c_str());
|
||||
GetAnonyString(deviceId).c_str());
|
||||
return;
|
||||
}
|
||||
callbacks_.insert_or_assign(deviceId, callback);
|
||||
|
@ -116,6 +116,15 @@ ohos_shared_library("devicestatus_service") {
|
||||
"interaction/drag:interaction_drag",
|
||||
]
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
deps += [
|
||||
"${device_status_root_path}/intention/adapters/dinput_adapter:intention_dinput_adapter",
|
||||
"${device_status_root_path}/intention/adapters/dsoftbus_adapter:intention_dsoftbus_adapter",
|
||||
"${device_status_root_path}/intention/adapters/input_adapter:intention_input_adapter",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:intention_plugin_manager",
|
||||
]
|
||||
}
|
||||
|
||||
if (fusion_interaction_coordination) {
|
||||
deps += [ "interaction/coordination:coordination" ]
|
||||
}
|
||||
@ -128,11 +137,8 @@ ohos_shared_library("devicestatus_service") {
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
public_deps += [
|
||||
"${device_status_root_path}/intention/adapters/dinput_adapter:intention_dinput_adapter",
|
||||
"${device_status_root_path}/intention/adapters/input_adapter:intention_input_adapter",
|
||||
"${device_status_root_path}/intention/ipc/socket:intention_socket_session_manager",
|
||||
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_server",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:intention_plugin_manager",
|
||||
"${device_status_root_path}/intention/services/intention_service:intention_service",
|
||||
]
|
||||
}
|
||||
@ -174,6 +180,15 @@ ohos_static_library("devicestatus_static_service") {
|
||||
"interaction/drag:interaction_drag",
|
||||
]
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
deps += [
|
||||
"${device_status_root_path}/intention/adapters/dinput_adapter:intention_dinput_adapter",
|
||||
"${device_status_root_path}/intention/adapters/dsoftbus_adapter:intention_dsoftbus_adapter",
|
||||
"${device_status_root_path}/intention/adapters/input_adapter:intention_input_adapter",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:intention_plugin_manager",
|
||||
]
|
||||
}
|
||||
|
||||
if (fusion_interaction_coordination) {
|
||||
deps += [ "interaction/coordination:coordination" ]
|
||||
}
|
||||
@ -191,11 +206,8 @@ ohos_static_library("devicestatus_static_service") {
|
||||
|
||||
if (fusion_intention_framework) {
|
||||
public_deps += [
|
||||
"${device_status_root_path}/intention/adapters/dinput_adapter:intention_dinput_adapter",
|
||||
"${device_status_root_path}/intention/adapters/input_adapter:intention_input_adapter",
|
||||
"${device_status_root_path}/intention/ipc/socket:intention_socket_session_manager",
|
||||
"${device_status_root_path}/intention/ipc/tunnel:intention_tunnel_server",
|
||||
"${device_status_root_path}/intention/scheduler/plugin_manager:intention_plugin_manager",
|
||||
"${device_status_root_path}/intention/services/intention_service:intention_service",
|
||||
]
|
||||
}
|
||||
|
@ -327,13 +327,12 @@ int32_t CoordinationSM::DeactivateCoordination(bool isUnchained)
|
||||
stopNetworkId = sinkNetworkId_;
|
||||
}
|
||||
isUnchained_ = isUnchained;
|
||||
FI_HILOGD("IsUnchained_:%{public}d, stopNetworkId:%{public}s", isUnchained_, AnonyNetworkId(stopNetworkId).c_str());
|
||||
FI_HILOGD("IsUnchained_:%{public}d, stopNetworkId:%{public}s", isUnchained_, GetAnonyString(stopNetworkId).c_str());
|
||||
auto state = GetCurrentState();
|
||||
CHKPR(state, ERROR_NULL_POINTER);
|
||||
int32_t ret = state->DeactivateCoordination(stopNetworkId, isUnchained, preparedNetworkId_);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("DeactivateCoordination failed, stopNetworkId:%{public}s, preparedNetworkId:%{public}s",
|
||||
AnonyNetworkId(stopNetworkId).c_str(), AnonyNetworkId(preparedNetworkId_).c_str());
|
||||
FI_HILOGE("DeactivateCoordination failed, stopNetworkId:%{public}s", GetAnonyString(stopNetworkId).c_str());
|
||||
isStopping_ = false;
|
||||
isUnchained_ = false;
|
||||
}
|
||||
@ -363,7 +362,7 @@ void CoordinationSM::StartRemoteCoordination(const std::string &remoteNetworkId,
|
||||
auto *context = COOR_EVENT_MGR->GetIContext();
|
||||
CHKPV(context);
|
||||
COOR_SM->SetSinkNetworkId(remoteNetworkId);
|
||||
FI_HILOGD("The remoteNetworkId:%{public}s", AnonyNetworkId(remoteNetworkId).c_str());
|
||||
FI_HILOGD("The remoteNetworkId:%{public}s", GetAnonyString(remoteNetworkId).c_str());
|
||||
int32_t ret = context->GetDelegateTasks().PostAsyncTask(std::bind(&CoordinationEventManager::OnCoordinationMessage,
|
||||
COOR_EVENT_MGR, CoordinationMessage::ACTIVATE, remoteNetworkId));
|
||||
if (ret != RET_OK) {
|
||||
@ -470,12 +469,12 @@ void CoordinationSM::StopRemoteCoordinationResult(bool isSuccess)
|
||||
}
|
||||
if (!preparedNetworkId_.first.empty() && !preparedNetworkId_.second.empty() && isUnchained_) {
|
||||
FI_HILOGI("The sink preparedNetworkId isn't empty, first:%{public}s, second:%{public}s",
|
||||
AnonyNetworkId(preparedNetworkId_.first).c_str(), AnonyNetworkId(preparedNetworkId_.second).c_str());
|
||||
GetAnonyString(preparedNetworkId_.first).c_str(), GetAnonyString(preparedNetworkId_.second).c_str());
|
||||
bool ret = UnchainCoordination(preparedNetworkId_.first, preparedNetworkId_.second);
|
||||
if (ret) {
|
||||
COOR_SM->NotifyChainRemoved();
|
||||
std::string localNetworkId = COORDINATION::GetLocalNetworkId();
|
||||
FI_HILOGD("localNetworkId:%{public}s", AnonyNetworkId(localNetworkId).c_str());
|
||||
FI_HILOGD("localNetworkId:%{public}s", GetAnonyString(localNetworkId).c_str());
|
||||
COOR_SOFTBUS_ADAPTER->NotifyUnchainedResult(localNetworkId, sinkNetworkId_, ret);
|
||||
} else {
|
||||
FI_HILOGE("Failed to unchain coordination");
|
||||
@ -580,12 +579,12 @@ void CoordinationSM::OnStopFinish(bool isSuccess, const std::string &remoteNetwo
|
||||
}
|
||||
if (!preparedNetworkId_.first.empty() && !preparedNetworkId_.second.empty() && isUnchained_) {
|
||||
FI_HILOGI("The local preparedNetworkId isn't empty, first:%{public}s, second:%{public}s",
|
||||
AnonyNetworkId(preparedNetworkId_.first).c_str(), AnonyNetworkId(preparedNetworkId_.second).c_str());
|
||||
GetAnonyString(preparedNetworkId_.first).c_str(), GetAnonyString(preparedNetworkId_.second).c_str());
|
||||
bool ret = UnchainCoordination(preparedNetworkId_.first, preparedNetworkId_.second);
|
||||
if (ret) {
|
||||
COOR_SM->NotifyChainRemoved();
|
||||
std::string localNetworkId = COORDINATION::GetLocalNetworkId();
|
||||
FI_HILOGD("localNetworkId:%{public}s", AnonyNetworkId(localNetworkId).c_str());
|
||||
FI_HILOGD("localNetworkId:%{public}s", GetAnonyString(localNetworkId).c_str());
|
||||
COOR_SOFTBUS_ADAPTER->NotifyUnchainedResult(localNetworkId, remoteNetworkId, ret);
|
||||
} else {
|
||||
FI_HILOGE("Failed to unchain coordination");
|
||||
@ -819,7 +818,7 @@ void CoordinationSM::OnDeviceOnline(const std::string &networkId)
|
||||
{
|
||||
std::string localNetworkId = COORDINATION::GetLocalNetworkId();
|
||||
FI_HILOGI("Online device networkId:%{public}s, localNetworkId:%{public}s",
|
||||
AnonyNetworkId(networkId).c_str(), AnonyNetworkId(localNetworkId).c_str());
|
||||
GetAnonyString(networkId).c_str(), GetAnonyString(localNetworkId).c_str());
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
onlineDevice_.push_back(networkId);
|
||||
DP_ADAPTER->RegisterCrossingStateListener(networkId,
|
||||
@ -832,8 +831,8 @@ void CoordinationSM::OnDeviceOffline(const std::string &networkId)
|
||||
CALL_INFO_TRACE;
|
||||
std::string localNetworkId = COORDINATION::GetLocalNetworkId();
|
||||
FI_HILOGI("Local device networkId:%{public}s, remote device networkId:%{public}s,"
|
||||
"offline device networkId:%{public}s", AnonyNetworkId(localNetworkId).c_str(),
|
||||
AnonyNetworkId(sinkNetworkId_).c_str(), AnonyNetworkId(networkId).c_str());
|
||||
"offline device networkId:%{public}s", GetAnonyString(localNetworkId).c_str(),
|
||||
GetAnonyString(sinkNetworkId_).c_str(), GetAnonyString(networkId).c_str());
|
||||
{
|
||||
DP_ADAPTER->UnregisterCrossingStateListener(networkId);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
@ -893,7 +892,7 @@ void CoordinationSM::Dump(int32_t fd)
|
||||
"coordinationState:%s | startDeviceDhid:%s | remoteNetworkId:%s | isStarting:%s | isStopping:%s\n"
|
||||
"physicalX:%d | physicalY:%d | displayX:%d | displayY:%d | interceptorId:%d | monitorId:%d | filterId:%d\n",
|
||||
GetDeviceCoordinationState(currentState_).c_str(), startDeviceDhid_.c_str(),
|
||||
AnonyNetworkId(remoteNetworkId_).c_str(), isStarting_ ? "true" : "false",
|
||||
GetAnonyString(remoteNetworkId_).c_str(), isStarting_ ? "true" : "false",
|
||||
isStopping_ ? "true" : "false", mouseLocation_.first, mouseLocation_.second, displayX_,
|
||||
displayY_, interceptorId_, monitorId_, filterId_);
|
||||
if (onlineDevice_.empty()) {
|
||||
|
@ -258,7 +258,7 @@ int32_t CoordinationSoftbusAdapter::OpenInputSoftbus(const std::string &remoteNe
|
||||
}
|
||||
char peerNetworkId[PKG_NAME_SIZE_MAX] = { 0 };
|
||||
if (ChkAndCpyStr(peerNetworkId, PKG_NAME_SIZE_MAX, remoteNetworkId.c_str()) != RET_OK) {
|
||||
FI_HILOGE("Invalid peerNetworkId:%{public}s", AnonyNetworkId(remoteNetworkId).c_str());
|
||||
FI_HILOGE("Invalid peerNetworkId:%{public}s", GetAnonyString(remoteNetworkId).c_str());
|
||||
return RET_ERR;
|
||||
}
|
||||
char pkgName[PKG_NAME_SIZE_MAX] = FI_PKG_NAME;
|
||||
|
@ -79,14 +79,14 @@ int32_t CoordinationStateFree::DeactivateCoordination(const std::string &network
|
||||
|
||||
if (!preparedNetworkId.first.empty() && !preparedNetworkId.second.empty()) {
|
||||
FI_HILOGI("preparedNetworkId is not empty, first:%{public}s, second:%{public}s, networkId:%{public}s",
|
||||
AnonyNetworkId(preparedNetworkId.first).c_str(), AnonyNetworkId(preparedNetworkId.second).c_str(),
|
||||
AnonyNetworkId(networkId).c_str());
|
||||
GetAnonyString(preparedNetworkId.first).c_str(), GetAnonyString(preparedNetworkId.second).c_str(),
|
||||
GetAnonyString(networkId).c_str());
|
||||
if (networkId == preparedNetworkId.first || networkId == preparedNetworkId.second) {
|
||||
bool ret = COOR_SM->UnchainCoordination(preparedNetworkId.first, preparedNetworkId.second);
|
||||
if (ret) {
|
||||
COOR_SM->NotifyChainRemoved();
|
||||
std::string localNetworkId = COORDINATION::GetLocalNetworkId();
|
||||
FI_HILOGD("localNetworkId:%{public}s", AnonyNetworkId(localNetworkId).c_str());
|
||||
FI_HILOGD("localNetworkId:%{public}s", GetAnonyString(localNetworkId).c_str());
|
||||
COOR_SOFTBUS_ADAPTER->NotifyUnchainedResult(localNetworkId, networkId, ret);
|
||||
} else {
|
||||
FI_HILOGE("Failed to unchain coordination");
|
||||
|
@ -136,7 +136,7 @@ void CoordinationStateIn::OnStopRemoteInput(bool isSuccess,
|
||||
const std::string &remoteNetworkId, int32_t startDeviceId)
|
||||
{
|
||||
FI_HILOGD("In, remoteNetworkId:%{public}s, startDeviceId:%{public}d",
|
||||
AnonyNetworkId(remoteNetworkId).c_str(), startDeviceId);
|
||||
GetAnonyString(remoteNetworkId).c_str(), startDeviceId);
|
||||
if (COOR_SM->IsStarting()) {
|
||||
FI_HILOGD("Is starting in");
|
||||
std::string taskName = "start_finish_task";
|
||||
|
@ -37,7 +37,7 @@ std::string GetLocalNetworkId()
|
||||
return {};
|
||||
}
|
||||
std::string networkId(localNode->networkId, sizeof(localNode->networkId));
|
||||
FI_HILOGD("Get local node device info, networkId:%{public}s", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGD("Get local node device info, networkId:%{public}s", GetAnonyString(networkId).c_str());
|
||||
return localNode->networkId;
|
||||
}
|
||||
} // namespace COORDINATION
|
||||
|
@ -131,7 +131,7 @@ int32_t DeviceProfileAdapter::RegisterCrossingStateListener(const std::string &n
|
||||
return RET_OK;
|
||||
}
|
||||
callbacks_[networkId] = callback;
|
||||
FI_HILOGI("Register crossing state listener success, networkId:%{public}s", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGI("Register crossing state listener success, networkId:%{public}s", GetAnonyString(networkId).c_str());
|
||||
int32_t ret = RegisterProfileListener(networkId);
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Register profile listener failed");
|
||||
@ -145,7 +145,7 @@ int32_t DeviceProfileAdapter::UnregisterCrossingStateListener(const std::string
|
||||
FI_HILOGE("DeviceId is empty");
|
||||
return RET_ERR;
|
||||
}
|
||||
FI_HILOGI("Unregister crossing state listener, networkId:%{public}s", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGI("Unregister crossing state listener, networkId:%{public}s", GetAnonyString(networkId).c_str());
|
||||
std::lock_guard<std::mutex> guard(adapterLock_);
|
||||
auto it = profileEventCallbacks_.find(networkId);
|
||||
if (it != profileEventCallbacks_.end()) {
|
||||
@ -205,7 +205,7 @@ void DeviceProfileAdapter::OnProfileChanged(const std::string &networkId)
|
||||
FI_HILOGI("Crossing switch state:%{public}s", stateStr.c_str());
|
||||
} else {
|
||||
callbacks_.erase(it);
|
||||
FI_HILOGW("Remove networkId:%{public}s profile changed callback", AnonyNetworkId(networkId).c_str());
|
||||
FI_HILOGW("Remove networkId:%{public}s profile changed callback", GetAnonyString(networkId).c_str());
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
|
@ -210,7 +210,6 @@ int32_t DragManager::StopDrag(const DragDropResult &dropResult)
|
||||
FI_HILOGE("On stop drag failed");
|
||||
ret = RET_ERR;
|
||||
}
|
||||
SetDragState(DragState::STOP);
|
||||
if (dropResult.result == DragResult::DRAG_SUCCESS && dropResult.mainWindow > 0) {
|
||||
Rosen::WMError result = Rosen::WindowManager::GetInstance().RaiseWindowToTop(dropResult.mainWindow);
|
||||
if (result != Rosen::WMError::WM_OK) {
|
||||
@ -226,6 +225,7 @@ int32_t DragManager::StopDrag(const DragDropResult &dropResult)
|
||||
DRAG_DATA_MGR.ResetDragData();
|
||||
dragResult_ = static_cast<DragResult>(dropResult.result);
|
||||
StateChangedNotify(DragState::STOP);
|
||||
SetDragState(DragState::STOP);
|
||||
if (isControlMultiScreenVisible_) {
|
||||
isControlMultiScreenVisible_ = false;
|
||||
}
|
||||
@ -732,10 +732,12 @@ int32_t DragManager::OnStopDrag(DragResult result, bool hasCustomAnimation)
|
||||
}
|
||||
dragAction_.store(DragAction::MOVE);
|
||||
DragData dragData = DRAG_DATA_MGR.GetDragData();
|
||||
if ((dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) && !DRAG_DATA_MGR.IsMotionDrag()) {
|
||||
if (dragData.sourceType == MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
|
||||
dragDrawing_.EraseMouseIcon();
|
||||
FI_HILOGI("Set the pointer cursor visible");
|
||||
MMI::InputManager::GetInstance()->SetPointerVisible(true);
|
||||
if (dragState_ != DragState::MOTION_DRAGGING) {
|
||||
FI_HILOGI("Set the pointer cursor visible");
|
||||
MMI::InputManager::GetInstance()->SetPointerVisible(true);
|
||||
}
|
||||
}
|
||||
FI_HILOGI("Stop drag, appened extra data");
|
||||
MMI::InputManager::GetInstance()->AppendExtraData(DragManager::CreateExtraData(false));
|
||||
@ -795,7 +797,7 @@ void DragManager::RegisterNotifyPullUp(std::function<void(bool)> callback)
|
||||
void DragManager::StateChangedNotify(DragState state)
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
if ((stateChangedCallback_ != nullptr) && (!DRAG_DATA_MGR.IsMotionDrag())) {
|
||||
if ((stateChangedCallback_ != nullptr) && (dragState_ != DragState::MOTION_DRAGGING)) {
|
||||
stateChangedCallback_(state);
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,10 @@
|
||||
#include "drag_manager.h"
|
||||
#include "i_context.h"
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#include "dinput_adapter.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "input_adapter.h"
|
||||
#include "intention_service.h"
|
||||
#include "i_dinput_adapter.h"
|
||||
#include "i_input_adapter.h"
|
||||
#include "i_plugin_manager.h"
|
||||
#include "socket_session_manager.h"
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#include "stationary_callback.h"
|
||||
@ -68,6 +68,7 @@ public:
|
||||
ISocketSessionManager& GetSocketSessionManager() override;
|
||||
IInputAdapter& GetInput() override;
|
||||
IDInputAdapter& GetDInput() override;
|
||||
IDSoftbusAdapter& GetDSoftbus() override;
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
|
||||
void Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency,
|
||||
@ -132,6 +133,9 @@ private:
|
||||
void DisableDevMgr();
|
||||
int32_t OnAddHotAreaListener(int32_t pid);
|
||||
int32_t OnRemoveHotAreaListener(int32_t pid);
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
void EnableDSoftbus();
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
int32_t OnRegisterCoordinationListener(int32_t pid);
|
||||
@ -158,9 +162,10 @@ private:
|
||||
#endif // OHOS_BUILD_ENABLE_MOTION_DRAG
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
SocketSessionManager socketSessionMgr_;
|
||||
PluginManager pluginMgr_;
|
||||
InputAdapter input_;
|
||||
std::shared_ptr<DInputAdapter> dinput_;
|
||||
std::shared_ptr<IDInputAdapter> dinput_;
|
||||
std::unique_ptr<IInputAdapter> input_;
|
||||
std::unique_ptr<IPluginManager> pluginMgr_;
|
||||
std::unique_ptr<IDSoftbusAdapter> dsoftbus_;
|
||||
sptr<IntentionService> intention_;
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
};
|
||||
|
@ -35,6 +35,12 @@
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_hisysevent.h"
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#include "dinput_adapter.h"
|
||||
#include "dsoftbus_adapter.h"
|
||||
#include "input_adapter.h"
|
||||
#include "plugin_manager.h"
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#ifdef OHOS_BUILD_ENABLE_MOTION_DRAG
|
||||
#include "motion_drag.h"
|
||||
#endif // OHOS_BUILD_ENABLE_MOTION_DRAG
|
||||
@ -62,6 +68,9 @@ DeviceStatusService::DeviceStatusService()
|
||||
{
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
dinput_ = std::make_shared<DInputAdapter>(this);
|
||||
input_ = std::make_unique<InputAdapter>();
|
||||
pluginMgr_ = std::make_unique<PluginManager>(this);
|
||||
dsoftbus_ = std::make_unique<DSoftbusAdapter>();
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
}
|
||||
|
||||
@ -87,6 +96,7 @@ void DeviceStatusService::OnStart()
|
||||
return;
|
||||
}
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
EnableDSoftbus();
|
||||
intention_ = sptr<IntentionService>::MakeSptr(this);
|
||||
if (!Publish(intention_)) {
|
||||
#else
|
||||
@ -146,18 +156,39 @@ ISocketSessionManager& DeviceStatusService::GetSocketSessionManager()
|
||||
|
||||
IPluginManager& DeviceStatusService::GetPluginManager()
|
||||
{
|
||||
return pluginMgr_;
|
||||
return *pluginMgr_;
|
||||
}
|
||||
|
||||
IInputAdapter& DeviceStatusService::GetInput()
|
||||
{
|
||||
return input_;
|
||||
return *input_;
|
||||
}
|
||||
|
||||
IDInputAdapter& DeviceStatusService::GetDInput()
|
||||
{
|
||||
return *dinput_;
|
||||
}
|
||||
|
||||
IDSoftbusAdapter& DeviceStatusService::GetDSoftbus()
|
||||
{
|
||||
return *dsoftbus_;
|
||||
}
|
||||
|
||||
void DeviceStatusService::EnableDSoftbus()
|
||||
{
|
||||
CALL_INFO_TRACE;
|
||||
int32_t ret = dsoftbus_->Enable();
|
||||
if (ret != RET_OK) {
|
||||
FI_HILOGE("Failed to enable dsoftbus, try again later");
|
||||
int32_t timerId = timerMgr_.AddTimer(DEFAULT_WAIT_TIME_MS, WAIT_FOR_ONCE,
|
||||
std::bind(&DeviceStatusService::EnableDSoftbus, this));
|
||||
if (timerId < 0) {
|
||||
FI_HILOGE("AddTimer failed, Failed to enable dsoftbus");
|
||||
}
|
||||
} else {
|
||||
FI_HILOGI("Enable dsoftbus successfully");
|
||||
}
|
||||
}
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
|
||||
int32_t DeviceStatusService::Dump(int32_t fd, const std::vector<std::u16string> &args)
|
||||
@ -229,14 +260,12 @@ bool DeviceStatusService::Init()
|
||||
FI_HILOGE("Dump init failed");
|
||||
goto INIT_FAIL;
|
||||
}
|
||||
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#if defined(OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK)
|
||||
if (socketSessionMgr_.Init() != RET_OK) {
|
||||
FI_HILOGE("Failed to initialize socket session manager");
|
||||
goto INIT_FAIL;
|
||||
}
|
||||
pluginMgr_.Init(this);
|
||||
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
|
||||
#ifdef OHOS_BUILD_ENABLE_COORDINATION
|
||||
#elif defined(OHOS_BUILD_ENABLE_COORDINATION)
|
||||
COOR_EVENT_MGR->SetIContext(this);
|
||||
COOR_SM->Init();
|
||||
#endif // OHOS_BUILD_ENABLE_COORDINATION
|
||||
|
@ -101,11 +101,6 @@ inline bool MultiplyInt64(int64_t op1, int64_t op2, int64_t& res)
|
||||
return MultiplyInt(op1, op2, std::numeric_limits<int64_t>::min(), std::numeric_limits<int64_t>::max(), res);
|
||||
}
|
||||
|
||||
inline std::string AnonyNetworkId(const std::string &networkId)
|
||||
{
|
||||
return networkId.substr(0, SUBSTR_NETWORK_ID_LEN);
|
||||
}
|
||||
|
||||
size_t StringSplit(const std::string &str, const std::string &sep, std::vector<std::string> &vecList);
|
||||
std::string GetAnonyString(const std::string &value);
|
||||
std::string StringPrintf(const char *format, ...);
|
||||
|
@ -39,7 +39,6 @@
|
||||
"OHOS::Msdp::DeviceStatus::StringSplit(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::vector<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>, std::__h::allocator<std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>>>>&)";
|
||||
"OHOS::Msdp::DeviceStatus::StringPrintf(char const*, ...)";
|
||||
"OHOS::Msdp::DeviceStatus::GetAnonyString(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
|
||||
"OHOS::Msdp::DeviceStatus::AnonyNetworkId(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&)";
|
||||
"OHOS::Msdp::DeviceStatus::DragDataPacker::Marshalling(OHOS::Msdp::DeviceStatus::DragData const&, OHOS::Parcel&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::DragDataPacker::UnMarshalling(OHOS::Parcel&, OHOS::Msdp::DeviceStatus::DragData&, bool)";
|
||||
"OHOS::Msdp::DeviceStatus::DragDataPacker::CheckDragData(OHOS::Msdp::DeviceStatus::DragData const&)";
|
||||
|
Loading…
Reference in New Issue
Block a user