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 TEXT_MANAGER_INCLUDED
18 #define TEXT_MANAGER_INCLUDED
19 
20 #include <ImsMediaDefine.h>
21 #include <ImsMediaEventHandler.h>
22 #include <BaseManager.h>
23 #include <TextSession.h>
24 #include <TextConfig.h>
25 #include <MediaQualityThreshold.h>
26 #include <android/native_window.h>
27 #include <unordered_map>
28 
29 using namespace std;
30 using namespace android::telephony::imsmedia;
31 
32 class TextManager : public BaseManager
33 {
34 public:
35     /**
36      * @brief the request handler to handle request message in an individual thread
37      */
38     class RequestHandler : public ImsMediaEventHandler
39     {
40     protected:
41         virtual void processEvent(
42                 uint32_t event, uint64_t sessionId, uint64_t paramA, uint64_t paramB);
43     };
44 
45     /**
46      * @brief the response handler to handle request message in an individual thread
47      */
48     class ResponseHandler : public ImsMediaEventHandler
49     {
50     protected:
51         virtual void processEvent(
52                 uint32_t event, uint64_t sessionId, uint64_t paramA, uint64_t paramB);
53     };
54 
55     static TextManager* getInstance();
56     virtual int getState(int sessionId);
57     virtual void sendMessage(const int sessionId, const android::Parcel& parcel);
58 
59 protected:
60     TextManager();
61     virtual ~TextManager();
62     ImsMediaResult openSession(
63             const int sessionId, const int rtpFd, const int rtcpFd, TextConfig* config);
64     ImsMediaResult closeSession(const int sessionId);
65     virtual bool deactivateOtherSessionIfActive(const int sessionId);
66     ImsMediaResult modifySession(const int sessionId, TextConfig* config);
67     virtual void setMediaQualityThreshold(const int sessionId, MediaQualityThreshold* threshold);
68     virtual ImsMediaResult sendRtt(const int sessionId, const android::String8* text);
69 
70     static TextManager* sManager;
71     std::unordered_map<int, std::unique_ptr<TextSession>> mSessions;
72     RequestHandler mRequestHandler;
73     ResponseHandler mResponseHandler;
74 };
75 
76 #endif
77