mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 00:20:44 +00:00
add continuation manager
Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com> Change-Id: Ib67b8ee49ec0c28667352ff367ed44646a09cc0b Signed-off-by: zhangmingxiang <zhangmingxiang@huawei.com>
This commit is contained in:
parent
912def657a
commit
c886c89ee7
14
etc/param/dms.para
Executable file
14
etc/param/dms.para
Executable file
@ -0,0 +1,14 @@
|
||||
# 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.
|
||||
|
||||
const.distributedsched.panelname="ohos.samples.eTSServiceExtAbility_ServiceExtAbility"
|
14
etc/param/dms.para.dac
Executable file
14
etc/param/dms.para.dac
Executable file
@ -0,0 +1,14 @@
|
||||
# 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.
|
||||
|
||||
const.distributedsched. = dms:dms:0775
|
46
interfaces/innerkits/common/include/distributed_sched_client.h
Executable file
46
interfaces/innerkits/common/include/distributed_sched_client.h
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_CLIENT_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_CLIENT_H
|
||||
|
||||
#include "continuation_extra_params.h"
|
||||
#include "device_connect_status.h"
|
||||
#include "device_selection_notifier_stub.h"
|
||||
#include "distributed_sched_interface.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedSchedClient {
|
||||
DECLARE_SINGLE_INSTANCE(DistributedSchedClient);
|
||||
|
||||
public:
|
||||
int32_t Register(const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams, int32_t& token);
|
||||
int32_t Unregister(int32_t token);
|
||||
int32_t RegisterDeviceSelectionCallback(
|
||||
int32_t token, const std::string& cbType, const sptr<DeviceSelectionNotifierStub>& notifier);
|
||||
int32_t UnregisterDeviceSelectionCallback(int32_t token, const std::string& cbType);
|
||||
int32_t UpdateConnectStatus(int32_t token, const std::string& deviceId,
|
||||
const DeviceConnectStatus& deviceConnectStatus);
|
||||
int32_t StartDeviceManager(
|
||||
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
|
||||
private:
|
||||
sptr<IDistributedSched> GetDmsProxy();
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_CLIENT_H
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_PROXY_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_PROXY_H
|
||||
|
||||
#include "distributed_sched_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedSchedProxy : public IRemoteProxy<IDistributedSched> {
|
||||
public:
|
||||
explicit DistributedSchedProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IDistributedSched>(impl) {}
|
||||
~DistributedSchedProxy() {}
|
||||
int32_t Register(
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams, int32_t& token) override;
|
||||
int32_t Unregister(int32_t token) override;
|
||||
int32_t RegisterDeviceSelectionCallback(
|
||||
int32_t token, const std::string& cbType, const sptr<IRemoteObject>& notifier) override;
|
||||
int32_t UnregisterDeviceSelectionCallback(int32_t token, const std::string& cbType) override;
|
||||
int32_t UpdateConnectStatus(int32_t token, const std::string& deviceId,
|
||||
const DeviceConnectStatus& deviceConnectStatus) override;
|
||||
int32_t StartDeviceManager(
|
||||
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
|
||||
int32_t OnDeviceConnect(int32_t token, const std::vector<ContinuationResult>& continuationResults) override;
|
||||
int32_t OnDeviceDisconnect(int32_t token, const std::vector<std::string>& deviceIds) override;
|
||||
int32_t OnDeviceCancel(int32_t token) override;
|
||||
private:
|
||||
static inline BrokerDelegator<DistributedSchedProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_PROXY_H
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_EXTRA_PARAMS_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_EXTRA_PARAMS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "continuation_mode.h"
|
||||
#include "parcel.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class ContinuationExtraParams : public Parcelable {
|
||||
public:
|
||||
ContinuationExtraParams() = default;
|
||||
~ContinuationExtraParams() = default;
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static ContinuationExtraParams *Unmarshalling(Parcel &parcel);
|
||||
|
||||
void SetDeviceType(std::vector<std::string> deviceTypeVec);
|
||||
std::vector<std::string> GetDeviceType() const;
|
||||
|
||||
void SetTargetBundle(std::string targetBundle);
|
||||
std::string GetTargetBundle() const;
|
||||
|
||||
void SetDescription(std::string description);
|
||||
std::string GetDescription() const;
|
||||
|
||||
void SetFilter(std::string filter);
|
||||
std::string GetFilter() const;
|
||||
|
||||
void SetContinuationMode(ContinuationMode continuationMode);
|
||||
ContinuationMode GetContinuationMode() const;
|
||||
|
||||
void SetAuthInfo(std::string authInfo);
|
||||
std::string GetAuthInfo() const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> deviceTypeVec_;
|
||||
std::string targetBundle_;
|
||||
std::string description_;
|
||||
std::string filter_;
|
||||
ContinuationMode continuationMode_;
|
||||
std::string authInfo_;
|
||||
};
|
||||
|
||||
class ContinationManagerUtils {
|
||||
public:
|
||||
ContinationManagerUtils() = default;
|
||||
~ContinationManagerUtils() = default;
|
||||
|
||||
static std::vector<std::u16string> Str8VecToStr16Vec(const std::vector<std::string>& input);
|
||||
static std::vector<std::string> Str16VecToStr8Vec(const std::vector<std::u16string>& input);
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_EXTRA_PARAMS_H
|
38
interfaces/innerkits/continuation_manager/include/continuation_mode.h
Executable file
38
interfaces/innerkits/continuation_manager/include/continuation_mode.h
Executable file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_MODE_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_MODE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
/**
|
||||
* @enum ContinuationMode
|
||||
* ContinuationMode defines the description of additional parameters for continuation.
|
||||
*/
|
||||
enum class ContinuationMode {
|
||||
/**
|
||||
* Collaboration with a single device.
|
||||
*/
|
||||
COLLABORATION_SINGLE = 0,
|
||||
|
||||
/**
|
||||
* Collaboration with a mutiple device.
|
||||
*/
|
||||
COLLABORATION_MUTIPLE = 1,
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_MODE_H
|
54
interfaces/innerkits/continuation_manager/include/continuation_result.h
Executable file
54
interfaces/innerkits/continuation_manager/include/continuation_result.h
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_RESULT_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_RESULT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class ContinuationResult : public Parcelable {
|
||||
public:
|
||||
ContinuationResult() = default;
|
||||
~ContinuationResult() = default;
|
||||
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static ContinuationResult *Unmarshalling(Parcel &parcel);
|
||||
|
||||
void SetDeviceId(std::string deviceId);
|
||||
std::string GetDeviceId() const;
|
||||
|
||||
void SetDeviceType(std::string deviceType);
|
||||
std::string GetDeviceType() const;
|
||||
|
||||
void SetDeviceName(std::string deviceName);
|
||||
std::string GetDeviceName() const;
|
||||
|
||||
static bool ReadContinuationResultsFromParcel(Parcel& parcel,
|
||||
std::vector<ContinuationResult>& continuationResults);
|
||||
static bool WriteContinuationResultsToParcel(Parcel& parcel,
|
||||
const std::vector<ContinuationResult>& continuationResults);
|
||||
private:
|
||||
std::string deviceId_;
|
||||
std::string deviceType_;
|
||||
std::string deviceName_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_CONTINUATION_RESULT_H
|
48
interfaces/innerkits/continuation_manager/include/device_connect_status.h
Executable file
48
interfaces/innerkits/continuation_manager/include/device_connect_status.h
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_CONNECT_STATUS_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_CONNECT_STATUS_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
/**
|
||||
* @enum DeviceConnectStatus
|
||||
* DeviceConnectStatus defines the device connection status.
|
||||
*/
|
||||
enum class DeviceConnectStatus {
|
||||
/**
|
||||
* Device initial status.
|
||||
*/
|
||||
IDLE = 0,
|
||||
|
||||
/**
|
||||
* Device connecting status.
|
||||
*/
|
||||
CONNECTING = 1,
|
||||
|
||||
/**
|
||||
* Device connected status.
|
||||
*/
|
||||
CONNECTED = 2,
|
||||
|
||||
/**
|
||||
* Device disconnected status.
|
||||
*/
|
||||
DISCONNECTING = 3,
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_CONNECT_STATUS_H
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_SELECTION_NOTIFIER_STUB_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_SELECTION_NOTIFIER_STUB_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "message_parcel.h"
|
||||
#include "idevice_selection_notifier.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DeviceSelectionNotifierStub : public IRemoteStub<IDeviceSelectionNotifier> {
|
||||
public:
|
||||
DeviceSelectionNotifierStub() = default;
|
||||
virtual ~DeviceSelectionNotifierStub() = default;
|
||||
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option) override;
|
||||
|
||||
private:
|
||||
using Handler = int32_t(DeviceSelectionNotifierStub::*)(MessageParcel& data, MessageParcel& reply);
|
||||
using HandlersMap = std::map<uint32_t, Handler>;
|
||||
|
||||
static HandlersMap InitHandlersMap();
|
||||
|
||||
int32_t OnDeviceConnectInner(MessageParcel& data, MessageParcel& reply);
|
||||
int32_t OnDeviceDisconnectInner(MessageParcel& data, MessageParcel& reply);
|
||||
|
||||
private:
|
||||
static const HandlersMap handlersMap_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DEVICE_SELECTION_NOTIFIER_STUB_H
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_I_DEVICE_SELECTION_NOTIFIER_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_I_DEVICE_SELECTION_NOTIFIER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "continuation_result.h"
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string EVENT_CONNECT = "deviceConnect";
|
||||
const std::string EVENT_DISCONNECT = "deviceDisconnect";
|
||||
}
|
||||
|
||||
class IDeviceSelectionNotifier : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedSchedule.IDeviceSelectionNotifier");
|
||||
|
||||
IDeviceSelectionNotifier() = default;
|
||||
virtual ~IDeviceSelectionNotifier() = default;
|
||||
|
||||
virtual void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) {}
|
||||
virtual void OnDeviceDisconnect(const std::vector<std::string>& deviceIds) {}
|
||||
|
||||
enum RequestCode {
|
||||
EVENT_DEVICE_CONNECT = 1,
|
||||
EVENT_DEVICE_DISCONNECT = 2,
|
||||
};
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_I_DEVICE_SELECTION_NOTIFIER_H
|
29
interfaces/kits/napi/continuation_manager/continuation_manager_module.cpp
Executable file
29
interfaces/kits/napi/continuation_manager/continuation_manager_module.cpp
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 "native_engine/native_engine.h"
|
||||
#include "js_continuation_manager.h"
|
||||
|
||||
extern "C" __attribute__((constructor)) void NAPI_application_continuationmanager_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "continuation.continuationManager",
|
||||
.fileName = "continuation/libcontinuationmanager_napi.so/continuationmanager.js",
|
||||
.registerCallback = OHOS::DistributedSchedule::JsContinuationManagerInit,
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
541
interfaces/kits/napi/continuation_manager/js_continuation_manager.cpp
Executable file
541
interfaces/kits/napi/continuation_manager/js_continuation_manager.cpp
Executable file
@ -0,0 +1,541 @@
|
||||
/*
|
||||
* 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 "js_continuation_manager.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "distributed_sched_client.h"
|
||||
#include "device_connect_status.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
using namespace OHOS::AbilityRuntime;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
namespace {
|
||||
const std::string TAG = "JsContinuationManager";
|
||||
constexpr int32_t ERR_NOT_OK = -1;
|
||||
constexpr int32_t ARG_COUNT_ONE = 1;
|
||||
constexpr int32_t ARG_COUNT_TWO = 2;
|
||||
constexpr int32_t ARG_COUNT_THREE = 3;
|
||||
}
|
||||
|
||||
void JsContinuationManager::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOGI("JsContinuationManager::Finalizer is called");
|
||||
std::unique_ptr<JsContinuationManager>(static_cast<JsContinuationManager*>(data));
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::Register(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegister(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::Unregister(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnregister(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::RegisterDeviceSelectionCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnRegisterDeviceSelectionCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::UnregisterDeviceSelectionCallback(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsContinuationManager* me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUnregisterDeviceSelectionCallback(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::UpdateConnectStatus(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnUpdateConnectStatus(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::StartDeviceManager(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartDeviceManager(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::InitDeviceConnectStateObject(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnInitDeviceConnectStateObject(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::InitContinuationModeObject(NativeEngine *engine, NativeCallbackInfo *info)
|
||||
{
|
||||
JsContinuationManager *me = CheckParamsAndGetThis<JsContinuationManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnInitContinuationModeObject(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnRegister(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t errCode = 0;
|
||||
decltype(info.argc) unwrapArgc = 0;
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOGI("register options is used.");
|
||||
if (!UnWrapContinuationExtraParams(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[0]), continuationExtraParams)) {
|
||||
HILOGE("Parse continuationExtraParams failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
unwrapArgc++;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[continuationExtraParams, unwrapArgc, errCode](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
int32_t token = -1;
|
||||
int32_t ret = (unwrapArgc == 0) ? DistributedSchedClient::GetInstance().Register(nullptr, token) :
|
||||
DistributedSchedClient::GetInstance().Register(continuationExtraParams, token);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateNumber(token));
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ret, "Register failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnRegister",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnUnregister(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t errCode = 0;
|
||||
if (info.argc == 0) {
|
||||
HILOGE("Params not match");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!errCode && !ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[token, errCode](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
int32_t ret = DistributedSchedClient::GetInstance().Unregister(token);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ret, "Unregister failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARG_COUNT_ONE) ? nullptr : info.argv[ARG_COUNT_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnUnregister",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnRegisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (info.argc != ARG_COUNT_THREE) {
|
||||
HILOGE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
HILOGE("Parse cbType failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* jsListenerObj = info.argv[ARG_COUNT_TWO];
|
||||
if (!IfCallbackValid(jsListenerObj)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (IfCallbackRegistered(token, cbType)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::unique_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(jsListenerObj, 1));
|
||||
sptr<JsDeviceSelectionListener> deviceSelectionListener = new JsDeviceSelectionListener(&engine);
|
||||
if (deviceSelectionListener == nullptr) {
|
||||
HILOGE("deviceSelectionListener is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t ret = DistributedSchedClient::GetInstance().RegisterDeviceSelectionCallback(
|
||||
token, cbType, deviceSelectionListener);
|
||||
if (ret == ERR_OK) {
|
||||
deviceSelectionListener->AddCallback(cbType, jsListenerObj);
|
||||
CallbackPair callbackPair = std::make_pair(std::move(callbackRef), deviceSelectionListener);
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
jsCbMap_[token][cbType] = std::move(callbackPair); // move assignment
|
||||
}
|
||||
HILOGI("RegisterDeviceSelectionListener success");
|
||||
} else {
|
||||
deviceSelectionListener = nullptr;
|
||||
HILOGE("RegisterDeviceSelectionListener failed");
|
||||
}
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManager::OnUnregisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (info.argc != ARG_COUNT_TWO) {
|
||||
HILOGE("Params not match");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
HILOGE("Parse cbType failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (cbType != EVENT_CONNECT && cbType != EVENT_DISCONNECT) {
|
||||
HILOGE("type: %{public}s not support!", cbType.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!IfCallbackRegistered(token, cbType)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
CallbackPair& callbackPair = jsCbMap_[token][cbType];
|
||||
auto& listener = callbackPair.second;
|
||||
int32_t ret = DistributedSchedClient::GetInstance().UnregisterDeviceSelectionCallback(token, cbType);
|
||||
if (ret == ERR_OK) {
|
||||
listener->RemoveCallback(cbType);
|
||||
jsCbMap_[token].erase(cbType);
|
||||
if (jsCbMap_[token].empty()) {
|
||||
jsCbMap_.erase(token);
|
||||
}
|
||||
HILOGI("UnregisterDeviceSelectionCallback success");
|
||||
} else {
|
||||
HILOGE("UnregisterDeviceSelectionCallback failed");
|
||||
}
|
||||
}
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnUpdateConnectStatus(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t errCode = 0;
|
||||
if (info.argc < ARG_COUNT_THREE) {
|
||||
HILOGE("Params not match");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!errCode && !ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
std::string deviceId;
|
||||
if (!errCode && !ConvertFromJsValue(engine, info.argv[ARG_COUNT_ONE], deviceId)) {
|
||||
HILOGE("Parse deviceId failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::IDLE;
|
||||
if (!errCode && !ConvertFromJsValue(engine, info.argv[ARG_COUNT_TWO], deviceConnectStatus)) {
|
||||
HILOGE("Parse device connect status failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[token, deviceId, deviceConnectStatus, errCode](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
int32_t ret = DistributedSchedClient::GetInstance().UpdateConnectStatus(token, deviceId, deviceConnectStatus);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ret, "UpdateConnectStatus failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= ARG_COUNT_THREE) ? nullptr : info.argv[ARG_COUNT_THREE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnUpdateConnectStatus",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnStartDeviceManager(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
HILOGD("called.");
|
||||
int32_t errCode = 0;
|
||||
if (info.argc < ARG_COUNT_ONE) {
|
||||
HILOGE("Params not match");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
int32_t token = -1;
|
||||
if (!errCode && !ConvertFromJsValue(engine, info.argv[0], token)) {
|
||||
HILOGE("Parse token failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
decltype(info.argc) unwrapArgc = ARG_COUNT_ONE;
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
|
||||
if (info.argc > ARG_COUNT_ONE && info.argv[ARG_COUNT_ONE]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOGI("startDeviceManager options is used.");
|
||||
if (!UnWrapContinuationExtraParams(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[ARG_COUNT_ONE]), continuationExtraParams)) {
|
||||
HILOGE("Parse continuationExtraParams failed");
|
||||
errCode = ERR_NOT_OK;
|
||||
}
|
||||
unwrapArgc++;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[token, continuationExtraParams, unwrapArgc, errCode](NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
if (errCode != 0) {
|
||||
task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
int32_t ret = (unwrapArgc == ARG_COUNT_ONE) ? DistributedSchedClient::GetInstance().StartDeviceManager(token) :
|
||||
DistributedSchedClient::GetInstance().StartDeviceManager(token, continuationExtraParams);
|
||||
if (ret == ERR_OK) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, ret, "StartDeviceManager failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsContinuationManager::OnStartDeviceManager",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnInitDeviceConnectStateObject(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
napi_value object;
|
||||
napi_env env = reinterpret_cast<napi_env>(&engine);
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "IDLE",
|
||||
static_cast<int32_t>(DeviceConnectStatus::IDLE)));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "CONNECTING",
|
||||
static_cast<int32_t>(DeviceConnectStatus::CONNECTING)));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "CONNECTED",
|
||||
static_cast<int32_t>(DeviceConnectStatus::CONNECTED)));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "DISCONNECTING",
|
||||
static_cast<int32_t>(DeviceConnectStatus::DISCONNECTING)));
|
||||
|
||||
return reinterpret_cast<NativeValue*>(object);
|
||||
}
|
||||
|
||||
NativeValue *JsContinuationManager::OnInitContinuationModeObject(NativeEngine &engine, NativeCallbackInfo &info)
|
||||
{
|
||||
napi_value object;
|
||||
napi_env env = reinterpret_cast<napi_env>(&engine);
|
||||
NAPI_CALL(env, napi_create_object(env, &object));
|
||||
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "COLLABORATION_SINGLE",
|
||||
static_cast<int32_t>(ContinuationMode::COLLABORATION_SINGLE)));
|
||||
NAPI_CALL(env, SetEnumItem(env, object, "COLLABORATION_MULTIPLE",
|
||||
static_cast<int32_t>(ContinuationMode::COLLABORATION_MUTIPLE)));
|
||||
|
||||
return reinterpret_cast<NativeValue*>(object);
|
||||
}
|
||||
|
||||
napi_status JsContinuationManager::SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value)
|
||||
{
|
||||
napi_status status;
|
||||
napi_value itemName;
|
||||
napi_value itemValue;
|
||||
|
||||
NAPI_CALL_BASE(env, status = napi_create_string_utf8(env, name, NAPI_AUTO_LENGTH, &itemName), status);
|
||||
NAPI_CALL_BASE(env, status = napi_create_int32(env, value, &itemValue), status);
|
||||
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemName, itemValue), status);
|
||||
NAPI_CALL_BASE(env, status = napi_set_property(env, object, itemValue, itemName), status);
|
||||
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
bool JsContinuationManager::IfCallbackValid(NativeValue* listenerObj)
|
||||
{
|
||||
if (listenerObj == nullptr) {
|
||||
HILOGE("listenerObj is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (!listenerObj->IsCallable()) {
|
||||
HILOGE("listenerObj is not callable");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsContinuationManager::IfCallbackRegistered(int32_t token, const std::string& cbType)
|
||||
{
|
||||
std::lock_guard<std::mutex> jsCbMapLock(jsCbMapMutex_);
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(token) == jsCbMap_.end()) {
|
||||
HILOGE("token %{public}d not registered callback!", token);
|
||||
return false;
|
||||
}
|
||||
if (jsCbMap_[token].empty() || jsCbMap_[token].find(cbType) == jsCbMap_[token].end()) {
|
||||
HILOGE("cbType %{public}s not registered callback!", cbType.c_str());
|
||||
return false;
|
||||
}
|
||||
HILOGI("callback already registered, token: %{public}d, cbType %{public}s", token, cbType.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsContinuationManager::UnWrapContinuationExtraParams(napi_env env, napi_value options,
|
||||
std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (!IsTypeForNapiValue(env, options, napi_object)) {
|
||||
HILOGE("options is invalid.");
|
||||
return false;
|
||||
}
|
||||
std::vector<std::string> deviceTypeStringList;
|
||||
if (UnwrapStringArrayByPropertyName(env, options, "deviceType", deviceTypeStringList)) {
|
||||
continuationExtraParams->SetDeviceType(deviceTypeStringList);
|
||||
}
|
||||
std::string targetBundleString("");
|
||||
if (UnwrapStringByPropertyName(env, options, "targetBundle", targetBundleString)) {
|
||||
continuationExtraParams->SetTargetBundle(targetBundleString);
|
||||
}
|
||||
std::string descriptionString("");
|
||||
if (UnwrapStringByPropertyName(env, options, "description", descriptionString)) {
|
||||
continuationExtraParams->SetDescription(descriptionString);
|
||||
}
|
||||
nlohmann::json filterJson;
|
||||
if (UnwrapJsonByPropertyName(env, options, "filter", filterJson)) {
|
||||
std::string filterString = filterJson.dump();
|
||||
continuationExtraParams->SetFilter(filterString);
|
||||
}
|
||||
int32_t continuationMode = 0;
|
||||
if (UnwrapInt32ByPropertyName(env, options, "continuationMode", continuationMode)) {
|
||||
continuationExtraParams->SetContinuationMode(static_cast<ContinuationMode>(continuationMode));
|
||||
}
|
||||
nlohmann::json authInfoJson;
|
||||
if (UnwrapJsonByPropertyName(env, options, "authInfo", authInfoJson)) {
|
||||
std::string authInfoString = authInfoJson.dump();
|
||||
continuationExtraParams->SetAuthInfo(authInfoString);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsContinuationManager::UnwrapJsonByPropertyName(const napi_env& env, const napi_value& param,
|
||||
const std::string& fieldStr, nlohmann::json& jsonObj)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (!IsTypeForNapiValue(env, param, napi_object)) {
|
||||
HILOGE("param is invalid.");
|
||||
return false;
|
||||
}
|
||||
napi_value jsonField = nullptr;
|
||||
napi_get_named_property(env, param, fieldStr.c_str(), &jsonField);
|
||||
napi_valuetype jsValueType = napi_undefined;
|
||||
napi_value jsProNameList = nullptr;
|
||||
uint32_t jsProCount = 0;
|
||||
napi_get_property_names(env, jsonField, &jsProNameList);
|
||||
napi_get_array_length(env, jsProNameList, &jsProCount);
|
||||
|
||||
napi_value jsProName = nullptr;
|
||||
napi_value jsProValue = nullptr;
|
||||
for (uint32_t index = 0; index < jsProCount; index++) {
|
||||
napi_get_element(env, jsProNameList, index, &jsProName);
|
||||
std::string strProName = UnwrapStringFromJS(env, jsProName);
|
||||
napi_get_named_property(env, jsonField, strProName.c_str(), &jsProValue);
|
||||
napi_typeof(env, jsProValue, &jsValueType);
|
||||
switch (jsValueType) {
|
||||
case napi_string: {
|
||||
std::string elementValue = UnwrapStringFromJS(env, jsProValue);
|
||||
HILOGI("Property name=%{public}s, string, value=%{public}s", strProName.c_str(), elementValue.c_str());
|
||||
jsonObj[strProName] = elementValue;
|
||||
break;
|
||||
}
|
||||
case napi_boolean: {
|
||||
bool elementValue = false;
|
||||
napi_get_value_bool(env, jsProValue, &elementValue);
|
||||
HILOGI("Property name=%{public}s, boolean, value=%{public}d.", strProName.c_str(), elementValue);
|
||||
jsonObj[strProName] = elementValue;
|
||||
break;
|
||||
}
|
||||
case napi_number: {
|
||||
int32_t elementValue = 0;
|
||||
if (napi_get_value_int32(env, jsProValue, &elementValue) != napi_ok) {
|
||||
HILOGE("Property name=%{public}s, Property int32_t parse error", strProName.c_str());
|
||||
} else {
|
||||
HILOGI("Property name=%{public}s, number, value=%{public}d.", strProName.c_str(), elementValue);
|
||||
jsonObj[strProName] = elementValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
HILOGE("Property name=%{public}s, value type not support.", strProName.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsContinuationManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
HILOGD("called.");
|
||||
if (engine == nullptr || exportObj == nullptr) {
|
||||
HILOGE("Invalid input parameters");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
HILOGE("convertNativeValueTo result is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<JsContinuationManager> jsContinuationManager = std::make_unique<JsContinuationManager>();
|
||||
object->SetNativePointer(jsContinuationManager.release(), JsContinuationManager::Finalizer, nullptr);
|
||||
|
||||
BindNativeFunction(*engine, *object, "register", JsContinuationManager::Register);
|
||||
BindNativeFunction(*engine, *object, "unregister", JsContinuationManager::Unregister);
|
||||
BindNativeFunction(*engine, *object, "on", JsContinuationManager::RegisterDeviceSelectionCallback);
|
||||
BindNativeFunction(*engine, *object, "off", JsContinuationManager::UnregisterDeviceSelectionCallback);
|
||||
BindNativeFunction(*engine, *object, "updateConnectStatus", JsContinuationManager::UpdateConnectStatus);
|
||||
BindNativeFunction(*engine, *object, "startDeviceManager", JsContinuationManager::StartDeviceManager);
|
||||
BindNativeProperty(*object, "DeviceConnectState", JsContinuationManager::InitDeviceConnectStateObject);
|
||||
BindNativeProperty(*object, "ContinuationMode", JsContinuationManager::InitContinuationModeObject);
|
||||
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
71
interfaces/kits/napi/continuation_manager/js_continuation_manager.h
Executable file
71
interfaces/kits/napi/continuation_manager/js_continuation_manager.h
Executable file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_JS_CONTINUATION_MANAGER_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_JS_CONTINUATION_MANAGER_H
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "continuation_extra_params.h"
|
||||
#include "js_device_selection_listener.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
using JsDeviceSelectionListenerPtr = std::shared_ptr<JsDeviceSelectionListener>;
|
||||
|
||||
class JsContinuationManager final {
|
||||
public:
|
||||
JsContinuationManager() = default;
|
||||
~JsContinuationManager() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint);
|
||||
static NativeValue* Register(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* Unregister(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* RegisterDeviceSelectionCallback(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* UnregisterDeviceSelectionCallback(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* UpdateConnectStatus(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* StartDeviceManager(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* InitDeviceConnectStateObject(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* InitContinuationModeObject(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
private:
|
||||
using CallbackPair = std::pair<std::unique_ptr<NativeReference>, sptr<JsDeviceSelectionListener>>;
|
||||
NativeValue* OnRegister(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnUnregister(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnRegisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnUnregisterDeviceSelectionCallback(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnUpdateConnectStatus(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnStartDeviceManager(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnInitDeviceConnectStateObject(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
NativeValue* OnInitContinuationModeObject(NativeEngine &engine, NativeCallbackInfo &info);
|
||||
napi_status SetEnumItem(napi_env env, napi_value object, const char* name, int32_t value);
|
||||
|
||||
bool IfCallbackValid(NativeValue* listenerObj);
|
||||
bool IfCallbackRegistered(int32_t token, const std::string& cbType);
|
||||
bool UnWrapContinuationExtraParams(napi_env env, napi_value options,
|
||||
std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
|
||||
bool UnwrapJsonByPropertyName(const napi_env& env, const napi_value& param,
|
||||
const std::string& fieldStr, nlohmann::json& jsonObj);
|
||||
|
||||
std::mutex jsCbMapMutex_;
|
||||
std::map<int32_t, std::map<std::string, CallbackPair>> jsCbMap_;
|
||||
};
|
||||
|
||||
NativeValue* JsContinuationManagerInit(NativeEngine* engine, NativeValue* exportObj);
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_JS_CONTINUATION_MANAGER_H
|
54
interfaces/kits/napi/continuation_manager/js_device_selection_listener.h
Executable file
54
interfaces/kits/napi/continuation_manager/js_device_selection_listener.h
Executable file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_JS_DEVICE_SELECTION_LISTENER_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_JS_DEVICE_SELECTION_LISTENER_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "device_selection_notifier_stub.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class JsDeviceSelectionListener : public DeviceSelectionNotifierStub {
|
||||
public:
|
||||
explicit JsDeviceSelectionListener(NativeEngine* engine) : engine_(engine) {}
|
||||
virtual ~JsDeviceSelectionListener() = default;
|
||||
|
||||
void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) override;
|
||||
void OnDeviceDisconnect(const std::vector<std::string>& deviceIds) override;
|
||||
|
||||
void AddCallback(const std::string& cbType, NativeValue* jsListenerObj);
|
||||
void RemoveCallback(const std::string& cbType);
|
||||
|
||||
private:
|
||||
void CallJsMethod(const std::string& methodName, const std::vector<ContinuationResult>& continuationResults);
|
||||
void CallJsMethod(const std::string& methodName, const std::vector<std::string>& deviceIds);
|
||||
void CallJsMethodInner(const std::string& methodName, const std::vector<ContinuationResult>& continuationResults);
|
||||
void CallJsMethodInner(const std::string& methodName, const std::vector<std::string>& deviceIds);
|
||||
NativeValue* WrapContinuationResult(NativeEngine& engine, const ContinuationResult& continuationResult);
|
||||
NativeValue* WrapContinuationResultArray(NativeEngine& engine,
|
||||
const std::vector<ContinuationResult>& continuationResults);
|
||||
NativeValue* WrapDeviceIdArray(NativeEngine& engine, const std::vector<std::string>& deviceIds);
|
||||
|
||||
NativeEngine* engine_ = nullptr;
|
||||
std::mutex jsCallBackMapMutex_;
|
||||
std::map<std::string, std::unique_ptr<NativeReference>> jsCallBackMap_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_JS_DEVICE_SELECTION_LISTENER_H
|
48
services/dtbabilitymgr/include/continuationManager/app_connection_stub.h
Executable file
48
services/dtbabilitymgr/include/continuationManager/app_connection_stub.h
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_APP_CONNECTION_STUB_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_APP_CONNECTION_STUB_H
|
||||
|
||||
#include "ability_connect_callback_interface.h"
|
||||
|
||||
#include "continuation_extra_params.h"
|
||||
#include "nocopyable.h"
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class APPConnectionStub : public IRemoteStub<AAFwk::IAbilityConnection> {
|
||||
public:
|
||||
APPConnectionStub(int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr);
|
||||
virtual ~APPConnectionStub() = default;
|
||||
|
||||
void OnAbilityConnectDone(const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject,
|
||||
int32_t resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int32_t resultCode) override;
|
||||
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
|
||||
MessageOption& option) override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_MOVE(APPConnectionStub);
|
||||
int32_t token_;
|
||||
std::shared_ptr<ContinuationExtraParams> continuationExtraParams_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_APP_CONNECTION_STUB_H
|
41
services/dtbabilitymgr/include/continuationManager/connect_status_info.h
Executable file
41
services/dtbabilitymgr/include/continuationManager/connect_status_info.h
Executable file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_CONNECT_STATUS_INFO_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_CONNECT_STATUS_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "device_connect_status.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class ConnectStatusInfo {
|
||||
public:
|
||||
ConnectStatusInfo(const std::string& deviceId, const DeviceConnectStatus& deviceConnectStatus)
|
||||
: deviceId_(deviceId), deviceConnectStatus_(deviceConnectStatus) {}
|
||||
~ConnectStatusInfo() = default;
|
||||
|
||||
std::string GetDeviceId() const;
|
||||
void SetDeviceId(const std::string& deviceId);
|
||||
DeviceConnectStatus GetDeviceConnectStatus() const;
|
||||
void SetDeviceConnectStatus(const DeviceConnectStatus& deviceConnectStatus);
|
||||
private:
|
||||
std::string deviceId_;
|
||||
DeviceConnectStatus deviceConnectStatus_ = DeviceConnectStatus::IDLE;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_CONNECT_STATUS_INFO_H
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_DEVICE_SELECTION_NOTIFIER_PROXY_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_DEVICE_SELECTION_NOTIFIER_PROXY_H
|
||||
|
||||
#include "idevice_selection_notifier.h"
|
||||
|
||||
#include "iremote_object.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DeviceSelectionNotifierProxy : public IRemoteProxy<IDeviceSelectionNotifier> {
|
||||
public:
|
||||
explicit DeviceSelectionNotifierProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IDeviceSelectionNotifier>(impl) {}
|
||||
virtual ~DeviceSelectionNotifierProxy() = default;
|
||||
|
||||
void OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults) override;
|
||||
void OnDeviceDisconnect(const std::vector<std::string>& deviceIds) override;
|
||||
private:
|
||||
static inline BrokerDelegator<DeviceSelectionNotifierProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_DEVICE_SELECTION_NOTIFIER_PROXY_H
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_NOTIFIER_DEATH_RECIPIENT_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_NOTIFIER_DEATH_RECIPIENT_H
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class NotifierDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
NotifierDeathRecipient() = default;
|
||||
~NotifierDeathRecipient() override = default;
|
||||
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_NOTIFIER_DEATH_RECIPIENT_H
|
43
services/dtbabilitymgr/include/continuationManager/notifier_info.h
Executable file
43
services/dtbabilitymgr/include/continuationManager/notifier_info.h
Executable file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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_DISTRIBUTED_SCHED_NOTIFIER_INFO_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_NOTIFIER_INFO_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "connect_status_info.h"
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class NotifierInfo {
|
||||
public:
|
||||
NotifierInfo() = default;
|
||||
~NotifierInfo() = default;
|
||||
|
||||
using NotifierMap = std::map<std::string, sptr<IRemoteObject>>;
|
||||
NotifierMap& GetNotifierMap();
|
||||
sptr<IRemoteObject> GetNotifier(const std::string& cbType);
|
||||
void SetNotifier(const std::string& cbType, const sptr<IRemoteObject>& notifier);
|
||||
std::shared_ptr<ConnectStatusInfo> GetConnectStatusInfo() const;
|
||||
void SetConnectStatusInfo(const std::shared_ptr<ConnectStatusInfo>& connectStatusInfo);
|
||||
private:
|
||||
NotifierMap notifierMap_;
|
||||
std::shared_ptr<ConnectStatusInfo> connectStatusInfo_;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_NOTIFIER_INFO_H
|
91
services/dtbabilitymgr/src/continuationManager/app_connection_stub.cpp
Executable file
91
services/dtbabilitymgr/src/continuationManager/app_connection_stub.cpp
Executable file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 "continuationManager/app_connection_stub.h"
|
||||
|
||||
#include "distributed_sched_service.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "ipc_types.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
using namespace AAFwk;
|
||||
namespace {
|
||||
const std::string TAG = "APPConnectionStub";
|
||||
}
|
||||
|
||||
APPConnectionStub::APPConnectionStub(int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams)
|
||||
{
|
||||
token_ = token;
|
||||
continuationExtraParams_ = continuationExtraParams;
|
||||
}
|
||||
|
||||
int32_t APPConnectionStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
HILOGD("code = %{public}u", code);
|
||||
std::u16string descriptor = IAbilityConnection::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOGE("local descriptor is not equal to remote");
|
||||
return ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
sptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
|
||||
if (element == nullptr) {
|
||||
HILOGE("element is nullptr");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t resultCode = ERR_NONE;
|
||||
switch (code) {
|
||||
case IAbilityConnection::ON_ABILITY_CONNECT_DONE: {
|
||||
if (auto remoteObject = data.ReadRemoteObject()) {
|
||||
resultCode = data.ReadInt32();
|
||||
OnAbilityConnectDone(*element, remoteObject, resultCode);
|
||||
return ERR_NONE;
|
||||
}
|
||||
HILOGE("remoteObject is nullptr");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
case IAbilityConnection::ON_ABILITY_DISCONNECT_DONE: {
|
||||
resultCode = data.ReadInt32();
|
||||
OnAbilityDisconnectDone(*element, resultCode);
|
||||
return ERR_NONE;
|
||||
}
|
||||
default: {
|
||||
HILOGE("unknown code");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void APPConnectionStub::OnAbilityConnectDone(const AppExecFwk::ElementName& element,
|
||||
const sptr<IRemoteObject>& remoteObject, int32_t resultCode)
|
||||
{
|
||||
HILOGD("called.");
|
||||
DistributedSchedService::GetInstance().ScheduleStartDeviceManager(remoteObject, token_, continuationExtraParams_);
|
||||
return;
|
||||
}
|
||||
|
||||
void APPConnectionStub::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element,
|
||||
int32_t resultCode)
|
||||
{
|
||||
HILOGD("called.");
|
||||
DistributedSchedService::GetInstance().ScheduleStartDeviceManager(nullptr, token_, continuationExtraParams_);
|
||||
return;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
46
services/dtbabilitymgr/src/continuationManager/connect_status_info.cpp
Executable file
46
services/dtbabilitymgr/src/continuationManager/connect_status_info.cpp
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 "continuationManager/connect_status_info.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "ConnectStatusInfo";
|
||||
}
|
||||
|
||||
std::string ConnectStatusInfo::GetDeviceId() const
|
||||
{
|
||||
return deviceId_;
|
||||
}
|
||||
|
||||
void ConnectStatusInfo::SetDeviceId(const std::string& deviceId)
|
||||
{
|
||||
deviceId_ = deviceId;
|
||||
}
|
||||
|
||||
DeviceConnectStatus ConnectStatusInfo::GetDeviceConnectStatus() const
|
||||
{
|
||||
return deviceConnectStatus_;
|
||||
}
|
||||
|
||||
void ConnectStatusInfo::SetDeviceConnectStatus(const DeviceConnectStatus& deviceConnectStatus)
|
||||
{
|
||||
deviceConnectStatus_ = deviceConnectStatus;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
146
services/dtbabilitymgr/src/continuationManager/continuation_extra_params.cpp
Executable file
146
services/dtbabilitymgr/src/continuationManager/continuation_extra_params.cpp
Executable file
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 "continuation_extra_params.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "ContinuationExtraParams";
|
||||
}
|
||||
|
||||
bool ContinuationExtraParams::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
std::vector<std::u16string> deviceTypeVec;
|
||||
if (!parcel.ReadString16Vector(&deviceTypeVec)) {
|
||||
HILOGE("read device type failed.");
|
||||
return false;
|
||||
}
|
||||
SetDeviceType(ContinationManagerUtils::Str16VecToStr8Vec(deviceTypeVec));
|
||||
SetTargetBundle(Str16ToStr8(parcel.ReadString16()));
|
||||
SetDescription(Str16ToStr8(parcel.ReadString16()));
|
||||
SetFilter(Str16ToStr8(parcel.ReadString16()));
|
||||
SetContinuationMode(static_cast<ContinuationMode>(parcel.ReadInt32()));
|
||||
SetAuthInfo(Str16ToStr8(parcel.ReadString16()));
|
||||
return true;
|
||||
}
|
||||
|
||||
ContinuationExtraParams *ContinuationExtraParams::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
ContinuationExtraParams *continuationExtraParams = new (std::nothrow) ContinuationExtraParams();
|
||||
if (continuationExtraParams == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!continuationExtraParams->ReadFromParcel(parcel)) {
|
||||
delete continuationExtraParams;
|
||||
continuationExtraParams = nullptr;
|
||||
}
|
||||
|
||||
return continuationExtraParams;
|
||||
}
|
||||
|
||||
bool ContinuationExtraParams::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
parcel.WriteString16Vector(ContinationManagerUtils::Str8VecToStr16Vec(GetDeviceType()));
|
||||
parcel.WriteString16(Str8ToStr16(GetTargetBundle()));
|
||||
parcel.WriteString16(Str8ToStr16(GetDescription()));
|
||||
parcel.WriteString16(Str8ToStr16(GetFilter()));
|
||||
parcel.WriteInt32(static_cast<int32_t>(GetContinuationMode()));
|
||||
parcel.WriteString16(Str8ToStr16(GetAuthInfo()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetDeviceType(std::vector<std::string> deviceTypeVec)
|
||||
{
|
||||
deviceTypeVec_ = deviceTypeVec;
|
||||
}
|
||||
|
||||
std::vector<std::string> ContinuationExtraParams::GetDeviceType() const
|
||||
{
|
||||
return deviceTypeVec_;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetTargetBundle(std::string targetBundle)
|
||||
{
|
||||
targetBundle_ = targetBundle;
|
||||
}
|
||||
|
||||
std::string ContinuationExtraParams::GetTargetBundle() const
|
||||
{
|
||||
return targetBundle_;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetDescription(std::string description)
|
||||
{
|
||||
description_ = description;
|
||||
}
|
||||
|
||||
std::string ContinuationExtraParams::GetDescription() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetFilter(std::string filter)
|
||||
{
|
||||
filter_ = filter;
|
||||
}
|
||||
|
||||
std::string ContinuationExtraParams::GetFilter() const
|
||||
{
|
||||
return filter_;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetContinuationMode(ContinuationMode continuationMode)
|
||||
{
|
||||
continuationMode_ = continuationMode;
|
||||
}
|
||||
|
||||
ContinuationMode ContinuationExtraParams::GetContinuationMode() const
|
||||
{
|
||||
return continuationMode_;
|
||||
}
|
||||
|
||||
void ContinuationExtraParams::SetAuthInfo(std::string authInfo)
|
||||
{
|
||||
authInfo_ = authInfo;
|
||||
}
|
||||
|
||||
std::string ContinuationExtraParams::GetAuthInfo() const
|
||||
{
|
||||
return authInfo_;
|
||||
}
|
||||
|
||||
std::vector<std::u16string> ContinationManagerUtils::Str8VecToStr16Vec(const std::vector<std::string>& input)
|
||||
{
|
||||
std::vector<std::u16string> output;
|
||||
for (auto iter = input.begin(); iter != input.end(); iter++) {
|
||||
output.emplace_back(Str8ToStr16(*iter));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::string> ContinationManagerUtils::Str16VecToStr8Vec(const std::vector<std::u16string>& input)
|
||||
{
|
||||
std::vector<std::string> output;
|
||||
for (auto iter = input.begin(); iter != input.end(); iter++) {
|
||||
output.emplace_back(Str16ToStr8(*iter));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
144
services/dtbabilitymgr/src/continuationManager/continuation_result.cpp
Executable file
144
services/dtbabilitymgr/src/continuationManager/continuation_result.cpp
Executable file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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 "continuation_result.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "ContinuationResult";
|
||||
constexpr int32_t VALUE_NULL = -1; // no object in parcel
|
||||
constexpr int32_t VALUE_OBJECT = 1; // object exist in parcel
|
||||
}
|
||||
|
||||
bool ContinuationResult::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
SetDeviceId(Str16ToStr8(parcel.ReadString16()));
|
||||
SetDeviceType(Str16ToStr8(parcel.ReadString16()));
|
||||
SetDeviceName(Str16ToStr8(parcel.ReadString16()));
|
||||
return true;
|
||||
}
|
||||
|
||||
ContinuationResult *ContinuationResult::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
ContinuationResult *continuationResult = new (std::nothrow) ContinuationResult();
|
||||
if (continuationResult == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!continuationResult->ReadFromParcel(parcel)) {
|
||||
delete continuationResult;
|
||||
continuationResult = nullptr;
|
||||
}
|
||||
|
||||
return continuationResult;
|
||||
}
|
||||
|
||||
bool ContinuationResult::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
parcel.WriteString16(Str8ToStr16(GetDeviceId()));
|
||||
parcel.WriteString16(Str8ToStr16(GetDeviceType()));
|
||||
parcel.WriteString16(Str8ToStr16(GetDeviceName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
void ContinuationResult::SetDeviceId(std::string deviceId)
|
||||
{
|
||||
deviceId_ = deviceId;
|
||||
}
|
||||
|
||||
std::string ContinuationResult::GetDeviceId() const
|
||||
{
|
||||
return deviceId_;
|
||||
}
|
||||
|
||||
void ContinuationResult::SetDeviceType(std::string deviceType)
|
||||
{
|
||||
deviceType_ = deviceType;
|
||||
}
|
||||
|
||||
std::string ContinuationResult::GetDeviceType() const
|
||||
{
|
||||
return deviceType_;
|
||||
}
|
||||
|
||||
void ContinuationResult::SetDeviceName(std::string deviceName)
|
||||
{
|
||||
deviceName_ = deviceName;
|
||||
}
|
||||
|
||||
std::string ContinuationResult::GetDeviceName() const
|
||||
{
|
||||
return deviceName_;
|
||||
}
|
||||
|
||||
bool ContinuationResult::ReadContinuationResultsFromParcel(Parcel& parcel,
|
||||
std::vector<ContinuationResult>& continuationResults)
|
||||
{
|
||||
continuationResults.clear();
|
||||
int32_t empty = parcel.ReadInt32();
|
||||
if (empty == VALUE_OBJECT) {
|
||||
int32_t len = parcel.ReadInt32();
|
||||
HILOGD("read size: %{public}d", len);
|
||||
if (len < 0) {
|
||||
HILOGE("size Unmarshalling failed");
|
||||
return false;
|
||||
}
|
||||
size_t size = static_cast<size_t>(len);
|
||||
if ((size > parcel.GetReadableBytes()) || (continuationResults.max_size() < size)) {
|
||||
HILOGE("size convert failed, size = %{public}zu", size);
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
ContinuationResult* continuationResult = parcel.ReadParcelable<ContinuationResult>();
|
||||
if (continuationResult == nullptr) {
|
||||
HILOGE("ContinuationResult Unmarshalling failed");
|
||||
return false;
|
||||
}
|
||||
continuationResults.emplace_back(*continuationResult);
|
||||
delete continuationResult;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ContinuationResult::WriteContinuationResultsToParcel(Parcel& parcel,
|
||||
const std::vector<ContinuationResult>& continuationResults)
|
||||
{
|
||||
size_t size = continuationResults.size();
|
||||
if (size == 0) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(size))) {
|
||||
return false;
|
||||
}
|
||||
for (auto& continuationResult : continuationResults) {
|
||||
if (!parcel.WriteParcelable(&continuationResult)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 "continuationManager/device_selection_notifier_proxy.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "ipc_object_proxy.h"
|
||||
#include "ipc_types.h"
|
||||
#include "parcel_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::u16string DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDeviceSelectionNotifier";
|
||||
const std::string TAG = "DeviceSelectionNotifierProxy";
|
||||
}
|
||||
|
||||
void DeviceSelectionNotifierProxy::OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults)
|
||||
{
|
||||
HILOGD("called");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
|
||||
return;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults)) {
|
||||
return;
|
||||
}
|
||||
int32_t errCode = Remote()->SendRequest(IDeviceSelectionNotifier::EVENT_DEVICE_CONNECT, data, reply, option);
|
||||
HILOGD("result = %{public}d", errCode);
|
||||
}
|
||||
|
||||
void DeviceSelectionNotifierProxy::OnDeviceDisconnect(const std::vector<std::string>& deviceIds)
|
||||
{
|
||||
HILOGD("called");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(DEVICE_SELECTION_NOTIFIER_INTERFACE_TOKEN)) {
|
||||
return;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
PARCEL_WRITE_HELPER_NORET(data, StringVector, deviceIds);
|
||||
int32_t errCode = Remote()->SendRequest(IDeviceSelectionNotifier::EVENT_DEVICE_DISCONNECT, data, reply, option);
|
||||
HILOGD("result = %{public}d", errCode);
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 "device_selection_notifier_stub.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DeviceSelectionNotifierStub";
|
||||
}
|
||||
|
||||
const DeviceSelectionNotifierStub::HandlersMap DeviceSelectionNotifierStub::handlersMap_ =
|
||||
DeviceSelectionNotifierStub::InitHandlersMap();
|
||||
|
||||
DeviceSelectionNotifierStub::HandlersMap DeviceSelectionNotifierStub::InitHandlersMap()
|
||||
{
|
||||
DeviceSelectionNotifierStub::HandlersMap m;
|
||||
m[EVENT_DEVICE_CONNECT] = &DeviceSelectionNotifierStub::OnDeviceConnectInner;
|
||||
m[EVENT_DEVICE_DISCONNECT] = &DeviceSelectionNotifierStub::OnDeviceDisconnectInner;
|
||||
return m;
|
||||
}
|
||||
|
||||
int32_t DeviceSelectionNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
HILOGI("code = %{public}u", code);
|
||||
std::u16string descriptor = DeviceSelectionNotifierStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOGE("descriptor check failed");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto iter = handlersMap_.find(code);
|
||||
if (iter != handlersMap_.end()) {
|
||||
auto handler = iter->second;
|
||||
if (handler != nullptr) {
|
||||
return (this->*handler)(data, reply);
|
||||
}
|
||||
}
|
||||
HILOGW("unknown request code, please check");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t DeviceSelectionNotifierStub::OnDeviceConnectInner(MessageParcel& data,
|
||||
[[maybe_unused]] MessageParcel& reply)
|
||||
{
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
if (!ContinuationResult::ReadContinuationResultsFromParcel(data, continuationResults)) {
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
OnDeviceConnect(continuationResults);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t DeviceSelectionNotifierStub::OnDeviceDisconnectInner(MessageParcel& data,
|
||||
[[maybe_unused]] MessageParcel& reply)
|
||||
{
|
||||
std::vector<std::string> deviceIds;
|
||||
if (!data.ReadStringVector(&deviceIds)) {
|
||||
HILOGE("read deviceIds failed.");
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
OnDeviceDisconnect(deviceIds);
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
33
services/dtbabilitymgr/src/continuationManager/notifier_death_recipient.cpp
Executable file
33
services/dtbabilitymgr/src/continuationManager/notifier_death_recipient.cpp
Executable file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "continuationManager/notifier_death_recipient.h"
|
||||
|
||||
#include "distributed_sched_adapter.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "NotifierDeathRecipient";
|
||||
}
|
||||
void NotifierDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
HILOGI("OnRemoteDied called");
|
||||
DistributedSchedAdapter::GetInstance().ProcessNotifierDied(remote.promote());
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
51
services/dtbabilitymgr/src/continuationManager/notifier_info.cpp
Executable file
51
services/dtbabilitymgr/src/continuationManager/notifier_info.cpp
Executable file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 "continuationManager/notifier_info.h"
|
||||
|
||||
#include "dtbschedmgr_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "NotifierInfo";
|
||||
}
|
||||
|
||||
NotifierInfo::NotifierMap& NotifierInfo::GetNotifierMap()
|
||||
{
|
||||
return notifierMap_;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> NotifierInfo::GetNotifier(const std::string& cbType)
|
||||
{
|
||||
return notifierMap_[cbType];
|
||||
}
|
||||
|
||||
void NotifierInfo::SetNotifier(const std::string& cbType, const sptr<IRemoteObject>& notifier)
|
||||
{
|
||||
notifierMap_[cbType] = notifier;
|
||||
}
|
||||
|
||||
std::shared_ptr<ConnectStatusInfo> NotifierInfo::GetConnectStatusInfo() const
|
||||
{
|
||||
return connectStatusInfo_;
|
||||
}
|
||||
|
||||
void NotifierInfo::SetConnectStatusInfo(const std::shared_ptr<ConnectStatusInfo>& connectStatusInfo)
|
||||
{
|
||||
connectStatusInfo_ = connectStatusInfo;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user