• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "hdf_message_task.h"
10 #include "hdf_message_looper.h"
11 #include "osal_mem.h"
12 #include "osal_message.h"
13 
HdfMessageTaskSendMessageLater(struct HdfMessageTask * task,struct HdfMessage * msg,bool sync,long delay)14 int32_t HdfMessageTaskSendMessageLater(
15     struct HdfMessageTask *task, struct HdfMessage *msg, bool sync, long delay)
16 {
17     if (msg != NULL) {
18         if (msg->target == NULL) {
19             msg->target = task;
20         }
21         if (sync) {
22             if (task->messageHandler != NULL && task->messageHandler->Dispatch != NULL) {
23                 int ret = task->messageHandler->Dispatch(task, msg);
24                 OsalMemFree(msg);
25                 return ret;
26             }
27         } else {
28             HdfMessageQueueEnqueue(task->messageQueue, msg, delay);
29             return HDF_SUCCESS;
30         }
31     }
32 
33     return HDF_ERR_INVALID_PARAM;
34 }
35 
HdfMessageTaskSendMessage(struct HdfMessageTask * task,struct HdfMessage * msg,bool sync)36 int32_t HdfMessageTaskSendMessage(struct HdfMessageTask *task, struct HdfMessage *msg, bool sync)
37 {
38     return HdfMessageTaskSendMessageLater(task, msg, sync, 0);
39 }
40 
HdfMessageTaskDispatchMessage(struct HdfMessageTask * task,struct HdfMessage * msg)41 void HdfMessageTaskDispatchMessage(struct HdfMessageTask *task, struct HdfMessage *msg)
42 {
43     struct IHdfMessageHandler *handler = task->messageHandler;
44     if ((handler != NULL) && (handler->Dispatch != NULL)) {
45         handler->Dispatch(task, msg);
46     }
47 }
48 
HdfMessageTaskConstruct(struct HdfMessageTask * inst,struct HdfMessageLooper * looper,struct IHdfMessageHandler * handler)49 void HdfMessageTaskConstruct(struct HdfMessageTask *inst,
50     struct HdfMessageLooper *looper, struct IHdfMessageHandler *handler)
51 {
52     if (inst != NULL && looper != NULL) {
53         inst->SendMessage = HdfMessageTaskSendMessage;
54         inst->messageHandler = handler;
55         inst->messageQueue = &looper->messageQueue;
56         inst->DispatchMessage = HdfMessageTaskDispatchMessage;
57     }
58 }
59 
60