This commit is contained in:
2024-09-27 19:16:49 +08:00
commit 49d0cea04d
10000 changed files with 1616312 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef EDM_ERRORS_H
#define EDM_ERRORS_H
#include <cstdint>
#include <errors.h>
namespace OHOS {
namespace ExternalDeviceManager {
#define EDM_MODULE_ID 1
constexpr int32_t EDM_ERR_OFFSET = ErrCodeOffset(SUBSYS_DRIVERS, EDM_MODULE_ID);
enum UsbErrCode : int32_t {
EDM_OK = 0,
EDM_NOK = EDM_ERR_OFFSET,
EDM_ERR_GET_SYSTEM_ABILITY_MANAGER_FAILED,
EDM_ERR_GET_SERVICE_FAILED,
EDM_ERR_CONNECTION_FAILED,
EDM_ERR_NOT_SUPPORT,
EDM_ERR_INVALID_PARAM,
EDM_ERR_INVALID_OBJECT,
EDM_EER_MALLOC_FAIL,
EDM_ERR_TIMEOUT,
EDM_ERR_DEVICE_BUSY,
EDM_ERR_IO,
EDM_ERR_NO_PERM,
EDM_ERR_OUT_OF_RANGE,
EDM_ERR_JSON_PARSE_FAIL,
EDM_ERR_JSON_OBJ_ERR,
EDM_ERR_USB_ERR,
};
} // namespace ExternalDeviceManager
} // namespace OHOS
#endif // EDM_ERRORS_H

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef EXT_OBJECT_H
#define EXT_OBJECT_H
#include <memory>
#include <string>
#include "edm_errors.h"
namespace OHOS {
namespace ExternalDeviceManager {
enum BusType : uint32_t {
BUS_TYPE_INVALID = 0,
BUS_TYPE_USB = 1,
BUS_TYPE_MAX,
BUS_TYPE_TEST,
};
class DrvBundleStateCallback;
class DriverInfoExt {
public:
virtual ~DriverInfoExt() = default;
virtual int32_t Serialize(std::string &str) = 0;
virtual int32_t UnSerialize(const std::string &str) = 0;
};
class DriverInfo : public DriverInfoExt {
public:
int32_t Serialize(std::string &str) override;
int32_t UnSerialize(const std::string &str) override;
std::string GetBusName() const
{
return bus_;
}
std::shared_ptr<DriverInfoExt> GetInfoExt() const
{
return driverInfoExt_;
}
private:
friend class DrvBundleStateCallback;
std::string bus_;
std::string vendor_;
std::string version_;
std::shared_ptr<DriverInfoExt> driverInfoExt_;
};
class DeviceInfo {
public:
DeviceInfo(
uint32_t busDeviceId,
BusType busType = BusType::BUS_TYPE_INVALID,
const std::string &description = "") : description_(description)
{
devInfo_.devBusInfo.busType = busType;
devInfo_.devBusInfo.busDeviceId = busDeviceId;
}
virtual ~DeviceInfo() = default;
BusType GetBusType() const
{
return devInfo_.devBusInfo.busType;
}
uint64_t GetDeviceId() const
{
return devInfo_.deviceId;
}
uint32_t GetBusDevId() const
{
return devInfo_.devBusInfo.busDeviceId;
}
const std::string& GetDeviceDescription() const
{
return description_;
}
private:
union DevInfo {
uint64_t deviceId;
struct {
BusType busType;
uint32_t busDeviceId;
} devBusInfo;
} devInfo_;
std::string description_ {""};
};
} // namespace ExternalDeviceManager
} // namespace OHOS
#endif // EXT_OBJECT_H

View File

@@ -0,0 +1,107 @@
/*
* Copyright (c) 2021 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 HILOG_WRAPPER_H
#define HILOG_WRAPPER_H
#define CONFIG_HILOG
#ifdef CONFIG_HILOG
#include "hilog/log.h"
namespace OHOS {
namespace ExternalDeviceManager {
#define FORMATED_EDM(fmt, ...) "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__
#ifdef EDM_LOGF
#undef EDM_LOGF
#endif
#ifdef EDM_LOGE
#undef EDM_LOGE
#endif
#ifdef EDM_LOGW
#undef EDM_LOGW
#endif
#ifdef EDM_LOGI
#undef EDM_LOGI
#endif
#ifdef EDM_LOGD
#undef EDM_LOGD
#endif
// param of log interface, such as EDM_LOGF.
enum UsbMgrSubModule {
MODULE_FRAMEWORK = 0,
MODULE_SERVICE,
MODULE_DEV_MGR,
MODULE_PKG_MGR,
MODULE_EA_MGR,
MODULE_BUS_USB,
MODULE_COMMON,
MODULE_USB_DDK,
EDM_MODULE_TEST,
EDM_MODULE_BUTT,
};
// 0xD002550: part:ExternalDeviceManager module:Edm.
constexpr unsigned int BASE_EDM_DOMAIN_ID = 0xD002550;
enum UsbMgrDomainId {
EDM_FRAMEWORK_DOMAIN = BASE_EDM_DOMAIN_ID + MODULE_FRAMEWORK,
EDM_SERVICE_DOMAIN,
EDM_DEV_MGR_DOMAIN,
EDM_PKG_MGR_DOMAIN,
EDM_EA_MGR_DOMAIN,
EDM_BUS_USB_DOMAIN,
EDM_COMMON_DOMAIN,
EDM_USB_DDK_DOMAIN,
EDM_TEST,
EDM_BUTT,
};
constexpr OHOS::HiviewDFX::HiLogLabel EDM_MGR_LABEL[EDM_MODULE_BUTT] = {
{LOG_CORE, EDM_FRAMEWORK_DOMAIN, "EdmFwk" },
{LOG_CORE, EDM_SERVICE_DOMAIN, "EdmService" },
{LOG_CORE, EDM_DEV_MGR_DOMAIN, "EdmDevMgr" },
{LOG_CORE, EDM_PKG_MGR_DOMAIN, "EdmPkgMgr" },
{LOG_CORE, EDM_EA_MGR_DOMAIN, "EdmEaMgr" },
{LOG_CORE, EDM_BUS_USB_DOMAIN, "EdmBusUsbMgr"},
{LOG_CORE, EDM_COMMON_DOMAIN, "EdmCommon" },
{LOG_CORE, EDM_USB_DDK_DOMAIN, "EdmUsbDdk" },
{LOG_CORE, EDM_TEST, "EdmTest" },
};
// In order to improve performance, do not check the module range, module should less than EDM_MODULE_BUTT.
#define EDM_LOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
#define EDM_LOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
#define EDM_LOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
#define EDM_LOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
#define EDM_LOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
} // namespace ExternalDeviceManager
} // namespace OHOS
#else
#define EDM_LOGF(...)
#define EDM_LOGE(...)
#define EDM_LOGW(...)
#define EDM_LOGI(...)
#define EDM_LOGD(...)
#endif // CONFIG_HILOG
#endif // HILOG_WRAPPER_H

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IUSB_EXTENSION_H
#define IUSB_EXTENSION_H
#include <vector>
#include <stdint.h>
#include <string>
#include <memory>
#include "application_info.h"
#include "ext_object.h"
#include "idev_change_callback.h"
namespace OHOS {
namespace ExternalDeviceManager {
using namespace std;
using namespace OHOS::AppExecFwk;
class IBusExtension {
public:
virtual ~IBusExtension() = default;
virtual shared_ptr<DriverInfoExt> ParseDriverInfo(const vector<Metadata> &metadata) = 0;
virtual shared_ptr<DriverInfoExt> GetNewDriverInfoExtObject() = 0;
virtual bool MatchDriver(const DriverInfo &driver, const DeviceInfo &device) = 0;
virtual int32_t SetDevChangeCallback(shared_ptr<IDevChangeCallback> callback) = 0;
};
}
}
#endif

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IDEV_CHANGE_CALLBACK_H
#define IDEV_CHANGE_CALLBACK_H
#include <memory>
#include "ext_object.h"
namespace OHOS {
namespace ExternalDeviceManager {
class IDevChangeCallback {
public:
virtual ~IDevChangeCallback() = default;
virtual int32_t OnDeviceAdd(std::shared_ptr<DeviceInfo> device);
virtual int32_t OnDeviceRemove(std::shared_ptr<DeviceInfo> device);
};
} // namespace ExternalDeviceManager
} // namespace OHOS
#endif // IDEV_CHANGE_CALLBACK_H

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_EDM_SINGLE_INSTANCE_H
#define OHOS_EDM_SINGLE_INSTANCE_H
namespace OHOS {
namespace ExternalDeviceManager {
#define DECLARE_SINGLE_INSTANCE_BASE(className) \
public: \
static className &GetInstance(); \
\
private: \
className(const className &) = delete; \
className &operator=(const className &) = delete; \
className(className &&) = delete; \
className &operator=(className &&) = delete;
#define DECLARE_SINGLE_INSTANCE(className) \
DECLARE_SINGLE_INSTANCE_BASE(className) \
\
private: \
className() = default; \
~className() = default;
// please remeber release instance
#define IMPLEMENT_SINGLE_INSTANCE(className) \
className &className::GetInstance() \
{ \
static auto instance = new className(); \
return *instance; \
}
}; // namespace ExternalDeviceManager
}; // namespace OHOS
#endif