sync l2 code to l1

This commit is contained in:
gonghui
2021-05-17 20:03:06 +08:00
parent 9bccf34cd6
commit 81b9092b75
67 changed files with 1737 additions and 467 deletions
@@ -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);
+69 -55
View File
@@ -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++;
}
}
+14 -15
View File
@@ -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 */
+8 -9
View File
@@ -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();
+26 -21
View File
@@ -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++;
+6 -6
View File
@@ -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;
}
+8 -8
View File
@@ -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;
}
+5 -2
View File
@@ -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);
+3 -2
View File
@@ -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;
+4 -1
View File
@@ -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);
+2
View File
@@ -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 */
+5 -3
View File
@@ -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 */
+51 -39
View File
@@ -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);
}
+4 -4
View File
@@ -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);
+15 -19
View File
@@ -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);
}
}
+1 -1
View File
@@ -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);
+24 -11
View File
@@ -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);
+35 -12
View File
@@ -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) ||
+19 -14
View File
@@ -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()
+1 -3
View File
@@ -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)
+7 -4
View File
@@ -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);
+1 -1
View File
@@ -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)
{
+124 -65
View File
@@ -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;
}
+3 -1
View File
@@ -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 */
+3
View File
@@ -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);
+9 -2
View File
@@ -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);
}
}
+1 -1
View File
@@ -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));
+44 -20
View File
@@ -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;
+6 -6
View File
@@ -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;
}
+1 -1
View File
@@ -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;
-1
View File
@@ -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);
+56
View File
@@ -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 */
+84
View File
@@ -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);
+2 -2
View File
@@ -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)
+3
View File
@@ -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()
-1
View File
@@ -27,4 +27,3 @@ void DevSvcRecordDelete(struct HdfSListNode *listEntry)
OsalMemFree(listEntry);
}
}
+5 -5
View File
@@ -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 */
/** @} */
+1 -16
View File
@@ -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.
*
+1 -1
View File
@@ -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.
+47
View File
@@ -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 */
+18 -10
View File
@@ -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
+2
View File
@@ -37,6 +37,8 @@
extern "C" {
#endif /* __cplusplus */
#define OSAL_WAIT_FOREVER 0xFFFFFFFF
/**
* @brief Describes a semaphore.
*/
+6
View File
@@ -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.
+40
View File
@@ -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 */
+32
View File
@@ -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 */
+41
View File
@@ -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
View File
@@ -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
*/
+2
View File
@@ -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
+38
View File
@@ -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 */
+50
View File
@@ -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 */
/** @} */
+34
View File
@@ -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 */
+38
View File
@@ -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 */
+49
View File
@@ -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
+254
View File
@@ -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;
}
+53
View File
@@ -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;
}
}
+59
View File
@@ -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
View File
@@ -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;
+11
View File
@@ -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;
}
+99
View File
@@ -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, &param);
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);
}
}
+30
View File
@@ -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);
}
}
+91
View File
@@ -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);
}