1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef IMS_MEDIA_EVENTHANDLER_H
18 #define IMS_MEDIA_EVENTHANDLER_H
19 
20 #include <stdint.h>
21 #include <list>
22 #include <mutex>
23 #include <IImsMediaThread.h>
24 #include <ImsMediaCondition.h>
25 
26 /**
27  * @class ImsMediaEventHandler
28  * @brief Thread based event handler
29  * - Call SendEvent() method to send an evnet
30  * - Child class should implement processEvent() method.
31  * - processEvent() method will be called when an event is received.
32  */
33 class ImsMediaEventHandler : public IImsMediaThread
34 {
35 private:
36     std::list<uint32_t> mListevent;
37     std::list<uint64_t> mListParamA;
38     std::list<uint64_t> mListParamB;
39     std::list<uint64_t> mListParamC;
40     static std::list<ImsMediaEventHandler*> gListEventHandler;
41     static std::mutex mMutex;
42     ImsMediaCondition mCondition;
43     ImsMediaCondition mConditionExit;
44     bool mbTerminate;
45     char mName[MAX_EVENTHANDLER_NAME];
46     std::mutex mMutexEvent;
47 
48 public:
49     ImsMediaEventHandler();
50     virtual ~ImsMediaEventHandler();
51     void Init(const char* strName);
52     void Deinit();
53     static void SendEvent(const char* strEventHandlerName, uint32_t event, uint64_t paramA,
54             uint64_t paramB = 0, uint64_t paramC = 0);
55     char* getName();
56 
57 private:
58     void AddEvent(uint32_t event, uint64_t paramA, uint64_t paramB, uint64_t paramC);
59     virtual void processEvent(
60             uint32_t event, uint64_t paramA, uint64_t paramB, uint64_t paramC) = 0;
61     virtual void* run();  // thread method
62 };
63 
64 #endif