mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-21 03:35:25 -04:00
solve the warings of C90
Signed-off-by: YOUR_NAME <guodongqi2@huawei.com>
This commit is contained in:
@@ -31,12 +31,13 @@ static struct DeviceResourceNode *CreateTreeNode(const char *start, int32_t offs
|
||||
struct DeviceResourceNode *parentNode, char **treeMem)
|
||||
{
|
||||
struct DeviceResourceNode *newNode = (struct DeviceResourceNode *)(*treeMem);
|
||||
struct DeviceResourceNode *curNode = NULL;
|
||||
*treeMem += sizeof(struct DeviceResourceNode);
|
||||
newNode->name = start + offset + HCS_PREFIX_LENGTH;
|
||||
newNode->hashValue = offset + sizeof(struct HbcHeader);
|
||||
if (parentNode != NULL) {
|
||||
newNode->parent = parentNode;
|
||||
struct DeviceResourceNode *curNode = parentNode->child;
|
||||
curNode = parentNode->child;
|
||||
while ((curNode != NULL) && (curNode->sibling != NULL)) {
|
||||
curNode = curNode->sibling;
|
||||
}
|
||||
@@ -64,15 +65,17 @@ static bool UpdateTreeStack(struct TreeStack **treeStack, int32_t *treeLayer, st
|
||||
|
||||
static bool AddAttrInNode(const char *start, struct DeviceResourceNode *parentNode, char **treeMem)
|
||||
{
|
||||
struct DeviceResourceAttr *newAttr = NULL;
|
||||
struct DeviceResourceAttr *curAttr = NULL;
|
||||
if (parentNode == NULL) {
|
||||
HDF_LOGE("%s failed, the parentNode is NULL", __func__);
|
||||
return false;
|
||||
}
|
||||
struct DeviceResourceAttr *newAttr = (struct DeviceResourceAttr *)(*treeMem);
|
||||
newAttr = (struct DeviceResourceAttr *)(*treeMem);
|
||||
*treeMem += sizeof(struct DeviceResourceAttr);
|
||||
newAttr->name = start + HCS_PREFIX_LENGTH;
|
||||
newAttr->value = start + HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(newAttr->name);
|
||||
struct DeviceResourceAttr *curAttr = parentNode->attrData;
|
||||
curAttr = parentNode->attrData;
|
||||
parentNode->attrData = newAttr;
|
||||
newAttr->next = curAttr;
|
||||
return true;
|
||||
@@ -82,12 +85,14 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
|
||||
struct TreeStack **treeStack, int32_t *treeLayerOrMemLen)
|
||||
{
|
||||
int32_t termOffset = HcsGetNodeOrAttrLength(treeStart + offset);
|
||||
struct DeviceResourceNode *parentOrCurNode = NULL;
|
||||
struct DeviceResourceNode *newNode = NULL;
|
||||
uint32_t newNodeOffset;
|
||||
if (termOffset <= 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeOrAttrLength error, errno: %d", __func__, termOffset);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct DeviceResourceNode *parentOrCurNode = NULL;
|
||||
switch (HcsGetPrefix(treeStart + offset)) {
|
||||
case CONFIG_NODE:
|
||||
if (*treeMem == NULL) {
|
||||
@@ -95,8 +100,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM
|
||||
break;
|
||||
}
|
||||
parentOrCurNode = GetParentNode(offset, *treeStack, treeLayerOrMemLen, termOffset);
|
||||
struct DeviceResourceNode *newNode = CreateTreeNode(treeStart, offset, parentOrCurNode, treeMem);
|
||||
uint32_t newNodeOffset;
|
||||
newNode = CreateTreeNode(treeStart, offset, parentOrCurNode, treeMem);
|
||||
(void)HcsSwapToUint32(&newNodeOffset, treeStart + offset + HCS_STRING_LENGTH(newNode->name) +
|
||||
HCS_PREFIX_LENGTH, CONFIG_DWORD);
|
||||
newNodeOffset += offset + termOffset;
|
||||
|
||||
@@ -22,23 +22,26 @@ static int32_t GetHcsTreeSize(const char *blob, int32_t nodeLength)
|
||||
bool HcsDecompile(const char *hcsBlob, uint32_t offset, struct DeviceResourceNode **root)
|
||||
{
|
||||
int32_t nodeLength = HcsGetNodeLength(hcsBlob + offset);
|
||||
int32_t treeMemLength;
|
||||
char *treeMem = NULL;
|
||||
int32_t treeLayer;
|
||||
if (nodeLength < 0) {
|
||||
HDF_LOGE("%s failed, HcsGetNodeLength error", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength);
|
||||
treeMemLength = GetHcsTreeSize(hcsBlob + offset, nodeLength);
|
||||
if (treeMemLength <= 0) {
|
||||
HDF_LOGE("%s failed, GetHcsTreeSize error, treeMemLength = %d", __func__, treeMemLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
char *treeMem = (char *)OsalMemCalloc(treeMemLength);
|
||||
treeMem = (char *)OsalMemCalloc(treeMemLength);
|
||||
if (treeMem == NULL) {
|
||||
HDF_LOGE("%s failed, OsalMemCalloc error", __func__);
|
||||
return false;
|
||||
}
|
||||
int32_t treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root);
|
||||
treeLayer = GenerateCfgTree(hcsBlob + offset, nodeLength, treeMem, root);
|
||||
if (treeLayer <= 0) {
|
||||
HDF_LOGE("%s failed, the treeLayer is %d", __func__, treeLayer);
|
||||
OsalMemFree(treeMem);
|
||||
|
||||
@@ -67,11 +67,12 @@ static size_t SbufRawImplGetLeftReadSize(struct HdfSBufRaw *sbuf)
|
||||
static bool SbufRawImplWriteRollback(struct HdfSbufImpl *impl, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
size_t alignSize;
|
||||
if (sbuf == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
alignSize = SbufRawImplGetAlignSize(size);
|
||||
if (sbuf->writePos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
@@ -83,11 +84,12 @@ static bool SbufRawImplWriteRollback(struct HdfSbufImpl *impl, uint32_t size)
|
||||
static bool SbufRawImplReadRollback(struct HdfSbufImpl *impl, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
size_t alignSize;
|
||||
if (sbuf == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
alignSize = SbufRawImplGetAlignSize(size);
|
||||
if (sbuf->readPos < alignSize) {
|
||||
return false;
|
||||
}
|
||||
@@ -141,12 +143,14 @@ static size_t SbufRawImplGetDataSize(const struct HdfSbufImpl *impl)
|
||||
|
||||
static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize)
|
||||
{
|
||||
uint32_t newSize;
|
||||
uint8_t *newData = NULL;
|
||||
if (sbuf->isBind) {
|
||||
HDF_LOGE("%s: binded sbuf oom", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t newSize = SbufRawImplGetAlignSize(sbuf->capacity + growSize);
|
||||
newSize = SbufRawImplGetAlignSize(sbuf->capacity + growSize);
|
||||
if (newSize < sbuf->capacity) {
|
||||
HDF_LOGE("%s: grow size overflow", __func__);
|
||||
return false;
|
||||
@@ -156,7 +160,7 @@ static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t *newData = OsalMemCalloc(newSize);
|
||||
newData = OsalMemCalloc(newSize);
|
||||
if (newData == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return false;
|
||||
@@ -179,6 +183,10 @@ static bool SbufRawImplGrow(struct HdfSBufRaw *sbuf, uint32_t growSize)
|
||||
static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
size_t alignSize;
|
||||
size_t writeableSize;
|
||||
uint8_t *dest = NULL;
|
||||
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -187,13 +195,13 @@ static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(size);
|
||||
alignSize = SbufRawImplGetAlignSize(size);
|
||||
// in case of desireCapacity overflow
|
||||
if (alignSize < size) {
|
||||
HDF_LOGE("desireCapacity overflow");
|
||||
return false;
|
||||
}
|
||||
size_t writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
|
||||
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;
|
||||
@@ -203,7 +211,7 @@ static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint
|
||||
writeableSize = SbufRawImplGetLeftWriteSize(sbuf);
|
||||
}
|
||||
|
||||
uint8_t *dest = sbuf->data + sbuf->writePos;
|
||||
dest = sbuf->data + sbuf->writePos;
|
||||
if (memcpy_s(dest, writeableSize, data, size) != EOK) {
|
||||
return false; /* never hits */
|
||||
}
|
||||
@@ -215,6 +223,7 @@ static bool SbufRawImplWrite(struct HdfSbufImpl *impl, const uint8_t *data, uint
|
||||
static bool SbufRawImplRead(struct HdfSbufImpl *impl, uint8_t *data, uint32_t readSize)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
size_t alignSize;
|
||||
if (sbuf == NULL || sbuf->data == NULL || data == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -223,7 +232,7 @@ static bool SbufRawImplRead(struct HdfSbufImpl *impl, uint8_t *data, uint32_t re
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t alignSize = SbufRawImplGetAlignSize(readSize);
|
||||
alignSize = SbufRawImplGetAlignSize(readSize);
|
||||
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("Read out of buffer range");
|
||||
return false;
|
||||
@@ -350,12 +359,13 @@ static bool SbufRawImplReadInt8(struct HdfSbufImpl *impl, int8_t *value)
|
||||
static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data, uint32_t *readSize)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
int buffSize = 0;
|
||||
size_t alignSize;
|
||||
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;
|
||||
}
|
||||
@@ -365,7 +375,7 @@ static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data
|
||||
*readSize = 0;
|
||||
return true;
|
||||
}
|
||||
size_t alignSize = SbufRawImplGetAlignSize(buffSize);
|
||||
alignSize = SbufRawImplGetAlignSize(buffSize);
|
||||
if (alignSize > SbufRawImplGetLeftReadSize(sbuf)) {
|
||||
HDF_LOGE("%s:readBuff out of range", __func__);
|
||||
(void)SbufRawImplReadRollback(impl, sizeof(int32_t));
|
||||
@@ -381,22 +391,24 @@ static bool SbufRawImplReadBuffer(struct HdfSbufImpl *impl, const uint8_t **data
|
||||
static const char *SbufRawImplReadString(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
int32_t strLen = 0;
|
||||
size_t alignSize;
|
||||
char *str = NULL;
|
||||
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);
|
||||
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);
|
||||
str = (char *)(sbuf->data + sbuf->readPos);
|
||||
sbuf->readPos += alignSize;
|
||||
/* Set '\0' at end of the string forcibly. */
|
||||
str[strLen - 1] = '\0';
|
||||
@@ -406,11 +418,12 @@ static const char *SbufRawImplReadString(struct HdfSbufImpl *impl)
|
||||
static struct HdfSbufImpl *SbufRawImplCopy(const struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
struct HdfSBufRaw *new = NULL;
|
||||
if (sbuf == NULL || sbuf->data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBufRaw *new = SbufRawImplNewInstance(sbuf->capacity);
|
||||
new = SbufRawImplNewInstance(sbuf->capacity);
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -428,11 +441,12 @@ static struct HdfSbufImpl *SbufRawImplCopy(const struct HdfSbufImpl *impl)
|
||||
static struct HdfSbufImpl *SbufRawImplMove(struct HdfSbufImpl *impl)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = SBUF_RAW_CAST(impl);
|
||||
struct HdfSBufRaw *new = NULL;
|
||||
if (sbuf == NULL || sbuf->isBind) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSBufRaw *new = OsalMemCalloc(sizeof(struct HdfSBufRaw));
|
||||
new = OsalMemCalloc(sizeof(struct HdfSBufRaw));
|
||||
if (new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -494,11 +508,12 @@ static void SbufInterfaceAssign(struct HdfSbufImpl *inf)
|
||||
|
||||
static struct HdfSBufRaw *SbufRawImplNewInstance(size_t capacity)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = NULL;
|
||||
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));
|
||||
sbuf = (struct HdfSBufRaw *)OsalMemCalloc(sizeof(struct HdfSBufRaw));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("Sbuf instance failure");
|
||||
return NULL;
|
||||
@@ -529,6 +544,7 @@ struct HdfSbufImpl *SbufObtainRaw(size_t capacity)
|
||||
|
||||
struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size)
|
||||
{
|
||||
struct HdfSBufRaw *sbuf = NULL;
|
||||
if (base == 0 || size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -537,7 +553,7 @@ struct HdfSbufImpl *SbufBindRaw(uintptr_t base, size_t size)
|
||||
HDF_LOGE("Base not in 4-byte alignment");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSBufRaw *sbuf = (struct HdfSBufRaw *)OsalMemAlloc(sizeof(struct HdfSBufRaw));
|
||||
sbuf = (struct HdfSBufRaw *)OsalMemAlloc(sizeof(struct HdfSBufRaw));
|
||||
if (sbuf == NULL) {
|
||||
HDF_LOGE("%s: oom", __func__);
|
||||
return NULL;
|
||||
|
||||
@@ -545,8 +545,9 @@ static unsigned int HdfVNodeAdapterPoll(struct file *filep, poll_table *wait)
|
||||
|
||||
static int HdfVNodeAdapterClose(struct OsalCdev *cdev, struct file *filep)
|
||||
{
|
||||
struct HdfVNodeAdapterClient *client = NULL;
|
||||
(void)cdev;
|
||||
struct HdfVNodeAdapterClient *client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
|
||||
client = (struct HdfVNodeAdapterClient *)OsalGetFilePriv(filep);
|
||||
if (client->ioServiceClient.device != NULL && client->ioServiceClient.device->service != NULL &&
|
||||
client->ioServiceClient.device->service->Release != NULL) {
|
||||
client->ioServiceClient.device->service->Release(&client->ioServiceClient);
|
||||
|
||||
@@ -53,6 +53,10 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
|
||||
int32_t deviceClass = 0;
|
||||
const char *svcName = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)stub;
|
||||
static struct SubscriberCallback callback = {
|
||||
.deviceObject = NULL,
|
||||
.OnServiceConnected = NULL,
|
||||
};
|
||||
if (data == NULL || devMgrSvc == NULL) {
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return ret;
|
||||
@@ -65,10 +69,6 @@ int DeviceManagerDispatch(struct HdfObject *stub, int code, struct HdfSBuf *data
|
||||
HDF_LOGE("%s: get svc name is null", __func__);
|
||||
break;
|
||||
}
|
||||
static struct SubscriberCallback callback = {
|
||||
.deviceObject = NULL,
|
||||
.OnServiceConnected = NULL,
|
||||
};
|
||||
ret = DevSvcManagerClntSubscribeService(svcName, callback);
|
||||
break;
|
||||
case DEVMGR_UNLOAD_SERVICE:
|
||||
@@ -107,13 +107,14 @@ int DeviceManagerIsQuickLoad(void)
|
||||
|
||||
int DeviceManagerStart(void)
|
||||
{
|
||||
struct HdfIoService *ioService = NULL;
|
||||
struct IDevmgrService *instance = DevmgrServiceGetInstance();
|
||||
|
||||
if (instance == NULL || instance->StartService == 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);
|
||||
ioService = HdfIoServicePublish(DEV_MGR_NODE, DEV_MGR_NODE_PERM);
|
||||
if (ioService != NULL) {
|
||||
static struct HdfIoDispatcher dispatcher = {
|
||||
.Dispatch = DeviceManagerDispatch,
|
||||
@@ -126,11 +127,12 @@ int DeviceManagerStart(void)
|
||||
|
||||
int DeviceManagerStartStep2()
|
||||
{
|
||||
struct DevmgrService *devMgrSvc = NULL;
|
||||
if (DeviceManagerIsQuickLoad() == DEV_MGR_SLOW_LOAD) {
|
||||
HDF_LOGW("%s: device manager is not set to QuickLoad mode", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
return DevmgrServiceLoadLeftDriver(devMgrSvc);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,13 @@ const struct DeviceResourceNode *HdfGetRootNode(void)
|
||||
|
||||
static bool HdfHostListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond)
|
||||
{
|
||||
struct HdfHostInfo *attrFirst = NULL;
|
||||
struct HdfHostInfo *attrSecond = NULL;
|
||||
if (listEntryFirst == NULL || listEntrySecond == NULL) {
|
||||
return false;
|
||||
}
|
||||
struct HdfHostInfo *attrFirst = (struct HdfHostInfo *)listEntryFirst;
|
||||
struct HdfHostInfo *attrSecond = (struct HdfHostInfo *)listEntrySecond;
|
||||
attrFirst = (struct HdfHostInfo *)listEntryFirst;
|
||||
attrSecond = (struct HdfHostInfo *)listEntrySecond;
|
||||
return attrFirst->priority <= attrSecond->priority;
|
||||
}
|
||||
|
||||
@@ -138,11 +140,13 @@ bool HdfAttributeManagerGetHostList(struct HdfSList *hostList)
|
||||
|
||||
static bool HdfDeviceListCompare(struct HdfSListNode *listEntryFirst, struct HdfSListNode *listEntrySecond)
|
||||
{
|
||||
struct HdfDeviceInfo *attrFirst = NULL;
|
||||
struct HdfDeviceInfo *attrSecond = NULL;
|
||||
if (listEntryFirst == NULL || listEntrySecond == NULL) {
|
||||
return false;
|
||||
}
|
||||
struct HdfDeviceInfo *attrFirst = (struct HdfDeviceInfo *)listEntryFirst;
|
||||
struct HdfDeviceInfo *attrSecond = (struct HdfDeviceInfo *)listEntrySecond;
|
||||
attrFirst = (struct HdfDeviceInfo *)listEntryFirst;
|
||||
attrSecond = (struct HdfDeviceInfo *)listEntrySecond;
|
||||
return attrFirst->priority <= attrSecond->priority;
|
||||
}
|
||||
|
||||
@@ -244,14 +248,16 @@ struct HdfSList *HdfAttributeManagerGetDeviceList(uint16_t hostId, const char *h
|
||||
{
|
||||
uint16_t deviceIdx = 0;
|
||||
const struct DeviceResourceNode *hostNode = GetHostNode(hostName);
|
||||
struct HdfSList *deviceList = NULL;
|
||||
const struct DeviceResourceNode *device = NULL;
|
||||
if (hostNode == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
struct HdfSList *deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
|
||||
deviceList = (struct HdfSList *)OsalMemCalloc(sizeof(struct HdfSList));
|
||||
if (deviceList == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
const struct DeviceResourceNode *device = hostNode->child;
|
||||
device = hostNode->child;
|
||||
while (device != NULL) {
|
||||
const struct DeviceResourceNode *deviceNode = device->child;
|
||||
while (deviceNode != NULL) {
|
||||
@@ -294,11 +300,13 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const voi
|
||||
struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance();
|
||||
struct HdfDeviceInfo *deviceNodeInfo = NULL;
|
||||
char *svcName = NULL;
|
||||
if (devMgrSvc == NULL || moduleName == NULL || serviceName == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct HdfDeviceInfo *deviceNodeInfo = HdfDeviceInfoNewInstance();
|
||||
deviceNodeInfo = HdfDeviceInfoNewInstance();
|
||||
if (deviceNodeInfo == NULL) {
|
||||
return false;
|
||||
}
|
||||
@@ -319,7 +327,7 @@ bool HdfDeviceListAdd(const char *moduleName, const char *serviceName, const voi
|
||||
deviceNodeInfo->permission = deviceInfo->permission;
|
||||
deviceNodeInfo->deviceMatchAttr = deviceInfo->deviceMatchAttr;
|
||||
deviceNodeInfo->moduleName = deviceInfo->moduleName;
|
||||
char *svcName = OsalMemCalloc(strlen(serviceName) + 1);
|
||||
svcName = OsalMemCalloc(strlen(serviceName) + 1);
|
||||
if (svcName == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ static int DeviceNodeExtDispatch(struct HdfObject *stub, int code, struct HdfSBu
|
||||
struct IDeviceIoService *deviceMethod = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
uint64_t ioClientPtr = 0;
|
||||
|
||||
if (stub == NULL) {
|
||||
HDF_LOGE("device ext dispatch: stub is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
uint64_t ioClientPtr = 0;
|
||||
if (!HdfSbufReadUint64(reply, &ioClientPtr) || ioClientPtr == 0) {
|
||||
HDF_LOGE("device ext dispatch: input ioClient is null");
|
||||
return HDF_FAILURE;
|
||||
@@ -59,10 +59,11 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct HdfDeviceObject *deviceObject = NULL;
|
||||
struct DeviceNodeExt *devNodeExt = (struct DeviceNodeExt *)inst;
|
||||
int ret;
|
||||
if (devNodeExt == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
int ret = HdfDeviceNodePublishPublicService(inst, serviceName);
|
||||
ret = HdfDeviceNodePublishPublicService(inst, serviceName);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("failed to publish device service, ret is %d", ret);
|
||||
return HDF_FAILURE;
|
||||
@@ -77,10 +78,10 @@ static int DeviceNodeExtPublishService(struct HdfDeviceNode *inst, const char *s
|
||||
if (deviceInfo->policy == SERVICE_POLICY_CAPACITY) {
|
||||
devNodeExt->ioService = HdfIoServicePublish(serviceName, deviceInfo->permission);
|
||||
if (devNodeExt->ioService != NULL) {
|
||||
devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
|
||||
static struct HdfIoDispatcher dispatcher = {
|
||||
.Dispatch = DeviceNodeExtDispatch
|
||||
};
|
||||
devNodeExt->ioService->target = (struct HdfObject*)(&inst->deviceObject);
|
||||
devNodeExt->ioService->dispatcher = &dispatcher;
|
||||
} else {
|
||||
HDF_LOGE("Device remote service bind failed");
|
||||
|
||||
@@ -13,18 +13,20 @@
|
||||
static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
|
||||
{
|
||||
int i;
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
size_t *addrBegin = NULL;
|
||||
*driverCount = (int32_t)(((uint8_t *)(HDF_DRIVER_END()) - (uint8_t *)(HDF_DRIVER_BEGIN())) / sizeof(size_t));
|
||||
if (*driverCount <= 0) {
|
||||
HDF_LOGE("%s: failed to hdf get device counts", __func__);
|
||||
return NULL;
|
||||
}
|
||||
struct HdfDriverEntry *driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
|
||||
driverEntry = OsalMemCalloc(*driverCount * sizeof(struct HdfDriverEntry));
|
||||
if (driverEntry == NULL) {
|
||||
HDF_LOGE("%s: failed to alloc driver entry mem", __func__);
|
||||
*driverCount = 0;
|
||||
return NULL;
|
||||
}
|
||||
size_t *addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
|
||||
addrBegin = (size_t *)(HDF_DRIVER_BEGIN());
|
||||
for (i = 0; i < *driverCount; i++) {
|
||||
driverEntry[i] = *(struct HdfDriverEntry *)(*addrBegin);
|
||||
addrBegin++;
|
||||
@@ -35,12 +37,12 @@ static struct HdfDriverEntry *HdfDriverEntryConstruct(int32_t *driverCount)
|
||||
struct HdfDriverEntry *HdfDriverLoaderGetDriverEntry(const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
int i;
|
||||
static struct HdfDriverEntry *driverEntry = NULL;
|
||||
static int32_t driverCount = 0;
|
||||
if ((deviceInfo == NULL) || (deviceInfo->moduleName == NULL) || (deviceInfo->svcName == NULL)) {
|
||||
HDF_LOGE("%s: failed to get device entry, input deviceInfo is NULL", __func__);
|
||||
return NULL;
|
||||
}
|
||||
static struct HdfDriverEntry *driverEntry = NULL;
|
||||
static int32_t driverCount = 0;
|
||||
if (driverEntry == NULL) {
|
||||
driverEntry = HdfDriverEntryConstruct(&driverCount);
|
||||
if (driverEntry == NULL) {
|
||||
|
||||
@@ -114,6 +114,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
struct HdfDevice *device = NULL;
|
||||
struct DevHostService *hostService = (struct DevHostService *)inst;
|
||||
struct IDriverLoader *driverLoader = HdfDriverLoaderGetInstance();
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
|
||||
if ((deviceInfo == NULL) || (driverLoader == NULL) || (driverLoader->UnLoadNode == NULL)) {
|
||||
HDF_LOGE("failed to del device, input param is null");
|
||||
@@ -127,7 +128,7 @@ int DevHostServiceDelDevice(struct IDevHostService *inst, const struct HdfDevice
|
||||
}
|
||||
|
||||
driverLoader->UnLoadNode(driverLoader, deviceInfo);
|
||||
struct HdfDeviceNode *devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo);
|
||||
devNode = DevHostServiceSeparateDeviceNode(&device->devNodes, deviceInfo);
|
||||
if (device->super.Detach != NULL) {
|
||||
device->super.Detach(&device->super, devNode);
|
||||
} else {
|
||||
@@ -223,12 +224,12 @@ void DevHostServiceConstruct(struct DevHostService *service)
|
||||
|
||||
void DevHostServiceDestruct(struct DevHostService *service)
|
||||
{
|
||||
struct HdfDevice *device = NULL;
|
||||
struct HdfDevice *tmp = NULL;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@
|
||||
int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *service)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to add service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->AddService == NULL) {
|
||||
HDF_LOGE("serviceManager AddService function is null");
|
||||
return HDF_FAILURE;
|
||||
@@ -35,12 +36,13 @@ int DevSvcManagerClntAddService(const char *svcName, struct HdfDeviceObject *ser
|
||||
const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to get service, client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->GetService == NULL) {
|
||||
HDF_LOGE("serviceManager GetService function is null");
|
||||
return NULL;
|
||||
@@ -51,12 +53,13 @@ const struct HdfObject *DevSvcManagerClntGetService(const char *svcName)
|
||||
struct HdfDeviceObject *DevSvcManagerClntGetDeviceObject(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to get device object, client is null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->GetObject == NULL) {
|
||||
HDF_LOGE("failed to get device object, method not implement");
|
||||
return NULL;
|
||||
@@ -91,12 +94,13 @@ void HdfUnregisterDevice(const char *moduleName, const char *serviceName)
|
||||
int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCallback callback)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to subscribe service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->SubscribeService == NULL) {
|
||||
HDF_LOGE("failed to subscribe service, method not implement");
|
||||
return HDF_FAILURE;
|
||||
@@ -107,12 +111,13 @@ int DevSvcManagerClntSubscribeService(const char *svcName, struct SubscriberCall
|
||||
int DevSvcManagerClntUnsubscribeService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to unsubscribe service, client is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->UnsubscribeService == NULL) {
|
||||
HDF_LOGE("failed to unsubscribe service, method not implement");
|
||||
return HDF_FAILURE;
|
||||
@@ -123,12 +128,13 @@ int DevSvcManagerClntUnsubscribeService(const char *svcName)
|
||||
void DevSvcManagerClntRemoveService(const char *svcName)
|
||||
{
|
||||
struct DevSvcManagerClnt *devSvcMgrClnt = DevSvcManagerClntGetInstance();
|
||||
struct IDevSvcManager *serviceManager = NULL;
|
||||
if (devSvcMgrClnt == NULL) {
|
||||
HDF_LOGE("failed to remove service, devSvcMgrClnt is null");
|
||||
return;
|
||||
}
|
||||
|
||||
struct IDevSvcManager *serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
serviceManager = devSvcMgrClnt->devSvcMgrIf;
|
||||
if (serviceManager == NULL || serviceManager->RemoveService == NULL) {
|
||||
HDF_LOGE("failed to remove service, method not implement");
|
||||
return;
|
||||
|
||||
@@ -25,11 +25,12 @@ static int HdfDeviceNodePublishLocalService(
|
||||
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo)
|
||||
{
|
||||
uint32_t matchId;
|
||||
struct DevHostService *hostService = NULL;
|
||||
if ((devNode == NULL) || (deviceInfo == NULL)) {
|
||||
HDF_LOGE("failed to publish local service, device is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostService *hostService = devNode->hostService;
|
||||
hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
HDF_LOGE("failed to publish local service, host service is null");
|
||||
return HDF_FAILURE;
|
||||
@@ -42,15 +43,16 @@ static int HdfDeviceNodePublishLocalService(
|
||||
static int HdfDeviceNodePublishService(
|
||||
struct HdfDeviceNode *devNode, const struct HdfDeviceInfo *deviceInfo, struct IHdfDevice *device)
|
||||
{
|
||||
(void)device;
|
||||
int status = HDF_SUCCESS;
|
||||
struct IDeviceNode *nodeIf = NULL;
|
||||
(void)device;
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_NONE) ||
|
||||
((deviceInfo->svcName != NULL) && (strlen(deviceInfo->svcName) == 0))) {
|
||||
HDF_LOGI("policy is %d", SERVICE_POLICY_NONE);
|
||||
return status;
|
||||
}
|
||||
|
||||
struct IDeviceNode *nodeIf = &devNode->super;
|
||||
nodeIf = &devNode->super;
|
||||
if ((deviceInfo->policy == SERVICE_POLICY_PUBLIC) ||
|
||||
(deviceInfo->policy == SERVICE_POLICY_CAPACITY)) {
|
||||
if (nodeIf->PublishService != NULL) {
|
||||
@@ -66,15 +68,17 @@ static int HdfDeviceNodePublishService(
|
||||
int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devInst)
|
||||
{
|
||||
struct HdfDevice *device = (struct HdfDevice *)devInst;
|
||||
struct HdfDriverEntry *driverEntry = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct IHdfDeviceToken *deviceToken = NULL;
|
||||
int ret;
|
||||
if (device == NULL || devNode == NULL) {
|
||||
HDF_LOGE("failed to launch service, device or service is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
struct HdfDriverEntry *driverEntry = devNode->driverEntry;
|
||||
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
|
||||
struct IHdfDeviceToken *deviceToken = NULL;
|
||||
|
||||
driverEntry = devNode->driverEntry;
|
||||
deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("failed to launch service, deviceInfo is null");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
@@ -84,7 +88,7 @@ int HdfDeviceLaunchNode(struct HdfDeviceNode *devNode, struct IHdfDevice *devIns
|
||||
HDF_LOGE("failed to launch service, deviceEntry invalid");
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
int ret = driverEntry->Init(&devNode->deviceObject);
|
||||
ret = driverEntry->Init(&devNode->deviceObject);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_DEV_ERR_DEV_INIT_FAIL;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,12 @@ int32_t HdfDeviceSubscribeService(
|
||||
uint32_t matchId;
|
||||
struct DevHostService *hostService = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
if (deviceObject == NULL || serviceName == NULL) {
|
||||
HDF_LOGE("failed to subscribe service, deviceObject/serviceName is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
hostService = devNode->hostService;
|
||||
if (hostService == NULL) {
|
||||
@@ -44,13 +45,15 @@ int32_t HdfDeviceSubscribeService(
|
||||
|
||||
const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
const struct HdfDeviceInfo *deviceInfo = NULL;
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("failed to get service name, deviceObject is invalid");
|
||||
return NULL;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
const struct HdfDeviceInfo *deviceInfo = devNode->deviceInfo;
|
||||
deviceInfo = devNode->deviceInfo;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("failed to get service name, deviceInfo is null");
|
||||
return NULL;
|
||||
@@ -60,33 +63,37 @@ const char *HdfDeviceGetServiceName(const struct HdfDeviceObject *deviceObject)
|
||||
|
||||
int HdfPmRegisterPowerListener(struct HdfDeviceObject *deviceObject, const struct IPowerEventListener *listener)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
if (deviceObject == NULL) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
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)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
if (deviceObject == NULL) {
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
HdfDeviceNodeRemovePowerStateListener(devNode, listener);
|
||||
}
|
||||
|
||||
void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct IPowerStateToken *tokenIf = NULL;
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
if ((tokenIf != NULL) && (tokenIf->AcquireWakeLock != NULL)) {
|
||||
tokenIf->AcquireWakeLock(tokenIf);
|
||||
}
|
||||
@@ -94,13 +101,15 @@ void HdfPmAcquireDevice(struct HdfDeviceObject *deviceObject)
|
||||
|
||||
void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct IPowerStateToken *tokenIf = NULL;
|
||||
if (deviceObject == NULL) {
|
||||
HDF_LOGE("%s: input param is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
struct HdfDeviceNode *devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct IPowerStateToken *tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
tokenIf = (struct IPowerStateToken *)devNode->powerToken;
|
||||
if ((tokenIf != NULL) && (tokenIf->ReleaseWakeLock != NULL)) {
|
||||
tokenIf->ReleaseWakeLock(tokenIf);
|
||||
}
|
||||
@@ -108,13 +117,15 @@ void HdfPmReleaseDevice(struct HdfDeviceObject *deviceObject)
|
||||
|
||||
void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
|
||||
{
|
||||
struct HdfDeviceNode *devNode = NULL;
|
||||
struct PowerStateToken *token = NULL;
|
||||
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(
|
||||
devNode = (struct HdfDeviceNode *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfDeviceObject, deviceObject, struct HdfDeviceNode, deviceObject);
|
||||
struct PowerStateToken *token = devNode->powerToken;
|
||||
token = devNode->powerToken;
|
||||
if (token != NULL) {
|
||||
token->mode = mode;
|
||||
}
|
||||
|
||||
@@ -47,10 +47,11 @@ void HdfServiceObserverRecordRecycle(struct HdfServiceObserverRecord *observerRe
|
||||
|
||||
bool HdfServiceObserverRecordCompare(struct HdfSListNode *listEntry, uint32_t serviceKey)
|
||||
{
|
||||
struct HdfServiceObserverRecord *record = NULL;
|
||||
if (listEntry == NULL) {
|
||||
return false;
|
||||
}
|
||||
struct HdfServiceObserverRecord *record = (struct HdfServiceObserverRecord *)listEntry;
|
||||
record = (struct HdfServiceObserverRecord *)listEntry;
|
||||
if (record->serviceKey == serviceKey) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
|
||||
static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
|
||||
{
|
||||
struct PowerStateToken *stateToken = NULL;
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
|
||||
if (stateToken->psmState == PSM_STATE_ACTIVE) {
|
||||
@@ -36,17 +37,19 @@ static void PowerStateTokenOnFirstAcquire(struct HdfSRef *sref)
|
||||
|
||||
static void PowerStateTokenOnLastRelease(struct HdfSRef *sref)
|
||||
{
|
||||
struct PowerStateToken *stateToken = NULL;
|
||||
const struct IPowerEventListener *listener = NULL;
|
||||
if (sref == NULL) {
|
||||
return;
|
||||
}
|
||||
struct PowerStateToken *stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
stateToken = (struct PowerStateToken *)HDF_SLIST_CONTAINER_OF(
|
||||
struct HdfSRef, sref, struct PowerStateToken, wakeRef);
|
||||
|
||||
if (stateToken->psmState != PSM_STATE_ACTIVE && stateToken->psmState != PSM_STATE_IDLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
const struct IPowerEventListener *listener = stateToken->listener;
|
||||
listener = stateToken->listener;
|
||||
if ((listener != NULL) && (listener->Suspend != NULL)) {
|
||||
listener->Suspend(stateToken->deviceObject);
|
||||
}
|
||||
|
||||
@@ -139,16 +139,18 @@ static void DevmgrServiceUpdateStatus(struct DevHostServiceClnt *hostClnt, uint1
|
||||
static int DevmgrServiceAttachDevice(
|
||||
struct IDevmgrService *inst, const struct HdfDeviceInfo *deviceInfo, struct IHdfDeviceToken *token)
|
||||
{
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DeviceTokenClnt *tokenClnt = NULL;
|
||||
if (deviceInfo == NULL) {
|
||||
HDF_LOGE("failed to attach device, deviceInfo is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DevHostServiceClnt *hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
|
||||
hostClnt = DevmgrServiceFindDeviceHost(inst, deviceInfo->hostId);
|
||||
if (hostClnt == NULL) {
|
||||
HDF_LOGE("failed to attach device, hostClnt is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
struct DeviceTokenClnt *tokenClnt = DeviceTokenClntNewInstance(token);
|
||||
tokenClnt = DeviceTokenClntNewInstance(token);
|
||||
if (tokenClnt == NULL) {
|
||||
HDF_LOGE("failed to attach device, tokenClnt is null");
|
||||
return HDF_FAILURE;
|
||||
@@ -271,11 +273,12 @@ int DevmgrServicePowerStateChange(struct IDevmgrService *devmgrService, enum Hdf
|
||||
|
||||
bool DevmgrServiceConstruct(struct DevmgrService *inst)
|
||||
{
|
||||
struct IDevmgrService *devMgrSvcIf = NULL;
|
||||
if (OsalMutexInit(&inst->devMgrMutex) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s:failed to mutex init ", __func__);
|
||||
return false;
|
||||
}
|
||||
struct IDevmgrService *devMgrSvcIf = (struct IDevmgrService *)inst;
|
||||
devMgrSvcIf = (struct IDevmgrService *)inst;
|
||||
if (devMgrSvcIf != NULL) {
|
||||
devMgrSvcIf->AttachDevice = DevmgrServiceAttachDevice;
|
||||
devMgrSvcIf->AttachDeviceHost = DevmgrServiceAttachDeviceHost;
|
||||
@@ -313,11 +316,11 @@ struct IDevmgrService *DevmgrServiceGetInstance()
|
||||
void DevmgrServiceRelease(struct HdfObject *object)
|
||||
{
|
||||
struct DevmgrService *devmgrService = (struct DevmgrService *)object;
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevHostServiceClnt *hostClntTmp = NULL;
|
||||
if (devmgrService == NULL) {
|
||||
return;
|
||||
}
|
||||
struct DevHostServiceClnt *hostClnt = NULL;
|
||||
struct DevHostServiceClnt *hostClntTmp = NULL;
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(hostClnt, hostClntTmp, &devmgrService->hosts, struct DevHostServiceClnt, node) {
|
||||
DListRemove(&hostClnt->node);
|
||||
DevHostServiceClntDelete(hostClnt);
|
||||
|
||||
@@ -43,12 +43,13 @@ static struct DevSvcRecord *DevSvcManagerSearchService(struct IDevSvcManager *in
|
||||
int DevSvcManagerAddService(struct IDevSvcManager *inst, const char *svcName, struct HdfDeviceObject *service)
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
struct DevSvcRecord *record = NULL;
|
||||
if ((devSvcManager == NULL) || (service == NULL) || (svcName == NULL)) {
|
||||
HDF_LOGE("failed to add service, input param is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
struct DevSvcRecord *record = DevSvcRecordNewInstance();
|
||||
record = DevSvcRecordNewInstance();
|
||||
if (record == NULL) {
|
||||
HDF_LOGE("failed to add service , record is null");
|
||||
return HDF_FAILURE;
|
||||
@@ -66,11 +67,12 @@ int DevSvcManagerSubscribeService(struct IDevSvcManager *inst, const char *svcNa
|
||||
{
|
||||
int ret = HDF_FAILURE;
|
||||
struct DevSvcManager *devSvcMgr = (struct DevSvcManager *)inst;
|
||||
struct HdfObject *deviceService = NULL;
|
||||
if (svcName == NULL || devSvcMgr == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct HdfObject *deviceService = DevSvcManagerGetService(inst, svcName);
|
||||
deviceService = DevSvcManagerGetService(inst, svcName);
|
||||
if (deviceService != NULL) {
|
||||
if (callBack.OnServiceConnected != NULL) {
|
||||
callBack.OnServiceConnected(callBack.deviceObject, deviceService);
|
||||
@@ -85,10 +87,11 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
|
||||
{
|
||||
struct DevSvcManager *devSvcManager = (struct DevSvcManager *)inst;
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
struct DevSvcRecord *serviceRecord = NULL;
|
||||
if (svcName == NULL || devSvcManager == NULL) {
|
||||
return;
|
||||
}
|
||||
struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
if (serviceRecord != NULL) {
|
||||
OsalMutexLock(&devSvcManager->mutex);
|
||||
HdfSListRemove(&devSvcManager->services, &serviceRecord->entry);
|
||||
@@ -100,11 +103,12 @@ void DevSvcManagerRemoveService(struct IDevSvcManager *inst, const char *svcName
|
||||
struct HdfDeviceObject *DevSvcManagerGetObject(struct IDevSvcManager *inst, const char *svcName)
|
||||
{
|
||||
uint32_t serviceKey = HdfStringMakeHashKey(svcName, 0);
|
||||
struct DevSvcRecord *serviceRecord = NULL;
|
||||
if (svcName == NULL) {
|
||||
HDF_LOGE("Get service failed, svcName is null");
|
||||
return NULL;
|
||||
}
|
||||
struct DevSvcRecord *serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
serviceRecord = DevSvcManagerSearchService(inst, serviceKey);
|
||||
if (serviceRecord != NULL) {
|
||||
return serviceRecord->value;
|
||||
}
|
||||
@@ -122,11 +126,12 @@ struct HdfObject *DevSvcManagerGetService(struct IDevSvcManager *inst, const cha
|
||||
|
||||
bool DevSvcManagerConstruct(struct DevSvcManager *inst)
|
||||
{
|
||||
struct IDevSvcManager *devSvcMgrIf = NULL;
|
||||
if (inst == NULL) {
|
||||
HDF_LOGE("%s: inst is null!", __func__);
|
||||
return false;
|
||||
}
|
||||
struct IDevSvcManager *devSvcMgrIf = &inst->super;
|
||||
devSvcMgrIf = &inst->super;
|
||||
devSvcMgrIf->AddService = DevSvcManagerAddService;
|
||||
devSvcMgrIf->SubscribeService = DevSvcManagerSubscribeService;
|
||||
devSvcMgrIf->UnsubscribeService = NULL;
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
static int DriverInstallerStartDeviceHost(uint32_t devHostId, const char *devHostName)
|
||||
{
|
||||
struct IDevHostService *hostServiceIf = DevHostServiceNewInstance(devHostId, devHostName);
|
||||
int ret;
|
||||
if ((hostServiceIf == NULL) || (hostServiceIf->StartService == NULL)) {
|
||||
HDF_LOGE("hostServiceIf or hostServiceIf->StartService is null");
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
int ret = hostServiceIf->StartService(hostServiceIf);
|
||||
ret = hostServiceIf->StartService(hostServiceIf);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("failed to start host service, ret: %d", ret);
|
||||
DevHostServiceFreeInstance(hostServiceIf);
|
||||
|
||||
@@ -26,12 +26,13 @@ uint32_t HdfStringMakeHashKey(const char *key, uint32_t mask)
|
||||
struct HdfCString *HdfCStringObtain(const char *str)
|
||||
{
|
||||
struct HdfCString *instance = NULL;
|
||||
size_t size;
|
||||
if (str != NULL) {
|
||||
size_t strLen = strlen(str);
|
||||
if (strLen > CSTRING_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
size_t size = sizeof(struct HdfCString) + strLen + 1;
|
||||
size = sizeof(struct HdfCString) + strLen + 1;
|
||||
instance = (struct HdfCString *)OsalMemCalloc(size);
|
||||
if (instance == NULL) {
|
||||
HDF_LOGE("HdfCStringObtain failed, alloc memory failed");
|
||||
|
||||
+18
-8
@@ -119,6 +119,7 @@ static struct MapNode *MapCreateNode(const char *key, uint32_t hash,
|
||||
int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize)
|
||||
{
|
||||
struct MapNode *node = NULL;
|
||||
uint32_t hash;
|
||||
|
||||
if (map == NULL || key == NULL || value == NULL || valueSize == 0) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
@@ -126,7 +127,7 @@ int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize)
|
||||
if (valueSize > HDF_MAP_KEY_MAX_SIZE || strlen(key) > HDF_MAP_VALUE_MAX_SIZE) {
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
uint32_t hash = MapHash(key);
|
||||
hash = MapHash(key);
|
||||
if (map->nodeSize > 0 && map->nodes != NULL) {
|
||||
uint32_t idx = MapHashIdx(map, hash);
|
||||
node = map->nodes[idx];
|
||||
@@ -167,13 +168,17 @@ int32_t MapSet(Map *map, const char *key, const void *value, uint32_t valueSize)
|
||||
|
||||
void* MapGet(const Map *map, const char *key)
|
||||
{
|
||||
uint32_t hash;
|
||||
uint32_t idx;
|
||||
struct MapNode *node = NULL;
|
||||
|
||||
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];
|
||||
hash = MapHash(key);
|
||||
idx = MapHashIdx(map, hash);
|
||||
node = map->nodes[idx];
|
||||
|
||||
while (node != NULL) {
|
||||
if (node->hash == hash && node->key != NULL && !strcmp(node->key, key)) {
|
||||
@@ -188,14 +193,19 @@ void* MapGet(const Map *map, const char *key)
|
||||
|
||||
int32_t MapErase(Map *map, const char *key)
|
||||
{
|
||||
uint32_t hash;
|
||||
uint32_t idx;
|
||||
struct MapNode *node = NULL;
|
||||
struct MapNode *prev = NULL;
|
||||
|
||||
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;
|
||||
hash = MapHash(key);
|
||||
idx = MapHashIdx(map, hash);
|
||||
node = map->nodes[idx];
|
||||
prev = node;
|
||||
|
||||
while (node != NULL) {
|
||||
if (node->hash == hash && node->key != NULL && !strcmp(node->key, key)) {
|
||||
|
||||
@@ -180,11 +180,11 @@ struct HdfSListNode *HdfSListNext(struct HdfSListNode *link)
|
||||
|
||||
struct HdfSListNode *HdfSListPop(struct HdfSList *list)
|
||||
{
|
||||
struct HdfSListNode *first = NULL;
|
||||
if (list == NULL || list->root == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct HdfSListNode *first = list->root;
|
||||
first = list->root;
|
||||
list->root = first->next;
|
||||
return first;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user