mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
Description: add input funcs part II
Match-id-29b54c981942d34dd7daee7e9130d99a158def3f
This commit is contained in:
@@ -25,6 +25,7 @@ ohos_shared_library("libdinput_handler") {
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${service_common}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
|
||||
@@ -30,19 +30,25 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "input_hub.h"
|
||||
|
||||
#ifndef API_EXPORT
|
||||
#define API_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DistributedInputHandler : public IHardwareHandler {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DistributedInputHandler);
|
||||
public:
|
||||
virtual int32_t Initialize() override;
|
||||
virtual std::vector<DHItem> Query() override;
|
||||
virtual std::map<std::string, std::string> QueryExtraInfo() override;
|
||||
virtual bool IsSupportPlugin() override;
|
||||
virtual void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
virtual void UnRegisterPluginListener() override;
|
||||
API_EXPORT virtual int32_t Initialize() override;
|
||||
API_EXPORT virtual std::vector<DHItem> Query() override;
|
||||
API_EXPORT virtual std::map<std::string, std::string> QueryExtraInfo() override;
|
||||
API_EXPORT virtual bool IsSupportPlugin() override;
|
||||
API_EXPORT virtual void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
API_EXPORT virtual void UnRegisterPluginListener() override;
|
||||
|
||||
API_EXPORT void FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
API_EXPORT void FindDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
private:
|
||||
DistributedInputHandler();
|
||||
~DistributedInputHandler();
|
||||
@@ -69,7 +75,7 @@ private:
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler();
|
||||
API_EXPORT IHardwareHandler* GetHardwareHandler();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -40,8 +41,7 @@ namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DistributedInputHandler);
|
||||
DistributedInputHandler::DistributedInputHandler()
|
||||
: collectThreadID_(-1), isCollectingEvents_(false),
|
||||
isStartCollectEventThread(false)
|
||||
: collectThreadID_(-1), isCollectingEvents_(false), isStartCollectEventThread(false)
|
||||
{
|
||||
inputHub_ = std::make_unique<InputHub>();
|
||||
this->m_listener = nullptr;
|
||||
@@ -82,15 +82,33 @@ int32_t DistributedInputHandler::Initialize()
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputHandler::FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
if (inputHub_ != nullptr) {
|
||||
inputHub_->GetDevicesInfoByType(inputTypes, datas);
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputHandler::FindDevicesInfoByDhId(
|
||||
std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
if (inputHub_ != nullptr) {
|
||||
inputHub_->GetDevicesInfoByDhId(dhidsVec, datas);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DHItem> DistributedInputHandler::Query()
|
||||
{
|
||||
std::vector<DHItem> retInfos;
|
||||
std::vector<InputDevice> vecInput = inputHub_->GetAllInputDevices();
|
||||
for (auto iter : vecInput) {
|
||||
DHItem item;
|
||||
item.dhId = iter.descriptor;
|
||||
StructTransJson(iter, item.attrs);
|
||||
retInfos.push_back(item);
|
||||
|
||||
if (inputHub_ != nullptr) {
|
||||
std::vector<InputDevice> vecInput = inputHub_->GetAllInputDevices();
|
||||
for (auto iter : vecInput) {
|
||||
DHItem item;
|
||||
item.dhId = iter.descriptor;
|
||||
StructTransJson(iter, item.attrs);
|
||||
retInfos.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
return retInfos;
|
||||
@@ -142,8 +160,7 @@ bool DistributedInputHandler::InitCollectEventsThread()
|
||||
collectThreadID_ = -1;
|
||||
int32_t ret = pthread_create(&collectThreadID_, &attr, CollectEventsThread, this);
|
||||
if (ret != 0) {
|
||||
DHLOGE(
|
||||
"DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
DHLOGE("DistributedInputHandler::InitCollectEventsThread create thread failed:%d \n", ret);
|
||||
pthread_attr_destroy(&attr);
|
||||
collectThreadID_ = -1;
|
||||
isCollectingEvents_ = false;
|
||||
@@ -165,6 +182,10 @@ void *DistributedInputHandler::CollectEventsThread(void *param)
|
||||
|
||||
void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId)
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGE("inputHub_ not initialized");
|
||||
return;
|
||||
}
|
||||
while (isCollectingEvents_) {
|
||||
size_t count = inputHub_->StartCollectInputHandler(mEventBuffer, INPUT_DEVICE_BUFFER_SIZE);
|
||||
if (count > 0) {
|
||||
|
||||
Reference in New Issue
Block a user