1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MESSAGE_HANDLER_H 17 #define MESSAGE_HANDLER_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef struct SoftBusMessage SoftBusMessage; 27 typedef struct SoftBusHandler SoftBusHandler; 28 typedef struct SoftBusLooperContext SoftBusLooperContext; 29 typedef struct SoftBusLooper SoftBusLooper; 30 typedef struct FfrtMsgQueue MsgQueue; 31 32 struct SoftBusLooper { 33 SoftBusLooperContext *context; 34 MsgQueue *queue; 35 bool dumpable; 36 void (*PostMessage)(const SoftBusLooper *looper, SoftBusMessage *msg); 37 void (*PostMessageDelay)(const SoftBusLooper *looper, SoftBusMessage *msg, uint64_t delayMillis); 38 void (*RemoveMessage)(const SoftBusLooper *looper, const SoftBusHandler *handler, int32_t what); 39 // customFunc, when match, return 0 40 void (*RemoveMessageCustom)(const SoftBusLooper *looper, const SoftBusHandler *handler, 41 int32_t (*)(const SoftBusMessage*, void*), void *args); 42 }; 43 44 struct SoftBusHandler { 45 char *name; 46 SoftBusLooper *looper; 47 void (*HandleMessage)(SoftBusMessage *msg); 48 }; 49 50 struct SoftBusMessage { 51 int32_t what; 52 uint64_t arg1; 53 uint64_t arg2; 54 int64_t time; 55 void *obj; 56 SoftBusHandler *handler; 57 void (*FreeMessage)(SoftBusMessage *msg); 58 }; 59 60 SoftBusMessage *MallocMessage(void); 61 62 void FreeMessage(SoftBusMessage *msg); 63 64 enum LooperType { 65 LOOP_TYPE_DEFAULT = 1, 66 LOOP_TYPE_CONN, 67 LOOP_TYPE_LNN, 68 LOOP_TYPE_DISC, 69 LOOP_TYPE_LANE 70 }; 71 72 SoftBusLooper *GetLooper(int looper); 73 74 int LooperInit(void); 75 76 void SetLooper(int type, SoftBusLooper *looper); 77 78 void LooperDeinit(void); 79 80 void DumpLooper(const SoftBusLooper *looper); 81 82 SoftBusLooper *CreateNewLooper(const char *name); 83 84 void DestroyLooper(SoftBusLooper *looper); 85 86 void SetLooperDumpable(SoftBusLooper *looper, bool dumpable); 87 88 #ifdef __cplusplus 89 } 90 #endif 91 92 #endif /* MESSAGE_HANDLER_H */ 93