mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-27 17:51:04 +00:00
!356 Modify interfaces and utils
Merge pull request !356 from mayunteng/1208_3
This commit is contained in:
commit
a52713f1ed
@ -13,29 +13,31 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DEVICESTATUS_CALLBACK_STUB_H
|
||||
#define DEVICESTATUS_CALLBACK_STUB_H
|
||||
#ifndef DEVICE_STATUS_CALLBACK_STUB_H
|
||||
#define DEVICE_STATUS_CALLBACK_STUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
#include <nocopyable.h>
|
||||
|
||||
#include "devicestatus_data_utils.h"
|
||||
#include "idevicestatus_callback.h"
|
||||
#include "message_option.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
#include "devicestatus_data_utils.h"
|
||||
#include "idevicestatus_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class DeviceStatusCallbackStub : public IRemoteStub<IdevicestatusCallback> {
|
||||
class DeviceStatusCallbackStub : public IRemoteStub<IRemoteDevStaCallback> {
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(DeviceStatusCallbackStub);
|
||||
DeviceStatusCallbackStub() = default;
|
||||
virtual ~DeviceStatusCallbackStub() = default;
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& __attribute__((unused))value) override {}
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
void OnDeviceStatusChanged(const Data &value) override {}
|
||||
|
||||
private:
|
||||
int32_t OnDeviceStatusChangedStub(MessageParcel& data);
|
||||
int32_t OnDeviceStatusChangedStub(MessageParcel &data);
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "devicestatus_data_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -33,7 +32,7 @@ struct DeviceStatusEventListener {
|
||||
|
||||
class DeviceStatusEvent {
|
||||
public:
|
||||
explicit DeviceStatusEvent(napi_env env);
|
||||
DeviceStatusEvent(napi_env env);
|
||||
DeviceStatusEvent() = default;
|
||||
virtual ~DeviceStatusEvent();
|
||||
|
||||
|
@ -33,12 +33,12 @@ class DeviceStatusCallback : public DeviceStatusCallbackStub {
|
||||
public:
|
||||
explicit DeviceStatusCallback(napi_env env) : env_(env) {}
|
||||
virtual ~DeviceStatusCallback() {};
|
||||
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData &devicestatusData) override;
|
||||
void OnDeviceStatusChanged(const Data &devicestatusData) override;
|
||||
static void EmitOnEvent(uv_work_t *work, int status);
|
||||
private:
|
||||
napi_env env_ = { nullptr };
|
||||
std::mutex mutex_;
|
||||
DeviceStatusDataUtils::DeviceStatusData data_;
|
||||
Data data_;
|
||||
};
|
||||
|
||||
class DeviceStatusNapi : public DeviceStatusEvent {
|
||||
@ -56,7 +56,7 @@ public:
|
||||
static int32_t ConvertTypeToInt(const std::string &type);
|
||||
void OnDeviceStatusChangedDone(int32_t type, int32_t value, bool isOnce);
|
||||
static DeviceStatusNapi* GetDeviceStatusNapi();
|
||||
static std::map<int32_t, sptr<IdevicestatusCallback>> callbackMap_;
|
||||
static std::map<int32_t, sptr<IRemoteDevStaCallback>> callbackMap_;
|
||||
|
||||
private:
|
||||
static bool CheckArguments(napi_env env, napi_callback_info info);
|
||||
|
@ -18,44 +18,45 @@
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
int32_t DeviceStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, \
|
||||
int32_t DeviceStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DEV_HILOGD(SERVICE, "cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
|
||||
std::u16string descriptor = DeviceStatusCallbackStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
std::u16string descripter = DeviceStatusCallbackStub::GetDescriptor();
|
||||
std::u16string remoteDescripter = data.ReadInterfaceToken();
|
||||
if (descripter != remoteDescripter) {
|
||||
DEV_HILOGE(SERVICE, "DeviceStatusCallbackStub::OnRemoteRequest failed, descriptor mismatch");
|
||||
return E_DEVICESTATUS_GET_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case static_cast<int32_t>(IdevicestatusCallback::DEVICESTATUS_CHANGE): {
|
||||
case static_cast<int32_t>(IRemoteDevStaCallback::DEVICESTATUS_CHANGE): {
|
||||
return OnDeviceStatusChangedStub(data);
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
return ERR_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceStatusCallbackStub::OnDeviceStatusChangedStub(MessageParcel& data)
|
||||
int32_t DeviceStatusCallbackStub::OnDeviceStatusChangedStub(MessageParcel &data)
|
||||
{
|
||||
DEV_HILOGD(SERVICE, "Enter");
|
||||
int32_t type;
|
||||
int32_t value;
|
||||
READINT32(data, type, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
READINT32(data, value, E_DEVICESTATUS_READ_PARCEL_ERROR);
|
||||
DeviceStatusDataUtils::DeviceStatusData devicestatusData = {
|
||||
static_cast<DeviceStatusDataUtils::DeviceStatusType>(type),
|
||||
static_cast<DeviceStatusDataUtils::DeviceStatusValue>(value)
|
||||
Data devicestatusData = {
|
||||
static_cast<Type>(type),
|
||||
static_cast<OnChangedValue>(value)
|
||||
};
|
||||
OnDeviceStatusChanged(devicestatusData);
|
||||
return ERR_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
|
@ -89,7 +89,6 @@ bool DeviceStatusEvent::On(int32_t eventType, napi_value handler, bool isOnce)
|
||||
bool DeviceStatusEvent::Off(int32_t eventType, napi_value handler)
|
||||
{
|
||||
DEV_HILOGD(JS_NAPI, "DeviceStatusEvent off in for event:%{public}d", eventType);
|
||||
|
||||
auto iter = eventMap_.find(eventType);
|
||||
if (iter == eventMap_.end()) {
|
||||
DEV_HILOGE(JS_NAPI, "eventType %{public}d not find", eventType);
|
||||
@ -156,10 +155,6 @@ bool DeviceStatusEvent::OffOnce(int32_t eventType, napi_value handler)
|
||||
void DeviceStatusEvent::CheckRet(int32_t eventType, size_t argc, int32_t value,
|
||||
std::shared_ptr<DeviceStatusEventListener> &typeHandler)
|
||||
{
|
||||
if (value == 0) {
|
||||
DEV_HILOGE(JS_NAPI, "value is invalid");
|
||||
return;
|
||||
}
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(env_, &scope);
|
||||
if (scope == nullptr) {
|
||||
@ -205,13 +200,11 @@ void DeviceStatusEvent::SendRet(int32_t eventType, int32_t value, napi_value &re
|
||||
DEV_HILOGE(JS_NAPI, "Failed to set name");
|
||||
return;
|
||||
}
|
||||
if (value >= static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID)
|
||||
&& value <= static_cast<int32_t>(DeviceStatusDataUtils::DeviceStatusValue::VALUE_EXIT)) {
|
||||
status = napi_create_int32(env_, value, &tmpValue);
|
||||
if (status != napi_ok) {
|
||||
DEV_HILOGE(JS_NAPI, "Failed to get int32");
|
||||
return;
|
||||
}
|
||||
bool flag = (value == 1);
|
||||
status = napi_get_boolean(env_, flag, &tmpValue);
|
||||
if (status != napi_ok) {
|
||||
DEV_HILOGE(JS_NAPI, "Failed to get_boolean");
|
||||
return;
|
||||
}
|
||||
status = napi_set_named_property(env_, result, "value", tmpValue);
|
||||
if (status != napi_ok) {
|
||||
|
@ -38,14 +38,14 @@ static const std::vector<std::string> vecDeviceStatusValue {
|
||||
};
|
||||
thread_local DeviceStatusNapi *g_obj = nullptr;
|
||||
} // namespace
|
||||
std::map<int32_t, sptr<IdevicestatusCallback>> DeviceStatusNapi::callbackMap_;
|
||||
std::map<int32_t, sptr<IRemoteDevStaCallback>> DeviceStatusNapi::callbackMap_;
|
||||
napi_ref DeviceStatusNapi::devicestatusValueRef_ = nullptr;
|
||||
|
||||
struct ResponseEntity {
|
||||
DeviceStatusDataUtils::DeviceStatusValue value;
|
||||
OnChangedValue value;
|
||||
};
|
||||
|
||||
void DeviceStatusCallback::OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
|
||||
void DeviceStatusCallback::OnDeviceStatusChanged(const Data& devicestatusData)
|
||||
{
|
||||
DEV_HILOGD(JS_NAPI, "OnDeviceStatusChanged enter");
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
@ -72,7 +72,7 @@ void DeviceStatusCallback::OnDeviceStatusChanged(const DeviceStatusDataUtils::De
|
||||
|
||||
void DeviceStatusCallback::EmitOnEvent(uv_work_t *work, int status)
|
||||
{
|
||||
DeviceStatusDataUtils::DeviceStatusData* data = static_cast<DeviceStatusDataUtils::DeviceStatusData*>(work->data);
|
||||
Data* data = static_cast<Data*>(work->data);
|
||||
delete work;
|
||||
if (data == nullptr) {
|
||||
DEV_HILOGE(JS_NAPI, "work->data is nullptr");
|
||||
@ -101,6 +101,11 @@ DeviceStatusNapi::DeviceStatusNapi(napi_env env) : DeviceStatusEvent(env)
|
||||
env_ = env;
|
||||
callbackRef_ = nullptr;
|
||||
devicestatusValueRef_ = nullptr;
|
||||
DeviceStatusClient::GetInstance().RegisterDeathListener([this] {
|
||||
DEV_HILOGI(JS_NAPI, "Receive death notification");
|
||||
callbackMap_.clear();
|
||||
ClearEventMap();
|
||||
});
|
||||
}
|
||||
|
||||
DeviceStatusNapi::~DeviceStatusNapi()
|
||||
@ -127,13 +132,13 @@ void DeviceStatusNapi::OnDeviceStatusChangedDone(int32_t type, int32_t value, bo
|
||||
int32_t DeviceStatusNapi::ConvertTypeToInt(const std::string &type)
|
||||
{
|
||||
if (type == "still") {
|
||||
return DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL;
|
||||
} else if (type == "relativeStill") {
|
||||
return DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL;
|
||||
} else if (type == "carBluetooth") {
|
||||
return DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH;
|
||||
return Type::TYPE_STILL;
|
||||
} else if (type == "horizontalPosition") {
|
||||
return Type::TYPE_HORIZONTAL_POSITION;
|
||||
} else if (type == "verticalPosition") {
|
||||
return Type::TYPE_VERTICAL_POSITION;
|
||||
} else {
|
||||
return DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
|
||||
return Type::TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,14 +258,15 @@ napi_value DeviceStatusNapi::SubscribeDeviceStatusCallback(napi_env env, napi_ca
|
||||
DEV_HILOGD(JS_NAPI, "Callback exists");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IdevicestatusCallback> callback;
|
||||
sptr<IRemoteDevStaCallback> callback;
|
||||
callback = new (std::nothrow) DeviceStatusCallback(env);
|
||||
if (callback == nullptr) {
|
||||
DEV_HILOGE(JS_NAPI, "callback is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
DeviceStatusClient::GetInstance().SubscribeCallback(DeviceStatusDataUtils::DeviceStatusType(type), callback);
|
||||
auto ret = callbackMap_.insert(std::pair<int32_t, sptr<IdevicestatusCallback>>(type, callback));
|
||||
DeviceStatusClient::GetInstance().SubscribeCallback(Type(type),
|
||||
ActivityEvent(event), ReportLatencyNs(latency), callback);
|
||||
auto ret = callbackMap_.insert(std::pair<int32_t, sptr<IRemoteDevStaCallback>>(type, callback));
|
||||
if (!ret.second) {
|
||||
DEV_HILOGE(JS_NAPI, "Failed to insert");
|
||||
return nullptr;
|
||||
@ -309,8 +315,10 @@ napi_value DeviceStatusNapi::SubscribeDeviceStatus(napi_env env, napi_callback_i
|
||||
int32_t event = eventMode;
|
||||
int32_t latency = latencyMode;
|
||||
DEV_HILOGD(JS_NAPI, "type:%{public}d, event:%{public}d, latency:%{public}d", type, event, latency);
|
||||
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
|
||||
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
|
||||
|
||||
NAPI_ASSERT(env, (type >= Type::TYPE_STILL) && (type <= Type::TYPE_LID_OPEN), "type is illegal");
|
||||
NAPI_ASSERT(env, (event >= ActivityEvent::ENTER) && (event <= ActivityEvent::ENTER_EXIT), "event is illegal");
|
||||
NAPI_ASSERT(env, (latency >= ReportLatencyNs::SHORT) && (latency <= ReportLatencyNs::LONG), "latency is illegal");
|
||||
return SubscribeDeviceStatusCallback(env, info, args, type, event, latency);
|
||||
}
|
||||
|
||||
@ -338,8 +346,7 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback
|
||||
return nullptr;
|
||||
}
|
||||
int32_t type = ConvertTypeToInt(typeBuf.data());
|
||||
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
|
||||
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
|
||||
NAPI_ASSERT(env, (type >= Type::TYPE_STILL) && (type <= Type::TYPE_LID_OPEN), "type is illegal");
|
||||
int32_t eventMode = 0;
|
||||
status = napi_get_value_int32(env, args[ARG_1], &eventMode);
|
||||
if (status != napi_ok) {
|
||||
@ -347,6 +354,7 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback
|
||||
return nullptr;
|
||||
}
|
||||
int32_t event = eventMode;
|
||||
NAPI_ASSERT(env, (event >= ActivityEvent::ENTER) && (event <= ActivityEvent::ENTER_EXIT), "event is illegal");
|
||||
DEV_HILOGD(JS_NAPI, "type:%{public}d, event:%{public}d", type, event);
|
||||
if (!g_obj->Off(type, args[ARG_2])) {
|
||||
DEV_HILOGE(JS_NAPI, "Not ready to Unsubscribe for type:%{public}d", type);
|
||||
@ -354,8 +362,7 @@ napi_value DeviceStatusNapi::UnsubscribeDeviceStatus(napi_env env, napi_callback
|
||||
}
|
||||
auto callbackIter = callbackMap_.find(type);
|
||||
if (callbackIter != callbackMap_.end()) {
|
||||
DeviceStatusClient::GetInstance().UnsubscribeCallback(DeviceStatusDataUtils::DeviceStatusType(type),
|
||||
callbackIter->second);
|
||||
DeviceStatusClient::GetInstance().UnsubscribeCallback(Type(type), ActivityEvent(event), callbackIter->second);
|
||||
callbackMap_.erase(type);
|
||||
} else {
|
||||
NAPI_ASSERT(env, false, "No existed callback");
|
||||
@ -389,8 +396,7 @@ napi_value DeviceStatusNapi::GetDeviceStatus(napi_env env, napi_callback_info in
|
||||
return nullptr;
|
||||
}
|
||||
int32_t type = ConvertTypeToInt(typeBuf.data());
|
||||
NAPI_ASSERT(env, (type >= DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL) &&
|
||||
(type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN), "type is illegal");
|
||||
NAPI_ASSERT(env, (type >= Type::TYPE_STILL) && (type <= Type::TYPE_LID_OPEN), "type is illegal");
|
||||
if (g_obj == nullptr) {
|
||||
g_obj = new (std::nothrow) DeviceStatusNapi(env);
|
||||
if (g_obj == nullptr) {
|
||||
@ -410,10 +416,10 @@ napi_value DeviceStatusNapi::GetDeviceStatus(napi_env env, napi_callback_info in
|
||||
DEV_HILOGE(JS_NAPI, "type:%{public}d already exists", type);
|
||||
return nullptr;
|
||||
}
|
||||
DeviceStatusDataUtils::DeviceStatusData devicestatusData =
|
||||
DeviceStatusClient::GetInstance().GetDeviceStatusData(DeviceStatusDataUtils::DeviceStatusType(type));
|
||||
Data devicestatusData = DeviceStatusClient::GetInstance().GetDeviceStatusData(Type(type));
|
||||
g_obj->OnDeviceStatusChangedDone(devicestatusData.type, devicestatusData.value, true);
|
||||
g_obj->OffOnce(devicestatusData.type, args[ARG_1]);
|
||||
DEV_HILOGD(JS_NAPI, "Exit");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
57
frameworks/native/src/bytrace_adapter.cpp
Normal file
57
frameworks/native/src/bytrace_adapter.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "bytrace_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
namespace {
|
||||
std::string clientSubscribe = "ClientSubscribe";
|
||||
std::string clientUnsubscribe = "ClientUnsubscribe";
|
||||
std::string serviceSubscribe = "ServiceSubscribe";
|
||||
std::string serviceUnsubscribe = "ServiceUnsubscribe";
|
||||
}
|
||||
void BytraceAdapter::StartBytrace(TraceBtn traceBtn, SubscribeType isSubscribe, SubscribeObject subscribeObject)
|
||||
{
|
||||
if (isSubscribe) {
|
||||
if (traceBtn == TRACE_START) {
|
||||
if (subscribeObject == CLIENT) {
|
||||
StartTrace(HITRACE_TAG_MSDP, clientSubscribe);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_MSDP, "client start subsvribe");
|
||||
} else {
|
||||
StartTrace(HITRACE_TAG_MSDP, serviceSubscribe);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_MSDP, "service start subsvribe");
|
||||
}
|
||||
} else {
|
||||
FinishTrace(HITRACE_TAG_MSDP);
|
||||
}
|
||||
} else {
|
||||
if (traceBtn == TRACE_START) {
|
||||
if (subscribeObject == CLIENT) {
|
||||
StartTrace(HITRACE_TAG_MSDP, clientUnsubscribe);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_MSDP, "client start unSubsvribe");
|
||||
} else {
|
||||
StartTrace(HITRACE_TAG_MSDP, serviceUnsubscribe);
|
||||
HITRACE_METER_NAME(HITRACE_TAG_MSDP, "service start unSubsvribe");
|
||||
}
|
||||
} else {
|
||||
FinishTrace(HITRACE_TAG_MSDP);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace MSDP
|
||||
} // namespace OHOS
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_client.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
#include "idevicestatus_callback.h"
|
||||
|
||||
@ -24,11 +25,10 @@ namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
void DeviceStatusAgent::DeviceStatusAgentCallback::OnDeviceStatusChanged(
|
||||
const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
|
||||
const Data& devicestatusData)
|
||||
{
|
||||
DEV_HILOGI(INNERKIT, "type=%{public}d, value=%{public}d",
|
||||
static_cast<DeviceStatusDataUtils::DeviceStatusType>(devicestatusData.type),
|
||||
static_cast<DeviceStatusDataUtils::DeviceStatusValue>(devicestatusData.value));
|
||||
DEV_HILOGI(INNERKIT, "type:%{punlic}d, value:%{public}d", static_cast<Type>(devicestatusData.type),
|
||||
static_cast<OnChangedValue>(devicestatusData.value));
|
||||
std::shared_ptr<DeviceStatusAgent> agent = agent_.lock();
|
||||
if (agent == nullptr) {
|
||||
DEV_HILOGE(SERVICE, "agent is nullptr");
|
||||
@ -37,50 +37,50 @@ void DeviceStatusAgent::DeviceStatusAgentCallback::OnDeviceStatusChanged(
|
||||
agent->agentEvent_->OnEventResult(devicestatusData);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusAgent::SubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type,
|
||||
int32_t DeviceStatusAgent::SubscribeAgentEvent(const Type& type,
|
||||
const ActivityEvent& event,
|
||||
const ReportLatencyNs& latency,
|
||||
const std::shared_ptr<DeviceStatusAgent::DeviceStatusAgentEvent>& agentEvent)
|
||||
{
|
||||
DEV_HILOGI(INNERKIT, "Enter");
|
||||
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
|
||||
if (agentEvent == nullptr) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
|
||||
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
|
||||
RegisterServiceEvent(type);
|
||||
if (type > Type::TYPE_INVALID && type <= Type::TYPE_LID_OPEN && event > ActivityEvent::EVENT_INVALID
|
||||
&& event <= ActivityEvent::ENTER_EXIT) {
|
||||
RegisterServiceEvent(type, event, latency);
|
||||
agentEvent_ = agentEvent;
|
||||
} else {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
return ERR_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceStatusAgent::UnsubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
|
||||
int32_t DeviceStatusAgent::UnsubscribeAgentEvent(const Type& type, const ActivityEvent& event)
|
||||
{
|
||||
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
|
||||
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
|
||||
UnRegisterServiceEvent(type);
|
||||
return ERR_OK;
|
||||
if (type > Type::TYPE_INVALID && type <= Type::TYPE_LID_OPEN && event > ActivityEvent::EVENT_INVALID
|
||||
&& event <= ActivityEvent::ENTER_EXIT) {
|
||||
UnRegisterServiceEvent(type, event);
|
||||
return RET_OK;
|
||||
}
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
void DeviceStatusAgent::RegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
|
||||
void DeviceStatusAgent::RegisterServiceEvent(const Type& type, const ActivityEvent& event,
|
||||
const ReportLatencyNs& latency)
|
||||
{
|
||||
DEV_HILOGI(INNERKIT, "Enter");
|
||||
callback_ = new (std::nothrow) DeviceStatusAgentCallback(shared_from_this());
|
||||
if (callback_ == nullptr) {
|
||||
DEV_HILOGE(INNERKIT, "callback_ is nullptr");
|
||||
return;
|
||||
}
|
||||
DeviceStatusClient::GetInstance().SubscribeCallback(type, callback_);
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
callback_ = new DeviceStatusAgentCallback(shared_from_this());
|
||||
DeviceStatusClient::GetInstance().SubscribeCallback(type, event, latency, callback_);
|
||||
}
|
||||
|
||||
void DeviceStatusAgent::UnRegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type)
|
||||
void DeviceStatusAgent::UnRegisterServiceEvent(const Type& type,
|
||||
const ActivityEvent& event)
|
||||
{
|
||||
DEV_HILOGI(INNERKIT, "Enter");
|
||||
DeviceStatusClient::GetInstance().UnsubscribeCallback(type, callback_);
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
DeviceStatusClient::GetInstance().UnsubscribeCallback(type, event, callback_);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
@ -13,22 +13,30 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "devicestatus_callback_proxy.h"
|
||||
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
|
||||
#include "iremote_object.h"
|
||||
#include "message_option.h"
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_callback_proxy.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
void DeviceStatusCallbackProxy::OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData)
|
||||
void DeviceStatusCallbackProxy::OnDeviceStatusChanged(const Data& devicestatusData)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
DEVICESTATUS_RETURN_IF(remote == nullptr);
|
||||
DEV_RET_IF_NULL(remote == nullptr);
|
||||
DEV_HILOGE(INNERKIT, "remote is nullptr");
|
||||
|
||||
std::map<Type, int32_t>::iterator typeHandler =
|
||||
DeviceStatusClient::GetInstance().GetTypeMap().find(devicestatusData.type);
|
||||
if (typeHandler != DeviceStatusClient::GetInstance().GetTypeMap().end()) {
|
||||
DEV_HILOGE(INNERKIT, "type not exist report failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -42,12 +50,13 @@ void DeviceStatusCallbackProxy::OnDeviceStatusChanged(const DeviceStatusDataUtil
|
||||
WRITEINT32(data, static_cast<int32_t>(devicestatusData.type));
|
||||
WRITEINT32(data, static_cast<int32_t>(devicestatusData.value));
|
||||
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(IdevicestatusCallback::DEVICESTATUS_CHANGE),
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(IRemoteDevStaCallback::DEVICESTATUS_CHANGE),
|
||||
data, reply, option);
|
||||
if (ret != ERR_OK) {
|
||||
if (ret != RET_OK) {
|
||||
DEV_HILOGE(INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // Msdp
|
||||
} // OHOS
|
||||
} // OHOS
|
||||
|
@ -22,12 +22,12 @@
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "coordination_manager_impl.h"
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "fi_log.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "coordination_manager_impl.h"
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
@ -52,47 +52,53 @@ ErrCode DeviceStatusClient::Connect()
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (devicestatusProxy_ != nullptr) {
|
||||
DEV_HILOGD(INNERKIT, "devicestatusProxy_ is not nullptr");
|
||||
return ERR_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sam == nullptr) {
|
||||
sptr<ISystemAbilityManager> sa = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (sa == nullptr) {
|
||||
DEV_HILOGE(INNERKIT, "GetSystemAbilityManager failed");
|
||||
return E_DEVICESTATUS_GET_SYSTEM_ABILITY_MANAGER_FAILED;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject_ = sam->CheckSystemAbility(MSDP_DEVICESTATUS_SERVICE_ID);
|
||||
if (remoteObject_ == nullptr) {
|
||||
sptr<IRemoteObject> remoteObject = sa->CheckSystemAbility(MSDP_DEVICESTATUS_SERVICE_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
DEV_HILOGE(INNERKIT, "CheckSystemAbility failed");
|
||||
return E_DEVICESTATUS_GET_SERVICE_FAILED;
|
||||
}
|
||||
|
||||
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new DeviceStatusDeathRecipient());
|
||||
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new (std::nothrow) DeviceStatusDeathRecipient());
|
||||
if (deathRecipient_ == nullptr) {
|
||||
DEV_HILOGE(INNERKIT, "Failed to create DeviceStatusDeathRecipient");
|
||||
return ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
if ((remoteObject_->IsProxyObject()) && (!remoteObject_->AddDeathRecipient(deathRecipient_))) {
|
||||
DEV_HILOGE(INNERKIT, "Add death recipient to DeviceStatus service failed");
|
||||
return E_DEVICESTATUS_ADD_DEATH_RECIPIENT_FAILED;
|
||||
if (remoteObject->IsProxyObject()) {
|
||||
if (!remoteObject->AddDeathRecipient(deathRecipient_)) {
|
||||
DEV_HILOGE(INNERKIT, "Add death recipient to DeviceStatus service failed");
|
||||
return E_DEVICESTATUS_ADD_DEATH_RECIPIENT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
devicestatusProxy_ = iface_cast<Idevicestatus>(remoteObject_);
|
||||
devicestatusProxy_ = iface_cast<Idevicestatus>(remoteObject);
|
||||
DEV_HILOGD(INNERKIT, "Connecting DeviceStatusService success");
|
||||
return ERR_OK;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
void DeviceStatusClient::ResetProxy(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
DEVICESTATUS_RETURN_IF(devicestatusProxy_ == nullptr);
|
||||
DEV_RET_IF_NULL(devicestatusProxy_ == nullptr);
|
||||
|
||||
auto serviceRemote = devicestatusProxy_->AsObject();
|
||||
if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) {
|
||||
serviceRemote->RemoveDeathRecipient(deathRecipient_);
|
||||
devicestatusProxy_ = nullptr;
|
||||
}
|
||||
if (deathListener_ != nullptr) {
|
||||
DEV_HILOGI(INNERKIT, "notify death listner");
|
||||
deathListener_();
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceStatusClient::DeviceStatusDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
@ -106,55 +112,57 @@ void DeviceStatusClient::DeviceStatusDeathRecipient::OnRemoteDied(const wptr<IRe
|
||||
DEV_HILOGD(INNERKIT, "Recv death notice");
|
||||
}
|
||||
|
||||
void DeviceStatusClient::SubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback)
|
||||
void DeviceStatusClient::SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
|
||||
sptr<IRemoteDevStaCallback> callback)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
DEVICESTATUS_RETURN_IF((callback == nullptr) || (Connect() != ERR_OK));
|
||||
DEV_HILOGI(INNERKIT, "Enter event:%{public}d,latency:%{public}d", event, latency);
|
||||
typeMap_.insert(std::make_pair(type, 1));
|
||||
DEV_HILOGD(INNERKIT, "typeMap_ %{public}d, type: %{public}d", typeMap_[type], type);
|
||||
DEV_RET_IF_NULL((callback == nullptr) || (Connect() != RET_OK));
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
|
||||
return;
|
||||
}
|
||||
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
|
||||
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
|
||||
devicestatusProxy_->Subscribe(type, callback);
|
||||
if (type > Type::TYPE_INVALID && type <= Type::TYPE_LID_OPEN) {
|
||||
devicestatusProxy_->Subscribe(type, event, latency, callback);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void DeviceStatusClient::UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
|
||||
{
|
||||
DEV_HILOGI(INNERKIT, "UNevent: %{public}d", event);
|
||||
typeMap_.erase(type);
|
||||
DEV_HILOGD(INNERKIT, "typeMap_ %{public}d", typeMap_[type]);
|
||||
DEV_RET_IF_NULL((callback == nullptr) || (Connect() != RET_OK));
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
|
||||
return;
|
||||
}
|
||||
if (type > Type::TYPE_INVALID && type <= Type::TYPE_LID_OPEN) {
|
||||
devicestatusProxy_->Unsubscribe(type, event, callback);
|
||||
}
|
||||
if (event > ActivityEvent::EVENT_INVALID && event <= ActivityEvent::ENTER_EXIT) {
|
||||
DEV_HILOGE(SERVICE, "event is failed");
|
||||
}
|
||||
return;
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
}
|
||||
|
||||
void DeviceStatusClient::UnsubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback)
|
||||
Data DeviceStatusClient::GetDeviceStatusData(Type type)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
DEVICESTATUS_RETURN_IF((callback == nullptr) || (Connect() != ERR_OK));
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
|
||||
return;
|
||||
}
|
||||
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
|
||||
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
|
||||
devicestatusProxy_->Unsubscribe(type, callback);
|
||||
}
|
||||
return;
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
}
|
||||
Data devicestatusData;
|
||||
devicestatusData.type = Type::TYPE_INVALID;
|
||||
devicestatusData.value = OnChangedValue::VALUE_INVALID;
|
||||
|
||||
DeviceStatusDataUtils::DeviceStatusData DeviceStatusClient::GetDeviceStatusData(const \
|
||||
DeviceStatusDataUtils::DeviceStatusType& type)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
DeviceStatusDataUtils::DeviceStatusData devicestatusData;
|
||||
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
|
||||
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
|
||||
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), devicestatusData);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), devicestatusData);
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
DEV_HILOGE(SERVICE, "devicestatusProxy_ is nullptr");
|
||||
return devicestatusData;
|
||||
}
|
||||
if (type > DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID
|
||||
&& type <= DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN) {
|
||||
if (type > Type::TYPE_INVALID
|
||||
&& type <= Type::TYPE_LID_OPEN) {
|
||||
devicestatusData = devicestatusProxy_->GetCache(type);
|
||||
}
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
@ -164,21 +172,21 @@ DeviceStatusDataUtils::DeviceStatusData DeviceStatusClient::GetDeviceStatusData(
|
||||
int32_t DeviceStatusClient::RegisterCoordinationListener()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->RegisterCoordinationListener();
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::UnregisterCoordinationListener()
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->UnregisterCoordinationListener();
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::EnableInputDeviceCoordination(int32_t userData, bool enabled)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->EnableInputDeviceCoordination(userData, enabled);
|
||||
}
|
||||
|
||||
@ -186,21 +194,21 @@ int32_t DeviceStatusClient::StartInputDeviceCoordination(int32_t userData,
|
||||
const std::string &sinkDeviceId, int32_t srcInputDeviceId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->StartInputDeviceCoordination(userData, sinkDeviceId, srcInputDeviceId);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::StopDeviceCoordination(int32_t userData)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->StopDeviceCoordination(userData);
|
||||
}
|
||||
|
||||
int32_t DeviceStatusClient::GetInputDeviceCoordinationState(int32_t userData, const std::string &deviceId)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
return devicestatusProxy_->GetInputDeviceCoordinationState(userData, deviceId);
|
||||
}
|
||||
|
||||
@ -208,7 +216,7 @@ int32_t DeviceStatusClient::GetInputDeviceCoordinationState(int32_t userData, co
|
||||
int32_t DeviceStatusClient::AllocSocketPair(const int32_t moduleType)
|
||||
{
|
||||
CALL_DEBUG_ENTER;
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((Connect() != ERR_OK), RET_ERR);
|
||||
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
if (devicestatusProxy_ == nullptr) {
|
||||
FI_HILOGE("Client has not connect server");
|
||||
@ -232,6 +240,10 @@ int32_t DeviceStatusClient::GetClientSocketFdOfAllocedSocketPair() const
|
||||
return socketFd_;
|
||||
}
|
||||
|
||||
void DeviceStatusClient::RegisterDeathListener(std::function<void()> deathListener)
|
||||
{
|
||||
deathListener_ = deathListener;
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
@ -18,13 +18,15 @@
|
||||
#include <message_option.h>
|
||||
#include <message_parcel.h>
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_data_utils.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "idevicestatus_callback.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
#include "devicestatus_common.h"
|
||||
#include "devicestatus_data_utils.h"
|
||||
#include "devicestatus_define.h"
|
||||
#include "bytrace_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
@ -32,13 +34,12 @@ namespace {
|
||||
constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MSDP_DOMAIN_ID, "DeviceStatusSrvProxy" };
|
||||
} // namespace
|
||||
|
||||
void DeviceStatusSrvProxy::Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback)
|
||||
void DeviceStatusSrvProxy::Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency,
|
||||
sptr<IRemoteDevStaCallback> callback)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
StartTrace(HITRACE_TAG_MSDP, "clientSubscribeStart");
|
||||
DEV_HILOGI(INNERKIT, "Enter event:%{public}d, latency:%{public}d", event, latency);
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
DEVICESTATUS_RETURN_IF((remote == nullptr) || (callback == nullptr));
|
||||
DEV_RET_IF_NULL((remote == nullptr) || (callback == nullptr));
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -50,57 +51,56 @@ void DeviceStatusSrvProxy::Subscribe(const DeviceStatusDataUtils::DeviceStatusTy
|
||||
}
|
||||
|
||||
WRITEINT32(data, type);
|
||||
WRITEINT32(data, event);
|
||||
WRITEINT32(data, latency);
|
||||
WRITEREMOTEOBJECT(data, callback->AsObject());
|
||||
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(Idevicestatus::DEVICESTATUS_SUBSCRIBE), data, reply, option);
|
||||
if (ret != ERR_OK) {
|
||||
if (ret != RET_OK) {
|
||||
DEV_HILOGE(INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_MSDP);
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
}
|
||||
|
||||
void DeviceStatusSrvProxy::Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type,
|
||||
const sptr<IdevicestatusCallback>& callback)
|
||||
void DeviceStatusSrvProxy::Unsubscribe(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
StartTrace(HITRACE_TAG_MSDP, "clientUnsubscribeStart");
|
||||
DEV_HILOGD(INNERKIT, "Enter, event:%{public}d", event);
|
||||
StartTrace(HITRACE_TAG_MSDP, "clientUnSubscribeStart");
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
DEVICESTATUS_RETURN_IF((remote == nullptr) || (callback == nullptr));
|
||||
DEV_RET_IF_NULL((remote == nullptr) || (callback == nullptr));
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
|
||||
DEV_HILOGE(INNERKIT, "Write descriptor failed!");
|
||||
DEV_HILOGE(INNERKIT, "Write descriptor failed");
|
||||
return;
|
||||
}
|
||||
|
||||
WRITEINT32(data, type);
|
||||
WRITEINT32(data, event);
|
||||
WRITEREMOTEOBJECT(data, callback->AsObject());
|
||||
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(Idevicestatus::DEVICESTATUS_UNSUBSCRIBE),
|
||||
data, reply, option);
|
||||
if (ret != ERR_OK) {
|
||||
if (ret != RET_OK) {
|
||||
DEV_HILOGE(INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return;
|
||||
}
|
||||
FinishTrace(HITRACE_TAG_MSDP);
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
}
|
||||
|
||||
DeviceStatusDataUtils::DeviceStatusData DeviceStatusSrvProxy::GetCache(const \
|
||||
DeviceStatusDataUtils::DeviceStatusType& type)
|
||||
Data DeviceStatusSrvProxy::GetCache(const Type& type)
|
||||
{
|
||||
DEV_HILOGD(INNERKIT, "Enter");
|
||||
DeviceStatusDataUtils::DeviceStatusData devicestatusData;
|
||||
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType::TYPE_INVALID;
|
||||
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue::VALUE_INVALID;
|
||||
Data devicestatusData;
|
||||
devicestatusData.type = Type::TYPE_INVALID;
|
||||
devicestatusData.value = OnChangedValue::VALUE_INVALID;
|
||||
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
DEVICESTATUS_RETURN_IF_WITH_RET((remote == nullptr), devicestatusData);
|
||||
DEV_RET_IF_NULL_WITH_RET((remote == nullptr), devicestatusData);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@ -114,7 +114,7 @@ DeviceStatusDataUtils::DeviceStatusData DeviceStatusSrvProxy::GetCache(const \
|
||||
WRITEINT32(data, type, devicestatusData);
|
||||
|
||||
int32_t ret = remote->SendRequest(static_cast<int32_t>(Idevicestatus::DEVICESTATUS_GETCACHE), data, reply, option);
|
||||
if (ret != ERR_OK) {
|
||||
if (ret != RET_OK) {
|
||||
DEV_HILOGE(INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return devicestatusData;
|
||||
}
|
||||
@ -123,8 +123,8 @@ DeviceStatusDataUtils::DeviceStatusData DeviceStatusSrvProxy::GetCache(const \
|
||||
int32_t devicestatusValue = -1;
|
||||
READINT32(reply, devicestatusType, devicestatusData);
|
||||
READINT32(reply, devicestatusValue, devicestatusData);
|
||||
devicestatusData.type = DeviceStatusDataUtils::DeviceStatusType(devicestatusType);
|
||||
devicestatusData.value = DeviceStatusDataUtils::DeviceStatusValue(devicestatusValue);
|
||||
devicestatusData.type = Type(devicestatusType);
|
||||
devicestatusData.value = OnChangedValue(devicestatusValue);
|
||||
DEV_HILOGD(INNERKIT, "type: %{public}d, value: %{public}d", devicestatusData.type, devicestatusData.value);
|
||||
DEV_HILOGD(INNERKIT, "Exit");
|
||||
return devicestatusData;
|
||||
|
45
interfaces/innerkits/include/bytrace_adapter.h
Normal file
45
interfaces/innerkits/include/bytrace_adapter.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_MSDP_BYTRACE_ADAPTER_H
|
||||
#define OHOS_MSDP_BYTRACE_ADAPTER_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "hitrace_meter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class BytraceAdapter {
|
||||
public:
|
||||
enum TraceBtn {
|
||||
TRACE_STOP = 0,
|
||||
TRACE_START = 1
|
||||
};
|
||||
enum SubscribeType {
|
||||
SUBSCRIBE,
|
||||
UNSUBSCRIBE
|
||||
};
|
||||
enum SubscribeObject {
|
||||
CLIENT,
|
||||
SERVICE
|
||||
};
|
||||
|
||||
static void StartBytrace(TraceBtn traceBtn, SubscribeType subscribeType, SubscribeObject subscribeObject);
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace MSDP
|
||||
} // namespace OHOS
|
||||
#endif // BYTRACE_ADAPTER_H
|
@ -31,29 +31,30 @@ public:
|
||||
class DeviceStatusAgentEvent {
|
||||
public:
|
||||
virtual ~DeviceStatusAgentEvent() = default;
|
||||
virtual bool OnEventResult(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) = 0;
|
||||
virtual bool OnEventResult(const Data& devicestatusData) = 0;
|
||||
};
|
||||
|
||||
class DeviceStatusAgentCallback : public DeviceStatusCallbackStub {
|
||||
public:
|
||||
explicit DeviceStatusAgentCallback(std::shared_ptr<DeviceStatusAgent> agent) : agent_(agent) {};
|
||||
virtual ~DeviceStatusAgentCallback() {};
|
||||
void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
|
||||
void OnDeviceStatusChanged(const Data& devicestatusData) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<DeviceStatusAgent> agent_;
|
||||
};
|
||||
|
||||
int32_t SubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type,
|
||||
int32_t SubscribeAgentEvent(const Type& type, const ActivityEvent& event, const ReportLatencyNs& latency,
|
||||
const std::shared_ptr<DeviceStatusAgent::DeviceStatusAgentEvent>& agentEvent);
|
||||
int32_t UnsubscribeAgentEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
|
||||
int32_t UnsubscribeAgentEvent(const Type& type, const ActivityEvent& event);
|
||||
friend class DeviceStatusAgentCallback;
|
||||
private:
|
||||
void RegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
|
||||
void UnRegisterServiceEvent(const DeviceStatusDataUtils::DeviceStatusType& type);
|
||||
sptr<IdevicestatusCallback> callback_;
|
||||
void RegisterServiceEvent(const Type& type, const ActivityEvent& event, const ReportLatencyNs& latency);
|
||||
void UnRegisterServiceEvent(const Type& type, const ActivityEvent& event);
|
||||
sptr<IRemoteDevStaCallback> callback_;
|
||||
std::shared_ptr<DeviceStatusAgentEvent> agentEvent_;
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_MSDP_DEVICESTATUS_AGENT_H
|
||||
#endif // OHOS_MSDP_DEVICESTATUS_AGENT_H
|
||||
|
@ -21,17 +21,18 @@
|
||||
|
||||
#include "idevicestatus_callback.h"
|
||||
#include "devicestatus_data_utils.h"
|
||||
#include "devicestatus_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class DeviceStatusCallbackProxy : public IRemoteProxy<IdevicestatusCallback> {
|
||||
class DeviceStatusCallbackProxy : public IRemoteProxy<IRemoteDevStaCallback> {
|
||||
public:
|
||||
explicit DeviceStatusCallbackProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IdevicestatusCallback>(impl) {}
|
||||
: IRemoteProxy<IRemoteDevStaCallback>(impl) {}
|
||||
~DeviceStatusCallbackProxy() = default;
|
||||
DISALLOW_COPY_AND_MOVE(DeviceStatusCallbackProxy);
|
||||
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) override;
|
||||
virtual void OnDeviceStatusChanged(const Data& devicestatusData) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<DeviceStatusCallbackProxy> delegator_;
|
||||
|
@ -16,7 +16,9 @@
|
||||
#ifndef DEVICESTATUS_CLIENT_H
|
||||
#define DEVICESTATUS_CLIENT_H
|
||||
|
||||
#include <functional>
|
||||
#include <singleton.h>
|
||||
#include <map>
|
||||
|
||||
#include "idevicestatus.h"
|
||||
#include "idevicestatus_callback.h"
|
||||
@ -31,13 +33,17 @@ class DeviceStatusClient final : public DelayedRefSingleton<DeviceStatusClient>
|
||||
DECLARE_DELAYED_REF_SINGLETON(DeviceStatusClient)
|
||||
|
||||
public:
|
||||
std::map<Type, int32_t> GetTypeMap()
|
||||
{
|
||||
return typeMap_;
|
||||
}
|
||||
DISALLOW_COPY_AND_MOVE(DeviceStatusClient);
|
||||
|
||||
void SubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback);
|
||||
void UnsubscribeCallback(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback);
|
||||
DeviceStatusDataUtils::DeviceStatusData GetDeviceStatusData(const DeviceStatusDataUtils::DeviceStatusType& type);
|
||||
void SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
|
||||
sptr<IRemoteDevStaCallback> callback);
|
||||
void UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback);
|
||||
Data GetDeviceStatusData(const Type type);
|
||||
void RegisterDeathListener(std::function<void()> deathListener);
|
||||
|
||||
int32_t RegisterCoordinationListener();
|
||||
int32_t UnregisterCoordinationListener();
|
||||
@ -63,10 +69,12 @@ private:
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
|
||||
void ResetProxy(const wptr<IRemoteObject>& remote);
|
||||
std::mutex mutex_;
|
||||
int32_t tokenType_ { -1 };
|
||||
int32_t tokenType_ { -1 };
|
||||
int32_t socketFd_ { -1 };
|
||||
std::map<Type, int32_t> typeMap_ = {};
|
||||
std::function<void()> deathListener_ { nullptr };
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // IDEVICESTATUS_H
|
||||
#endif // DEVICESTATUS_CLIENT_H
|
||||
|
@ -16,38 +16,78 @@
|
||||
#ifndef DEVICESTATUS_DATA_UTILS_H
|
||||
#define DEVICESTATUS_DATA_UTILS_H
|
||||
|
||||
#include<string>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class DeviceStatusDataUtils {
|
||||
public:
|
||||
enum DeviceStatusType {
|
||||
TYPE_INVALID = -1,
|
||||
TYPE_HIGH_STILL,
|
||||
TYPE_FINE_STILL,
|
||||
TYPE_CAR_BLUETOOTH,
|
||||
TYPE_STAND,
|
||||
TYPE_LID_OPEN,
|
||||
TYPE_MAX
|
||||
};
|
||||
constexpr double MOVEMENT_THRESHOLD = 0.001;
|
||||
enum Type {
|
||||
TYPE_INVALID = -1,
|
||||
TYPE_STILL,
|
||||
TYPE_HORIZONTAL_POSITION,
|
||||
TYPE_VERTICAL_POSITION,
|
||||
TYPE_LID_OPEN,
|
||||
TYPE_MAX
|
||||
};
|
||||
|
||||
enum DeviceStatusValue {
|
||||
VALUE_INVALID = -1,
|
||||
VALUE_ENTER = 1,
|
||||
VALUE_EXIT
|
||||
};
|
||||
enum TypeValue : bool {
|
||||
INVALID = false,
|
||||
VALID = true,
|
||||
};
|
||||
|
||||
enum Value {
|
||||
INVALID = 0,
|
||||
VALID
|
||||
};
|
||||
enum OnChangedValue {
|
||||
VALUE_INVALID = -1,
|
||||
VALUE_EXIT,
|
||||
VALUE_ENTER
|
||||
};
|
||||
|
||||
struct DeviceStatusData {
|
||||
DeviceStatusType type;
|
||||
DeviceStatusValue value;
|
||||
};
|
||||
enum ActivityEvent {
|
||||
EVENT_INVALID = 0,
|
||||
ENTER = 1,
|
||||
EXIT = 2,
|
||||
ENTER_EXIT = 3
|
||||
};
|
||||
|
||||
enum ReportLatencyNs {
|
||||
Latency_INVALID = -1,
|
||||
SHORT = 1,
|
||||
MIDDLE = 2,
|
||||
LONG = 3
|
||||
};
|
||||
enum Status {
|
||||
STATUS_INVALID = -1,
|
||||
STATUS_CANCEL,
|
||||
STATUS_START,
|
||||
STATUS_PROCESS,
|
||||
STATUS_FINISH
|
||||
};
|
||||
|
||||
enum Action {
|
||||
ACTION_INVALID = -1,
|
||||
ACTION_ENLARGE,
|
||||
ACTION_REDUCE,
|
||||
ACTION_UP,
|
||||
ACTION_LEFT,
|
||||
ACTION_DOWN,
|
||||
ACTION_RIGHT
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Type type;
|
||||
OnChangedValue value;
|
||||
Status status;
|
||||
Action action;
|
||||
double movement;
|
||||
|
||||
bool operator !=(const Data& r) const
|
||||
{
|
||||
if (type == r.type && value == r.value &&
|
||||
status - r.status && action == r.action && (movement - r.movement) < MOVEMENT_THRESHOLD) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
typedef struct DeviceStatusJsonData {
|
||||
@ -56,13 +96,13 @@ typedef struct DeviceStatusJsonData {
|
||||
}DeviceStatusJsonD;
|
||||
|
||||
static DeviceStatusJsonD DeviceStatusJson[] = {
|
||||
{DeviceStatusDataUtils::DeviceStatusType::TYPE_HIGH_STILL, "TYPE_HIGH_STILL"},
|
||||
{DeviceStatusDataUtils::DeviceStatusType::TYPE_FINE_STILL, "TYPE_FINE_STILL"},
|
||||
{DeviceStatusDataUtils::DeviceStatusType::TYPE_CAR_BLUETOOTH, "TYPE_CAR_BLUETOOTH"},
|
||||
{DeviceStatusDataUtils::DeviceStatusType::TYPE_STAND, "TYPE_STAND"},
|
||||
{DeviceStatusDataUtils::DeviceStatusType::TYPE_LID_OPEN, "TYPE_LID_OPEN"}
|
||||
{Type::TYPE_STILL, "STILL"},
|
||||
{Type::TYPE_HORIZONTAL_POSITION, "HORIZONTAL_POSITION"},
|
||||
{Type::TYPE_VERTICAL_POSITION, "VERTICAL_POSITION"},
|
||||
{Type::TYPE_LID_OPEN, "LID_OPEN"},
|
||||
{Type::TYPE_MAX, "MAX"}
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DEVICESTATUS_DATA_UTILS_H
|
||||
#endif // DEVICESTATUS_DATA_UTILS_H
|
||||
|
@ -31,12 +31,11 @@ public:
|
||||
~DeviceStatusSrvProxy() = default;
|
||||
DISALLOW_COPY_AND_MOVE(DeviceStatusSrvProxy);
|
||||
|
||||
virtual void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback) override;
|
||||
virtual void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback) override;
|
||||
virtual DeviceStatusDataUtils::DeviceStatusData GetCache(const \
|
||||
DeviceStatusDataUtils::DeviceStatusType& type) override;
|
||||
virtual void Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency,
|
||||
sptr<IRemoteDevStaCallback> callback) override;
|
||||
virtual void Unsubscribe(Type type, ActivityEvent event,
|
||||
sptr<IRemoteDevStaCallback> callback) override;
|
||||
virtual Data GetCache(const Type& type) override;
|
||||
|
||||
virtual int32_t RegisterCoordinationListener() override;
|
||||
virtual int32_t UnregisterCoordinationListener() override;
|
||||
|
@ -40,11 +40,14 @@ public:
|
||||
ALLOC_SOCKET_FD = 40
|
||||
};
|
||||
|
||||
virtual void Subscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback) = 0;
|
||||
virtual void Unsubscribe(const DeviceStatusDataUtils::DeviceStatusType& type, \
|
||||
const sptr<IdevicestatusCallback>& callback) = 0;
|
||||
virtual DeviceStatusDataUtils::DeviceStatusData GetCache(const DeviceStatusDataUtils::DeviceStatusType& type) = 0;
|
||||
virtual void Subscribe(Type type,
|
||||
ActivityEvent event,
|
||||
ReportLatencyNs latency,
|
||||
sptr<IRemoteDevStaCallback> callback) = 0;
|
||||
virtual void Unsubscribe(Type type,
|
||||
ActivityEvent event,
|
||||
sptr<IRemoteDevStaCallback> callback) = 0;
|
||||
virtual Data GetCache(const Type& type) = 0;
|
||||
|
||||
virtual int32_t RegisterCoordinationListener() = 0;
|
||||
virtual int32_t UnregisterCoordinationListener() = 0;
|
||||
|
@ -35,4 +35,4 @@ public:
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // IDEVICESTATUS_ALGORITHM_H
|
||||
#endif // IDEVICESTATUS_ALGORITHM_H
|
||||
|
@ -25,11 +25,11 @@ namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IdevicestatusAlgorithmCallback : public IRemoteBroker {
|
||||
public:
|
||||
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& data) = 0;
|
||||
virtual void OnDeviceStatusChanged(const Data& data) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IdevicestatusAlgorithmCallback");
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // IDEVICESTATUS_ALGORITHM_CALLBACK_H
|
||||
#endif // IDEVICESTATUS_ALGORITHM_CALLBACK_H
|
||||
|
@ -24,17 +24,17 @@
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
class IdevicestatusCallback : public IRemoteBroker {
|
||||
class IRemoteDevStaCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
DEVICESTATUS_CHANGE = 0,
|
||||
};
|
||||
|
||||
virtual void OnDeviceStatusChanged(const DeviceStatusDataUtils::DeviceStatusData& devicestatusData) = 0;
|
||||
virtual void OnDeviceStatusChanged(const Data& devicestatusData) = 0;
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IdevicestatusCallback");
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.msdp.IRemoteDevStaCallback");
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // IDEVICESTATUS_CALLBACK_H
|
||||
#endif // IDEVICESTATUS_CALLBACK_H
|
||||
|
@ -26,8 +26,8 @@ namespace DeviceStatus {
|
||||
class IdevicestatusStorage : public IRemoteBroker {
|
||||
public:
|
||||
struct DeviceStatusRecord {
|
||||
DeviceStatusDataUtils::DeviceStatusType type;
|
||||
DeviceStatusDataUtils::DeviceStatusValue value;
|
||||
Type type;
|
||||
OnChangedValue value;
|
||||
std::string date;
|
||||
std::string time;
|
||||
};
|
||||
@ -39,4 +39,4 @@ public:
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // IDEVICESTATUS_STORAGE_H
|
||||
#endif // IDEVICESTATUS_STORAGE_H
|
||||
|
@ -25,15 +25,15 @@
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
#define DEVICESTATUS_RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
|
||||
#define DEVICESTATUS_RETURN_IF(cond) if (cond) {return;}
|
||||
#define DEVICESTATUS_RETURN_IF_WITH_LOG(cond, loginfo) \
|
||||
do { \
|
||||
if (cond) { \
|
||||
#define DEV_RET_IF_NULL_WITH_RET(cond, retval) if (cond) {return (retval);}
|
||||
#define DEV_RET_IF_NULL(cond) if (cond) {return;}
|
||||
#define DEV_RET_IF_NULL_WITH_LOG(cond, loginfo) \
|
||||
do { \
|
||||
if (cond) { \
|
||||
DEV_HILOGE(COMMON, "%{public}s "#loginfo" ", __func__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0) \
|
||||
return; \
|
||||
} \
|
||||
} while (0) \
|
||||
|
||||
#define WRITEBOOL(parcel, data, ...) \
|
||||
do { \
|
||||
|
@ -55,7 +55,7 @@ sptr<T> DelayedSpSingleton<T>::GetInstance()
|
||||
if (!instance_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new (std::nothrow) T();
|
||||
instance_ = new T();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,15 @@ enum {
|
||||
ERROR_UNSUPPORT,
|
||||
ERROR_NULL_POINTER,
|
||||
};
|
||||
|
||||
enum {
|
||||
DEVICESTATUS_OK = 0,
|
||||
DEVICESTATUS_FAILED = -1,
|
||||
DEVICESTATUS_INVALID_FD = -2,
|
||||
DEVICESTATUS_NOT_FIND_JSON_ITEM = -3,
|
||||
};
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DEVICESTATUS_ERRORS_H
|
||||
#endif // DEVICESTATUS_ERRORS_H
|
||||
|
@ -32,4 +32,4 @@ public:
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
||||
#endif // DEVICESTATUS_PERMISSION_H
|
||||
#endif // DEVICESTATUS_PERMISSION_H
|
||||
|
Loading…
Reference in New Issue
Block a user