mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-20 00:33:44 -04:00
@@ -41,7 +41,7 @@ static bool DeviceResourceIfaceConstruct(struct DeviceResourceIface *instance, D
|
||||
HcsIfaceConstruct(instance);
|
||||
break;
|
||||
default:
|
||||
HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, type);
|
||||
HDF_LOGE("%s: Currently, this configuration type is not supported, the type is %d", __func__, type);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -71,7 +71,7 @@ static inline uint32_t HcsGetPrefix(const char *start)
|
||||
#define HCS_PREFIX_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
|
||||
#define HCS_BYTE_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 1)
|
||||
#define HCS_WORD_LENGTH (HcsIsByteAlign() ? HCS_DWORD_LENGTH : 2)
|
||||
#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1)) // add the '\0'.
|
||||
#define HCS_STRING_LENGTH(str) (HcsIsByteAlign() ? HcsAlignSize(strlen(str) + 1) : (strlen(str) + 1))
|
||||
int32_t HcsGetDataTypeOffset(const char *start);
|
||||
int32_t HcsGetAttrLength(const char *start);
|
||||
int32_t HcsGetNodeOrAttrLength(const char *start);
|
||||
@@ -82,4 +82,4 @@ bool HcsSwapToUint16(uint16_t *value, const char *realValue, uint32_t type);
|
||||
bool HcsSwapToUint32(uint32_t *value, const char *realValue, uint32_t type);
|
||||
bool HcsSwapToUint64(uint64_t *value, const char *realValue, uint32_t type);
|
||||
|
||||
#endif // HCS_BLOB_IF_H
|
||||
#endif /* HCS_BLOB_IF_H */
|
||||
@@ -13,9 +13,9 @@
|
||||
|
||||
#define TREE_STACK_MAX 64
|
||||
struct TreeStack {
|
||||
uint32_t offset; // the offset of node in blob
|
||||
struct DeviceResourceNode *node; // the node is the head node of every layer tree
|
||||
uint32_t offset; // The offset of the node in the blob.
|
||||
struct DeviceResourceNode *node; // The head node of a layer tree.
|
||||
};
|
||||
int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, struct DeviceResourceNode **root);
|
||||
|
||||
#endif // HCS_GENERATE_TREE_H
|
||||
#endif /* HCS_GENERATE_TREE_H */
|
||||
@@ -13,4 +13,4 @@
|
||||
|
||||
bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root);
|
||||
|
||||
#endif // HCS_PARSER_H
|
||||
#endif /* HCS_PARSER_H */
|
||||
@@ -56,4 +56,4 @@ const struct DeviceResourceNode *HcsGetNodeByRefAttr(const struct DeviceResource
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // HCS_TREE_IF_H
|
||||
#endif /* HCS_TREE_IF_H */
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
static bool g_byteAlign = false;
|
||||
|
||||
bool HcsIsByteAlign()
|
||||
bool HcsIsByteAlign(void)
|
||||
{
|
||||
return g_byteAlign;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ static bool CheckHcsBlobLength(uint32_t length, struct HbcHeader *header)
|
||||
HDF_LOGI("%s: the blobLength: %u, byteAlign: %d", __func__, blobLength, g_byteAlign);
|
||||
}
|
||||
if ((length != blobLength) || (blobLength < minLength)) {
|
||||
HDF_LOGE("%s failed, Hcsblob file length is %u, But the length of calculation is %u",
|
||||
HDF_LOGE("%s failed, Hcsblob file length is %u, but the calculated length is %u",
|
||||
__func__, length, blobLength);
|
||||
return false;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ bool HcsCheckBlobFormat(const char *start, uint32_t length)
|
||||
}
|
||||
header = (struct HbcHeader *)start;
|
||||
if (header->magicNumber != HBC_MAGIC_NUMBER) {
|
||||
HDF_LOGE("%s failed, the magic of HBC is %x", __func__, header->magicNumber);
|
||||
HDF_LOGE("%s failed, the magic number of HBC is %x", __func__, header->magicNumber);
|
||||
return false;
|
||||
}
|
||||
if (!CheckHcsBlobLength(length, header)) {
|
||||
|
||||
@@ -53,7 +53,7 @@ static bool UpdateTreeStack(struct TreeStack **treeStack, int32_t *treeLayer, st
|
||||
uint32_t offset)
|
||||
{
|
||||
if (*treeLayer >= (TREE_STACK_MAX - 1)) {
|
||||
HDF_LOGE("%s failed, the treeLayer error. treeLayer: %d", __func__, *treeLayer);
|
||||
HDF_LOGE("%s failed, the treeLayer error, treeLayer: %d", __func__, *treeLayer);
|
||||
return false;
|
||||
}
|
||||
(*treeLayer)++;
|
||||
@@ -83,7 +83,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
|
||||
{
|
||||
int32_t termOffset = HcsGetNodeOrAttrLength(treeStart + offset);
|
||||
if (termOffset <= 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength failed, errno: %d", __func__, termOffset);
|
||||
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength error, errno: %d", __func__, termOffset);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
|
||||
}
|
||||
parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset);
|
||||
if (!AddAttrInNode(treeStart + offset, parentOrCurNode, treeMem)) {
|
||||
HDF_LOGE("%s failed, the AddAttrInNode error", __func__);
|
||||
HDF_LOGE("%s failed, AddAttrInNode error", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
break;
|
||||
@@ -136,14 +136,14 @@ int32_t GenerateCfgTree(const char *treeStart, int32_t length, char *treeMem, st
|
||||
while ((offset < length) && (offset >= 0)) {
|
||||
int32_t eachOffset = ParseByteCode(treeStart, offset, &treeMem, &treeStack, &treeLayerOrMemLen);
|
||||
if (eachOffset <= 0) {
|
||||
HDF_LOGE("%s failed, the ParseByteCode error", __func__);
|
||||
HDF_LOGE("%s failed, ParseByteCode error", __func__);
|
||||
treeLayerOrMemLen = eachOffset;
|
||||
break;
|
||||
}
|
||||
offset += eachOffset;
|
||||
}
|
||||
if ((treeMem != NULL) && (root != NULL) && (treeLayerOrMemLen > 0)) {
|
||||
// the treeStack[1] is root
|
||||
// The treeStack[1] is root
|
||||
*root = treeStack[1].node;
|
||||
}
|
||||
OsalMemFree(treeStack);
|
||||
|
||||
@@ -23,19 +23,19 @@ bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNod
|
||||
{
|
||||
int32_t nodeLength = HcsGetNodeLength(hcsBlob + offset);
|
||||
if (nodeLength < 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeLength failed", __func__);
|
||||
HDF_LOGE("%s failed, HcsGetNodeLength error", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength);
|
||||
if (treeMemLength <= 0) {
|
||||
HDF_LOGE("%s failed, GetHcsTreeSize failed", __func__);
|
||||
HDF_LOGE("%s failed, GetHcsTreeSize error, treeMemLength = %d", __func__, treeMemLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
char *treeMem = (char *)OsalMemCalloc(treeMemLength);
|
||||
if (treeMem == NULL) {
|
||||
HDF_LOGE("%s failed, OsalMemCalloc Device tree memory failed", __func__);
|
||||
HDF_LOGE("%s failed, OsalMemCalloc error", __func__);
|
||||
return false;
|
||||
}
|
||||
int32_t treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root);
|
||||
|
||||
@@ -36,7 +36,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
|
||||
}
|
||||
|
||||
if (!HcsSwapToUint8(&value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return false;
|
||||
}
|
||||
return value ? true : false;
|
||||
@@ -44,7 +44,7 @@ bool HcsGetBool(const struct DeviceResourceNode *node, const char *attrName)
|
||||
|
||||
#define RETURN_DEFAULT_VALUE(attr, attrName, value, def) do { \
|
||||
if (((attr) == NULL) || ((attr)->value == NULL) || ((value) == NULL)) { \
|
||||
HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, return the default value", \
|
||||
HDF_LOGE("%s failed, the attr of %s is NULL, or the value is NULL, the value is default value", \
|
||||
__func__, ((attrName) == NULL) ? "error attrName" : (attrName)); \
|
||||
if ((value) != NULL) { \
|
||||
*(value) = (def); \
|
||||
@@ -60,7 +60,7 @@ int32_t HcsGetUint8(const struct DeviceResourceNode *node, const char *attrName,
|
||||
|
||||
if (!HcsSwapToUint8(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -73,7 +73,7 @@ int32_t HcsGetUint16(const struct DeviceResourceNode *node, const char *attrName
|
||||
|
||||
if (!HcsSwapToUint16(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -86,7 +86,7 @@ int32_t HcsGetUint32(const struct DeviceResourceNode *node, const char *attrName
|
||||
|
||||
if (!HcsSwapToUint32(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -99,7 +99,7 @@ int32_t HcsGetUint64(const struct DeviceResourceNode *node, const char *attrName
|
||||
|
||||
if (!HcsSwapToUint64(value, attr->value + HCS_PREFIX_LENGTH, HcsGetPrefix(attr->value))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -116,7 +116,7 @@ static const char *GetArrayElem(const struct DeviceResourceAttr *attr, uint32_t
|
||||
return NULL;
|
||||
}
|
||||
if (index >= count) {
|
||||
HDF_LOGE("%s failed, the index: %u >= count: %u", __func__, index, count);
|
||||
HDF_LOGE("%s failed, index: %u >= count: %u", __func__, index, count);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < index; i++) {
|
||||
@@ -144,7 +144,7 @@ int32_t HcsGetUint8ArrayElem(const struct DeviceResourceNode *node, const char *
|
||||
}
|
||||
if (!HcsSwapToUint8(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -165,7 +165,7 @@ int32_t HcsGetUint16ArrayElem(const struct DeviceResourceNode *node, const char
|
||||
}
|
||||
if (!HcsSwapToUint16(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -186,7 +186,7 @@ int32_t HcsGetUint32ArrayElem(const struct DeviceResourceNode *node, const char
|
||||
}
|
||||
if (!HcsSwapToUint32(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -202,7 +202,7 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char
|
||||
realValue = GetArrayElem(attr, index);
|
||||
if ((realValue == NULL) || !HcsSwapToUint64(value, realValue + HCS_PREFIX_LENGTH, HcsGetPrefix(realValue))) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, the realValue is NULL or incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, invalid realValue (NULL) or incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -211,11 +211,11 @@ int32_t HcsGetUint64ArrayElem(const struct DeviceResourceNode *node, const char
|
||||
#define CONTINUE_RETURN_DIFFERENT_ERRNO(ret, result) do { \
|
||||
if ((result) == HDF_ERR_INVALID_OBJECT) { \
|
||||
(ret) = HDF_ERR_INVALID_OBJECT; \
|
||||
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
|
||||
HDF_LOGE("%s failed, the result is %d", __func__, (result)); \
|
||||
continue; \
|
||||
} \
|
||||
if ((result) != HDF_SUCCESS) { \
|
||||
HDF_LOGE("%s failed, the ret is %d", __func__, (result)); \
|
||||
HDF_LOGE("%s failed, the result is %d", __func__, (result)); \
|
||||
return result; \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -316,7 +316,7 @@ int32_t HcsGetString(const struct DeviceResourceNode *node, const char *attrName
|
||||
RETURN_DEFAULT_VALUE(attr, attrName, value, def);
|
||||
if (HcsGetPrefix(attr->value) != CONFIG_STRING) {
|
||||
*value = def;
|
||||
HDF_LOGE("%s failed, Incorrect prefix code", __func__);
|
||||
HDF_LOGE("%s failed, incorrect prefix", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
*value = attr->value + HCS_PREFIX_LENGTH;
|
||||
@@ -366,7 +366,7 @@ const struct DeviceResourceNode *HcsGetNodeByMatchAttr(const struct DeviceResour
|
||||
const struct DeviceResourceNode *curNode = NULL;
|
||||
struct DeviceResourceIface *instance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if ((attrValue == NULL) || (instance == NULL) || (instance->GetRootNode == NULL)) {
|
||||
HDF_LOGE("%s failed, attrValue is NULL or DeviceResourceGetIfaceInstance error", __func__);
|
||||
HDF_LOGE("%s failed, attrValue or instance error", __func__);
|
||||
return NULL;
|
||||
}
|
||||
curNode = (node != NULL) ? node : instance->GetRootNode();
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace ConfigTest {
|
||||
const int8_t HDF_MSG_RESUL_DEFALUT = 3;
|
||||
const int8_t HDF_MSG_RESULT_DEFAULT = 3;
|
||||
|
||||
// hcs config test case number
|
||||
enum HdfTestCaseCmd {
|
||||
@@ -84,23 +84,19 @@ void HdfConfigTest::TearDownTestCase()
|
||||
HdfTestCloseService();
|
||||
}
|
||||
|
||||
void HdfConfigTest::SetUp()
|
||||
{
|
||||
}
|
||||
void HdfConfigTest::SetUp() {}
|
||||
|
||||
void HdfConfigTest::TearDown()
|
||||
{
|
||||
}
|
||||
void HdfConfigTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: HslTestCreateDMHslToTree001
|
||||
* @tc.desc: Create a config tree, enter config test
|
||||
* @tc.desc: Create a configuration tree and start configuration test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_CREATE_DM_HSL_TO_TREE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
printf("HdfConfigTest enter\n\r");
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
@@ -111,9 +107,9 @@ HWTEST_F(HdfConfigTest, HslTestCreateDMHslToTree001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -123,9 +119,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -135,9 +131,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeByMatchAttrFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -147,9 +143,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_BOOL_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -159,9 +155,9 @@ HWTEST_F(HdfConfigTest, HslTestGetBoolAttrValueFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -171,9 +167,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -183,9 +179,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8AttrValueFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -195,9 +191,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -207,9 +203,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayElemFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -219,9 +215,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArraySuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT8_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -231,9 +227,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint8ArrayFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -243,9 +239,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -255,9 +251,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16AttrValueFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -268,9 +264,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -280,9 +276,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayElemFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -292,9 +288,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArraySuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT16_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -304,9 +300,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint16ArrayFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -316,9 +312,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -328,9 +324,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32AttrValueFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -341,9 +337,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -353,9 +349,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayElemFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -365,9 +361,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArraySuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT32_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -377,9 +373,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint32ArrayFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -389,9 +385,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -401,9 +397,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64AttrValueFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -414,9 +410,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -426,9 +422,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayElemFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -438,9 +434,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArraySuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_UINT64_ARRAY_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -450,9 +446,9 @@ HWTEST_F(HdfConfigTest, HslTestGetUint64ArrayFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -462,9 +458,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_ELEM_NUM_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -474,9 +470,9 @@ HWTEST_F(HdfConfigTest, HslTestGetElemNumFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -486,9 +482,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_CHILD_NODE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -498,9 +494,9 @@ HWTEST_F(HdfConfigTest, HslTestGetChildNodeFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -510,9 +506,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_TRAVERSE_ATTR_IN_NODE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -522,9 +518,9 @@ HWTEST_F(HdfConfigTest, HslTestTraverseAttrInNodeFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -534,9 +530,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -546,9 +542,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -559,9 +555,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_STRING_ARRAY_ELEM_ATTR_VALUE_002, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -571,9 +567,9 @@ HWTEST_F(HdfConfigTest, HslTestGetStringArrayElemFail001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_001, HDF_MSG_RESULT_DEFAULT};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
@@ -583,9 +579,9 @@ HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefSuccess001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DQ0TB
|
||||
*/
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level1)
|
||||
HWTEST_F(HdfConfigTest, HslTestGetNodeAttrRefFail001, TestSize.Level0)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESUL_DEFALUT};
|
||||
struct HdfTestMsg msg = {TEST_CONFIG_TYPE, HDF_GET_NODE_BY_ATTR_REF_002, HDF_MSG_RESULT_DEFAULT};
|
||||
printf("HdfConfigTest last enter\n\r");
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
}
|
||||
|
||||
+236
-19
@@ -9,10 +9,11 @@
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
* @brief Provides functions to use the HarmonyOS Driver Foundation (HDF).
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management, driver message model,
|
||||
* and power management.
|
||||
* You can develop drivers based on the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
@@ -20,8 +21,8 @@
|
||||
/**
|
||||
* @file hdf_sbuf.h
|
||||
*
|
||||
* @brief Defines functions related to a <b>HdfSBuf</b>. The HDF provides data serialization and deserialization
|
||||
* capabilities for data transmission between user-mode applications and kernel-mode drivers.
|
||||
* @brief Declares functions related to the HDF SBUF. The HDF provides data serialization and deserialization
|
||||
* capabilities for data transmission between user-space applications and kernel-space drivers.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
@@ -33,19 +34,24 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#else
|
||||
typedef uint16_t char16_t;
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfSBuf;
|
||||
struct HdfSbufImpl;
|
||||
struct HdfRemoteService;
|
||||
|
||||
/**
|
||||
* @brief Defines a <b>HdfSBuf</b>.
|
||||
* @brief Enumerates HDF SBUF types.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf {
|
||||
size_t writePos; /**< Current write position */
|
||||
size_t readPos; /**< Current read position */
|
||||
size_t capacity; /**< Storage capacity, at most 512 KB. */
|
||||
uint8_t *data; /**< Pointer to data storage */
|
||||
bool isBind; /**< Whether to bind the externally transferred pointer for data storage */
|
||||
enum HdfSbufType {
|
||||
SBUF_RAW = 0, /* SBUF used for communication between the user space and the kernel space */
|
||||
SBUF_IPC, /* SBUF used for inter-process communication (IPC) */
|
||||
SBUF_IPC_HW, /* Reserved for extension */
|
||||
SBUF_TYPE_MAX, /* Maximum value of the SBUF type */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -60,6 +66,18 @@ struct HdfSBuf {
|
||||
*/
|
||||
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize);
|
||||
|
||||
/**
|
||||
* @brief Writes unpadded data to a <b>SBuf</b>. You can call {@link HdfSbufReadUnpadBuffer} to read the unpadded data.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param data Indicates the pointer to the data to write. The value cannot be a null pointer.
|
||||
* @param writeSize Indicates the size of the data to write. The value cannot be <b>0</b>.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize);
|
||||
|
||||
/**
|
||||
* @brief Writes a 64-bit unsigned integer to a <b>SBuf</b>.
|
||||
*
|
||||
@@ -159,13 +177,133 @@ bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value);
|
||||
*/
|
||||
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value);
|
||||
|
||||
/**
|
||||
* @brief Writes a wide character string to a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the wide character string to write.
|
||||
* @param size Indicates the size of the wide character string to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Writes a floating-point number to a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the floating-point number to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float value);
|
||||
|
||||
/**
|
||||
* @brief Writes a double-precision floating-point number to a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the double-precision floating-point number to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double value);
|
||||
|
||||
/**
|
||||
* @brief Writes a file descriptor to a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param fd Indicates the file descriptor to write.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd);
|
||||
|
||||
/**
|
||||
* @brief Writes an IPC service to a <b>SBuf</b>. The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param service Indicates the pointer to the IPC service to write.
|
||||
* @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service);
|
||||
|
||||
/**
|
||||
* @brief Reads an IPC service from a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the IPC service object if the operation is successful;
|
||||
* returns a null pointer otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Reads a file descriptor from a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns a valid file descriptor if the operation is successful; returns a negative value otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Reads a double-precision floating-point number from a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the double-precision floating-point number read,
|
||||
* which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a floating-point number from a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param value Indicates the pointer to the floating-point number read, which is requested by the caller.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *value);
|
||||
|
||||
/**
|
||||
* @brief Reads a wide character string from a <b>SBuf</b>.
|
||||
* The SBUF of the <b>SBUF_RAW</b> type does not support this function.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the wide character string if the operation is successful;
|
||||
* returns a null pointer otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Reads a data segment from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param data Indicates the double pointer to the data read. The data read is stored in <b>*data</b>,
|
||||
* which is requested by the caller. The memory pointed to by <b>*data</b> is managed by the <b>SBuf</b>
|
||||
* and they share the same lifecycle.
|
||||
* which is requested by the caller. The memory pointed to by <b>*data</b> is managed by
|
||||
* the <b>SBuf</b> and they share the same lifecycle.
|
||||
* @param readSize Indicates the pointer to the size of the data read.
|
||||
* @return Returns <b>true</b> if the operation is successful; returns <b>false</b> otherwise.
|
||||
*
|
||||
@@ -173,6 +311,17 @@ bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value);
|
||||
*/
|
||||
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize);
|
||||
|
||||
/**
|
||||
* @brief Reads unpadded data from a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param length Indicates the length of the data to read.
|
||||
* @return Returns the pointer to the unpadded data if the operation is successful; returns a null pointer otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Reads a 64-bit unsigned integer from a <b>SBuf</b>.
|
||||
*
|
||||
@@ -273,10 +422,11 @@ bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value);
|
||||
const char *HdfSbufReadString(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains the pointer to the data stored in a<b>SBuf</b>.
|
||||
* @brief Obtains the pointer to the data stored in a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the data stored in the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the data stored in the target <b>SBuf</b> if the operation is successful;
|
||||
* returns a null pointer otherwise.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
@@ -296,6 +446,7 @@ void HdfSbufFlush(struct HdfSBuf *sbuf);
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the <b>SBuf</b> capacity.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf);
|
||||
@@ -310,10 +461,20 @@ size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf);
|
||||
*/
|
||||
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Sets the data size of a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @param size Indicates the data size to set, which cannot exceed the size obtained via {@link HdfSbufGetDataSize}.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance.
|
||||
*
|
||||
* @param capacity Indicates the initial capacity of the<b>SBuf</b>.
|
||||
* @param capacity Indicates the initial capacity of the <b>SBuf</b>.
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
@@ -343,9 +504,9 @@ struct HdfSBuf *HdfSBufObtainDefaultSize(void);
|
||||
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Releases a <b>SBuf </b>.
|
||||
* @brief Releases a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the <b>SBuf</b> to release.
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
@@ -383,6 +544,62 @@ struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf);
|
||||
*/
|
||||
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance of a specified type.
|
||||
*
|
||||
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufTypedObtain(uint32_t type);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance of a specified type based on the implementation of an existing <b>SBuf</b>.
|
||||
*
|
||||
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
|
||||
* @param impl Indicates the pointer to the implementation of an existing <b>SBuf</b>.
|
||||
* @return Returns the new <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl);
|
||||
|
||||
/**
|
||||
* @brief Obtains a <b>SBuf</b> instance of a specified type with the given initial capacity.
|
||||
*
|
||||
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
|
||||
* @param capacity Indicates the initial capacity of the <b>SBuf</b>.
|
||||
* @return Returns the new <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity);
|
||||
|
||||
/**
|
||||
* @brief Creates a <b>SBuf</b> instance of a specified type with the specified data and size.
|
||||
* The pointer to the data stored in the <b>SBuf</b> is released by the caller,
|
||||
* and the written data size should not exceed the specified value of <b>size</b>.
|
||||
*
|
||||
* @param type Indicates the SBUF type, which is defined in {@link HdfSbufType}.
|
||||
* @param base Indicates the base of the data to use.
|
||||
* @param size Indicates the size of the data to use.
|
||||
* @return Returns the <b>SBuf</b> instance.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Obtains the implementation of a <b>SBuf</b>.
|
||||
*
|
||||
* @param sbuf Indicates the pointer to the target <b>SBuf</b>.
|
||||
* @return Returns the pointer to the implementation of the <b>SBuf</b>.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_SBU_IMPL_H
|
||||
#define HDF_SBU_IMPL_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfSbufConstructor {
|
||||
struct HdfSbufImpl *(*obtain)(size_t capacity);
|
||||
struct HdfSbufImpl *(*bind)(uintptr_t base, size_t size);
|
||||
};
|
||||
|
||||
struct HdfRemoteService;
|
||||
|
||||
struct HdfSbufImpl {
|
||||
bool (*writeBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize);
|
||||
bool (*writeUnpadBuffer)(struct HdfSbufImpl *sbuf, const uint8_t *data, uint32_t writeSize);
|
||||
bool (*writeUint64)(struct HdfSbufImpl *sbuf, uint64_t value);
|
||||
bool (*writeUint32)(struct HdfSbufImpl *sbuf, uint32_t value);
|
||||
bool (*writeUint16)(struct HdfSbufImpl *sbuf, uint16_t value);
|
||||
bool (*writeUint8)(struct HdfSbufImpl *sbuf, uint8_t value);
|
||||
bool (*writeInt64)(struct HdfSbufImpl *sbuf, int64_t value);
|
||||
bool (*writeInt32)(struct HdfSbufImpl *sbuf, int32_t value);
|
||||
bool (*writeInt16)(struct HdfSbufImpl *sbuf, int16_t value);
|
||||
bool (*writeInt8)(struct HdfSbufImpl *sbuf, int8_t value);
|
||||
bool (*writeString)(struct HdfSbufImpl *sbuf, const char *value);
|
||||
bool (*writeFileDescriptor)(struct HdfSbufImpl *sbuf, int fd);
|
||||
bool (*writeFloat)(struct HdfSbufImpl *sbuf, float value);
|
||||
bool (*writeDouble)(struct HdfSbufImpl *sbuf, double value);
|
||||
bool (*readDouble)(struct HdfSbufImpl *sbuf, double *value);
|
||||
bool (*readFloat)(struct HdfSbufImpl *sbuf, float *value);
|
||||
int (*readFileDescriptor)(struct HdfSbufImpl *sbuf);
|
||||
bool (*writeString16)(struct HdfSbufImpl *sbuf, const char16_t *value, uint32_t size);
|
||||
bool (*readBuffer)(struct HdfSbufImpl *sbuf, const uint8_t **data, uint32_t *readSize);
|
||||
const uint8_t *(*readUnpadBuffer)(struct HdfSbufImpl *sbuf, size_t length);
|
||||
bool (*readUint64)(struct HdfSbufImpl *sbuf, uint64_t *value);
|
||||
bool (*readUint32)(struct HdfSbufImpl *sbuf, uint32_t *value);
|
||||
bool (*readUint16)(struct HdfSbufImpl *sbuf, uint16_t *value);
|
||||
bool (*readUint8)(struct HdfSbufImpl *sbuf, uint8_t *value);
|
||||
bool (*readInt64)(struct HdfSbufImpl *sbuf, int64_t *value);
|
||||
bool (*readInt32)(struct HdfSbufImpl *sbuf, int32_t *value);
|
||||
bool (*readInt16)(struct HdfSbufImpl *sbuf, int16_t *value);
|
||||
bool (*readInt8)(struct HdfSbufImpl *sbuf, int8_t *value);
|
||||
const char *(*readString)(struct HdfSbufImpl *sbuf);
|
||||
const char16_t *(*readString16)(struct HdfSbufImpl *sbuf);
|
||||
int32_t (*writeRemoteService)(struct HdfSbufImpl *sbuf, const struct HdfRemoteService *service);
|
||||
struct HdfRemoteService *(*readRemoteService)(struct HdfSbufImpl *sbuf);
|
||||
const uint8_t *(*getData)(const struct HdfSbufImpl *sbuf);
|
||||
void (*flush)(struct HdfSbufImpl *sbuf);
|
||||
size_t (*getCapacity)(const struct HdfSbufImpl *sbuf);
|
||||
size_t (*getDataSize)(const struct HdfSbufImpl *sbuf);
|
||||
void (*setDataSize)(struct HdfSbufImpl *sbuf, size_t size);
|
||||
void (*recycle)(struct HdfSbufImpl *sbuf);
|
||||
struct HdfSbufImpl *(*move)(struct HdfSbufImpl *sbuf);
|
||||
struct HdfSbufImpl *(*copy)(const struct HdfSbufImpl *sbuf);
|
||||
void (*transDataOwnership)(struct HdfSbufImpl *sbuf);
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_SBUF_H */
|
||||
/** @} */
|
||||
+296
-304
@@ -6,459 +6,451 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "securec.h"
|
||||
#include "osal_mem.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_sbuf.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_sbuf_impl.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
#define HDF_SBUF_GROW_SIZE_DEFAULT 256
|
||||
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512kB
|
||||
#define HDF_SBUF_ALIGN 4
|
||||
#define HDF_SBUF_DEFAULT_SIZE 256
|
||||
#define HDF_SBUF_IMPL_CHECK_RETURN(sbuf, api, retCode) \
|
||||
do { \
|
||||
if (sbuf == NULL || sbuf->impl == NULL) { \
|
||||
HDF_LOGE("%s: invalid sbuf object", __func__); \
|
||||
return retCode; \
|
||||
} \
|
||||
if (sbuf->impl->api == NULL) { \
|
||||
HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \
|
||||
return retCode; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#ifdef S16_MAX
|
||||
#define INT16_MAX S16_MAX
|
||||
#else
|
||||
#define INT16_MAX 32767
|
||||
#endif // !S16_MAX
|
||||
#endif // INT16_MAX
|
||||
#define HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, api) \
|
||||
do { \
|
||||
if (sbuf == NULL || sbuf->impl == NULL) { \
|
||||
HDF_LOGE("%s: invalid sbuf object", __func__); \
|
||||
return; \
|
||||
} \
|
||||
if (sbuf->impl->api == NULL) { \
|
||||
HDF_LOGE(#api " is not support on %d sbuf", sbuf->type); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static inline size_t HdfSbufGetAlignSize(size_t size)
|
||||
struct HdfSBuf {
|
||||
struct HdfSbufImpl *impl;
|
||||
uint32_t type;
|
||||
};
|
||||
|
||||
struct HdfSbufImpl *SbufObtainRaw(size_t capacity);
|
||||
struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size);
|
||||
struct HdfSbufImpl *SbufObtainIpc(size_t capacity) __attribute__((weak));
|
||||
struct HdfSbufImpl *SbufBindIpc(uintptr_t base, size_t size) __attribute__((weak));
|
||||
struct HdfSbufImpl *SbufObtainIpcHw(size_t capacity) __attribute__((weak));
|
||||
struct HdfSbufImpl *SbufBindRawIpcHw(uintptr_t base, size_t size) __attribute__((weak));
|
||||
|
||||
static const struct HdfSbufConstructor g_sbufConstructorMap[SBUF_TYPE_MAX] = {
|
||||
[SBUF_RAW] = {
|
||||
.obtain = SbufObtainRaw,
|
||||
.bind = SbufBindRaw,
|
||||
},
|
||||
[SBUF_IPC] = {
|
||||
.obtain = SbufObtainIpc,
|
||||
.bind = SbufBindIpc,
|
||||
},
|
||||
[SBUF_IPC_HW] = {
|
||||
.obtain = SbufObtainIpcHw,
|
||||
.bind = SbufBindRawIpcHw,
|
||||
},
|
||||
};
|
||||
|
||||
static const struct HdfSbufConstructor *HdfSbufConstructorGet(uint32_t type)
|
||||
{
|
||||
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
|
||||
}
|
||||
|
||||
static size_t HdfSbufGetLeftWriteSize(struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos);
|
||||
}
|
||||
|
||||
static size_t HdfSbufGetLeftReadSize(struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos);
|
||||
}
|
||||
|
||||
static bool HdfSbufWriteRollback(struct HdfSBuf *sbuf, uint32_t size)
|
||||
{
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
if (sbuf->writePos < alignSize) {
|
||||
return false;
|
||||
if (type >= SBUF_TYPE_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->writePos -= alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufReadRollback(struct HdfSBuf *sbuf, uint32_t size)
|
||||
{
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
if (sbuf->readPos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sbuf->readPos -= alignSize;
|
||||
return true;
|
||||
return &g_sbufConstructorMap[type];
|
||||
}
|
||||
|
||||
uint8_t *HdfSbufGetData(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Get data is null, input sbuf is null");
|
||||
return NULL;
|
||||
}
|
||||
return (uint8_t *)sbuf->data;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getData, NULL);
|
||||
return (uint8_t *)sbuf->impl->getData(sbuf->impl);
|
||||
}
|
||||
|
||||
void HdfSbufFlush(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf != NULL) {
|
||||
sbuf->readPos = 0;
|
||||
sbuf->writePos = 0;
|
||||
}
|
||||
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, getData);
|
||||
sbuf->impl->flush(sbuf->impl);
|
||||
}
|
||||
|
||||
size_t HdfSbufGetCapacity(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf != NULL) ? sbuf->capacity : 0;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, HDF_FAILURE);
|
||||
return (sbuf != NULL && sbuf->impl != NULL) ? sbuf->impl->getCapacity(sbuf->impl) : 0;
|
||||
}
|
||||
|
||||
size_t HdfSbufGetDataSize(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
return (sbuf != NULL) ? sbuf->writePos : 0;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getDataSize, HDF_FAILURE);
|
||||
return sbuf->impl->getDataSize(sbuf->impl);
|
||||
}
|
||||
|
||||
static bool HdfSbufGrow(struct HdfSBuf *sbuf, uint32_t growSize)
|
||||
void HdfSbufSetDataSize(struct HdfSBuf *sbuf, size_t size)
|
||||
{
|
||||
if (sbuf->isBind) {
|
||||
HDF_LOGE("%s: binded sbuf oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t newSize = HdfSbufGetAlignSize(sbuf->capacity + growSize);
|
||||
if (newSize < sbuf->capacity) {
|
||||
HDF_LOGE("%s: grow size overflow", __func__);
|
||||
return false;
|
||||
}
|
||||
if (newSize > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: buf size over limit", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *newData = OsalMemCalloc(newSize);
|
||||
if (newData == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sbuf->data != NULL) {
|
||||
if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
|
||||
OsalMemFree(newData);
|
||||
return false;
|
||||
}
|
||||
OsalMemFree(sbuf->data);
|
||||
}
|
||||
|
||||
sbuf->data = newData;
|
||||
sbuf->capacity = newSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufWrite(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = HdfSbufGetAlignSize(size);
|
||||
// in case of desireCapacity overflow
|
||||
if (alignSize < size) {
|
||||
HDF_LOGE("desireCapacity is overflow");
|
||||
return false;
|
||||
}
|
||||
size_t writeableSize = HdfSbufGetLeftWriteSize(sbuf);
|
||||
if (alignSize > writeableSize) {
|
||||
size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT) :
|
||||
HDF_SBUF_GROW_SIZE_DEFAULT;
|
||||
if (!HdfSbufGrow(sbuf, growSize)) {
|
||||
return false;
|
||||
}
|
||||
writeableSize = HdfSbufGetLeftWriteSize(sbuf);
|
||||
}
|
||||
|
||||
uint8_t *dest = sbuf->data + sbuf->writePos;
|
||||
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
|
||||
return false; /* never hits */
|
||||
}
|
||||
|
||||
sbuf->writePos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HdfSbufRead(struct HdfSBuf *sbuf, uint8_t *data, uint32_t readSize)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readSize == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = HdfSbufGetAlignSize(readSize);
|
||||
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("Read out of buffer range");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) {
|
||||
return false; // never hits
|
||||
}
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, setDataSize);
|
||||
sbuf->impl->setDataSize(sbuf->impl, size);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteBuffer(struct HdfSBuf *sbuf, const void *data, uint32_t writeSize)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Write buffer failed, input param is invalid");
|
||||
return false;
|
||||
}
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, getCapacity, false);
|
||||
return sbuf->impl->writeBuffer(sbuf->impl, (const uint8_t *)data, writeSize);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUnpadBuffer(struct HdfSBuf *sbuf, const uint8_t *data, uint32_t writeSize)
|
||||
{
|
||||
if (data == NULL) {
|
||||
return HdfSbufWriteInt32(sbuf, 0);
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteInt32(sbuf, writeSize)) {
|
||||
return false;
|
||||
}
|
||||
if (!HdfSbufWrite(sbuf, data, writeSize)) {
|
||||
(void)HdfSbufWriteRollback(sbuf, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUnpadBuffer, false);
|
||||
return sbuf->impl->writeUnpadBuffer(sbuf->impl, data, writeSize);
|
||||
}
|
||||
|
||||
const uint8_t *HdfSbufReadUnpadBuffer(struct HdfSBuf *sbuf, size_t length)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUnpadBuffer, false);
|
||||
return sbuf->impl->readUnpadBuffer(sbuf->impl, length);
|
||||
}
|
||||
|
||||
bool HdfSbufReadBuffer(struct HdfSBuf *sbuf, const void **data, uint32_t *readSize)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) {
|
||||
HDF_LOGE("%s:input invalid", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int buffSize = 0;
|
||||
if (!HdfSbufReadInt32(sbuf, &buffSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffSize == 0) {
|
||||
*data = NULL;
|
||||
*readSize = 0;
|
||||
return true;
|
||||
}
|
||||
size_t alignSize = HdfSbufGetAlignSize(buffSize);
|
||||
if (alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("%s:readBuff out of range", __func__);
|
||||
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = sbuf->data + sbuf->readPos;
|
||||
*readSize = buffSize;
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readBuffer, false);
|
||||
return sbuf->impl->readBuffer(sbuf->impl, (const uint8_t **)data, readSize);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint64(struct HdfSBuf *sbuf, uint64_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint64, false);
|
||||
return sbuf->impl->writeUint64(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint32(struct HdfSBuf *sbuf, uint32_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint32, false);
|
||||
return sbuf->impl->writeUint32(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint16(struct HdfSBuf *sbuf, uint16_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint16, false);
|
||||
return sbuf->impl->writeUint16(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteUint8(struct HdfSBuf *sbuf, uint8_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeUint8, false);
|
||||
return sbuf->impl->writeUint8(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt64(struct HdfSBuf *sbuf, int64_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt64, false);
|
||||
return sbuf->impl->writeInt64(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt32(struct HdfSBuf *sbuf, int32_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt32, false);
|
||||
return sbuf->impl->writeInt32(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt16(struct HdfSBuf *sbuf, int16_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt16, false);
|
||||
return sbuf->impl->writeInt16(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteInt8(struct HdfSBuf *sbuf, int8_t value)
|
||||
{
|
||||
return HdfSbufWrite(sbuf, (uint8_t *)(&value), sizeof(value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeInt8, false);
|
||||
return sbuf->impl->writeInt8(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteString(struct HdfSBuf *sbuf, const char *value)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s:input null", __func__);
|
||||
return false;
|
||||
}
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString, false);
|
||||
return sbuf->impl->writeString(sbuf->impl, value);
|
||||
}
|
||||
|
||||
return HdfSbufWriteBuffer(sbuf, value, value ? (strlen(value) + 1) : 0);
|
||||
bool HdfSbufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false);
|
||||
return sbuf->impl->writeString16(sbuf->impl, value, size);
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint64(struct HdfSBuf *sbuf, uint64_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint64, false);
|
||||
return sbuf->impl->readUint64(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint32(struct HdfSBuf *sbuf, uint32_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint32, false);
|
||||
return sbuf->impl->readUint32(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint16(struct HdfSBuf *sbuf, uint16_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint16, false);
|
||||
return sbuf->impl->readUint16(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadUint8(struct HdfSBuf *sbuf, uint8_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readUint8, false);
|
||||
return sbuf->impl->readUint8(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt64(struct HdfSBuf *sbuf, int64_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt64, false);
|
||||
return sbuf->impl->readInt64(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt32(struct HdfSBuf *sbuf, int32_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt32, false);
|
||||
return sbuf->impl->readInt32(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt16(struct HdfSBuf *sbuf, int16_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt16, false);
|
||||
return sbuf->impl->readInt16(sbuf->impl, value);
|
||||
}
|
||||
|
||||
bool HdfSbufReadInt8(struct HdfSBuf *sbuf, int8_t *value)
|
||||
{
|
||||
return HdfSbufRead(sbuf, (uint8_t *)(value), sizeof(*value));
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readInt8, false);
|
||||
return sbuf->impl->readInt8(sbuf->impl, value);
|
||||
}
|
||||
|
||||
const char *HdfSbufReadString(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
HDF_LOGE("%s:input null", __func__);
|
||||
return NULL;
|
||||
}
|
||||
/* this length contains '\0' at the end. */
|
||||
int32_t strLen = 0;
|
||||
if (!HdfSbufReadInt32(sbuf, &strLen) || strLen <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
size_t alignSize = HdfSbufGetAlignSize(strLen);
|
||||
if (strLen > INT16_MAX || alignSize > HdfSbufGetLeftReadSize(sbuf)) {
|
||||
(void)HdfSbufReadRollback(sbuf, sizeof(int32_t));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *str = (char *)(sbuf->data + sbuf->readPos);
|
||||
sbuf->readPos += alignSize;
|
||||
/* force set '\0' at end of the string */
|
||||
str[strLen - 1] = '\0';
|
||||
return str;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString, false);
|
||||
return sbuf->impl->readString(sbuf->impl);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufObtainDefaultSize()
|
||||
bool HdfSBufWriteString16(struct HdfSBuf *sbuf, const char16_t *value, uint32_t size)
|
||||
{
|
||||
return HdfSBufObtain(HDF_SBUF_GROW_SIZE_DEFAULT);
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeString16, false);
|
||||
return sbuf->impl->writeString16(sbuf->impl, value, size);
|
||||
}
|
||||
|
||||
const char16_t *HdfSBufReadString16(struct HdfSBuf *sbuf)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readString16, false);
|
||||
return sbuf->impl->readString16(sbuf->impl);
|
||||
}
|
||||
|
||||
int32_t HdfSBufWriteRemoteService(struct HdfSBuf *sbuf, const struct HdfRemoteService *service)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeRemoteService, false);
|
||||
return sbuf->impl->writeRemoteService(sbuf->impl, service);
|
||||
}
|
||||
|
||||
struct HdfRemoteService *HdfSBufReadRemoteService(struct HdfSBuf *sbuf)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readRemoteService, false);
|
||||
return sbuf->impl->readRemoteService(sbuf->impl);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteFloat(struct HdfSBuf *sbuf, float data)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFloat, false);
|
||||
return sbuf->impl->writeFloat(sbuf->impl, data);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteDouble(struct HdfSBuf *sbuf, double data)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeDouble, false);
|
||||
return sbuf->impl->writeDouble(sbuf->impl, data);
|
||||
}
|
||||
|
||||
bool HdfSbufWriteFileDescriptor(struct HdfSBuf *sbuf, int fd)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, writeFileDescriptor, false);
|
||||
return sbuf->impl->writeFileDescriptor(sbuf->impl, fd);
|
||||
}
|
||||
|
||||
int HdfSbufReadFileDescriptor(struct HdfSBuf *sbuf)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFileDescriptor, false);
|
||||
return sbuf->impl->readFileDescriptor(sbuf->impl);
|
||||
}
|
||||
|
||||
bool HdfSbufReadDouble(struct HdfSBuf *sbuf, double *data)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readDouble, false);
|
||||
return sbuf->impl->readDouble(sbuf->impl, data);
|
||||
}
|
||||
|
||||
bool HdfSbufReadFloat(struct HdfSBuf *sbuf, float *data)
|
||||
{
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, readFloat, false);
|
||||
return sbuf->impl->readFloat(sbuf->impl, data);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufTypedObtainCapacity(uint32_t type, size_t capacity)
|
||||
{
|
||||
const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type);
|
||||
if (constructor == NULL) {
|
||||
HDF_LOGE("sbuf constructor %d not implement", type);
|
||||
return NULL;
|
||||
}
|
||||
if (constructor->obtain == NULL) {
|
||||
HDF_LOGE("sbuf constructor %d obtain method not implement", type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("instance sbuf failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->impl = constructor->obtain(capacity);
|
||||
if (sbuf->impl == NULL) {
|
||||
OsalMemFree(sbuf);
|
||||
HDF_LOGE("sbuf obtain fail, size=%u", (uint32_t)capacity);
|
||||
return NULL;
|
||||
}
|
||||
sbuf->type = type;
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufTypedObtainInplace(uint32_t type, struct HdfSbufImpl *impl)
|
||||
{
|
||||
if (type >= SBUF_TYPE_MAX || impl == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("obtain in-place sbuf failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->impl = impl;
|
||||
sbuf->type = type;
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufTypedObtain(uint32_t type)
|
||||
{
|
||||
return HdfSBufTypedObtainCapacity(type, HDF_SBUF_DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufTypedBind(uint32_t type, uintptr_t base, size_t size)
|
||||
{
|
||||
const struct HdfSbufConstructor *constructor = HdfSbufConstructorGet(type);
|
||||
if (constructor == NULL) {
|
||||
HDF_LOGE("sbuf constructor %d not implement", type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (constructor->bind == NULL) {
|
||||
HDF_LOGE("sbuf constructor %d bind method not implement", type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("instance sbuf failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->impl = constructor->bind(base, size);
|
||||
if (sbuf->impl == NULL) {
|
||||
OsalMemFree(sbuf);
|
||||
HDF_LOGE("sbuf bind fail");
|
||||
return NULL;
|
||||
}
|
||||
sbuf->type = type;
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufObtain(size_t capacity)
|
||||
{
|
||||
if (capacity > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: buf size over limit", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("instance usbuf failure");
|
||||
return NULL;
|
||||
}
|
||||
return HdfSBufTypedObtainCapacity(SBUF_RAW, capacity);
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)OsalMemCalloc(capacity);
|
||||
if (sbuf->data == NULL) {
|
||||
OsalMemFree(sbuf);
|
||||
HDF_LOGE("sbuf obtain oom, size=%u", (uint32_t)capacity);
|
||||
return NULL;
|
||||
}
|
||||
sbuf->capacity = capacity;
|
||||
sbuf->writePos = 0;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = false;
|
||||
return sbuf;
|
||||
struct HdfSBuf *HdfSBufObtainDefaultSize()
|
||||
{
|
||||
return HdfSBufObtain(HDF_SBUF_DEFAULT_SIZE);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufBind(uintptr_t base, size_t size)
|
||||
{
|
||||
if (base == 0 || size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
/* require 4 byte alignment for base */
|
||||
if ((base & 0x3) != 0) {
|
||||
HDF_LOGE("Base is not align for 4-byte");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBuf *sbuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)base;
|
||||
sbuf->capacity = size;
|
||||
sbuf->writePos = size;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = true;
|
||||
return sbuf;
|
||||
return HdfSBufTypedBind(SBUF_RAW, base, size);
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufCopy(const struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, copy, NULL);
|
||||
struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (newBuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *new = HdfSBufObtain(sbuf->capacity);
|
||||
if (new == NULL) {
|
||||
newBuf->impl = sbuf->impl->copy(sbuf->impl);
|
||||
if (newBuf->impl == NULL) {
|
||||
OsalMemFree(newBuf);
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->writePos) != EOK) {
|
||||
HdfSBufRecycle(new);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new;
|
||||
newBuf->type = sbuf->type;
|
||||
return newBuf;
|
||||
}
|
||||
|
||||
struct HdfSBuf *HdfSBufMove(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL || sbuf->isBind) {
|
||||
HDF_SBUF_IMPL_CHECK_RETURN(sbuf, move, NULL);
|
||||
struct HdfSBuf *newBuf = (struct HdfSBuf *)OsalMemAlloc(sizeof(struct HdfSBuf));
|
||||
if (newBuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBuf *new = OsalMemCalloc(sizeof(struct HdfSBuf));
|
||||
if (new == NULL) {
|
||||
newBuf->impl = sbuf->impl->move(sbuf->impl);
|
||||
if (newBuf->impl == NULL) {
|
||||
OsalMemFree(newBuf);
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
new->data = sbuf->data;
|
||||
|
||||
sbuf->data = NULL;
|
||||
sbuf->capacity = 0;
|
||||
HdfSbufFlush(sbuf);
|
||||
|
||||
return new;
|
||||
return newBuf;
|
||||
}
|
||||
|
||||
void HdfSbufTransDataOwnership(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sbuf->isBind = false;
|
||||
HDF_SBUF_IMPL_CHECK_RETURN_VOID(sbuf, transDataOwnership);
|
||||
sbuf->impl->transDataOwnership(sbuf->impl);
|
||||
}
|
||||
|
||||
void HdfSBufRecycle(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf != NULL) {
|
||||
if (sbuf->data != NULL && !sbuf->isBind) {
|
||||
OsalMemFree(sbuf->data);
|
||||
if (sbuf->impl != NULL && sbuf->impl->recycle != NULL) {
|
||||
sbuf->impl->recycle(sbuf->impl);
|
||||
sbuf->impl = NULL;
|
||||
}
|
||||
OsalMemFree(sbuf);
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfSbufImpl *HdfSbufGetImpl(struct HdfSBuf *sbuf)
|
||||
{
|
||||
if (sbuf != NULL) {
|
||||
return sbuf->impl;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,553 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_sbuf.h"
|
||||
#include "hdf_sbuf_impl.h"
|
||||
#include "osal_mem.h"
|
||||
#include "securec.h"
|
||||
|
||||
#define HDF_SBUF_GROW_SIZE_DEFAULT 256
|
||||
#define HDF_SBUF_MAX_SIZE (512 * 1024) // 512KB
|
||||
#define HDF_SBUF_ALIGN 4
|
||||
|
||||
#ifndef INT16_MAX
|
||||
#ifdef S16_MAX
|
||||
#define INT16_MAX S16_MAX
|
||||
#else
|
||||
#define INT16_MAX 32767
|
||||
#endif // !S16_MAX
|
||||
#endif // INT16_MAX
|
||||
|
||||
struct HdfSBufRaw {
|
||||
struct HdfSbufImpl infImpl;
|
||||
size_t writePos; /**< Current write position */
|
||||
size_t readPos; /**< Current read position */
|
||||
size_t capacity; /**< Storage capacity, 512 KB at most. */
|
||||
uint8_t *data; /**< Pointer to data storage */
|
||||
bool isBind; /**< Whether to bind the externally transferred pointer to data storage */
|
||||
};
|
||||
|
||||
#define SBUF_RAW_CAST(impl) (struct HdfSBufRaw *)(impl)
|
||||
|
||||
static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity);
|
||||
static void SbufInterfaceAssign(struct HdfSbufImpl *inf);
|
||||
|
||||
static size_t SbufRawImplGetAlignSize(size_t size)
|
||||
{
|
||||
return (size + HDF_SBUF_ALIGN - 1) & (~(HDF_SBUF_ALIGN - 1));
|
||||
}
|
||||
|
||||
static void SbufRawImplRecycle(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf != NULL) {
|
||||
if (sbuf->data != NULL && !sbuf->isBind) {
|
||||
OsalMemFree(sbuf->data);
|
||||
}
|
||||
OsalMemFree(sbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t SbufRawImplGetLeftWriteSize(struct HdfSBufRaw *sbuf)
|
||||
{
|
||||
return (sbuf->capacity < sbuf->writePos) ? 0 : (sbuf->capacity - sbuf->writePos);
|
||||
}
|
||||
|
||||
static size_t SbufRawImplGetLeftReadSize(struct HdfSBufRaw *sbuf)
|
||||
{
|
||||
return (sbuf->writePos < sbuf->readPos) ? 0 : (sbuf->writePos - sbuf->readPos);
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteRollback(struct HdfSbufImpl *impl, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
if (sbuf->writePos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sbuf->writePos -= alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadRollback(struct HdfSbufImpl *impl, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
if (sbuf->readPos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sbuf->readPos -= alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const uint8_t *SbufRawImplGetData(const struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("The obtained data is null, and the input Sbuf is null.");
|
||||
return NULL;
|
||||
}
|
||||
return (uint8_t *)sbuf->data;
|
||||
}
|
||||
|
||||
static void SbufRawImplSetDataSize(struct HdfSbufImpl *impl, size_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
if (size <= sbuf->capacity) {
|
||||
sbuf->readPos = 0;
|
||||
sbuf->writePos = size;
|
||||
}
|
||||
}
|
||||
|
||||
static void SbufRawImplFlush(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf != NULL) {
|
||||
sbuf->readPos = 0;
|
||||
sbuf->writePos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t SbufRawImplGetCapacity(const struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
return (sbuf != NULL) ? sbuf->capacity : 0;
|
||||
}
|
||||
|
||||
static size_t SbufRawImplGetDataSize(const struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
return (sbuf != NULL) ? sbuf->writePos : 0;
|
||||
}
|
||||
|
||||
static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize)
|
||||
{
|
||||
if (sbuf->isBind) {
|
||||
HDF_LOGE("%s: binded sbuf oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t newSize = SbufRawImplGetAlignSize(sbuf->capacity + growSize);
|
||||
if (newSize < sbuf->capacity) {
|
||||
HDF_LOGE("%s: grow size overflow", __func__);
|
||||
return false;
|
||||
}
|
||||
if (newSize > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: buf size over limit", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *newData = OsalMemCalloc(newSize);
|
||||
if (newData == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sbuf->data != NULL) {
|
||||
if (memcpy_s(newData, newSize, sbuf->data, sbuf->writePos) != EOK) {
|
||||
OsalMemFree(newData);
|
||||
return false;
|
||||
}
|
||||
OsalMemFree(sbuf->data);
|
||||
}
|
||||
|
||||
sbuf->data = newData;
|
||||
sbuf->capacity = newSize;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
// in case of desireCapacity overflow
|
||||
if (alignSize < size) {
|
||||
HDF_LOGE("desireCapacity overflow");
|
||||
return false;
|
||||
}
|
||||
size_t writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
|
||||
if (alignSize > writeableSize) {
|
||||
size_t growSize = (alignSize > HDF_SBUF_GROW_SIZE_DEFAULT) ? (alignSize + HDF_SBUF_GROW_SIZE_DEFAULT)
|
||||
: HDF_SBUF_GROW_SIZE_DEFAULT;
|
||||
if (!SbufRawImplGrow(sbuf, growSize)) {
|
||||
return false;
|
||||
}
|
||||
writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
|
||||
}
|
||||
|
||||
uint8_t *dest = sbuf->data + sbuf->writePos;
|
||||
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
|
||||
return false; /* never hits */
|
||||
}
|
||||
|
||||
sbuf->writePos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SbufRawImplRead(struct HdfSbufImpl *impl, uint8_t *data, uint32_t readSize)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readSize == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(readSize);
|
||||
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("Read out of buffer range");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(data, readSize, sbuf->data + sbuf->readPos, readSize) != EOK) {
|
||||
return false; // never hit
|
||||
}
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteUint64(struct HdfSbufImpl *impl, uint64_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteUint32(struct HdfSbufImpl *impl, uint32_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteUint16(struct HdfSbufImpl *impl, uint16_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteUint8(struct HdfSbufImpl *impl, uint8_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteInt64(struct HdfSbufImpl *impl, int64_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteInt32(struct HdfSbufImpl *impl, int32_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteInt16(struct HdfSbufImpl *impl, int16_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteInt8(struct HdfSbufImpl *impl, int8_t value)
|
||||
{
|
||||
return SbufRawImplWrite(impl, (uint8_t *)(&value), sizeof(value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteBuffer(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t writeSize)
|
||||
{
|
||||
if (impl == NULL) {
|
||||
HDF_LOGE("Failed to write the Sbuf, invalid input params");
|
||||
return false;
|
||||
}
|
||||
if (data == NULL) {
|
||||
return SbufRawImplWriteInt32(impl, 0);
|
||||
}
|
||||
|
||||
if (!SbufRawImplWriteInt32(impl, writeSize)) {
|
||||
return false;
|
||||
}
|
||||
if (!SbufRawImplWrite(impl, data, writeSize)) {
|
||||
(void)SbufRawImplWriteRollback(impl, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SbufRawImplWriteString(struct HdfSbufImpl *impl, const char *value)
|
||||
{
|
||||
if (impl == NULL) {
|
||||
HDF_LOGE("%s: input null", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return SbufRawImplWriteBuffer(impl, (const uint8_t *)value, value ? (strlen(value) + 1) : 0);
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadUint64(struct HdfSbufImpl *impl, uint64_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadUint32(struct HdfSbufImpl *impl, uint32_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadUint16(struct HdfSbufImpl *impl, uint16_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadUint8(struct HdfSbufImpl *impl, uint8_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadInt64(struct HdfSbufImpl *impl, int64_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadInt32(struct HdfSbufImpl *impl, int32_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadInt16(struct HdfSbufImpl *impl, int16_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadInt8(struct HdfSbufImpl *impl, int8_t *value)
|
||||
{
|
||||
return SbufRawImplRead(impl, (uint8_t *)(value), sizeof(*value));
|
||||
}
|
||||
|
||||
static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data, uint32_t *readSize)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL || readSize == NULL) {
|
||||
HDF_LOGE("%s: input invalid", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int buffSize = 0;
|
||||
if (!SbufRawImplReadInt32(impl, &buffSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffSize == 0) {
|
||||
*data = NULL;
|
||||
*readSize = 0;
|
||||
return true;
|
||||
}
|
||||
size_t alignSize = SbufRawImplGetAlignSize(buffSize);
|
||||
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("%s:readBuff out of range", __func__);
|
||||
(void)SbufRawImplReadRollback(impl, sizeof(int32_t));
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = sbuf->data + sbuf->readPos;
|
||||
*readSize = buffSize;
|
||||
sbuf->readPos += alignSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char *SbufRawImplReadString(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
HDF_LOGE("%s: input null", __func__);
|
||||
return NULL;
|
||||
}
|
||||
/* This length contains the '\0' at the end of the string. */
|
||||
int32_t strLen = 0;
|
||||
if (!SbufRawImplReadInt32(impl, &strLen) || strLen <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
size_t alignSize = SbufRawImplGetAlignSize(strLen);
|
||||
if (strLen > INT16_MAX || alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
|
||||
(void)SbufRawImplReadRollback(impl, sizeof(int32_t));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *str = (char *)(sbuf->data + sbuf->readPos);
|
||||
sbuf->readPos += alignSize;
|
||||
/* Set '\0' at end of the string forcibly. */
|
||||
str[strLen - 1] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
static struct HdfSbufImpl *SbufRawImplCopy(const struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBufRaw *new = SbufRawImplNewInstance(sbuf->capacity);
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
if (memcpy_s(new->data, new->capacity, sbuf->data, sbuf->capacity) != EOK) {
|
||||
SbufRawImplRecycle(&new->infImpl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &new->infImpl;
|
||||
}
|
||||
|
||||
static struct HdfSbufImpl *SbufRawImplMove(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL || sbuf->isBind) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBufRaw *new = OsalMemCalloc(sizeof(struct HdfSBufRaw));
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
new->capacity = sbuf->capacity;
|
||||
new->readPos = 0;
|
||||
new->writePos = sbuf->writePos;
|
||||
new->data = sbuf->data;
|
||||
|
||||
sbuf->data = NULL;
|
||||
sbuf->capacity = 0;
|
||||
SbufRawImplFlush(&sbuf->infImpl);
|
||||
SbufInterfaceAssign(&new->infImpl);
|
||||
|
||||
return &new->infImpl;
|
||||
}
|
||||
|
||||
static void SbufRawImplTransDataOwnership(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
if (sbuf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sbuf->isBind = false;
|
||||
}
|
||||
|
||||
static void SbufInterfaceAssign(struct HdfSbufImpl *inf)
|
||||
{
|
||||
inf->writeBuffer = SbufRawImplWriteBuffer;
|
||||
inf->writeUint64 = SbufRawImplWriteUint64;
|
||||
inf->writeUint32 = SbufRawImplWriteUint32;
|
||||
inf->writeUint16 = SbufRawImplWriteUint16;
|
||||
inf->writeUint8 = SbufRawImplWriteUint8;
|
||||
inf->writeInt64 = SbufRawImplWriteInt64;
|
||||
inf->writeInt32 = SbufRawImplWriteInt32;
|
||||
inf->writeInt16 = SbufRawImplWriteInt16;
|
||||
inf->writeInt8 = SbufRawImplWriteInt8;
|
||||
inf->writeString = SbufRawImplWriteString;
|
||||
inf->readBuffer = SbufRawImplReadBuffer;
|
||||
inf->readUint64 = SbufRawImplReadUint64;
|
||||
inf->readUint32 = SbufRawImplReadUint32;
|
||||
inf->readUint16 = SbufRawImplReadUint16;
|
||||
inf->readUint8 = SbufRawImplReadUint8;
|
||||
inf->readInt64 = SbufRawImplReadInt64;
|
||||
inf->readInt32 = SbufRawImplReadInt32;
|
||||
inf->readInt16 = SbufRawImplReadInt16;
|
||||
inf->readInt8 = SbufRawImplReadInt8;
|
||||
inf->readString = SbufRawImplReadString;
|
||||
inf->getData = SbufRawImplGetData;
|
||||
inf->flush = SbufRawImplFlush;
|
||||
inf->getCapacity = SbufRawImplGetCapacity;
|
||||
inf->getDataSize = SbufRawImplGetDataSize;
|
||||
inf->setDataSize = SbufRawImplSetDataSize;
|
||||
inf->recycle = SbufRawImplRecycle;
|
||||
inf->move = SbufRawImplMove;
|
||||
inf->copy = SbufRawImplCopy;
|
||||
inf->transDataOwnership = SbufRawImplTransDataOwnership;
|
||||
}
|
||||
|
||||
static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity)
|
||||
{
|
||||
if (capacity > HDF_SBUF_MAX_SIZE) {
|
||||
HDF_LOGE("%s: Sbuf size exceeding max limit", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemCalloc(sizeof(struct HdfSBufRaw));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Sbuf instance failure");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)OsalMemCalloc(capacity);
|
||||
if (sbuf->data == NULL) {
|
||||
OsalMemFree(sbuf);
|
||||
HDF_LOGE("sbuf obtain memory oom, size=%u", (uint32_t)capacity);
|
||||
return NULL;
|
||||
}
|
||||
sbuf->capacity = capacity;
|
||||
sbuf->writePos = 0;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = false;
|
||||
SbufInterfaceAssign(&sbuf->infImpl);
|
||||
return sbuf;
|
||||
}
|
||||
|
||||
struct HdfSbufImpl *SbufObtainRaw(size_t capacity)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SbufRawImplNewInstance(capacity);
|
||||
if (sbuf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &sbuf->infImpl;
|
||||
}
|
||||
|
||||
struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size)
|
||||
{
|
||||
if (base == 0 || size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
/* 4-byte alignment is required for base. */
|
||||
if ((base & 0x3) != 0) {
|
||||
HDF_LOGE("Base not in 4-byte alignment");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemAlloc(sizeof(struct HdfSBufRaw));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sbuf->data = (uint8_t *)base;
|
||||
sbuf->capacity = size;
|
||||
sbuf->writePos = size;
|
||||
sbuf->readPos = 0;
|
||||
sbuf->isBind = true;
|
||||
SbufInterfaceAssign(&sbuf->infImpl);
|
||||
return &sbuf->infImpl;
|
||||
}
|
||||
@@ -34,8 +34,8 @@ struct HdfDevListenerThread {
|
||||
struct pollfd *pfds;
|
||||
uint16_t pfdSize;
|
||||
bool pollChanged;
|
||||
struct DListHead *listenerListPtr;
|
||||
bool shouldStop;
|
||||
struct DListHead *listenerListPtr;
|
||||
uint8_t status;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,23 +20,23 @@ int32_t HdfLoadDriverByServiceName(const char *serviceName)
|
||||
}
|
||||
struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
|
||||
if (ioService == NULL) {
|
||||
HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
|
||||
HDF_LOGE("failed to get %s service", DEV_MGR_NODE);
|
||||
return ret;
|
||||
}
|
||||
data = HdfSBufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("fail to obtain sbuf data");
|
||||
HDF_LOGE("failed to obtain sbuf data");
|
||||
ret = HDF_DEV_ERR_NO_MEMORY;
|
||||
goto out;
|
||||
}
|
||||
if (!HdfSbufWriteString(data, serviceName)) {
|
||||
HDF_LOGE("fail to write sbuf");
|
||||
HDF_LOGE("failed to write sbuf");
|
||||
ret = HDF_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_LOAD_SERVICE, data, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("fail to send service call");
|
||||
HDF_LOGE("failed to load khdf driver %s", serviceName);
|
||||
}
|
||||
out:
|
||||
HdfIoServiceRecycle(ioService);
|
||||
@@ -54,23 +54,23 @@ int32_t HdfGetServiceNameByDeviceClass(DeviceClass deviceClass, struct HdfSBuf *
|
||||
}
|
||||
struct HdfIoService *ioService = HdfIoServiceBind(DEV_MGR_NODE);
|
||||
if (ioService == NULL) {
|
||||
HDF_LOGE("Fail to get %s service", DEV_MGR_NODE);
|
||||
HDF_LOGE("failed to get %s service", DEV_MGR_NODE);
|
||||
return ret;
|
||||
}
|
||||
data = HdfSBufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("fail to obtain sbuf data");
|
||||
HDF_LOGE("failed to obtain sbuf data");
|
||||
ret = HDF_DEV_ERR_NO_MEMORY;
|
||||
goto out;
|
||||
}
|
||||
if (!HdfSbufWriteInt32(data, deviceClass)) {
|
||||
HDF_LOGE("fail to write sbuf");
|
||||
HDF_LOGE("failed to write sbuf");
|
||||
ret = HDF_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
ret = ioService->dispatcher->Dispatch(&ioService->object, DEVMGR_GET_SERVICE, data, reply);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("fail to send service call");
|
||||
HDF_LOGE("failed to query service by class");
|
||||
}
|
||||
out:
|
||||
HdfIoServiceRecycle(ioService);
|
||||
|
||||
@@ -95,7 +95,7 @@ static int32_t HdfDevEventDispatchLocked(const struct HdfDevListenerThread *thre
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
|
||||
/* dispatch event to SERVICE GROUP listener */
|
||||
/* Dispatch events to the service group listener */
|
||||
if (thread->listenerListPtr != NULL) {
|
||||
DLIST_FOR_EACH_ENTRY(listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
|
||||
if (listener->onReceive != NULL) {
|
||||
@@ -103,21 +103,19 @@ static int32_t HdfDevEventDispatchLocked(const struct HdfDevListenerThread *thre
|
||||
} else if (listener->callBack != NULL) {
|
||||
(void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
|
||||
}
|
||||
HdfSbufFlush(sbuf);
|
||||
sbuf->writePos = bwr->readConsumed;
|
||||
HdfSbufSetDataSize(sbuf, bwr->readConsumed);
|
||||
}
|
||||
}
|
||||
|
||||
OsalMutexLock(&adapter->mutex);
|
||||
/* dispatch event to SERVICE(SyscallAdapter) listener */
|
||||
/* Dispatch events to the service (SyscallAdapter) listener */
|
||||
DLIST_FOR_EACH_ENTRY(listener, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
|
||||
if (listener->onReceive != NULL) {
|
||||
(void)listener->onReceive(listener, &adapter->super, bwr->cmdCode, sbuf);
|
||||
} else if (listener->callBack != NULL) {
|
||||
(void)listener->callBack(listener->priv, bwr->cmdCode, sbuf);
|
||||
}
|
||||
HdfSbufFlush(sbuf);
|
||||
sbuf->writePos = bwr->readConsumed;
|
||||
HdfSbufSetDataSize(sbuf, bwr->readConsumed);
|
||||
}
|
||||
OsalMutexUnlock(&adapter->mutex);
|
||||
|
||||
@@ -131,20 +129,20 @@ static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, i
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
|
||||
bwr.readBuffer = (uintptr_t)OsalMemAlloc(HDF_DEFAULT_BWR_READ_SIZE);
|
||||
bwr.cmdCode = -1;
|
||||
bwr.readConsumed = 0;
|
||||
bwr.readSize = HDF_DEFAULT_BWR_READ_SIZE;
|
||||
if (bwr.readBuffer == (uintptr_t)NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return HDF_DEV_ERR_NO_MEMORY;
|
||||
}
|
||||
bwr.cmdCode = -1;
|
||||
bwr.readConsumed = 0;
|
||||
bwr.readSize = HDF_DEFAULT_BWR_READ_SIZE;
|
||||
|
||||
OsalMutexLock(&thread->mutex);
|
||||
|
||||
struct HdfSyscallAdapter *adapter = HdfFdToAdapterLocked(thread, fd);
|
||||
if (adapter == NULL) {
|
||||
HDF_LOGI("%s:adapter invalid\n", __func__);
|
||||
OsalMSleep(1);
|
||||
HDF_LOGI("%s: invalid adapter", __func__);
|
||||
OsalMSleep(1); // yield to sync adapter list
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@@ -156,7 +154,9 @@ static int32_t HdfDevEventReadAndDispatch(struct HdfDevListenerThread *thread, i
|
||||
ret = errno;
|
||||
if (ret == -HDF_DEV_ERR_NORANGE) {
|
||||
if (HdfDevEventGrowReadBuffer(&bwr) == HDF_SUCCESS) {
|
||||
continue; /* read buffer may not enough, grow read buffer and try again */
|
||||
/* read buffer may not enough, grow read buffer and try again--The read buffere is insufficient.
|
||||
Expand the buffer and try again. */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ret == -HDF_DEV_ERR_NODATA) {
|
||||
@@ -209,14 +209,6 @@ static int32_t AssignPfds(struct HdfDevListenerThread *thread, struct pollfd **p
|
||||
return pfdCount;
|
||||
}
|
||||
|
||||
static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread)
|
||||
{
|
||||
OsalMutexDestroy(&thread->mutex);
|
||||
OsalMemFree(thread->pfds);
|
||||
OsalThreadDestroy(&thread->thread);
|
||||
OsalMemFree(thread);
|
||||
}
|
||||
|
||||
#define POLL_WAIT_TIME_MS 100
|
||||
static int32_t HdfDevEventListenTask(void *para)
|
||||
{
|
||||
@@ -262,8 +254,11 @@ exit:
|
||||
OsalMemFree(pfds);
|
||||
|
||||
if (thread->shouldStop) {
|
||||
/* exit due to async exit call, should free thread struct */
|
||||
HdfDevListenerThreadFree(thread);
|
||||
/* Exit due to async call and free the thread struct. */
|
||||
OsalMutexDestroy(&thread->mutex);
|
||||
OsalThreadDestroy(&thread->thread);
|
||||
OsalMemFree(thread->pfds);
|
||||
OsalMemFree(thread);
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
@@ -273,7 +268,7 @@ static int32_t HdfAdapterStartListenIoctl(int fd)
|
||||
{
|
||||
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_START, 0);
|
||||
if (ret) {
|
||||
HDF_LOGE("%s: fail to tell drv(%d) start %d %s", __func__, fd, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to notify drv(%d) of start %d %s", __func__, fd, errno, strerror(errno));
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
@@ -284,7 +279,7 @@ static int32_t HdfAdapterStopListenIoctl(int fd)
|
||||
{
|
||||
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_STOP, 0);
|
||||
if (ret) {
|
||||
HDF_LOGE("%s: fail to tell drv stop %d %s", __func__, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to notify drv(%d) of stop %d %s", __func__, fd, errno, strerror(errno));
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
@@ -295,7 +290,7 @@ static int32_t HdfAdapterExitListenIoctl(int fd)
|
||||
{
|
||||
int32_t ret = ioctl(fd, HDF_LISTEN_EVENT_EXIT, 0);
|
||||
if (ret) {
|
||||
HDF_LOGE("%s: fail to tell drv report exit %d %s", __func__, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to notify drv(%d) of exit %d %s", __func__, fd, errno, strerror(errno));
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
@@ -305,13 +300,13 @@ static int32_t HdfAdapterExitListenIoctl(int fd)
|
||||
static int32_t HdfDevListenerThreadDoInit(struct HdfDevListenerThread *thread)
|
||||
{
|
||||
if (OsalMutexInit(&thread->mutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: fail to create thread lock", __func__);
|
||||
HDF_LOGE("%s: failed to create thread lock", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t ret = OsalThreadCreate(&thread->thread, HdfDevEventListenTask, thread);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: fail to create thread", __func__);
|
||||
HDF_LOGE("%s: failed to create thread", __func__);
|
||||
thread->status = LISTENER_UNINITED;
|
||||
OsalMutexDestroy(&thread->mutex);
|
||||
return HDF_ERR_THREAD_CREATE_FAIL;
|
||||
@@ -499,7 +494,7 @@ static int32_t HdfIoServiceGroupThreadStart(struct HdfSyscallAdapterGroup *group
|
||||
|
||||
static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struct HdfSyscallAdapter *adapter)
|
||||
{
|
||||
/* if thread is not bind to service group, not need to do poll add */
|
||||
/* If thread is not bound to a service group, you do not need to add a poll. */
|
||||
if (thread->adapterListPtr == NULL) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -529,7 +524,7 @@ static int32_t HdfListenThreadPollAdd(struct HdfDevListenerThread *thread, struc
|
||||
|
||||
if (headAdapter != NULL) {
|
||||
if (ioctl(headAdapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
|
||||
HDF_LOGE("%s: fail to wakeup drv to add poll %d %s", __func__, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to wakeup drv to add poll %d %s", __func__, errno, strerror(errno));
|
||||
thread->pfds[index].fd = SYSCALL_INVALID_FD;
|
||||
ret = HDF_ERR_IO;
|
||||
break;
|
||||
@@ -568,11 +563,11 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct
|
||||
}
|
||||
|
||||
if (HdfAdapterStopListenIoctl(adapter->fd)) {
|
||||
HDF_LOGE("%s: fail to stop device report %d %s", __func__, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to stop device report %d %s", __func__, errno, strerror(errno));
|
||||
}
|
||||
|
||||
if (ioctl(adapter->fd, HDF_LISTEN_EVENT_WAKEUP, 0) != 0) {
|
||||
HDF_LOGE("%s: fail to wakeup drv to del poll %d %s", __func__, errno, strerror(errno));
|
||||
HDF_LOGE("%s: failed to wakeup drv to del poll %d %s", __func__, errno, strerror(errno));
|
||||
}
|
||||
DListRemove(&adapter->listNode);
|
||||
adapter->group = NULL;
|
||||
@@ -580,6 +575,14 @@ static void HdfListenThreadPollDel(struct HdfDevListenerThread *thread, struct
|
||||
OsalMutexUnlock(&thread->mutex);
|
||||
}
|
||||
|
||||
static void HdfDevListenerThreadFree(struct HdfDevListenerThread *thread)
|
||||
{
|
||||
OsalMutexDestroy(&thread->mutex);
|
||||
OsalMemFree(thread->pfds);
|
||||
OsalThreadDestroy(&thread->thread);
|
||||
OsalMemFree(thread);
|
||||
}
|
||||
|
||||
static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
@@ -648,10 +651,10 @@ static int32_t HdfSyscallAdapterDispatch(struct HdfObject *object, int32_t code,
|
||||
wrBuf.cmdCode = code;
|
||||
int32_t ret = ioctl(ioService->fd, HDF_WRITE_READ, &wrBuf);
|
||||
if (ret < 0) {
|
||||
HDF_LOGE("dispatch serv call ioctl fail %d", errno);
|
||||
HDF_LOGE("Failed to dispatch serv call ioctl %d", errno);
|
||||
}
|
||||
if (reply != NULL) {
|
||||
reply->writePos = wrBuf.readConsumed;
|
||||
HdfSbufSetDataSize(reply, wrBuf.readConsumed);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -660,41 +663,48 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
|
||||
{
|
||||
struct HdfSyscallAdapter *adapter = NULL;
|
||||
struct HdfIoService *ioService = NULL;
|
||||
char devNodePath[PATH_MAX] = {0};
|
||||
char realPath[PATH_MAX] = {0};
|
||||
char *devNodePath = NULL;
|
||||
char *realPath = NULL;
|
||||
|
||||
const char *devPath = DEV_NODE_PATH;
|
||||
if (access(DEV_NODE_PATH, F_OK) != 0) {
|
||||
devPath = DEV_PATH;
|
||||
}
|
||||
|
||||
devNodePath = OsalMemCalloc(PATH_MAX);
|
||||
realPath = OsalMemCalloc(PATH_MAX);
|
||||
if (devNodePath == NULL || realPath == NULL) {
|
||||
HDF_LOGE("%s: out of memory", __func__);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (sprintf_s(devNodePath, PATH_MAX - 1, "%s%s", devPath, serviceName) < 0) {
|
||||
HDF_LOGE("Get node path failed");
|
||||
return NULL;
|
||||
HDF_LOGE("Failed to get the node path");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (realpath(devNodePath, realPath) == NULL) {
|
||||
if (HdfLoadDriverByServiceName(serviceName) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s load %s driver failed", __func__, serviceName);
|
||||
return NULL;
|
||||
HDF_LOGE("%s: load %s driver failed", __func__, serviceName);
|
||||
goto out;
|
||||
}
|
||||
if (realpath(devNodePath, realPath) == NULL) {
|
||||
HDF_LOGE("%s file name %s is invalid", __func__, devNodePath);
|
||||
return NULL;
|
||||
HDF_LOGE("%s: file name %s is invalid", __func__, devNodePath);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
adapter = (struct HdfSyscallAdapter *)OsalMemCalloc(sizeof(struct HdfSyscallAdapter));
|
||||
if (adapter == NULL) {
|
||||
HDF_LOGE("Alloc syscall adapter failed");
|
||||
return NULL;
|
||||
HDF_LOGE("Failed to allocate SyscallAdapter");
|
||||
goto out;
|
||||
}
|
||||
|
||||
DListHeadInit(&adapter->listenerList);
|
||||
if (OsalMutexInit(&adapter->mutex)) {
|
||||
HDF_LOGE("%s: create mutex fail", __func__);
|
||||
HDF_LOGE("%s: Failed to create mutex", __func__);
|
||||
OsalMemFree(adapter);
|
||||
return NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
adapter->fd = open(realPath, O_RDWR);
|
||||
@@ -702,13 +712,16 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
|
||||
HDF_LOGE("Open file node %s failed, (%d)%s", realPath, errno, strerror(errno));
|
||||
OsalMutexDestroy(&adapter->mutex);
|
||||
OsalMemFree(adapter);
|
||||
return NULL;
|
||||
goto out;
|
||||
}
|
||||
ioService = &adapter->super;
|
||||
static struct HdfIoDispatcher dispatch = {
|
||||
.Dispatch = HdfSyscallAdapterDispatch,
|
||||
};
|
||||
ioService->dispatcher = &dispatch;
|
||||
out:
|
||||
OsalMemFree(devNodePath);
|
||||
OsalMemFree(realPath);
|
||||
return ioService;
|
||||
}
|
||||
|
||||
@@ -743,7 +756,7 @@ static int32_t HdfIoServiceThreadBindLocked(struct HdfSyscallAdapter *adapter)
|
||||
static int32_t HdfIoServiceStartListen(struct HdfSyscallAdapter *adapter)
|
||||
{
|
||||
if (HdfIoServiceThreadBindLocked(adapter) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:adapter bind thread fail", __func__);
|
||||
HDF_LOGE("%s: Failed to bind a thread to SyscallAdapter", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -755,7 +768,7 @@ static bool AddListenerToAdapterLocked(struct HdfSyscallAdapter *adapter, struct
|
||||
struct HdfDevEventlistener *it = NULL;
|
||||
DLIST_FOR_EACH_ENTRY(it, &adapter->listenerList, struct HdfDevEventlistener, listNode) {
|
||||
if (it == listener) {
|
||||
HDF_LOGE("add duplicate dev-event listener");
|
||||
HDF_LOGE("Add a listener for duplicate dev-event");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -770,7 +783,7 @@ int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDe
|
||||
}
|
||||
|
||||
if (listener->callBack == NULL && listener->onReceive == NULL) {
|
||||
HDF_LOGE("listenr onReceive func not implement");
|
||||
HDF_LOGE("Listenr onReceive func not implemented");
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
@@ -784,8 +797,9 @@ int32_t HdfDeviceRegisterEventListener(struct HdfIoService *target, struct HdfDe
|
||||
}
|
||||
|
||||
if (adapter->group != NULL) {
|
||||
/* service in group, should not bind to self hold thread and try to start group thread */
|
||||
/* Do not bind any service in a service goup to its own thread or start the group thread. */
|
||||
ret = HdfIoServiceGroupThreadStart(adapter->group);
|
||||
DListRemove(&listener->listNode);
|
||||
OsalMutexUnlock(&adapter->mutex);
|
||||
return ret;
|
||||
}
|
||||
@@ -806,7 +820,7 @@ int32_t HdfDeviceUnregisterEventListener(struct HdfIoService *target, struct Hdf
|
||||
}
|
||||
|
||||
if (listener->listNode.next == NULL || listener->listNode.prev == NULL) {
|
||||
HDF_LOGE("%s:broken listener, may double unregister", __func__);
|
||||
HDF_LOGE("%s: broken listener, may double unregister", __func__);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
@@ -872,7 +886,7 @@ int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struc
|
||||
}
|
||||
|
||||
if (listener->callBack == NULL && listener->onReceive == NULL) {
|
||||
HDF_LOGE("listenr onReceive func not implement");
|
||||
HDF_LOGE("listenr onReceive func not implemented");
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
struct HdfSyscallAdapterGroup *adapterGroup = CONTAINER_OF(group, struct HdfSyscallAdapterGroup, serviceGroup);
|
||||
@@ -891,8 +905,8 @@ int32_t HdfIoServiceGroupRegisterListener(struct HdfIoServiceGroup *group, struc
|
||||
struct HdfDevEventlistener *it = NULL;
|
||||
DLIST_FOR_EACH_ENTRY(it, &adapterGroup->listenerList, struct HdfDevEventlistener, listNode) {
|
||||
if (it == listener) {
|
||||
HDF_LOGE("add group listener failed, repeated registration");
|
||||
ret = HDF_ERR_INVALID_OBJECT;
|
||||
HDF_LOGE("Failed to add group listener, repeated registration");
|
||||
ret = HDF_ERR_INVALID_PARAM;
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
@@ -917,7 +931,7 @@ static int32_t GetListenerCount(struct HdfDevListenerThread *thread)
|
||||
|
||||
OsalMutexLock(&thread->mutex);
|
||||
if (thread->listenerListPtr != NULL) {
|
||||
DLIST_FOR_EACH_ENTRY (listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
|
||||
DLIST_FOR_EACH_ENTRY(listener, thread->listenerListPtr, struct HdfDevEventlistener, listNode) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#define HDF_LOG_TAG hdf_vnode
|
||||
#define VOID_DATA_SIZE 4
|
||||
#define EVENT_QUEUE_MAX 100
|
||||
#define MAX_RW_SIZE (1024*1204) // 1M
|
||||
#define MAX_RW_SIZE (1024 * 1204) // 1M
|
||||
|
||||
enum HdfVNodeClientStatus {
|
||||
VNODE_CLIENT_RUNNING,
|
||||
@@ -99,7 +99,7 @@ struct HdfIoService *HdfIoServiceAdapterObtain(const char *serviceName)
|
||||
}
|
||||
|
||||
svcMgr = DevSvcManagerClntGetInstance();
|
||||
if (svcMgr == NULL) {
|
||||
if (svcMgr == NULL || svcMgr->devSvcMgrIf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
deviceObject = svcMgr->devSvcMgrIf->GetObject(svcMgr->devSvcMgrIf, serviceName);
|
||||
@@ -146,7 +146,7 @@ static struct HdfSBuf *HdfSbufCopyFromUser(uintptr_t data, size_t size)
|
||||
return NULL;
|
||||
}
|
||||
if (CopyFromUser((void*)kData, (void*)data, size) != 0) {
|
||||
HDF_LOGE("%s:copy from user fail", __func__);
|
||||
HDF_LOGE("%s:failed to copy from user", __func__);
|
||||
OsalMemFree(kData);
|
||||
return NULL;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ static int HdfSbufCopyToUser(const struct HdfSBuf *sbuf, void *dstUser, size_t d
|
||||
}
|
||||
|
||||
if (CopyToUser(dstUser, HdfSbufGetData(sbuf), sbufSize) != 0) {
|
||||
HDF_LOGE("%s: copy buff data fail", __func__);
|
||||
HDF_LOGE("%s: failed to copy buff data", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (CopyFromUser(&bwr, (void*)bwrUser, sizeof(bwr)) != 0) {
|
||||
HDF_LOGE("Copy from user failed");
|
||||
HDF_LOGE("copy from user failed");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (bwr.writeSize > MAX_RW_SIZE || bwr.readSize > MAX_RW_SIZE) {
|
||||
@@ -216,12 +216,12 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
|
||||
|
||||
data = HdfSbufCopyFromUser(bwr.writeBuffer, bwr.writeSize);
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("Vnode adapter bind data is null");
|
||||
HDF_LOGE("vnode adapter bind data is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
reply = HdfSBufObtainDefaultSize();
|
||||
if (reply == NULL) {
|
||||
HDF_LOGE("%s:oom", __func__);
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
HdfSBufRecycle(data);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ static int HdfVNodeAdapterServCall(const struct HdfVNodeAdapterClient *client, u
|
||||
}
|
||||
bwr.readConsumed = HdfSbufGetDataSize(reply);
|
||||
if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
|
||||
HDF_LOGE("%s: copy bwr fail", __func__);
|
||||
HDF_LOGE("%s: fail to copy bwr", __func__);
|
||||
ret = HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ static int HdfVNodeAdapterReadDevEvent(struct HdfVNodeAdapterClient *client, uns
|
||||
}
|
||||
|
||||
if (CopyToUser(bwrUser, &bwr, sizeof(struct HdfWriteReadBuf)) != 0) {
|
||||
HDF_LOGE("%s: copy bwr fail", __func__);
|
||||
HDF_LOGE("%s: failed to copy bwr", __func__);
|
||||
ret = HDF_ERR_IO;
|
||||
}
|
||||
if (ret == HDF_SUCCESS) {
|
||||
@@ -461,7 +461,6 @@ static struct HdfVNodeAdapterClient *HdfNewVNodeAdapterClient(struct HdfVNodeAda
|
||||
client->serv = &adapter->ioService;
|
||||
client->status = VNODE_CLIENT_RUNNING;
|
||||
client->adapter = adapter;
|
||||
client->eventQueueSize = 0;
|
||||
client->ioServiceClient.device = (struct HdfDeviceObject *)adapter->ioService.target;
|
||||
client->ioServiceClient.priv = NULL;
|
||||
client->wakeup = 0;
|
||||
@@ -565,26 +564,26 @@ struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_
|
||||
};
|
||||
|
||||
if ((serviceName == NULL) || (mode > MAX_MODE_SIZE)) {
|
||||
HDF_LOGE("Input param is invalid, mode is %x", mode);
|
||||
HDF_LOGE("input param is invalid, mode is %x", mode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vnodeAdapter = (struct HdfVNodeAdapter *)OsalMemCalloc(sizeof(struct HdfVNodeAdapter));
|
||||
if (vnodeAdapter == NULL) {
|
||||
HDF_LOGE("Alloc remote service is null");
|
||||
HDF_LOGE("alloc remote service is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nodePathLength = strlen(serviceName) + strlen(DEV_NODE_PATH) + 1;
|
||||
vnodeAdapter->vNodePath = (char *)OsalMemCalloc(nodePathLength);
|
||||
if (vnodeAdapter->vNodePath == NULL) {
|
||||
HDF_LOGE("Alloc vnode path is null");
|
||||
HDF_LOGE("alloc vnode path is null");
|
||||
OsalMemFree(vnodeAdapter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sprintf_s(vnodeAdapter->vNodePath, nodePathLength, "%s%s", DEV_NODE_PATH, serviceName) < 0) {
|
||||
HDF_LOGE("Get node path failed");
|
||||
HDF_LOGE("failed to get node path");
|
||||
OsalMemFree(vnodeAdapter->vNodePath);
|
||||
OsalMemFree(vnodeAdapter);
|
||||
return NULL;
|
||||
@@ -602,7 +601,7 @@ struct HdfIoService *HdfIoServiceAdapterPublish(const char *serviceName, uint32_
|
||||
}
|
||||
ret = OsalRegisterCdev(vnodeAdapter->cdev, vnodeAdapter->vNodePath, mode, vnodeAdapter);
|
||||
if (ret != 0) {
|
||||
HDF_LOGE("register dev node %s failed, ret is: %d", vnodeAdapter->vNodePath, ret);
|
||||
HDF_LOGE("failed to register dev node %s, ret is: %d", vnodeAdapter->vNodePath, ret);
|
||||
OsalMutexDestroy(&vnodeAdapter->mutex);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_SERVICE_START_H
|
||||
#define DEVICE_SERVICE_START_H
|
||||
#ifndef DEVMGR_SERVICE_START_H
|
||||
#define DEVMGR_SERVICE_START_H
|
||||
|
||||
enum {
|
||||
DEV_MGR_SLOW_LOAD = 0,
|
||||
@@ -19,4 +19,4 @@ int DeviceManagerStartStep2(void);
|
||||
void DeviceManagerSetQuickLoad(int isQuickLoad);
|
||||
int DeviceManagerIsQuickLoad(void);
|
||||
|
||||
#endif /* DEVICE_SERVICE_START_H */
|
||||
#endif /* DEVMGR_SERVICE_START_H */
|
||||
|
||||
@@ -31,8 +31,7 @@ static void GetDeviceServiceNameByClass(DeviceClass deviceClass, struct HdfSBuf
|
||||
return;
|
||||
}
|
||||
|
||||
reply->readPos = 0;
|
||||
reply->writePos = 0;
|
||||
HdfSbufFlush(reply);
|
||||
HdfSListIteratorInit(&itHost, &devMgrSvc->hosts);
|
||||
while (HdfSListIteratorHasNext(&itHost)) {
|
||||
hostClnt = (struct DevHostServiceClnt *)HdfSListIteratorNext(&itHost);
|
||||
@@ -78,21 +77,21 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
|
||||
case DEVMGR_UNLOAD_SERVICE:
|
||||
svcName = HdfSbufReadString(data);
|
||||
if (svcName == NULL) {
|
||||
HDF_LOGE("%s: get svc name is null", __func__);
|
||||
HDF_LOGE("%s: svc name is null", __func__);
|
||||
break;
|
||||
}
|
||||
ret = DevSvcManagerClntUnsubscribeService(svcName);
|
||||
break;
|
||||
case DEVMGR_GET_SERVICE:
|
||||
if (!HdfSbufReadInt32(data, &deviceClass)) {
|
||||
HDF_LOGE("%s: get deviceClass failed", __func__);
|
||||
HDF_LOGE("%s: failed to get deviceClass", __func__);
|
||||
break;
|
||||
}
|
||||
GetDeviceServiceNameByClass(deviceClass, reply);
|
||||
ret = HDF_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
HDF_LOGE("%s: Currently, this configuration type is not supported. the type is %d", __func__, code);
|
||||
HDF_LOGE("%s: unsupported configuration type: %d", __func__, code);
|
||||
break;
|
||||
}
|
||||
OsalMutexUnlock(&devMgrSvc->devMgrMutex);
|
||||
@@ -104,17 +103,17 @@ void DeviceManagerSetQuickLoad(int loadFlag)
|
||||
g_isQuickLoad = loadFlag;
|
||||
}
|
||||
|
||||
int DeviceManagerIsQuickLoad()
|
||||
int DeviceManagerIsQuickLoad(void)
|
||||
{
|
||||
return g_isQuickLoad;
|
||||
}
|
||||
|
||||
int DeviceManagerStart()
|
||||
int DeviceManagerStart(void)
|
||||
{
|
||||
struct IDevmgrService *instance = DevmgrServiceGetInstance();
|
||||
|
||||
if (instance == NULL || instance->StartService == NULL) {
|
||||
HDF_LOGE("Device manager start failed, service instance is null!");
|
||||
HDF_LOGE("device manager start failed, service instance is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct HdfIoService *ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
|
||||
@@ -131,7 +130,7 @@ int DeviceManagerStart()
|
||||
int DeviceManagerStartStep2()
|
||||
{
|
||||
if (DeviceManagerIsQuickLoad() == DEV_MGR_SLOW_LOAD) {
|
||||
HDF_LOGW("%s device manager is not set quick load!", __func__);
|
||||
HDF_LOGW("%s: device manager is not set to QuickLoad mode", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
static struct DeviceResourceNode *g_hcsTreeRoot = NULL;
|
||||
|
||||
void HdfGetBuildInConfigData(const unsigned char **data, unsigned int *size);
|
||||
|
||||
static bool CreateHcsToTree(void)
|
||||
{
|
||||
uint32_t length;
|
||||
@@ -49,7 +50,7 @@ static bool CreateHcsToTree(void)
|
||||
const struct DeviceResourceNode *HcsGetRootNode(void)
|
||||
{
|
||||
if ((g_hcsTreeRoot == NULL) && !CreateHcsToTree()) {
|
||||
HDF_LOGE("%s failed", __func__);
|
||||
HDF_LOGE("%s: failed", __func__);
|
||||
return NULL;
|
||||
}
|
||||
return g_hcsTreeRoot;
|
||||
@@ -80,12 +81,12 @@ static bool GetHostInfo(const struct DeviceResourceNode *hostNode, struct HdfHos
|
||||
uint16_t readNum = 0;
|
||||
if ((HcsGetString(hostNode, ATTR_HOST_NAME, &hostInfo->hostName, NULL) != HDF_SUCCESS) ||
|
||||
(strcmp(hostInfo->hostName, "") == 0)) {
|
||||
HDF_LOGW("%s get host name failed", __func__);
|
||||
HDF_LOGW("%s: get host name failed", __func__);
|
||||
return false;
|
||||
}
|
||||
if ((HcsGetUint16(hostNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) ||
|
||||
(readNum > MAX_PRIORITY_NUM)) {
|
||||
HDF_LOGW("%s get host priority failed, priority is: %d", __func__, readNum);
|
||||
HDF_LOGW("%s: get host priority failed, priority is: %u", __func__, readNum);
|
||||
return false;
|
||||
}
|
||||
hostInfo->priority = readNum;
|
||||
@@ -103,7 +104,7 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
|
||||
|
||||
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
|
||||
if (hdfManagerNode == NULL) {
|
||||
HDF_LOGE("%s get hdf manager node is null", __func__);
|
||||
HDF_LOGE("%s: get hdf manager node is null", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,19 +113,17 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
|
||||
struct HdfHostInfo *hostInfo = HdfHostInfoNewInstance();
|
||||
if (hostInfo == NULL) {
|
||||
HdfSListFlush(hostList, HdfHostInfoDelete);
|
||||
HDF_LOGE("%s new hostInfo is null", __func__);
|
||||
HDF_LOGE("%s: new hostInfo is null", __func__);
|
||||
return false;
|
||||
}
|
||||
if (!GetHostInfo(hostNode, hostInfo)) {
|
||||
HdfHostInfoFreeInstance(hostInfo);
|
||||
hostInfo = NULL;
|
||||
hostNode = hostNode->sibling;
|
||||
continue;
|
||||
}
|
||||
hostInfo->hostId = hostId;
|
||||
if (!HdfSListAddOrder(hostList, &hostInfo->node, HdfHostListCompare)) {
|
||||
HdfHostInfoFreeInstance(hostInfo);
|
||||
hostInfo = NULL;
|
||||
hostNode = hostNode->sibling;
|
||||
continue;
|
||||
}
|
||||
@@ -149,7 +148,9 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
|
||||
const struct DeviceResourceNode *hdfManagerNode = NULL;
|
||||
const struct DeviceResourceNode *hostNode = NULL;
|
||||
const char *hostName = NULL;
|
||||
|
||||
if (inHostName == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
hdfManagerNode = GetHdfManagerNode(HcsGetRootNode());
|
||||
if (hdfManagerNode == NULL) {
|
||||
return NULL;
|
||||
@@ -171,17 +172,17 @@ static const struct DeviceResourceNode *GetHostNode(const char *inHostName)
|
||||
static bool CheckDeviceInfo(const struct HdfDeviceInfo *deviceNodeInfo)
|
||||
{
|
||||
if (deviceNodeInfo->policy > SERVICE_POLICY_PRIVATE) {
|
||||
HDF_LOGE("%s policy is invalid", __func__);
|
||||
HDF_LOGE("%s: policy %u is invalid", __func__, deviceNodeInfo->policy);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceNodeInfo->priority > MAX_PRIORITY_NUM) {
|
||||
HDF_LOGE("%s priority is invalid", __func__);
|
||||
HDF_LOGE("%s: priority %u is invalid", __func__, deviceNodeInfo->priority);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceNodeInfo->preload > DEVICE_PRELOAD_DISABLE) {
|
||||
HDF_LOGE("%s preload is invalid", __func__);
|
||||
HDF_LOGE("%s: preload %u is invalid", __func__, deviceNodeInfo->preload);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -193,43 +194,43 @@ static bool GetDeviceNodeInfo(const struct DeviceResourceNode *deviceNode, struc
|
||||
uint16_t readNum = 0;
|
||||
const char *readString = NULL;
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_POLICY, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get policy failed", __func__);
|
||||
HDF_LOGE("%s: failed to get policy", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->policy = readNum;
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PRIORITY, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get priority failed", __func__);
|
||||
HDF_LOGE("%s: failed to get priority", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->priority = readNum;
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PRELOAD, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get preload failed", __func__);
|
||||
HDF_LOGE("%s: failed to get preload", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->preload = readNum;
|
||||
|
||||
if (HcsGetUint16(deviceNode, ATTR_DEV_PERMISSION, &readNum, 0) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get permission failed", __func__);
|
||||
HDF_LOGE("%s: failed to get permission", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->permission = readNum;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_MODULENAME, &readString, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get module name failed", __func__);
|
||||
HDF_LOGE("%s: failed to get module name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->moduleName = readString;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_SVCNAME, &readString, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get service name failed", __func__);
|
||||
HDF_LOGE("%s: failed to get service name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->svcName = readString;
|
||||
|
||||
if (HcsGetString(deviceNode, ATTR_DEV_MATCHATTR, &readString, NULL) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s get service name failed", __func__);
|
||||
HDF_LOGE("%s: failed to get matchattr name", __func__);
|
||||
return false;
|
||||
}
|
||||
deviceNodeInfo->deviceMatchAttr = readString;
|
||||
@@ -260,13 +261,13 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h
|
||||
deviceNodeInfo->hostId = hostId;
|
||||
if (!GetDeviceNodeInfo(deviceNode, deviceNodeInfo)) {
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
HDF_LOGE("%s get device failed", __func__);
|
||||
HDF_LOGE("%s: failed to get device", __func__);
|
||||
deviceNodeInfo = NULL;
|
||||
deviceNode = deviceNode->sibling;
|
||||
continue;
|
||||
}
|
||||
if (!HdfSListAddOrder(deviceList, &deviceNodeInfo->node, HdfDeviceListCompare)) {
|
||||
HDF_LOGE("%s add device %s failed", __func__, deviceNodeInfo->svcName);
|
||||
HDF_LOGE("%s: failed to add device %s", __func__, deviceNodeInfo->svcName);
|
||||
HdfDeviceInfoFreeInstance(deviceNodeInfo);
|
||||
deviceNodeInfo = NULL;
|
||||
deviceNode = deviceNode->sibling;
|
||||
@@ -323,7 +324,11 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName)
|
||||
if (svcName == NULL) {
|
||||
break;
|
||||
}
|
||||
strcpy(svcName, serviceName);
|
||||
if (strcpy_s(svcName, strlen(serviceName) + 1, serviceName) != EOK) {
|
||||
HDF_LOGE("%s: failed to copy string", __func__);
|
||||
OsalMemFree(svcName);
|
||||
break;
|
||||
}
|
||||
deviceNodeInfo->svcName = svcName;
|
||||
HdfSListAdd(hostClnt->deviceInfos, &deviceNodeInfo->node);
|
||||
hostClnt->devCount++;
|
||||
|
||||
@@ -24,29 +24,29 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
|
||||
if (stub == NULL) {
|
||||
HDF_LOGE("input ioService null");
|
||||
HDF_LOGE("device ext dispatch: stub is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
uint64_t ioClientPtr = 0;
|
||||
if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
|
||||
HDF_LOGE("input ioClient null");
|
||||
HDF_LOGE("device ext dispatch: input ioClient is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSbufFlush(reply);
|
||||
devNode = CONTAINER_OF(stub, struct HdfDeviceNode, deviceObject);
|
||||
deviceMethod = devNode->deviceObject.service;
|
||||
if (deviceMethod == NULL) {
|
||||
HDF_LOGE("Device service interface is null");
|
||||
HDF_LOGE("device ext dispatch: device service interface is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Device deviceInfo is null");
|
||||
HDF_LOGE("device ext dispatch: device deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
|
||||
if (deviceMethod->Dispatch == NULL) {
|
||||
HDF_LOGE("Remote service dispatch is null");
|
||||
HDF_LOGE("device ext dispatch: remote service dispatch method is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return deviceMethod->Dispatch((struct HdfDeviceIoClient *)((uintptr_t)ioClientPtr), code, data, reply);
|
||||
@@ -64,7 +64,7 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
|
||||
}
|
||||
int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("Device publish service failed, ret is: %d", ret);
|
||||
HDF_LOGE("failed to publish device service, ret is %d", ret);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@ static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
|
||||
int i;
|
||||
*driverCount = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
|
||||
if (*driverCount <= 0) {
|
||||
HDF_LOGE("%s hdf get device counts failed!", __func__);
|
||||
HDF_LOGE("%s: failed to hdf get device counts", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfDriverEntry *driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("%s hdf alloc driver entry mem failed!", __func__);
|
||||
HDF_LOGE("%s: failed to alloc driver entry mem", __func__);
|
||||
*driverCount = 0;
|
||||
return NULL;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo
|
||||
{
|
||||
int i;
|
||||
if ((deviceInfo == NULL) || (deviceInfo->moduleName == NULL) || (deviceInfo->svcName == NULL)) {
|
||||
HDF_LOGE("%s hdf get device entry failed, input deviceInfo is NULL!", __func__);
|
||||
HDF_LOGE("%s: failed to get device entry, input deviceInfo is NULL", __func__);
|
||||
return NULL;
|
||||
}
|
||||
static struct HdfDriverEntry *driverEntry = NULL;
|
||||
@@ -44,24 +44,24 @@ struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo
|
||||
if (driverEntry == NULL) {
|
||||
driverEntry = HdfDriverEntryConstruct(&driverCount);
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("%s driver entry construct failed!", __func__);
|
||||
HDF_LOGE("%s: failed to construct driver entry", __func__);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < driverCount; i++) {
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("%s driver entry is null!", __func__);
|
||||
HDF_LOGE("%s: driver entry is null", __func__);
|
||||
return NULL;
|
||||
}
|
||||
if (driverEntry[i].moduleName == NULL) {
|
||||
HDF_LOGE("%s driver entry module name is null!", __func__);
|
||||
return NULL;
|
||||
HDF_LOGE("%s: driver entry module name is null", __func__);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(deviceInfo->moduleName, driverEntry[i].moduleName) == 0) {
|
||||
return &driverEntry[i];
|
||||
}
|
||||
}
|
||||
HDF_LOGE("Hdf get %s device entry failed!", deviceInfo->svcName);
|
||||
HDF_LOGE("failed to get device entry %s", deviceInfo->svcName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,20 +11,23 @@
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "hdf_dlist.h"
|
||||
#include "osal_mutex.h"
|
||||
#include "osal_sysevent.h"
|
||||
|
||||
struct DevHostService {
|
||||
struct IDevHostService super;
|
||||
uint16_t hostId;
|
||||
const char *hostName;
|
||||
struct HdfSList devices;
|
||||
struct DListHead devices;
|
||||
struct HdfServiceObserver observer;
|
||||
struct HdfSysEventNotifyNode sysEventNotifyNode;
|
||||
};
|
||||
|
||||
void DevHostServiceConstruct(struct DevHostService *service);
|
||||
void DevHostServiceDestruct(struct DevHostService *service);
|
||||
int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
|
||||
int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo);
|
||||
struct IDevHostService *DevHostServiceNewInstance(uint16_t hostId, const char *hostName);
|
||||
void DevHostServiceFreeInstance(struct IDevHostService *service);
|
||||
struct HdfObject *DevHostServiceCreate(void);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_object.h"
|
||||
#include "hdf_service_observer.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "hdf_dlist.h"
|
||||
#include "osal_mutex.h"
|
||||
|
||||
struct HdfDeviceNode;
|
||||
@@ -22,11 +22,12 @@ struct HdfDeviceNode;
|
||||
struct IHdfDevice {
|
||||
struct HdfObject object;
|
||||
int (*Attach)(struct IHdfDevice *, struct HdfDeviceNode *);
|
||||
void (*Detach)(struct IHdfDevice *, struct HdfDeviceNode *);
|
||||
};
|
||||
|
||||
struct HdfDevice {
|
||||
struct IHdfDevice super;
|
||||
struct HdfSListNode node;
|
||||
struct DListHead node;
|
||||
struct HdfSList services;
|
||||
uint16_t deviceId;
|
||||
uint16_t hostId;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "hdf_device.h"
|
||||
#include "hdf_device_info.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_pm.h"
|
||||
|
||||
struct HdfDeviceNode;
|
||||
struct DevHostService;
|
||||
@@ -34,7 +35,9 @@ struct HdfDeviceNode {
|
||||
};
|
||||
|
||||
int HdfDeviceNodeAddPowerStateListener(
|
||||
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener);
|
||||
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
|
||||
void HdfDeviceNodeRemovePowerStateListener(
|
||||
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener);
|
||||
void HdfDeviceNodeConstruct(struct HdfDeviceNode *service);
|
||||
void HdfDeviceNodeDestruct(struct HdfDeviceNode *service);
|
||||
struct HdfDeviceNode *HdfDeviceNodeNewInstance(void);
|
||||
|
||||
@@ -25,10 +25,12 @@ struct HdfDriverLoader {
|
||||
};
|
||||
|
||||
struct HdfObject *HdfDriverLoaderCreate(void);
|
||||
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst);
|
||||
void HdfDriverLoaderRelease(struct HdfObject *object);
|
||||
struct IDriverLoader *HdfDriverLoaderGetInstance(void);
|
||||
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo);
|
||||
struct HdfDeviceNode *HdfDriverLoaderLoadNode(
|
||||
struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
|
||||
void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo);
|
||||
|
||||
#endif /* HDF_DRIVER_LOADER_H */
|
||||
|
||||
@@ -11,17 +11,19 @@
|
||||
|
||||
#include "hdf_sref.h"
|
||||
#include "power_state_token_if.h"
|
||||
#include "hdf_pm.h"
|
||||
|
||||
struct PowerStateToken {
|
||||
struct IPowerStateToken super;
|
||||
struct IPowerEventListener *listener;
|
||||
const struct IPowerEventListener *listener;
|
||||
struct HdfDeviceObject *deviceObject;
|
||||
struct HdfSRef wakeRef;
|
||||
HdfPowerState state;
|
||||
uint32_t mode;
|
||||
};
|
||||
|
||||
struct PowerStateToken *PowerStateTokenNewInstance(
|
||||
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener);
|
||||
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
|
||||
void PowerStateTokenFreeInstance(struct PowerStateToken *stateToken);
|
||||
|
||||
int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state);
|
||||
#endif /* POWER_STATE_TOKEN_H */
|
||||
@@ -10,9 +10,7 @@
|
||||
#include "devmgr_service_clnt.h"
|
||||
#include "devsvc_manager_clnt.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_node_ext.h"
|
||||
#include "hdf_driver_loader.h"
|
||||
#include "hdf_io_service.h"
|
||||
#include "hdf_log.h"
|
||||
#include "hdf_object_manager.h"
|
||||
#include "osal_mem.h"
|
||||
@@ -21,17 +19,13 @@
|
||||
|
||||
static struct HdfDevice *DevHostServiceFindDevice(struct DevHostService *inst, uint16_t deviceId)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDevice *deviceNode = NULL;
|
||||
if (inst == NULL) {
|
||||
HDF_LOGE("Find driver failed, inst is null");
|
||||
HDF_LOGE("failed to find driver, inst is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HdfSListIteratorInit(&it, &inst->devices);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceNode = (struct HdfDevice *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDevice, node);
|
||||
DLIST_FOR_EACH_ENTRY(deviceNode, &inst->devices, struct HdfDevice, node) {
|
||||
if (deviceNode->deviceId == deviceId) {
|
||||
return deviceNode;
|
||||
}
|
||||
@@ -43,7 +37,7 @@ static void DevHostServiceFreeDevice(struct DevHostService *inst, uint16_t devic
|
||||
{
|
||||
struct HdfDevice *deviceNode = DevHostServiceFindDevice(inst, deviceId);
|
||||
if (deviceNode != NULL) {
|
||||
HdfSListRemove(&inst->devices, &deviceNode->node);
|
||||
DListRemove(&deviceNode->node);
|
||||
HdfDeviceFreeInstance(deviceNode);
|
||||
}
|
||||
}
|
||||
@@ -54,12 +48,12 @@ static struct HdfDevice *DevHostServiceGetDevice(struct DevHostService *inst, ui
|
||||
if (device == NULL) {
|
||||
device = HdfDeviceNewInstance();
|
||||
if (device == NULL) {
|
||||
HDF_LOGE("Dev host service create driver instance failed");
|
||||
HDF_LOGE("Dev host service failed to create driver instance");
|
||||
return NULL;
|
||||
}
|
||||
device->hostId = inst->hostId;
|
||||
device->deviceId = deviceId;
|
||||
HdfSListAdd(&inst->devices, &device->node);
|
||||
DListInsertHead(&device->node, &inst->devices);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
@@ -70,16 +64,16 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
struct HdfDevice *device = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->LoadNode == NULL)) {
|
||||
HDF_LOGE("Add device failed, input param is null");
|
||||
HDF_LOGE("failed to add device, input param is null");
|
||||
return ret;
|
||||
}
|
||||
|
||||
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
|
||||
if (device == NULL || device->super.Attach == NULL) {
|
||||
ret = HDF_DEV_ERR_NO_MEMORY;
|
||||
if ((device == NULL) || (device->super.Attach == NULL)) {
|
||||
ret = HDF_DEV_ERR_NO_DEVICE;
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -96,48 +90,58 @@ int DevHostServiceAddDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
return HDF_SUCCESS;
|
||||
|
||||
error:
|
||||
if (!HdfSListIsEmpty(&hostService->devices)) {
|
||||
DevHostServiceFreeDevice(hostService, deviceInfo->deviceId);
|
||||
if (DListIsEmpty(&hostService->devices)) {
|
||||
DevHostServiceFreeDevice(hostService, hostService->hostId);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
|
||||
static struct HdfDeviceNode *DevHostServiceGetDeviceNode(struct HdfSList *deviceNodes,
|
||||
const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDeviceNode *deviceNode = NULL;
|
||||
HdfSListIteratorInit(&it, deviceNodes);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceNode = HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry);
|
||||
if (strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0 &&
|
||||
strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) {
|
||||
HdfSListRemove(deviceNodes, &deviceNode->entry);
|
||||
return deviceNode;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfDevice *device = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
|
||||
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
|
||||
HDF_LOGE("Add device failed, input param is null");
|
||||
HDF_LOGE("failed to del device, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
device = DevHostServiceGetDevice(hostService, deviceInfo->deviceId);
|
||||
if (device == NULL) {
|
||||
HDF_LOGW("Del device failed, device is not exist");
|
||||
HDF_LOGW("failed to del device, device is not exist");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
driverLoader->UnLoadNode(driverLoader, deviceInfo);
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDeviceNode *deviceNode = NULL;
|
||||
HdfSListIteratorInit(&it, &device->services);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSListNode, HdfSListIteratorNext(&it), struct HdfDeviceNode, entry);
|
||||
if ((strcmp(deviceNode->deviceInfo->moduleName, deviceInfo->moduleName) == 0) &&
|
||||
(strcmp(deviceNode->deviceInfo->svcName, deviceInfo->svcName) == 0)) {
|
||||
struct DeviceNodeExt *deviceNodeExt = (struct DeviceNodeExt *)deviceNode;
|
||||
HdfSListRemove(&device->services, &deviceNode->entry);
|
||||
DeviceNodeExtRelease(&deviceNodeExt->super.super.object);
|
||||
}
|
||||
}
|
||||
|
||||
if (!HdfSListIsEmpty(&hostService->devices)) {
|
||||
DevHostServiceFreeDevice(hostService, device->deviceId);
|
||||
struct HdfDeviceNode *devNode = DevHostServiceGetDeviceNode(&device->services, deviceInfo);
|
||||
if (device->super.Detach != NULL) {
|
||||
device->super.Detach(&device->super, devNode);
|
||||
} else {
|
||||
HdfDeviceNodeFreeInstance(devNode);
|
||||
}
|
||||
DevSvcManagerClntRemoveService(deviceInfo->svcName);
|
||||
if (HdfSListIsEmpty(&device->services)) {
|
||||
DevHostServiceFreeDevice(hostService, device->deviceId);
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -145,7 +149,7 @@ static int DevHostServiceStartService(struct IDevHostService *service)
|
||||
{
|
||||
struct DevHostService *hostService = (struct DevHostService*)service;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Start device service failed, hostService is null");
|
||||
HDF_LOGE("failed to start device service, hostService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevmgrServiceClntAttachDeviceHost(hostService->hostId, service);
|
||||
@@ -158,14 +162,22 @@ void DevHostServiceConstruct(struct DevHostService *service)
|
||||
hostServiceIf->AddDevice = DevHostServiceAddDevice;
|
||||
hostServiceIf->DelDevice = DevHostServiceDelDevice;
|
||||
hostServiceIf->StartService = DevHostServiceStartService;
|
||||
HdfSListInit(&service->devices);
|
||||
DListHeadInit(&service->devices);
|
||||
HdfServiceObserverConstruct(&service->observer);
|
||||
}
|
||||
}
|
||||
|
||||
void DevHostServiceDestruct(struct DevHostService *service)
|
||||
{
|
||||
HdfSListFlush(&service->devices, HdfDeviceDelete);
|
||||
if (service == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct HdfDevice *device = NULL;
|
||||
struct HdfDevice *tmp = NULL;
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(device, tmp, &service->devices, struct HdfDevice, node) {
|
||||
HdfDeviceFreeInstance(device);
|
||||
}
|
||||
HdfServiceObserverDestruct(&service->observer);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ int DevmgrServiceClntAttachDeviceHost(uint16_t hostId, struct IDevHostService *h
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
|
||||
HDF_LOGE("Attach device host failed, get device manager service client is null");
|
||||
HDF_LOGE("failed to attach device host, get device manager service client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devMgrSvcIf = inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf->AttachDeviceHost == NULL) {
|
||||
HDF_LOGE("Attach device host failed, attach device host function is null");
|
||||
HDF_LOGE("failed to attach device host, attach device host function is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return devMgrSvcIf->AttachDeviceHost(devMgrSvcIf, hostId, hostService);
|
||||
@@ -36,13 +36,13 @@ int DevmgrServiceClntAttachDevice(const struct HdfDeviceInfo *deviceInfo, struct
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if ((inst == NULL) || (inst->devMgrSvcIf == NULL)) {
|
||||
HDF_LOGE("Device manager service client attach device failed, inst is null");
|
||||
HDF_LOGE("devmgr client failed to attach device, inst is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
devMgrSvcIf = inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf->AttachDevice == NULL) {
|
||||
HDF_LOGE("Device manager service client attach device failed, dmsOps->AttachDevice is nul");
|
||||
HDF_LOGE("devmgr client failed to attach device, dmsOps->AttachDevice is nul");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return devMgrSvcIf->AttachDevice(devMgrSvcIf, deviceInfo, deviceToken);
|
||||
|
||||
@@ -20,13 +20,13 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to add service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->AddService == NULL) {
|
||||
HDF_LOGE("AddService function is not assigned");
|
||||
HDF_LOGE("serviceManager AddService function is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->AddService(serviceManager, svcName, service);
|
||||
@@ -36,13 +36,13 @@ const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to get service, client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->GetService == NULL) {
|
||||
HDF_LOGE("GetService function is not assigned");
|
||||
HDF_LOGE("serviceManager GetService function is null");
|
||||
return NULL;
|
||||
}
|
||||
return serviceManager->GetService(serviceManager, svcName);
|
||||
@@ -52,13 +52,13 @@ struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to get device object, client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->GetObject == NULL) {
|
||||
HDF_LOGE("GetObject function is not assigned");
|
||||
HDF_LOGE("failed to get device object, method not implement");
|
||||
return NULL;
|
||||
}
|
||||
return serviceManager->GetObject(serviceManager, svcName);
|
||||
@@ -82,10 +82,8 @@ struct HdfDeviceObject *HdfRegisterDevice(const char *moduleName, const char *se
|
||||
|
||||
void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
|
||||
{
|
||||
int ret;
|
||||
ret = DevmgrServiceUnLoadDevice(serviceName);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s unload device %s failed!", __func__, serviceName);
|
||||
if (DevmgrServiceUnLoadDevice(serviceName) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:failed to unload device %s !", __func__, serviceName);
|
||||
}
|
||||
HdfDeviceListDel(moduleName, serviceName);
|
||||
}
|
||||
@@ -94,13 +92,13 @@ int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCall
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to subscribe service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->SubscribeService == NULL) {
|
||||
HDF_LOGE("SubscribeService function is not assigned");
|
||||
HDF_LOGE("failed to subscribe service, method not implement");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->SubscribeService(serviceManager, svcName, callback);
|
||||
@@ -110,13 +108,13 @@ int DevSvcManagerClntUnsubscribeService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to unsubscribe service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->UnsubscribeService == NULL) {
|
||||
HDF_LOGE("UnsubService function is not assigned");
|
||||
HDF_LOGE("failed to unsubscribe service, method not implement");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return serviceManager->UnsubscribeService(serviceManager, svcName);
|
||||
@@ -126,13 +124,13 @@ void DevSvcManagerClntRemoveService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("Get device manager client is null");
|
||||
HDF_LOGE("failed to remove service, devSvcMgrClnt is null");
|
||||
return;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->RemoveService == NULL) {
|
||||
HDF_LOGE("Remove service function is not assigned");
|
||||
HDF_LOGE("failed to remove service, method not implement");
|
||||
return;
|
||||
}
|
||||
serviceManager->RemoveService(serviceManager, svcName);
|
||||
@@ -157,9 +155,7 @@ struct DevSvcManagerClnt *DevSvcManagerClntGetInstance()
|
||||
void DevSvcManagerClntFreeInstance(struct DevSvcManagerClnt *instance)
|
||||
{
|
||||
if (instance != NULL) {
|
||||
if (instance->devSvcMgrIf != NULL) {
|
||||
HdfObjectManagerFreeObject((struct HdfObject *)instance->devSvcMgrIf);
|
||||
}
|
||||
HdfObjectManagerFreeObject((struct HdfObject *)instance->devSvcMgrIf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int HdfDeviceAttach(struct IHdfDevice *devInst, struct HdfDeviceNode *dev
|
||||
struct HdfDevice *device = (struct HdfDevice *)devInst;
|
||||
struct IDeviceNode *nodeIf = (struct IDeviceNode *)devNode;
|
||||
if (device == NULL || nodeIf == NULL || nodeIf->LaunchNode == NULL) {
|
||||
HDF_LOGE("Device attach failed, input params is wrong");
|
||||
HDF_LOGE("failed to attach device, input params invalid");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
HdfSListAdd(&device->services, &devNode->entry);
|
||||
|
||||
@@ -26,12 +26,12 @@ static int HdfDeviceNodePublishLocalService(
|
||||
{
|
||||
uint32_t matchId;
|
||||
if ((devNode == NULL) || (deviceInfo == NULL)) {
|
||||
HDF_LOGE("Publish local service failed, device is null");
|
||||
HDF_LOGE("failed to publish local service, device is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostService *hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Publish local service failed, host service is null");
|
||||
HDF_LOGE("failed to publish local service, host service is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
|
||||
@@ -44,7 +44,8 @@ static int HdfDeviceNodePublishService(
|
||||
{
|
||||
(void)device;
|
||||
int status = HDF_SUCCESS;
|
||||
if (deviceInfo->policy == SERVICE_POLICY_NONE) {
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_NONE) ||
|
||||
((deviceInfo->svcName != NULL) && (strlen(deviceInfo->svcName) == 0))) {
|
||||
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
|
||||
return status;
|
||||
}
|
||||
@@ -66,7 +67,7 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
|
||||
{
|
||||
struct HdfDevice *device = (struct HdfDevice *)devInst;
|
||||
if (device == NULL || devNode == NULL) {
|
||||
HDF_LOGE("Launch service failed, device or service is null");
|
||||
HDF_LOGE("failed to launch service, device or service is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
@@ -75,12 +76,12 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
|
||||
struct IHdfDeviceToken *deviceToken = NULL;
|
||||
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Launch service failed, deviceInfo is null");
|
||||
HDF_LOGE("failed to launch service, deviceInfo is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if ((driverEntry == NULL) || (driverEntry->Init == NULL)) {
|
||||
HDF_LOGE("deviceEntry or deviceEntry->Init is null");
|
||||
HDF_LOGE("failed to launch service, deviceEntry invalid");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int ret = driverEntry->Init(&devNode->deviceObject);
|
||||
@@ -109,21 +110,33 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
|
||||
}
|
||||
|
||||
int HdfDeviceNodeAddPowerStateListener(
|
||||
struct HdfDeviceNode *devNode, struct IPowerEventListener *listener)
|
||||
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener)
|
||||
{
|
||||
if (devNode->powerToken != NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (devNode->powerToken == NULL) {
|
||||
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
|
||||
}
|
||||
|
||||
devNode->powerToken = PowerStateTokenNewInstance(&devNode->deviceObject, listener);
|
||||
return (devNode->powerToken != NULL) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
void HdfDeviceNodeRemovePowerStateListener(
|
||||
struct HdfDeviceNode *devNode, const struct IPowerEventListener *listener)
|
||||
{
|
||||
(void)listener;
|
||||
if (devNode == NULL || devNode->powerToken == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
PowerStateTokenFreeInstance(devNode->powerToken);
|
||||
devNode->powerToken = NULL;
|
||||
}
|
||||
|
||||
|
||||
int HdfDeviceNodePublishPublicService(struct HdfDeviceNode *devNode, const char *svcName)
|
||||
{
|
||||
if ((devNode == NULL) || (devNode->deviceObject.service == NULL)) {
|
||||
HDF_LOGE("device method is null");
|
||||
HDF_LOGE("failed to publish public service: devNode is NULL");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevSvcManagerClntAddService(svcName, &devNode->deviceObject);
|
||||
|
||||
@@ -23,19 +23,19 @@ int32_t HdfDeviceSubscribeService(
|
||||
struct DevHostService *hostService = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
if (deviceObject == NULL || serviceName == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
HDF_LOGE("failed to subscribe service, deviceObject/serviceName is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Get host service is null");
|
||||
HDF_LOGE("failed to subscribe service, hostService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Get device deviceInfo is null");
|
||||
HDF_LOGE("failed to subscribe service, deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
matchId = HdfMakeHardwareId(deviceInfo->hostId, deviceInfo->deviceId);
|
||||
@@ -45,34 +45,43 @@ int32_t HdfDeviceSubscribeService(
|
||||
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
HDF_LOGE("failed to get service name, deviceObject is invalid");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("Get device deviceInfo is null");
|
||||
HDF_LOGE("failed to get service name, deviceInfo is null");
|
||||
return NULL;
|
||||
}
|
||||
return deviceInfo->svcName;
|
||||
}
|
||||
|
||||
void HdfDeviceRegisterPowerListener(struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
return HdfDeviceNodeAddPowerStateListener(devNode, listener);
|
||||
}
|
||||
|
||||
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
HdfDeviceNodeAddPowerStateListener(devNode, listener);
|
||||
HdfDeviceNodeRemovePowerStateListener(devNode, listener);
|
||||
}
|
||||
|
||||
void HdfDeviceAcquireWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
@@ -83,10 +92,10 @@ void HdfDeviceAcquireWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
}
|
||||
}
|
||||
|
||||
void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s input param is invalid", __func__);
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
@@ -97,6 +106,20 @@ void HdfDeviceReleaseWakeLock(struct HdfDeviceObject *deviceObject)
|
||||
}
|
||||
}
|
||||
|
||||
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
|
||||
{
|
||||
if (deviceObject == NULL || mode > HDF_POWER_MODE_MAX) {
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct PowerStateToken *token = devNode->powerToken;
|
||||
if (token != NULL) {
|
||||
token->mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
|
||||
{
|
||||
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) ||
|
||||
|
||||
Regular → Executable
+19
-14
@@ -23,27 +23,28 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode(
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
|
||||
HDF_LOGE("loader or loader->GetDriverEntry is null");
|
||||
HDF_LOGE("failed to load node, loader is invalid");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
driverEntry = loader->GetDriverEntry(deviceInfo);
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("Load service failed, deviceEntry is null");
|
||||
HDF_LOGE("failed to load node, deviceEntry is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devNode = HdfDeviceNodeNewInstance();
|
||||
if (devNode == NULL) {
|
||||
HDF_LOGE("Load service failed, device node is null");
|
||||
HDF_LOGE("failed to load node, device node is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devNode->driverEntry = driverEntry;
|
||||
devNode->deviceInfo = deviceInfo;
|
||||
devNode->deviceObject.property = HcsGetNodeByMatchAttr(HdfGetRootNode(), deviceInfo->deviceMatchAttr);
|
||||
|
||||
if (devNode->deviceObject.property == NULL) {
|
||||
HDF_LOGW("Get property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
|
||||
HDF_LOGW("failed to load node, property is null, match attr is: %s", deviceInfo->deviceMatchAttr);
|
||||
}
|
||||
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) || (deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
|
||||
@@ -61,34 +62,38 @@ struct HdfDeviceNode *HdfDriverLoaderLoadNode(
|
||||
return devNode;
|
||||
}
|
||||
|
||||
static void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
|
||||
void HdfDriverLoaderUnLoadNode(struct IDriverLoader *loader, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
struct HdfDeviceObject *deviceObject = NULL;
|
||||
if ((loader == NULL) || (loader->GetDriverEntry == NULL)) {
|
||||
HDF_LOGE("loader or loader->GetDriverEntry is null");
|
||||
HDF_LOGE("failed to unload service, loader invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
driverEntry = loader->GetDriverEntry(deviceInfo);
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("Load service failed, driverEntry is null");
|
||||
HDF_LOGE("failed to unload service, driverEntry is null");
|
||||
return;
|
||||
}
|
||||
if (driverEntry->Release == NULL) {
|
||||
HDF_LOGI("Device Release func is null");
|
||||
HDF_LOGI("device release func is null");
|
||||
return;
|
||||
}
|
||||
deviceObject = DevSvcManagerClntGetDeviceObject(deviceInfo->svcName);
|
||||
driverEntry->Release(deviceObject);
|
||||
if (deviceObject != NULL) {
|
||||
driverEntry->Release(deviceObject);
|
||||
}
|
||||
}
|
||||
|
||||
static void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
|
||||
void HdfDriverLoaderConstruct(struct HdfDriverLoader *inst)
|
||||
{
|
||||
struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
|
||||
driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
|
||||
driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
|
||||
driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
|
||||
if (inst != NULL) {
|
||||
struct IDriverLoader *driverLoaderIf = (struct IDriverLoader *)inst;
|
||||
driverLoaderIf->LoadNode = HdfDriverLoaderLoadNode;
|
||||
driverLoaderIf->UnLoadNode = HdfDriverLoaderUnLoadNode;
|
||||
driverLoaderIf->GetDriverEntry = HdfDriverLoaderGetDriverEntry;
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfObject *HdfDriverLoaderCreate()
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
uint32_t HdfMakeHardwareId(uint16_t hostId, uint16_t deviceId)
|
||||
{
|
||||
uint32_t hardwareId = hostId;
|
||||
hardwareId = (hardwareId << HALF_INT_LEN) | deviceId;
|
||||
return hardwareId;
|
||||
return ((uint32_t)hostId << HALF_INT_LEN) | deviceId;
|
||||
}
|
||||
|
||||
struct HdfServiceObserverRecord *HdfServiceObserverRecordObtain(uint32_t serviceKey)
|
||||
|
||||
@@ -32,7 +32,6 @@ void HdfServiceObserverDestruct(struct HdfServiceObserver *observer)
|
||||
if (observer != NULL) {
|
||||
HdfSListFlush(&observer->services, HdfServiceObserverRecordDelete);
|
||||
OsalMutexDestroy(&observer->observerMutex);
|
||||
observer->observerMutex.realMutex = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,20 +50,22 @@ int HdfServiceObserverSubscribeService(struct HdfServiceObserver *observer,
|
||||
if (serviceRecord == NULL) {
|
||||
serviceRecord = HdfServiceObserverRecordObtain(serviceKey);
|
||||
if (serviceRecord == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, serviceRecord is null");
|
||||
HDF_LOGE("failed to subscribe service, serviceRecord is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
subscriber = HdfServiceSubscriberObtain(callback, matchId);
|
||||
if (subscriber == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, subscriber is null");
|
||||
HDF_LOGE("failed to subscribe service, subscriber is null");
|
||||
HdfServiceObserverRecordRecycle(serviceRecord);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
OsalMutexLock(&observer->observerMutex);
|
||||
HdfSListAdd(&observer->services, &serviceRecord->entry);
|
||||
OsalMutexUnlock(&observer->observerMutex);
|
||||
} else {
|
||||
subscriber = HdfServiceSubscriberObtain(callback, matchId);
|
||||
if (subscriber == NULL) {
|
||||
HDF_LOGE("SubscribeService failed, hdf search list is null, subscriber is null");
|
||||
HDF_LOGE("failed to subscribe service, subscriber obtain null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +102,9 @@ int HdfServiceObserverPublishService(struct HdfServiceObserver *observer,
|
||||
serviceRecord->publisher = service;
|
||||
serviceRecord->matchId = matchId;
|
||||
serviceRecord->policy = policy;
|
||||
OsalMutexLock(&observer->observerMutex);
|
||||
HdfSListAdd(&observer->services, &serviceRecord->entry);
|
||||
OsalMutexUnlock(&observer->observerMutex);
|
||||
} else {
|
||||
serviceRecord->publisher = service;
|
||||
HdfServiceObserverRecordNotifySubscribers(serviceRecord, matchId, policy);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "osal_mem.h"
|
||||
#include "hdf_service_subscriber.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
struct HdfServiceSubscriber *HdfServiceSubscriberObtain(struct SubscriberCallback callback, uint32_t matchId)
|
||||
{
|
||||
|
||||
@@ -11,12 +11,110 @@
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_sysevent.h"
|
||||
|
||||
static void PowerStateTokenAcqureWakeLock(struct IPowerStateToken *token)
|
||||
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
|
||||
if (stateToken->state == POWER_STATE_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf != NULL && devMgrSvcIf->AcquireWakeLock != NULL) {
|
||||
devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
}
|
||||
|
||||
if (stateToken->state == POWER_STATE_INACTIVE || stateToken->state == POWER_STATE_IDLE) {
|
||||
const struct IPowerEventListener *listener = stateToken->listener;
|
||||
if ((listener != NULL) && (listener->Resume != NULL)) {
|
||||
listener->Resume(stateToken->deviceObject);
|
||||
}
|
||||
}
|
||||
stateToken->state = POWER_STATE_ACTIVE;
|
||||
}
|
||||
|
||||
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
|
||||
if (stateToken->state != POWER_STATE_ACTIVE && stateToken->state != POWER_STATE_IDLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
const struct IPowerEventListener *listener = stateToken->listener;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stateToken->state == POWER_STATE_ACTIVE) {
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if ((devMgrSvcIf != NULL) && (devMgrSvcIf->AcquireWakeLock != NULL)) {
|
||||
devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
}
|
||||
}
|
||||
|
||||
if ((listener != NULL) && (listener->Suspend != NULL)) {
|
||||
listener->Suspend(stateToken->deviceObject);
|
||||
}
|
||||
stateToken->state = POWER_STATE_INACTIVE;
|
||||
}
|
||||
|
||||
int PowerStateOnSysStateChange(struct PowerStateToken *stateToken, int32_t state)
|
||||
{
|
||||
if (stateToken == NULL || stateToken->listener == NULL || stateToken->mode != HDF_POWER_SYS_CTRL) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case KEVENT_POWER_SUSPEND:
|
||||
if (stateToken->listener->Suspend != NULL) {
|
||||
return stateToken->listener->Suspend(stateToken->deviceObject);
|
||||
}
|
||||
break;
|
||||
case KEVENT_POWER_RESUME:
|
||||
if (stateToken->listener->Resume != NULL) {
|
||||
return stateToken->listener->Resume(stateToken->deviceObject);
|
||||
}
|
||||
break;
|
||||
case KEVENT_POWER_DISPLAY_OFF:
|
||||
if (stateToken->listener->DozeSuspend != NULL) {
|
||||
return stateToken->listener->DozeSuspend(stateToken->deviceObject);
|
||||
}
|
||||
break;
|
||||
case KEVENT_POWER_DISPLAY_ON:
|
||||
if (stateToken->listener->DozeResume != NULL) {
|
||||
return stateToken->listener->DozeResume(stateToken->deviceObject);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void PowerStateTokenAcquireWakeLock(struct IPowerStateToken *token)
|
||||
{
|
||||
struct HdfSRef *sref = NULL;
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
|
||||
if (stateToken == NULL) {
|
||||
if (stateToken == NULL || stateToken->mode != HDF_POWER_DYNAMIC_CTRL) {
|
||||
return;
|
||||
}
|
||||
sref = (struct HdfSRef *)&stateToken->wakeRef;
|
||||
@@ -29,79 +127,32 @@ static void PowerStateTokenReleaseWakeLock(struct IPowerStateToken *token)
|
||||
{
|
||||
struct HdfSRef *sref = NULL;
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)token;
|
||||
if (stateToken == NULL) {
|
||||
if (stateToken == NULL || stateToken->mode != HDF_POWER_DYNAMIC_CTRL) {
|
||||
return;
|
||||
}
|
||||
sref = (struct HdfSRef *)&stateToken->wakeRef;
|
||||
if ((sref != NULL) && (sref->Release != NULL)) {
|
||||
if ((sref == NULL) || (sref->Release == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Not allowed to decrease the ref count to negative */
|
||||
if (HdfSRefCount(sref) == 0) {
|
||||
PowerStateTokenOnLastRelease(sref);
|
||||
} else {
|
||||
sref->Release(sref);
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
if (stateToken->state != POWER_STATE_ACTIVE) {
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct IPowerEventListener* listener = stateToken->listener;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if (devMgrSvcIf == NULL || devMgrSvcIf->AcquireWakeLock == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf->AcquireWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
if (stateToken->state == POWER_STATE_INACTIVE) {
|
||||
if ((listener != NULL) && (listener->Resume != NULL)) {
|
||||
listener->Resume(stateToken->deviceObject);
|
||||
}
|
||||
}
|
||||
stateToken->state = POWER_STATE_ACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
if (stateToken->state == POWER_STATE_ACTIVE) {
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
struct IPowerEventListener *listener = stateToken->listener;
|
||||
struct DevmgrServiceClnt *inst = DevmgrServiceClntGetInstance();
|
||||
if (inst == NULL) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst->devMgrSvcIf;
|
||||
if ((devMgrSvcIf == NULL) || (devMgrSvcIf->AcquireWakeLock == NULL)) {
|
||||
return;
|
||||
}
|
||||
devMgrSvcIf->ReleaseWakeLock(devMgrSvcIf, &stateToken->super);
|
||||
if ((listener != NULL) && (listener->Suspend != NULL)) {
|
||||
listener->Suspend(stateToken->deviceObject);
|
||||
}
|
||||
stateToken->state = POWER_STATE_INACTIVE;
|
||||
}
|
||||
}
|
||||
|
||||
static void PowerStateTokenConstruct(
|
||||
struct PowerStateToken *powerStateToken, struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
static int32_t PowerStateTokenConstruct(struct PowerStateToken *powerStateToken,
|
||||
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
|
||||
{
|
||||
struct IPowerStateToken *tokenIf = &powerStateToken->super;
|
||||
struct IHdfSRefListener *srefListener = (struct IHdfSRefListener *)OsalMemCalloc(sizeof(struct IHdfSRefListener));
|
||||
if (srefListener == NULL) {
|
||||
return;
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
tokenIf->AcquireWakeLock = PowerStateTokenAcqureWakeLock;
|
||||
tokenIf->AcquireWakeLock = PowerStateTokenAcquireWakeLock;
|
||||
tokenIf->ReleaseWakeLock = PowerStateTokenReleaseWakeLock;
|
||||
|
||||
srefListener->OnFirstAcquire = PowerStateTokenOnFirstAcquire;
|
||||
@@ -111,16 +162,24 @@ static void PowerStateTokenConstruct(
|
||||
powerStateToken->listener = listener;
|
||||
powerStateToken->deviceObject = deviceObject;
|
||||
HdfSRefConstruct(&powerStateToken->wakeRef, srefListener);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
struct PowerStateToken *PowerStateTokenNewInstance(
|
||||
struct HdfDeviceObject *deviceObject, struct IPowerEventListener *listener)
|
||||
struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
|
||||
{
|
||||
struct PowerStateToken *stateToken =
|
||||
(struct PowerStateToken *)OsalMemCalloc(sizeof(struct PowerStateToken));
|
||||
if (stateToken != NULL) {
|
||||
PowerStateTokenConstruct(stateToken, deviceObject, listener);
|
||||
if (stateToken == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PowerStateTokenConstruct(stateToken, deviceObject, listener) != HDF_SUCCESS) {
|
||||
OsalMemFree(stateToken);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return stateToken;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
#include "devhost_service_if.h"
|
||||
#include "hdf_slist.h"
|
||||
#include "hdf_map.h"
|
||||
|
||||
struct DevHostServiceClnt {
|
||||
struct HdfSListNode node;
|
||||
struct HdfSList devices;
|
||||
struct HdfSList *deviceInfos;
|
||||
Map *deviceHashMap;
|
||||
struct IDevHostService *hostService;
|
||||
uint16_t devCount;
|
||||
uint16_t hostId;
|
||||
@@ -25,7 +27,7 @@ struct DevHostServiceClnt {
|
||||
|
||||
int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt);
|
||||
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName);
|
||||
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt* hostClnt);
|
||||
void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt);
|
||||
void DevHostServiceClntDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#endif /* DEVHOST_SERVICE_CLNT_H */
|
||||
|
||||
@@ -29,4 +29,7 @@ int DevSvcManagerAddService(struct IDevSvcManager *manager, const char *svcName,
|
||||
struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *manager, const char *svcName);
|
||||
void DevSvcManagerRemoveService(struct IDevSvcManager *manager, const char *svcName);
|
||||
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback);
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName);
|
||||
|
||||
#endif /* DEVICE_SERVICE_MANAGER_H */
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
struct PowerStateTokenClnt {
|
||||
struct HdfSListNode entry;
|
||||
HdfPowerState powerState;
|
||||
struct IPowerStateToken* tokenIf;
|
||||
struct IPowerStateToken *tokenIf;
|
||||
};
|
||||
|
||||
struct PowerStateTokenClnt *PowerStateTokenClntNewInstance(struct IPowerStateToken *tokenIf);
|
||||
|
||||
@@ -23,7 +23,7 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct IDevHostService *devHostSvcIf = NULL;
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("Install driver failed, hostClnt is null");
|
||||
HDF_LOGE("failed to install driver, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
|
||||
}
|
||||
ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("Install %s driver failed, ret = %d", deviceInfo->svcName, ret);
|
||||
HDF_LOGE("failed to install driver %s, ret = %d", deviceInfo->svcName, ret);
|
||||
}
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
@@ -53,6 +53,12 @@ int DevHostServiceClntInstallDriver(struct DevHostServiceClnt *hostClnt)
|
||||
static void DevHostServiceClntConstruct(struct DevHostServiceClnt *hostClnt)
|
||||
{
|
||||
HdfSListInit(&hostClnt->devices);
|
||||
hostClnt->deviceHashMap = (Map *)OsalMemCalloc(sizeof(Map));
|
||||
if (hostClnt->deviceHashMap == NULL) {
|
||||
HDF_LOGE("%s:failed to malloc deviceHashMap", __func__);
|
||||
return;
|
||||
}
|
||||
MapInit(hostClnt->deviceHashMap);
|
||||
}
|
||||
|
||||
struct DevHostServiceClnt *DevHostServiceClntNewInstance(uint16_t hostId, const char *hostName)
|
||||
@@ -73,6 +79,7 @@ void DevHostServiceClntFreeInstance(struct DevHostServiceClnt *hostClnt)
|
||||
if (hostClnt != NULL) {
|
||||
HdfSListFlush(&hostClnt->devices, DeviceTokenClntDelete);
|
||||
HdfSListFlush(hostClnt->deviceInfos, HdfDeviceInfoDelete);
|
||||
OsalMemFree(hostClnt->deviceHashMap);
|
||||
OsalMemFree(hostClnt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ struct DeviceTokenClnt *DeviceTokenClntNewInstance(struct IHdfDeviceToken *token
|
||||
{
|
||||
struct DeviceTokenClnt *tokenClnt = NULL;
|
||||
if (tokenIf == NULL) {
|
||||
HDF_LOGE("New token client failed, tokenIf is null");
|
||||
HDF_LOGE("failed to create token client, tokenIf is null");
|
||||
return NULL;
|
||||
}
|
||||
tokenClnt = (struct DeviceTokenClnt *)OsalMemCalloc(sizeof(struct DeviceTokenClnt));
|
||||
|
||||
@@ -17,12 +17,15 @@
|
||||
#include "hdf_object_manager.h"
|
||||
#include "power_state_manager.h"
|
||||
|
||||
|
||||
#define HDF_LOG_TAG devmgr_service
|
||||
|
||||
static int DevmgrServiceActiveDevice(struct DevHostServiceClnt *hostClnt, struct HdfDeviceInfo *deviceInfo, bool isLoad)
|
||||
{
|
||||
struct IDevHostService *devHostSvcIf = (struct IDevHostService *)hostClnt->hostService;
|
||||
if (devHostSvcIf == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (isLoad && (deviceInfo->preload != DEVICE_PRELOAD_ENABLE)) {
|
||||
int ret = devHostSvcIf->AddDevice(devHostSvcIf, deviceInfo);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
@@ -83,7 +86,7 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
|
||||
if (deviceInfo->preload == DEVICE_PRELOAD_ENABLE_STEP2) {
|
||||
ret = DevmgrServiceActiveDevice(hostClnt, deviceInfo, true);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s load driver %s failed!", __func__, deviceInfo->moduleName);
|
||||
HDF_LOGE("%s:failed to load driver %s", __func__, deviceInfo->moduleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +94,6 @@ int32_t DevmgrServiceLoadLeftDriver(struct DevmgrService *devMgrSvc)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int DevmgrServiceLoadDevice(const char *svcName)
|
||||
{
|
||||
return DevmgrServiceFindAndActiveDevice(svcName, true);
|
||||
@@ -108,7 +110,7 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *dmService = (struct DevmgrService *)inst;
|
||||
if (dmService == NULL) {
|
||||
HDF_LOGE("Find device host failed, dmService is null");
|
||||
HDF_LOGE("failed to find device host, dmService is null");
|
||||
return NULL;
|
||||
}
|
||||
HdfSListIteratorInit(&it, &dmService->hosts);
|
||||
@@ -118,29 +120,49 @@ static struct DevHostServiceClnt *DevmgrServiceFindDeviceHost(struct IDevmgrServ
|
||||
return hostClnt;
|
||||
}
|
||||
}
|
||||
HDF_LOGE("Find host failed, host id is %u", hostId);
|
||||
HDF_LOGE("failed to find host, host id is %u", hostId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, uint16_t deviceId, uint16_t status)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
|
||||
HdfSListIteratorInit(&it, hostClnt->deviceInfos);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&it);
|
||||
if (deviceInfo->deviceId == deviceId) {
|
||||
deviceInfo->status = status;
|
||||
HDF_LOGD("%s host:%s %u device:%s %u status:%u", __func__, hostClnt->hostName,
|
||||
hostClnt->hostId, deviceInfo->svcName, deviceId, deviceInfo->status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
HDF_LOGE("%s: not find device %u in host %u", __func__, hostClnt->hostId, deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
static int DevmgrServiceAttachDevice(
|
||||
struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
|
||||
{
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("deviceInfo is null");
|
||||
HDF_LOGE("failed to attach device, deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("hostClnt is null");
|
||||
HDF_LOGE("failed to attach device, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DeviceTokenClnt *tokenClnt = DeviceTokenClntNewInstance(token);
|
||||
if (tokenClnt == NULL) {
|
||||
HDF_LOGE("tokenClnt is null");
|
||||
HDF_LOGE("failed to attach device, tokenClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
tokenClnt->deviceInfo = deviceInfo;
|
||||
DevmgrServiceUpdateStatus(hostClnt, deviceInfo->deviceId, HDF_SERVICE_USABLE);
|
||||
HdfSListAdd(&hostClnt->devices, &tokenClnt->node);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -150,20 +172,21 @@ static int DevmgrServiceAttachDeviceHost(
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, hostId);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("Attach device host failed, hostClnt is null");
|
||||
HDF_LOGE("failed to attach device host, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("Attach device host failed, hostService is null");
|
||||
HDF_LOGE("failed to attach device host, hostService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
hostClnt->hostService = hostService;
|
||||
hostClnt->deviceInfos = HdfAttributeManagerGetDeviceList(hostClnt->hostId, hostClnt->hostName);
|
||||
if (hostClnt->deviceInfos == NULL) {
|
||||
HDF_LOGE("Get device list failed");
|
||||
return HDF_FAILURE;
|
||||
HDF_LOGW("failed to get device list ");
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
hostClnt->devCount = HdfSListCount(hostClnt->deviceInfos);
|
||||
hostClnt->hostService = hostService;
|
||||
return DevHostServiceClntInstallDriver(hostClnt);
|
||||
}
|
||||
|
||||
@@ -181,7 +204,7 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
}
|
||||
HdfSListInit(&hostList);
|
||||
if (!HdfAttributeManagerGetHostList(&hostList)) {
|
||||
HDF_LOGW("%s get host list is null", __func__);
|
||||
HDF_LOGW("%s: host list is null", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
HdfSListIteratorInit(&it, &hostList);
|
||||
@@ -189,13 +212,13 @@ static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst)
|
||||
hostAttr = (struct HdfHostInfo *)HdfSListIteratorNext(&it);
|
||||
hostClnt = DevHostServiceClntNewInstance(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGW("Create new device host client failed");
|
||||
HDF_LOGW("failed to create new device host client");
|
||||
continue;
|
||||
}
|
||||
HdfSListAdd(&inst->hosts, &hostClnt->node);
|
||||
hostClnt->hostPid = installer->StartDeviceHost(hostAttr->hostId, hostAttr->hostName);
|
||||
if (hostClnt->hostPid == HDF_FAILURE) {
|
||||
HDF_LOGW("Start device host failed, host id is %u", hostAttr->hostId);
|
||||
HDF_LOGW("failed to start device host, host id is %u", hostAttr->hostId);
|
||||
HdfSListRemove(&inst->hosts, &hostClnt->node);
|
||||
DevHostServiceClntFreeInstance(hostClnt);
|
||||
}
|
||||
@@ -208,7 +231,7 @@ int DevmgrServiceStartService(struct IDevmgrService *inst)
|
||||
{
|
||||
struct DevmgrService *dmService = (struct DevmgrService *)inst;
|
||||
if (dmService == NULL) {
|
||||
HDF_LOGE("Start device manager service failed, dmService is null");
|
||||
HDF_LOGE("failed to start device manager service, dmService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return DevmgrServiceStartDeviceHosts(dmService);
|
||||
@@ -217,7 +240,7 @@ int DevmgrServiceStartService(struct IDevmgrService *inst)
|
||||
bool DevmgrServiceConstruct(struct DevmgrService *inst)
|
||||
{
|
||||
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s mutex init failed", __func__);
|
||||
HDF_LOGE("%s:failed to mutex init ", __func__);
|
||||
return false;
|
||||
}
|
||||
struct IDevmgrService *devMgrSvcIf = (struct IDevmgrService *)inst;
|
||||
@@ -228,11 +251,12 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst)
|
||||
devMgrSvcIf->AcquireWakeLock = DevmgrServiceAcquireWakeLock;
|
||||
devMgrSvcIf->ReleaseWakeLock = DevmgrServiceReleaseWakeLock;
|
||||
HdfSListInit(&inst->hosts);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct HdfObject *DevmgrServiceCreate()
|
||||
{
|
||||
static bool isDevMgrServiceInit = false;
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
#define HDF_LOG_TAG devsvc_manager
|
||||
|
||||
struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
|
||||
static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *inst, uint32_t serviceKey)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct DevSvcRecord *record = NULL;
|
||||
struct DevSvcRecord *searchResult = NULL;
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
if (devSvcManager == NULL) {
|
||||
HDF_LOGE("Search service failed, devSvcManager is null");
|
||||
HDF_LOGE("failed to search service, devSvcManager is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, st
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
if ((devSvcManager == NULL) || (service == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGE("Add service failed, input param is null");
|
||||
HDF_LOGE("failed to add service, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct DevSvcRecord *record = DevSvcRecordNewInstance();
|
||||
if (record == NULL) {
|
||||
HDF_LOGE("Add service failed, record is null");
|
||||
HDF_LOGE("failed to add service , record is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
|
||||
HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
|
||||
OsalMutexUnlock(&devSvcManager->mutex);
|
||||
}
|
||||
DevSvcRecordFreeInstance(serviceRecord);
|
||||
}
|
||||
|
||||
struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName)
|
||||
@@ -134,7 +135,7 @@ bool DevSvcManagerConstruct(struct DevSvcManager *inst)
|
||||
devSvcMgrIf->GetObject = DevSvcManagerGetObject;
|
||||
HdfSListInit(&inst->services);
|
||||
if (OsalMutexInit(&inst->mutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("Device service manager create mutex failed!");
|
||||
HDF_LOGE("failed to create device service manager mutex");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -171,4 +172,3 @@ struct IDevSvcManager *DevSvcManagerGetInstance()
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHos
|
||||
}
|
||||
int ret = hostServiceIf->StartService(hostServiceIf);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("Start host service failed, ret is: %d", ret);
|
||||
HDF_LOGE("failed to start host service, ret: %d", ret);
|
||||
DevHostServiceFreeInstance(hostServiceIf);
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -62,7 +62,6 @@ static void PowerStateManagerReleaseWakeLock(
|
||||
|
||||
static void PowerStateManagerConstruct(struct PowerStateManager *inst)
|
||||
{
|
||||
// not support system acquire and release
|
||||
static struct IHdfSRefListener wakeLockRefListener = {
|
||||
.OnFirstAcquire = NULL,
|
||||
.OnLastRelease = NULL,
|
||||
|
||||
@@ -72,12 +72,12 @@ int IoServiceTest::OnDevEventReceived(struct HdfDevEventlistener *listener, stru
|
||||
{
|
||||
OsalTimespec time;
|
||||
OsalGetTime(&time);
|
||||
HDF_LOGE("%s received event[%d] from %s at %llu.%llu", (char *)listener->priv, eventCount++, (char *)service->priv,
|
||||
HDF_LOGE("%s: received event[%d] from %s at %llu.%llu", (char *)listener->priv, eventCount++, (char *)service->priv,
|
||||
time.sec, time.usec);
|
||||
|
||||
const char *string = HdfSbufReadString(data);
|
||||
if (string == nullptr) {
|
||||
HDF_LOGE("fail to read string in event data");
|
||||
HDF_LOGE("failed to read string in event data");
|
||||
return 0;
|
||||
}
|
||||
struct Eventlistener *l = CONTAINER_OF(listener, struct Eventlistener, listener);
|
||||
@@ -140,7 +140,7 @@ static int SendEvent(struct HdfIoService *serv, const char *eventData)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *testServ = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(testServ, nullptr);
|
||||
@@ -149,11 +149,11 @@ HWTEST_F(IoServiceTest, HdfIoService001, TestSize.Level1)
|
||||
|
||||
/* *
|
||||
* @tc.name: HdfIoService002
|
||||
* @tc.desc: service group linten test
|
||||
* @tc.desc: service group listen test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv, nullptr);
|
||||
@@ -203,7 +203,7 @@ HWTEST_F(IoServiceTest, HdfIoService002, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv, nullptr);
|
||||
@@ -258,7 +258,7 @@ HWTEST_F(IoServiceTest, HdfIoService003, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv1 = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv1, nullptr);
|
||||
@@ -283,7 +283,7 @@ HWTEST_F(IoServiceTest, HdfIoService004, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService005, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv, nullptr);
|
||||
@@ -467,7 +467,7 @@ HWTEST_F(IoServiceTest, HdfIoService008, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
|
||||
ASSERT_NE(group, nullptr);
|
||||
@@ -504,7 +504,7 @@ HWTEST_F(IoServiceTest, HdfIoService009, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoServiceGroup *group = HdfIoServiceGroupObtain();
|
||||
ASSERT_NE(group, nullptr);
|
||||
@@ -544,7 +544,7 @@ HWTEST_F(IoServiceTest, HdfIoService010, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv, nullptr);
|
||||
@@ -573,7 +573,7 @@ HWTEST_F(IoServiceTest, HdfIoService011, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level1)
|
||||
HWTEST_F(IoServiceTest, HdfIoService012, TestSize.Level0)
|
||||
{
|
||||
struct HdfIoService *serv = HdfIoServiceBind(testSvcName);
|
||||
ASSERT_NE(serv, nullptr);
|
||||
|
||||
@@ -84,19 +84,19 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0)
|
||||
int32_t ret = HDF_FAILURE;
|
||||
struct HdfSBuf *data = NULL;
|
||||
struct HdfIoService *ioService = HdfIoServiceBind(SAMPLE_SERVICE);
|
||||
ASSERT_TRUE(ioService != NULL);
|
||||
EXPECT_TRUE(ioService != NULL);
|
||||
data = HdfSBufObtainDefaultSize();
|
||||
ASSERT_TRUE(data != NULL);
|
||||
EXPECT_TRUE(data != NULL);
|
||||
EXPECT_TRUE(HdfSbufWriteString(data, "sample_driver"));
|
||||
EXPECT_TRUE(HdfSbufWriteString(data, "sample_service1"));
|
||||
int64_t timeBefore = OsalGetSysTimeMs();
|
||||
uint64_t timeBefore = OsalGetSysTimeMs();
|
||||
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_REGISTER_DEVICE, data, NULL);
|
||||
EXPECT_TRUE(ret == HDF_SUCCESS);
|
||||
int64_t timeAfter = OsalGetSysTimeMs();
|
||||
uint64_t timeAfter = OsalGetSysTimeMs();
|
||||
EXPECT_TRUE((timeAfter - timeBefore) < 100);
|
||||
|
||||
struct HdfIoService *ioService1 = HdfIoServiceBind("sample_service1");
|
||||
ASSERT_TRUE(ioService1 != NULL);
|
||||
EXPECT_TRUE(ioService1 != NULL);
|
||||
HdfIoServiceRecycle(ioService1);
|
||||
|
||||
ret = ioService->dispatcher->Dispatch(&ioService->object, SAMPLE_DRIVER_UNREGISTER_DEVICE, data, NULL);
|
||||
|
||||
@@ -21,7 +21,7 @@ static const int DEFAULT_LOOP_COUNT = 500;
|
||||
static const int DEFAULT_BIG_LOOP_COUNT = 1000;
|
||||
static const int DATA_MOD = 26;
|
||||
|
||||
class SBufTest : public ::testing::Test {
|
||||
class HdfSBufTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {}
|
||||
|
||||
@@ -243,7 +243,7 @@ protected:
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestObtain001, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestObtain001, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtain(DEFAULT_SBUF_SIZE);
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -256,7 +256,7 @@ HWTEST_F(SBufTest, SbufTestObtain001, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestWriteUint64002, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestWriteUint64002, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -271,7 +271,7 @@ HWTEST_F(SBufTest, SbufTestWriteUint64002, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -288,7 +288,7 @@ HWTEST_F(SBufTest, SbufTestWriteUint64Loop003, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -297,7 +297,7 @@ HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
|
||||
auto ret = HdfSbufWriteInt64(sBuf, INT64_MAX);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
uint64_t val = 0;
|
||||
for (int j = 0; j < loop; ++j) {
|
||||
@@ -318,7 +318,7 @@ HWTEST_F(SBufTest, SbufTestReadUint64Loop004, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestInt8005, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -331,7 +331,7 @@ HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
int8_t val = 0;
|
||||
@@ -351,7 +351,7 @@ HWTEST_F(SBufTest, SbufTestInt8005, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestInt16006, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -364,7 +364,7 @@ HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
int16_t val = 0;
|
||||
@@ -384,7 +384,7 @@ HWTEST_F(SBufTest, SbufTestInt16006, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestInt32007, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -397,7 +397,7 @@ HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
int32_t val = 0;
|
||||
@@ -417,7 +417,7 @@ HWTEST_F(SBufTest, SbufTestInt32007, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestInt64008, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -430,7 +430,7 @@ HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint64_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
int64_t val = 0;
|
||||
@@ -450,7 +450,7 @@ HWTEST_F(SBufTest, SbufTestInt64008, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestUInt32009, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -463,7 +463,7 @@ HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
uint32_t val = 0;
|
||||
@@ -483,7 +483,7 @@ HWTEST_F(SBufTest, SbufTestUInt32009, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestUInt16010, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -496,7 +496,7 @@ HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
uint16_t val = 0;
|
||||
@@ -516,7 +516,7 @@ HWTEST_F(SBufTest, SbufTestUInt16010, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestUInt8011, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -529,7 +529,7 @@ HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_EQ(dataSize, loop * sizeof(uint32_t));
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
uint8_t val = 0;
|
||||
@@ -549,7 +549,7 @@ HWTEST_F(SBufTest, SbufTestUInt8011, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestString012, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -561,12 +561,11 @@ HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
for (int j = 0; j < loop; ++j) {
|
||||
const char *readStr = HdfSbufReadString(readBuf);
|
||||
ASSERT_NE(readStr, nullptr);
|
||||
ASSERT_EQ(std::string(readStr), str);
|
||||
}
|
||||
HdfSBufRecycle(readBuf);
|
||||
@@ -579,7 +578,7 @@ HWTEST_F(SBufTest, SbufTestString012, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestNullString013, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -589,7 +588,7 @@ HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
|
||||
ASSERT_EQ(true, ret);
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_NE((size_t)0, dataSize);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
auto val = HdfSbufReadString(readBuf);
|
||||
ASSERT_EQ(nullptr, val);
|
||||
@@ -607,7 +606,7 @@ HWTEST_F(SBufTest, SbufTestNullString013, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestBuffer014, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -619,7 +618,7 @@ HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
for (int j = 0; j < loop; ++j) {
|
||||
@@ -640,7 +639,7 @@ HWTEST_F(SBufTest, SbufTestBuffer014, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestNullBuffer015, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -650,7 +649,7 @@ HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
|
||||
ASSERT_EQ(true, ret);
|
||||
size_t dataSize = HdfSbufGetDataSize(sBuf);
|
||||
ASSERT_NE((size_t)0, dataSize);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
const uint8_t *buffVal = nullptr;
|
||||
uint32_t buffLen = 0;
|
||||
@@ -673,7 +672,7 @@ HWTEST_F(SBufTest, SbufTestNullBuffer015, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
|
||||
HWTEST_F(HdfSBufTest, SbufTestRandomDataSeq016, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -683,7 +682,7 @@ HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
|
||||
bool ret = PushDataSequence(sBuf);
|
||||
ASSERT_EQ(true, ret);
|
||||
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)sBuf->data, sBuf->writePos);
|
||||
HdfSBuf *readBuf = HdfSBufBind((uintptr_t)HdfSbufGetData(sBuf), HdfSbufGetDataSize(sBuf));
|
||||
ASSERT_NE(readBuf, nullptr);
|
||||
|
||||
ret = PullDataSequence(readBuf);
|
||||
@@ -698,7 +697,7 @@ HWTEST_F(SBufTest, SbufTestRandomDataSeq016, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0)
|
||||
HWTEST_F(HdfSBufTest, SbufTestRandomRWDataSeq017, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -731,7 +730,7 @@ HWTEST_F(SBufTest, SbufTestRandomRWDataSeq017, TestSize.Level0)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestSbufMove018, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestSbufMove018, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
@@ -768,7 +767,7 @@ HWTEST_F(SBufTest, SbufTestSbufMove018, TestSize.Level1)
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000F869B
|
||||
*/
|
||||
HWTEST_F(SBufTest, SbufTestSbufMoveHalf019, TestSize.Level1)
|
||||
HWTEST_F(HdfSBufTest, SbufTestSbufMoveHalf019, TestSize.Level1)
|
||||
{
|
||||
HdfSBuf *sBuf = HdfSBufObtainDefaultSize();
|
||||
ASSERT_NE(sBuf, nullptr);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_SEC_H
|
||||
#define HDF_SEC_H
|
||||
|
||||
#if defined(__KERNEL__)
|
||||
#include <linux/ioctl.h>
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <sys/ioctl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define DEVICE_HDF_SECURE_NAME "hdf_secure"
|
||||
#define HDF_SECURE_MAGIC 'S'
|
||||
|
||||
/* event commands */
|
||||
#define HDF_SECURE_SET_INFO _IO(HDF_SECURE_MAGIC, 0x1)
|
||||
#define HDF_SECURE_SET_CURRENT_ID _IO(HDF_SECURE_MAGIC, 0x2)
|
||||
#define HDF_SECURE_DELETE_INFO _IO(HDF_SECURE_MAGIC, 0x3)
|
||||
|
||||
#define HDF_DECLARE_BITMAP(name, bits) \
|
||||
uint64_t name[HDF_BITS_TO_LONGS(bits)]
|
||||
#define HDF_BITS_TO_LONGS(nr) HDF_DIV_ROUND_UP(nr, HDF_BITS_PER_BYTE * sizeof(uint64_t))
|
||||
#define HDF_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
||||
#define HDF_BITS_PER_BYTE 8
|
||||
|
||||
#define SECMAP_MAX_SIZE 64
|
||||
#define ID_MAX_SIZE 65
|
||||
|
||||
struct SecInfo {
|
||||
char secId[ID_MAX_SIZE];
|
||||
HDF_DECLARE_BITMAP(secMap, SECMAP_MAX_SIZE);
|
||||
};
|
||||
uint32_t hdf_permission_check(uint8_t type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_SEC_H */
|
||||
Regular → Executable
+84
@@ -12,9 +12,24 @@
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_slist.h"
|
||||
|
||||
#define USB_PNP_INFO_MAX_INTERFACES 32
|
||||
#define USB_PNP_DEBUG_STRING ""
|
||||
|
||||
enum {
|
||||
HDF_SERVICE_UNUSABLE,
|
||||
HDF_SERVICE_USABLE,
|
||||
};
|
||||
|
||||
enum {
|
||||
HDF_DEV_LOCAL_SERVICE,
|
||||
HDF_DEV_REMOTE_SERVICE,
|
||||
};
|
||||
|
||||
struct HdfDeviceInfo {
|
||||
struct HdfSListNode node;
|
||||
bool isDynamic;
|
||||
uint16_t status;
|
||||
uint16_t deviceType;
|
||||
uint16_t hostId;
|
||||
uint16_t deviceId;
|
||||
uint16_t policy;
|
||||
@@ -24,6 +39,75 @@ struct HdfDeviceInfo {
|
||||
const char *moduleName;
|
||||
const char *svcName;
|
||||
const char *deviceMatchAttr;
|
||||
const void *private;
|
||||
};
|
||||
|
||||
enum UsbPnpNotifyServiceCmd {
|
||||
USB_PNP_NOTIFY_ADD_INTERFACE,
|
||||
USB_PNP_NOTIFY_REMOVE_INTERFACE,
|
||||
USB_PNP_NOTIFY_REPORT_INTERFACE,
|
||||
};
|
||||
|
||||
enum UsbPnpNotifyRemoveType {
|
||||
USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM,
|
||||
USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM,
|
||||
};
|
||||
|
||||
enum {
|
||||
USB_PNP_NOTIFY_MATCH_VENDOR = 0x0001,
|
||||
USB_PNP_NOTIFY_MATCH_PRODUCT = 0x0002,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_LOW = 0x0004,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_HIGH = 0x0008,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_CLASS = 0x0010,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_SUBCLASS = 0x0020,
|
||||
USB_PNP_NOTIFY_MATCH_DEV_PROTOCOL = 0x0040,
|
||||
USB_PNP_NOTIFY_MATCH_INT_CLASS = 0x0080,
|
||||
USB_PNP_NOTIFY_MATCH_INT_SUBCLASS = 0x0100,
|
||||
USB_PNP_NOTIFY_MATCH_INT_PROTOCOL = 0x0200,
|
||||
USB_PNP_NOTIFY_MATCH_INT_NUMBER = 0x0400,
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyServiceInfo {
|
||||
int32_t length;
|
||||
|
||||
int32_t devNum;
|
||||
int32_t busNum;
|
||||
|
||||
int32_t interfaceLength;
|
||||
uint8_t interfaceNumber[USB_PNP_INFO_MAX_INTERFACES];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct UsbPnpNotifyInterfaceInfo {
|
||||
uint8_t interfaceClass;
|
||||
uint8_t interfaceSubClass;
|
||||
uint8_t interfaceProtocol;
|
||||
|
||||
uint8_t interfaceNumber;
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyDeviceInfo {
|
||||
uint16_t vendorId;
|
||||
uint16_t productId;
|
||||
|
||||
uint16_t bcdDeviceLow;
|
||||
uint16_t bcdDeviceHigh;
|
||||
|
||||
uint8_t deviceClass;
|
||||
uint8_t deviceSubClass;
|
||||
uint8_t deviceProtocol;
|
||||
};
|
||||
|
||||
struct UsbPnpNotifyMatchInfoTable {
|
||||
uint32_t usbDevAddr;
|
||||
int32_t devNum;
|
||||
int32_t busNum;
|
||||
|
||||
struct UsbPnpNotifyDeviceInfo deviceInfo;
|
||||
|
||||
uint8_t removeType;
|
||||
uint8_t numInfos;
|
||||
|
||||
struct UsbPnpNotifyInterfaceInfo interfaceInfo[USB_PNP_INFO_MAX_INTERFACES];
|
||||
};
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance(void);
|
||||
|
||||
@@ -20,8 +20,8 @@ extern "C" {
|
||||
#define DEV_MGR_NODE "dev_mgr"
|
||||
#define MAX_MODE_SIZE 0777
|
||||
#define DEV_NODE_PATH_MODE 0755
|
||||
#define HDF_WRITE_READ _IOWR('b', 1, struct HdfSBuf)
|
||||
#define HDF_READ_DEV_EVENT _IOR('b', 2, struct HdfSBuf)
|
||||
#define HDF_WRITE_READ _IOWR('b', 1, struct HdfSBuf*)
|
||||
#define HDF_READ_DEV_EVENT _IOR('b', 2, struct HdfSBuf*)
|
||||
#define HDF_LISTEN_EVENT_START _IO('b', 3)
|
||||
#define HDF_LISTEN_EVENT_STOP _IO('b', 4)
|
||||
#define HDF_LISTEN_EVENT_WAKEUP _IO('b', 5)
|
||||
|
||||
Regular → Executable
+3
@@ -19,6 +19,8 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
|
||||
}
|
||||
deviceInfo->isDynamic = false;
|
||||
deviceInfo->hostId = 0;
|
||||
deviceInfo->status = HDF_SERVICE_UNUSABLE;
|
||||
deviceInfo->deviceType = HDF_DEV_LOCAL_SERVICE;
|
||||
deviceInfo->deviceId = 0;
|
||||
deviceInfo->policy = SERVICE_POLICY_INVALID;
|
||||
deviceInfo->priority = 0;
|
||||
@@ -27,6 +29,7 @@ void HdfDeviceInfoConstruct(struct HdfDeviceInfo *deviceInfo)
|
||||
deviceInfo->svcName = NULL;
|
||||
deviceInfo->moduleName = NULL;
|
||||
deviceInfo->deviceMatchAttr = NULL;
|
||||
deviceInfo->private = NULL;
|
||||
}
|
||||
|
||||
struct HdfDeviceInfo *HdfDeviceInfoNewInstance()
|
||||
|
||||
@@ -27,4 +27,3 @@ void DevSvcRecordDelete(struct HdfSListNode *listEntry)
|
||||
OsalMemFree(listEntry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
* @addtogroup DriverConfig
|
||||
* @{
|
||||
*
|
||||
* @brief Defines an API for HDF driver developers to read driver configuration information.
|
||||
* @brief Defines APIs for HDF driver developers to read driver configuration information.
|
||||
*
|
||||
* During version compilation of the device resource source file defined by developers, the compilation tool
|
||||
* (for example, the compilation tool of the HCS file is hc-gen) generates bytecodes. When the HDF starts,
|
||||
* it transfers the bytecode memory to the <b>DriverConfig</b> module. The <b>DriverConfig</b> module converts
|
||||
* the bytecodes into a configuration tree and provides an API for developers to query the tree.
|
||||
* the bytecodes into a configuration tree and provides APIs for developers to query the tree.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
@@ -24,7 +24,7 @@
|
||||
/**
|
||||
* @file device_resource_if.h
|
||||
*
|
||||
* @brief Declares the API for querying the configuration tree.
|
||||
* @brief Declares the APIs for querying the configuration tree.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
@@ -142,7 +142,7 @@ struct DeviceResourceIface {
|
||||
int32_t (*GetUint8ArrayElem)(const struct DeviceResourceNode *node, const char *attrName, uint32_t index,
|
||||
uint8_t *value, uint8_t def);
|
||||
/**
|
||||
* @brief Obtains the values of a <b>Uint8</b> array attribute of a configuration tree node.
|
||||
* @brief Obtains the value of a <b>Uint8</b> array attribute of a configuration tree node.
|
||||
*
|
||||
* @param node Indicates the pointer to the configuration tree node.
|
||||
* @param attrName Indicates the pointer to the name of the array attribute.
|
||||
@@ -443,5 +443,5 @@ struct DeviceResourceIface *DeviceResourceGetIfaceInstance(DeviceResourceType ty
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // DEVICE_RESOURCE_IF_H
|
||||
#endif /* DEVICE_RESOURCE_IF_H */
|
||||
/** @} */
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
* @brief Provides Hardware Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
@@ -177,21 +177,6 @@ struct SubscriberCallback {
|
||||
int32_t (*OnServiceConnected)(struct HdfDeviceObject *deviceObject, const struct HdfObject *service);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the power management functions provided by the HDF for the driver.
|
||||
*
|
||||
* To use the power management mechanism provided by the HDF, implement operations of <b>IPowerEventListener</b> and
|
||||
* invoke {@linkHdfDeviceRegisterPowerListener} to register the operations with the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct IPowerEventListener {
|
||||
/** Wakes up the driver device. The driver developer implements the operation. */
|
||||
void (*Resume)(struct HdfDeviceObject *deviceObject);
|
||||
/** Hibernates the driver device. The driver developer implements the operation. */
|
||||
void (*Suspend)(struct HdfDeviceObject *deviceObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the entry structure of the driver in the HDF.
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* @addtogroup Core
|
||||
* @{
|
||||
*
|
||||
* @brief Provides OpenHarmony Driver Foundation (HDF) APIs.
|
||||
* @brief Provides Hardware Driver Foundation (HDF) APIs.
|
||||
*
|
||||
* The HDF implements driver framework capabilities such as driver loading, service management,
|
||||
* and driver message model. You can develop drivers based on the HDF.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
#ifndef HDF_POWER_MANAGEMENT_H
|
||||
#define HDF_POWER_MANAGEMENT_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
#include "osal_sysevent.h"
|
||||
|
||||
enum PowerManagementMode {
|
||||
HDF_POWER_SYS_CTRL,
|
||||
HDF_POWER_DYNAMIC_CTRL,
|
||||
HDF_POWER_MODE_MAX,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines the power management functions provided by the HDF for the driver.
|
||||
*
|
||||
* To use the power management mechanism provided by the HDF, implement operations of <b>IPowerEventListener</b> and
|
||||
* invoke {@linkHdfDeviceRegisterPowerListener} to register the operations with the HDF.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
struct IPowerEventListener {
|
||||
int (*DozeResume)(struct HdfDeviceObject *deviceObject);
|
||||
int (*DozeSuspend)(struct HdfDeviceObject *deviceObject);
|
||||
/** Wakes up the driver device. The driver developer implements the operation. */
|
||||
int (*Resume)(struct HdfDeviceObject *deviceObject);
|
||||
/** Hibernates the driver device. The driver developer implements the operation. */
|
||||
int (*Suspend)(struct HdfDeviceObject *deviceObject);
|
||||
};
|
||||
|
||||
static inline bool HdfPmIsWakeEvent(int sysEvent)
|
||||
{
|
||||
return sysEvent >= KEVENT_POWER_RESUME && sysEvent <= KEVENT_POWER_DISPLAY_ON;
|
||||
}
|
||||
|
||||
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
|
||||
void HdfPmUnregisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener);
|
||||
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject);
|
||||
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject);
|
||||
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode);
|
||||
#endif /* HDF_POWER_MANAGEMENT_H */
|
||||
@@ -87,6 +87,23 @@ struct OsalFwBlock {
|
||||
*/
|
||||
int32_t OsalRequestFirmware(struct OsalFirmware *fw, const char *fwName, void *device);
|
||||
|
||||
/**
|
||||
* @brief Sets the offset for reading a firmware file to implement random access to the firmware file.
|
||||
*
|
||||
* @param fw Indicates the pointer to the firmware file {@link OsalFirmware}.
|
||||
* @param offset Indicates the offset where the firmware content is to read.
|
||||
*
|
||||
* @return Returns a value listed below: \n
|
||||
* HDF_STATUS | Description
|
||||
* ----------------------| -----------------------
|
||||
* HDF_SUCCESS | The operation is successful.
|
||||
* HDF_ERR_INVALID_PARAM | Invalid parameter.
|
||||
*
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
|
||||
|
||||
/**
|
||||
* @brief Reads a firmware file.
|
||||
*
|
||||
@@ -103,7 +120,7 @@ int32_t OsalRequestFirmware(struct OsalFirmware *fw, const char *fwName, void *d
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
|
||||
int32_t OsalReadFirmware(struct OsalFirmware *fw, struct OsalFwBlock *block);
|
||||
|
||||
/**
|
||||
* @brief Releases a firmware file.
|
||||
@@ -122,15 +139,6 @@ int32_t OsalSeekFirmware(struct OsalFirmware *fw, uint32_t offset);
|
||||
* @since 1.0
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OsalReadFirmware(struct OsalFirmware *fw, struct OsalFwBlock *block);
|
||||
|
||||
/**
|
||||
* Release firmware resource
|
||||
*
|
||||
* @param : fw Firmware parameter, see detail in OsalFirmware
|
||||
* block Firmware data block, see detail in hdf_FWBlock
|
||||
* @return : true or false
|
||||
*/
|
||||
int32_t OsalReleaseFirmware(struct OsalFirmware *fw);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OSAL_WAIT_FOREVER 0xFFFFFFFF
|
||||
|
||||
/**
|
||||
* @brief Describes a semaphore.
|
||||
*/
|
||||
|
||||
@@ -194,6 +194,12 @@ static inline void DListMerge(struct DListHead *list, struct DListHead *head)
|
||||
&(pos)->member != (head); \
|
||||
(pos) = CONTAINER_OF((pos)->member.next, type, member))
|
||||
|
||||
|
||||
#define DLIST_FOR_EACH_ENTRY_REVERSE(pos, head, type, member) \
|
||||
for ((pos) = CONTAINER_OF((head)->prev, type, member); \
|
||||
&(pos)->member != (head); \
|
||||
(pos) = CONTAINER_OF((pos)->member.prev, type, member))
|
||||
|
||||
/**
|
||||
* @brief Traverses all nodes in a doubly linked list.
|
||||
* This function is used to delete the nodes pointed to by <b>pos</b> during traversal.
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_MAP_H
|
||||
#define HDF_MAP_H
|
||||
|
||||
#include "hdf_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct MapNode;
|
||||
|
||||
typedef struct {
|
||||
struct MapNode **nodes; /**< Map node bucket */
|
||||
uint32_t nodeSize; /**< Map node count */
|
||||
uint32_t bucketSize; /**< Map node bucket size */
|
||||
} Map;
|
||||
|
||||
void MapInit(Map *map);
|
||||
|
||||
void MapDelete(Map *map);
|
||||
|
||||
int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize);
|
||||
|
||||
void *MapGet(const Map *map, const char *key);
|
||||
|
||||
int32_t MapErase(Map *map, const char *key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_MAP_H */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_MESSAGE_LOOPER_H
|
||||
#define HDF_MESSAGE_LOOPER_H
|
||||
|
||||
#include "osal_msg_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MESSAGE_STOP_LOOP (-1)
|
||||
|
||||
struct HdfMessageLooper {
|
||||
struct HdfMessageQueue messageQueue;
|
||||
void (*Start)(struct HdfMessageLooper *);
|
||||
void (*Stop)(struct HdfMessageLooper *);
|
||||
};
|
||||
|
||||
void HdfMessageLooperConstruct(struct HdfMessageLooper *looper);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_MESSAGE_LOOPER_H */
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_MESSAGE_TASK_H
|
||||
#define HDF_MESSAGE_TASK_H
|
||||
|
||||
#include "hdf_message_looper.h"
|
||||
#include "osal_msg_queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfMessageTask;
|
||||
|
||||
struct IHdfMessageHandler {
|
||||
int32_t (*Dispatch)(struct HdfMessageTask *task, struct HdfMessage *msg);
|
||||
};
|
||||
|
||||
struct HdfMessageTask {
|
||||
int32_t (*SendMessage)(struct HdfMessageTask *task, struct HdfMessage *msg, bool sync);
|
||||
void (*RemoveMessage)(struct HdfMessageTask *task, struct HdfMessage *msg);
|
||||
void (*SendMessageLater)(struct HdfMessageTask *task, struct HdfMessage *msg, long delay);
|
||||
void (*DispatchMessage)(struct HdfMessageTask *task, struct HdfMessage *msg);
|
||||
struct HdfMessageQueue *messageQueue;
|
||||
struct IHdfMessageHandler *messageHandler;
|
||||
};
|
||||
|
||||
void HdfMessageTaskConstruct(struct HdfMessageTask *inst,
|
||||
struct HdfMessageLooper *looper, struct IHdfMessageHandler *handler);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_MESSAGE_TASK_H */
|
||||
+20
-22
@@ -31,14 +31,14 @@ struct HdfSListIterator {
|
||||
|
||||
typedef void (*HdfSListDeleter)(struct HdfSListNode *);
|
||||
|
||||
typedef bool (*HdfSListSearchCompare)(struct HdfSListNode *, uint32_t);
|
||||
typedef bool (*HdfSListSearchComparer)(struct HdfSListNode *, uint32_t);
|
||||
|
||||
typedef bool (*HdfSListAddCompare)(struct HdfSListNode *, struct HdfSListNode *);
|
||||
typedef bool (*HdfSListAddComparer)(struct HdfSListNode *, struct HdfSListNode *);
|
||||
|
||||
/*
|
||||
* @brief Init the list
|
||||
*
|
||||
* @param[in] list :the operation list.
|
||||
* @param[in] list the operation list.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
@@ -48,13 +48,13 @@ void HdfSListInit(struct HdfSList *list);
|
||||
* @brief search to see whether specific element is attach into the list.
|
||||
*
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] searchKey -search key of list node.
|
||||
* @param[in] comparer -comparer of list node.
|
||||
* @param[in] searchKey search key of list node.
|
||||
* @param[in] comparer comparer of list node.
|
||||
*
|
||||
* @return struct HdfSListNode of search result
|
||||
* -# NULL if not found.
|
||||
*/
|
||||
struct HdfSListNode *HdfSListSearch(struct HdfSList *list, uint32_t searchKey, HdfSListSearchCompare compare);
|
||||
struct HdfSListNode *HdfSListSearch(struct HdfSList *list, uint32_t searchKey, HdfSListSearchComparer comparer);
|
||||
|
||||
/*
|
||||
* @brief tests if list is empty
|
||||
@@ -77,8 +77,8 @@ struct HdfSListNode *HdfSListGetLast(struct HdfSList *list);
|
||||
/*
|
||||
* @brief add item to the head of the list
|
||||
*
|
||||
* @param[in] list :the operation list.
|
||||
* @param[in] p_node :the new element to add.
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] link the new element to add.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ void HdfSListAdd(struct HdfSList *list, struct HdfSListNode *link);
|
||||
* @brief add item to list as last element
|
||||
*
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] p_node :the new element to add.
|
||||
* @param[in] link the new element to add.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
@@ -98,22 +98,19 @@ void HdfSListAddTail(struct HdfSList *list, struct HdfSListNode *link);
|
||||
* @brief add item to list as ordered
|
||||
*
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] p_node :the new element to add.
|
||||
* @param[in] comparer :compared.
|
||||
* @param[in] link the new element to add.
|
||||
* @param[in] comparer comparer of list node.
|
||||
*
|
||||
* @return bool result of queue status.
|
||||
*/
|
||||
bool HdfSListAddOrder(struct HdfSList *list, struct HdfSListNode *link, HdfSListAddCompare compare);
|
||||
bool HdfSListAddOrder(struct HdfSList *list, struct HdfSListNode *link, HdfSListAddComparer comparer);
|
||||
|
||||
/*
|
||||
* @brief remove item from list
|
||||
*
|
||||
* @param[in] list :the operation list.
|
||||
* @param[in] p_node :the element to remove.
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] link the element to remove.
|
||||
*
|
||||
* @return the result of remove node.
|
||||
* -# HDF_SUCCESS link has been successfully removed.
|
||||
* -# HDF_FAILURE link was not found in the list.
|
||||
*/
|
||||
void HdfSListRemove(struct HdfSList *list, struct HdfSListNode *link);
|
||||
|
||||
@@ -121,7 +118,7 @@ void HdfSListRemove(struct HdfSList *list, struct HdfSListNode *link);
|
||||
* @brief flush the list and free memory
|
||||
*
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] deleter :the func of free memory.
|
||||
* @param[in] deleter the function of free memory.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
@@ -130,7 +127,7 @@ void HdfSListFlush(struct HdfSList *list, HdfSListDeleter deleter);
|
||||
/*
|
||||
* @brief calculate the element count in the list.
|
||||
*
|
||||
* @param[in] list :the list to count.
|
||||
* @param[in] list the list to count.
|
||||
*
|
||||
* @return the count of list.
|
||||
*/
|
||||
@@ -146,9 +143,9 @@ int HdfSListCount(struct HdfSList *list);
|
||||
struct HdfSListNode *HdfSListPeek(struct HdfSList *list);
|
||||
|
||||
/*
|
||||
* @brief get next element of p_link;
|
||||
* @brief get next element of link;
|
||||
*
|
||||
* @param[in] p_link: the operation link.
|
||||
* @param[in] link the operation link.
|
||||
*
|
||||
* @return the next element of the link pass in
|
||||
*/
|
||||
@@ -203,7 +200,8 @@ void HdfSListIteratorRemove(struct HdfSListIterator *iterator);
|
||||
/*
|
||||
* @brief insert new node before the node that iterator point to.and hold current iterator.
|
||||
*
|
||||
* @param[in] list the operation list.
|
||||
* @param[in] iterator the point of iterator.
|
||||
* @param[in] link the point of operation list.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
|
||||
@@ -27,10 +27,12 @@ struct HdfSRef {
|
||||
struct IHdfSRefListener *listener;
|
||||
void (*Acquire)(struct HdfSRef *);
|
||||
void (*Release)(struct HdfSRef *);
|
||||
int (*Count)(const struct HdfSRef *);
|
||||
};
|
||||
|
||||
void HdfSRefAcquire(struct HdfSRef *sref);
|
||||
void HdfSRefRelease(struct HdfSRef *sref);
|
||||
int HdfSRefCount(const struct HdfSRef *sref);
|
||||
void HdfSRefConstruct(struct HdfSRef *sref, struct IHdfSRefListener *listener);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef HDF_THREAD_H
|
||||
#define HDF_THREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "osal_thread.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfThread {
|
||||
struct OsalThread adapter;
|
||||
bool status;
|
||||
void (*ThreadEntry)(void *);
|
||||
bool (*IsRunning)();
|
||||
void (*Start)(struct HdfThread *thread);
|
||||
void (*Stop)(struct HdfThread *thread);
|
||||
};
|
||||
|
||||
void HdfThreadConstruct(struct HdfThread *thread);
|
||||
void HdfThreadDestruct(struct HdfThread *thread);
|
||||
struct HdfThread *HdfThreadNewInstance(void);
|
||||
void HdfThreadFreeInstance(struct HdfThread *instance);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* HDF_THREAD_H */
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_CDEV_H
|
||||
#define OSAL_CDEV_H
|
||||
|
||||
#include "osal_cdev_adapter.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef __user
|
||||
#define __user
|
||||
#endif
|
||||
|
||||
struct OsalCdev;
|
||||
struct file;
|
||||
|
||||
struct OsalCdevOps {
|
||||
int64_t (*seek)(struct file* filep, int64_t offset, int whence);
|
||||
ssize_t (*read)(struct file* filep, char __user* buffer, size_t buflen, int64_t* offset);
|
||||
ssize_t (*write)(struct file* filep, const char __user* buffer, size_t buflen, int64_t* offset);
|
||||
unsigned int (*poll)(struct file* filep, poll_table* pollTable);
|
||||
long (*ioctl)(struct file* filep, unsigned int cmd, unsigned long arg);
|
||||
int (*open)(struct OsalCdev* cdev, struct file* filep);
|
||||
int (*release)(struct OsalCdev* cdev, struct file* filep);
|
||||
};
|
||||
|
||||
struct OsalCdev* OsalAllocCdev(const struct OsalCdevOps* fops);
|
||||
int OsalRegisterCdev(struct OsalCdev* cdev, const char *name, unsigned int mode, void *priv);
|
||||
void OsalUnregisterCdev(struct OsalCdev* cdev);
|
||||
void OsalFreeCdev(struct OsalCdev* cdev);
|
||||
|
||||
void* OsalGetCdevPriv(struct OsalCdev* cdev);
|
||||
|
||||
void OsalSetFilePriv(struct file* filep, void *priv);
|
||||
void* OsalGetFilePriv(struct file* filep);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_CDEV_H */
|
||||
/** @} */
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_MESSAGE_H
|
||||
#define OSAL_MESSAGE_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfMessage {
|
||||
struct HdfSListNode entry;
|
||||
struct HdfMessageTask *target;
|
||||
int16_t messageId;
|
||||
uint64_t timeStamp;
|
||||
void *data[1];
|
||||
};
|
||||
|
||||
struct HdfMessage *HdfMessageObtain(size_t extendSize);
|
||||
void HdfMessageRecycle(struct HdfMessage *message);
|
||||
void HdfMessageDelete(struct HdfSListNode *listEntry);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_MESSAGE_H */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef OSAL_MSG_QUEUE_H
|
||||
#define OSAL_MSG_QUEUE_H
|
||||
|
||||
#include "hdf_slist.h"
|
||||
#include "osal_message.h"
|
||||
#include "osal_mutex.h"
|
||||
#include "osal_sem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct HdfMessageQueue {
|
||||
struct OsalMutex mutex;
|
||||
struct OsalSem semaphore;
|
||||
struct HdfSList list;
|
||||
};
|
||||
|
||||
void OsalMessageQueueInit(struct HdfMessageQueue *queue);
|
||||
void OsalMessageQueueDestroy(struct HdfMessageQueue *queue);
|
||||
void HdfMessageQueueEnqueue(
|
||||
struct HdfMessageQueue *queue, struct HdfMessage *message, long delayed);
|
||||
|
||||
struct HdfMessage *HdfMessageQueueNext(struct HdfMessageQueue *queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OSAL_MSG_QUEUE_H */
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
#ifndef OSAL_SYSEVENT_H
|
||||
#define OSAL_SYSEVENT_H
|
||||
|
||||
#include "hdf_dlist.h"
|
||||
|
||||
#define HDF_SYSEVENT 0xFADE
|
||||
|
||||
/* hdf sys event class definition */
|
||||
#define HDF_SYSEVENT_CLASS_POWER 0x00000001
|
||||
|
||||
/* hdf power event definition */
|
||||
enum PowerKeventId {
|
||||
KEVENT_POWER_SUSPEND,
|
||||
KEVENT_POWER_DISPLAY_OFF,
|
||||
KEVENT_POWER_RESUME,
|
||||
KEVENT_POWER_DISPLAY_ON,
|
||||
KEVENT_POWER_EVENT_MAX,
|
||||
};
|
||||
|
||||
struct HdfSysEvent {
|
||||
uint64_t eventClass;
|
||||
uint32_t eventid;
|
||||
const char *content;
|
||||
uint64_t syncToken;
|
||||
};
|
||||
|
||||
struct HdfSysEventNotifyNode;
|
||||
|
||||
typedef int (*HdfSysEventNotifierFn)(
|
||||
struct HdfSysEventNotifyNode *self, uint64_t eventClass, uint32_t event, const char *content);
|
||||
|
||||
struct HdfSysEventNotifyNode {
|
||||
HdfSysEventNotifierFn callback;
|
||||
struct DListHead listNode;
|
||||
uint64_t classFilter;
|
||||
};
|
||||
|
||||
int HdfSysEventNotifyRegister(struct HdfSysEventNotifyNode *notifierNode, uint64_t classSet);
|
||||
void HdfSysEventNotifyUnregister(struct HdfSysEventNotifyNode *notifierNode);
|
||||
int HdfSysEventSend(uint64_t eventClass, uint32_t event, const char *content, bool sync);
|
||||
|
||||
#endif // #ifndef OSAL_SYSEVENT_H
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_map.h"
|
||||
#if defined(__KERNEL__)
|
||||
#include <linux/string.h>
|
||||
#else
|
||||
#include <string.h>
|
||||
#endif
|
||||
#include "osal_mem.h"
|
||||
#include "securec.h"
|
||||
|
||||
struct MapNode {
|
||||
uint32_t hash;
|
||||
uint32_t valueSize;
|
||||
void *key;
|
||||
void *value;
|
||||
struct MapNode *next;
|
||||
};
|
||||
|
||||
#define HDF_MIN_MAP_SIZE 8
|
||||
#define HDF_ENLARGE_FACTOR 2
|
||||
#define HDF_MAP_KEY_MAX_SIZE 1000
|
||||
#define HDF_MAP_VALUE_MAX_SIZE 1000
|
||||
|
||||
const uint32_t HASH_SEED = 131;
|
||||
|
||||
/* BKDR Hash */
|
||||
static uint32_t MapHash(const char *hashKey)
|
||||
{
|
||||
uint32_t hashValue = 0;
|
||||
|
||||
while (*hashKey) {
|
||||
hashValue = hashValue * HASH_SEED + (*hashKey++);
|
||||
}
|
||||
|
||||
return (hashValue & 0x7FFFFFFF);
|
||||
}
|
||||
|
||||
static uint32_t MapHashIdx(const Map *map, uint32_t hash)
|
||||
{
|
||||
return (hash & (map->bucketSize - 1));
|
||||
}
|
||||
|
||||
static void MapAddNode(Map *map, struct MapNode *node)
|
||||
{
|
||||
uint32_t idx = MapHashIdx(map, node->hash);
|
||||
node->next = map->nodes[idx];
|
||||
map->nodes[idx] = node;
|
||||
}
|
||||
|
||||
static int32_t MapResize(Map *map, uint32_t size)
|
||||
{
|
||||
uint32_t bucketSize;
|
||||
struct MapNode **nodes = NULL;
|
||||
struct MapNode **tmp = NULL;
|
||||
uint32_t i;
|
||||
|
||||
nodes = (struct MapNode **)OsalMemCalloc(size * sizeof(*nodes));
|
||||
if (nodes == NULL) {
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
tmp = map->nodes;
|
||||
bucketSize = map->bucketSize;
|
||||
map->nodes = nodes;
|
||||
map->bucketSize = size;
|
||||
|
||||
if (tmp != NULL) {
|
||||
struct MapNode *node = NULL;
|
||||
struct MapNode *next = NULL;
|
||||
|
||||
/* remap node with new map size */
|
||||
for (i = 0; i < bucketSize; i++) {
|
||||
node = tmp[i];
|
||||
while (node != NULL) {
|
||||
next = node->next;
|
||||
MapAddNode(map, node);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
OsalMemFree(tmp);
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static struct MapNode *MapCreateNode(const char *key, uint32_t hash,
|
||||
const void *value, uint32_t valueSize)
|
||||
{
|
||||
uint32_t keySize = strlen(key) + 1;
|
||||
struct MapNode *node = (struct MapNode *)OsalMemCalloc(sizeof(*node) + keySize + valueSize);
|
||||
if (node == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node->hash = hash;
|
||||
node->key = (uint8_t *)node + sizeof(*node);
|
||||
node->value = (uint8_t *)node + sizeof(*node) + keySize;
|
||||
node->valueSize = valueSize;
|
||||
if (memcpy_s(node->key, keySize, key, keySize) != EOK) {
|
||||
OsalMemFree(node);
|
||||
return NULL;
|
||||
}
|
||||
if (memcpy_s(node->value, node->valueSize, value, valueSize) != EOK) {
|
||||
OsalMemFree(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize)
|
||||
{
|
||||
struct MapNode *node = NULL;
|
||||
|
||||
if (map == NULL || key == NULL || value == NULL || valueSize == 0) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (valueSize > HDF_MAP_KEY_MAX_SIZE || strlen(key) > HDF_MAP_VALUE_MAX_SIZE) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
uint32_t hash = MapHash(key);
|
||||
if (map->nodeSize > 0 && map->nodes != NULL) {
|
||||
uint32_t idx = MapHashIdx(map, hash);
|
||||
node = map->nodes[idx];
|
||||
while (node != NULL) {
|
||||
if (node->hash != hash || node->key == NULL || strcmp(node->key, key) != 0) {
|
||||
node = node->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
// size mismatch
|
||||
if (node->value == NULL || node->valueSize != valueSize) {
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
// update k-v node
|
||||
if (memcpy_s(node->value, node->valueSize, value, valueSize) != EOK) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
// Increase the bucket size to decrease the possibility of map search conflict.
|
||||
if (map->nodeSize >= map->bucketSize) {
|
||||
uint32_t size = (map->bucketSize < HDF_MIN_MAP_SIZE) ? HDF_MIN_MAP_SIZE : \
|
||||
(map->bucketSize << HDF_ENLARGE_FACTOR);
|
||||
MapResize(map, size);
|
||||
}
|
||||
|
||||
node = MapCreateNode(key, hash, value, valueSize);
|
||||
if (node == NULL) {
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
MapAddNode(map, node);
|
||||
map->nodeSize++;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void* MapGet(const Map *map, const char *key)
|
||||
{
|
||||
if (map == NULL || key == NULL || map->nodeSize == 0 || map->nodes == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t hash = MapHash(key);
|
||||
uint32_t idx = MapHashIdx(map, hash);
|
||||
struct MapNode *node = map->nodes[idx];
|
||||
|
||||
while (node != NULL) {
|
||||
if (node->hash == hash && node->key != NULL && !strcmp(node->key, key)) {
|
||||
return node->value;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t MapErase(Map *map, const char *key)
|
||||
{
|
||||
if (map == NULL || key == NULL || map->nodeSize == 0 || map->nodes == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint32_t hash = MapHash(key);
|
||||
uint32_t idx = MapHashIdx(map, hash);
|
||||
struct MapNode *node = map->nodes[idx];
|
||||
struct MapNode *prev = node;
|
||||
|
||||
while (node != NULL) {
|
||||
if (node->hash == hash && node->key != NULL && !strcmp(node->key, key)) {
|
||||
if (map->nodes[idx] == node) {
|
||||
map->nodes[idx] = node->next;
|
||||
} else {
|
||||
prev->next = node->next;
|
||||
}
|
||||
OsalMemFree(node);
|
||||
map->nodeSize--;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
prev = node;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
void MapInit(Map *map)
|
||||
{
|
||||
if (map == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
map->nodes = NULL;
|
||||
map->nodeSize = 0;
|
||||
map->bucketSize = 0;
|
||||
}
|
||||
|
||||
void MapDelete(Map *map)
|
||||
{
|
||||
uint32_t i;
|
||||
struct MapNode *node = NULL;
|
||||
struct MapNode *next = NULL;
|
||||
|
||||
if (map == NULL || map->nodes == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < map->bucketSize; i++) {
|
||||
node = map->nodes[i];
|
||||
while (node != NULL) {
|
||||
next = node->next;
|
||||
OsalMemFree(node);
|
||||
node = next;
|
||||
}
|
||||
}
|
||||
|
||||
OsalMemFree(map->nodes);
|
||||
|
||||
map->nodes = NULL;
|
||||
map->nodeSize = 0;
|
||||
map->bucketSize = 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_message_looper.h"
|
||||
#include "hdf_message_task.h"
|
||||
#include "osal_message.h"
|
||||
|
||||
void HdfMessageLooperStart(struct HdfMessageLooper *looper)
|
||||
{
|
||||
struct HdfMessage *message = NULL;
|
||||
while (looper != NULL) {
|
||||
message = HdfMessageQueueNext(&looper->messageQueue);
|
||||
if (message != NULL) {
|
||||
if (message->messageId == MESSAGE_STOP_LOOP) {
|
||||
HdfMessageRecycle(message);
|
||||
OsalMessageQueueDestroy(&looper->messageQueue);
|
||||
break;
|
||||
} else if (message->target != NULL) {
|
||||
struct HdfMessageTask *task = message->target;
|
||||
task->DispatchMessage(task, message);
|
||||
}
|
||||
HdfMessageRecycle(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HdfMessageLooperStop(struct HdfMessageLooper *looper)
|
||||
{
|
||||
if (looper == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct HdfMessage *message = HdfMessageObtain(0);
|
||||
if (message != NULL) {
|
||||
message->messageId = MESSAGE_STOP_LOOP;
|
||||
HdfMessageQueueEnqueue(&looper->messageQueue, message, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfMessageLooperConstruct(struct HdfMessageLooper *looper)
|
||||
{
|
||||
if (looper != NULL) {
|
||||
OsalMessageQueueInit(&looper->messageQueue);
|
||||
looper->Start = HdfMessageLooperStart;
|
||||
looper->Stop = HdfMessageLooperStop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "hdf_message_task.h"
|
||||
#include "hdf_message_looper.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_message.h"
|
||||
|
||||
int32_t HdfMessageTaskSendMessageLater(
|
||||
struct HdfMessageTask *task, struct HdfMessage *msg, bool sync, long delay)
|
||||
{
|
||||
if (msg != NULL) {
|
||||
if (msg->target == NULL) {
|
||||
msg->target = task;
|
||||
}
|
||||
if (sync) {
|
||||
if (task->messageHandler != NULL && task->messageHandler->Dispatch != NULL) {
|
||||
int ret = task->messageHandler->Dispatch(task, msg);
|
||||
OsalMemFree(msg);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
HdfMessageQueueEnqueue(task->messageQueue, msg, delay);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
int32_t HdfMessageTaskSendMessage(struct HdfMessageTask *task, struct HdfMessage *msg, bool sync)
|
||||
{
|
||||
return HdfMessageTaskSendMessageLater(task, msg, sync, 0);
|
||||
}
|
||||
|
||||
void HdfMessageTaskDispatchMessage(struct HdfMessageTask *task, struct HdfMessage *msg)
|
||||
{
|
||||
struct IHdfMessageHandler *handler = task->messageHandler;
|
||||
if ((handler != NULL) && (handler->Dispatch != NULL)) {
|
||||
handler->Dispatch(task, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfMessageTaskConstruct(struct HdfMessageTask *inst,
|
||||
struct HdfMessageLooper *looper, struct IHdfMessageHandler *handler)
|
||||
{
|
||||
if (inst != NULL && looper != NULL) {
|
||||
inst->SendMessage = HdfMessageTaskSendMessage;
|
||||
inst->messageHandler = handler;
|
||||
inst->messageQueue = &looper->messageQueue;
|
||||
inst->DispatchMessage = HdfMessageTaskDispatchMessage;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-19
@@ -23,16 +23,16 @@ bool HdfSListIsEmpty(struct HdfSList *list)
|
||||
return ((list == NULL) || (list->root == NULL));
|
||||
}
|
||||
|
||||
struct HdfSListNode *HdfSListSearch(struct HdfSList *list, uint32_t keyValue, HdfSListSearchCompare compare)
|
||||
struct HdfSListNode *HdfSListSearch(struct HdfSList *list, uint32_t keyValue, HdfSListSearchComparer comparer)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
if (compare == NULL) {
|
||||
if (comparer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
HdfSListIteratorInit(&it, list);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
struct HdfSListNode *listNode = HdfSListIteratorNext(&it);
|
||||
if (compare(listNode, keyValue)) {
|
||||
if (comparer(listNode, keyValue)) {
|
||||
return listNode;
|
||||
}
|
||||
}
|
||||
@@ -47,27 +47,17 @@ struct HdfSListNode *HdfSListGetLast(struct HdfSList *list)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (iterator = list->root; iterator; iterator = iterator->next) {
|
||||
if (iterator != NULL) {
|
||||
last = iterator;
|
||||
}
|
||||
for (iterator = list->root; iterator != NULL; iterator = iterator->next) {
|
||||
last = iterator;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
void HdfSListAdd(struct HdfSList *list, struct HdfSListNode *link)
|
||||
{
|
||||
struct HdfSListNode *iterator = NULL;
|
||||
if (list == NULL || link == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (iterator = list->root; iterator; iterator = iterator->next) {
|
||||
if (iterator == link) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
link->next = list->root;
|
||||
list->root = link;
|
||||
}
|
||||
@@ -89,10 +79,10 @@ void HdfSListAddTail(struct HdfSList *list, struct HdfSListNode *link)
|
||||
iterator->next = link;
|
||||
}
|
||||
|
||||
bool HdfSListAddOrder(struct HdfSList *list, struct HdfSListNode *link, HdfSListAddCompare compare)
|
||||
bool HdfSListAddOrder(struct HdfSList *list, struct HdfSListNode *link, HdfSListAddComparer comparer)
|
||||
{
|
||||
struct HdfSListNode *iterator = NULL;
|
||||
if (list == NULL || link == NULL || compare == NULL) {
|
||||
if (list == NULL || link == NULL || comparer == NULL) {
|
||||
HDF_LOGE("input is invalid");
|
||||
return false;
|
||||
}
|
||||
@@ -102,13 +92,13 @@ bool HdfSListAddOrder(struct HdfSList *list, struct HdfSListNode *link, HdfSList
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (compare(link, list->root)) {
|
||||
if (comparer(link, list->root)) {
|
||||
link->next = list->root;
|
||||
list->root = link;
|
||||
return true;
|
||||
}
|
||||
for (iterator = list->root; iterator && iterator->next; iterator = iterator->next) {
|
||||
if (compare(iterator, link) && compare(link, iterator->next)) {
|
||||
if (comparer(iterator, link) && comparer(link, iterator->next)) {
|
||||
link->next = iterator->next;
|
||||
iterator->next = link;
|
||||
return true;
|
||||
|
||||
@@ -28,6 +28,16 @@ void HdfSRefAcquire(struct HdfSRef *sref)
|
||||
}
|
||||
}
|
||||
|
||||
int HdfSRefCount(const struct HdfSRef *sref)
|
||||
{
|
||||
if (sref == NULL) {
|
||||
HDF_LOGE("invalid sref");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return OsalAtomicRead(&sref->refs);
|
||||
}
|
||||
|
||||
void HdfSRefRelease(struct HdfSRef *sref)
|
||||
{
|
||||
int32_t lockRef;
|
||||
@@ -55,5 +65,6 @@ void HdfSRefConstruct(struct HdfSRef *sref, struct IHdfSRefListener *listener)
|
||||
sref->listener = listener;
|
||||
sref->Acquire = HdfSRefAcquire;
|
||||
sref->Release = HdfSRefRelease;
|
||||
sref->Count = HdfSRefCount;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "hdf_thread_ex.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_thread.h"
|
||||
|
||||
void HdfThreadStart(struct HdfThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
}
|
||||
struct OsalThreadParam param = {
|
||||
.priority = OSAL_THREAD_PRI_DEFAULT,
|
||||
.stackSize = 0,
|
||||
};
|
||||
OsalThreadStart(&thread->adapter, ¶m);
|
||||
thread->status = true;
|
||||
}
|
||||
|
||||
void HdfThreadStop(struct HdfThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
}
|
||||
OsalThreadDestroy(&thread->adapter);
|
||||
thread->status = false;
|
||||
}
|
||||
|
||||
bool HdfThreadIsRunning(struct HdfThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return false;
|
||||
}
|
||||
return thread->status;
|
||||
}
|
||||
|
||||
void HdfThreadMain(void *argv)
|
||||
{
|
||||
struct HdfThread *thread = (struct HdfThread *)argv;
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
}
|
||||
if (thread->ThreadEntry != NULL) {
|
||||
thread->ThreadEntry(argv);
|
||||
} else {
|
||||
OsalThreadDestroy(&thread->adapter);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfThreadConstruct(struct HdfThread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
return;
|
||||
}
|
||||
thread->Start = HdfThreadStart;
|
||||
thread->Stop = HdfThreadStop;
|
||||
thread->IsRunning = HdfThreadIsRunning;
|
||||
thread->status = false;
|
||||
OsalThreadCreate(&thread->adapter, (OsalThreadEntry)HdfThreadMain, thread);
|
||||
}
|
||||
|
||||
void HdfThreadDestruct(struct HdfThread *thread)
|
||||
{
|
||||
if (thread != NULL && thread->IsRunning()) {
|
||||
thread->Stop(thread);
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfThread *HdfThreadNewInstance()
|
||||
{
|
||||
struct HdfThread *thread =
|
||||
(struct HdfThread *)OsalMemCalloc(sizeof(struct HdfThread));
|
||||
if (thread != NULL) {
|
||||
HdfThreadConstruct(thread);
|
||||
}
|
||||
return thread;
|
||||
}
|
||||
|
||||
void HdfThreadFreeInstance(struct HdfThread *thread)
|
||||
{
|
||||
if (thread != NULL) {
|
||||
HdfThreadDestruct(thread);
|
||||
OsalMemFree(thread);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "osal_message.h"
|
||||
#include "osal_mem.h"
|
||||
|
||||
struct HdfMessage *HdfMessageObtain(size_t extendSize)
|
||||
{
|
||||
size_t newSize = sizeof(struct HdfMessage) + extendSize;
|
||||
return (struct HdfMessage *)OsalMemCalloc(newSize);
|
||||
}
|
||||
|
||||
void HdfMessageRecycle(struct HdfMessage *message)
|
||||
{
|
||||
OsalMemFree(message);
|
||||
}
|
||||
|
||||
void HdfMessageDelete(struct HdfSListNode *listEntry)
|
||||
{
|
||||
struct HdfMessage *message = (struct HdfMessage *)listEntry;
|
||||
if (message != NULL) {
|
||||
HdfMessageRecycle(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "osal_msg_queue.h"
|
||||
#include "osal_message.h"
|
||||
#include "osal_time.h"
|
||||
|
||||
void OsalMessageQueueInit(struct HdfMessageQueue *queue)
|
||||
{
|
||||
if (queue != NULL) {
|
||||
OsalMutexInit(&queue->mutex);
|
||||
OsalSemInit(&queue->semaphore, 0);
|
||||
HdfSListInit(&queue->list);
|
||||
}
|
||||
}
|
||||
|
||||
void OsalMessageQueueDestroy(struct HdfMessageQueue *queue)
|
||||
{
|
||||
if (queue != NULL) {
|
||||
OsalMutexDestroy(&queue->mutex);
|
||||
OsalSemDestroy(&queue->semaphore);
|
||||
HdfSListFlush(&queue->list, HdfMessageDelete);
|
||||
}
|
||||
}
|
||||
|
||||
void HdfMessageQueueEnqueue(
|
||||
struct HdfMessageQueue *queue, struct HdfMessage *message, long delayed)
|
||||
{
|
||||
if (queue == NULL || message == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct HdfSListIterator it;
|
||||
(void)delayed;
|
||||
message->timeStamp += OsalGetSysTimeMs();
|
||||
OsalMutexLock(&queue->mutex);
|
||||
HdfSListIteratorInit(&it, &queue->list);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
struct HdfMessage *next = (struct HdfMessage *)HdfSListIteratorNext(&it);
|
||||
if (next->timeStamp > message->timeStamp) {
|
||||
HdfSListIteratorInsert(&it, &message->entry);
|
||||
goto complete;
|
||||
}
|
||||
}
|
||||
|
||||
HdfSListAddTail(&queue->list, &message->entry);
|
||||
complete:
|
||||
OsalMutexUnlock(&queue->mutex);
|
||||
OsalSemPost(&queue->semaphore);
|
||||
}
|
||||
|
||||
struct HdfMessage* HdfMessageQueueNext(struct HdfMessageQueue *queue)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
struct HdfMessage *message = NULL;
|
||||
uint64_t currentTime = OsalGetSysTimeMs();
|
||||
long miniTimeoutMs = OSAL_WAIT_FOREVER;
|
||||
OsalMutexLock(&queue->mutex);
|
||||
HdfSListIteratorInit(&it, &queue->list);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
message = (struct HdfMessage *)HdfSListIteratorNext(&it);
|
||||
if (message->timeStamp <= currentTime) {
|
||||
HdfSListIteratorRemove(&it);
|
||||
OsalMutexUnlock(&queue->mutex);
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
OsalMutexUnlock(&queue->mutex);
|
||||
OsalSemWait(&queue->semaphore, miniTimeoutMs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void HdfMessageQueueFlush(struct HdfMessageQueue *queue)
|
||||
{
|
||||
struct HdfSListIterator it;
|
||||
OsalMutexLock(&queue->mutex);
|
||||
HdfSListIteratorInit(&it, &queue->list);
|
||||
while (HdfSListIteratorHasNext(&it)) {
|
||||
struct HdfMessage *msgNode = (struct HdfMessage *)HdfSListIteratorNext(&it);
|
||||
HdfSListIteratorRemove(&it);
|
||||
HdfMessageRecycle(msgNode);
|
||||
}
|
||||
OsalMutexUnlock(&queue->mutex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user