Fix for N_SE-28854 N_SE-29290 N_SE-27358 N_SE-25429 N_SE-25498 N_SE-25689 N_SE-27155...
[apps/osp/Call.git] / inc / CallTelephonyManager.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 /**
18  * @file                CallTelephonyManager.h
19  * @brief               This is the header file for the %TelephonyManager class.
20  *
21  * This header file contains the declarations for %TelephonyManager class.
22  */
23 #ifndef _PHN_TELEPHONY_MANAGER_H_
24 #define _PHN_TELEPHONY_MANAGER_H_
25
26 #include <FBase.h>
27 #include <FSocial.h>
28 #include "ITapiCall.h"
29 #include "TapiUtility.h"
30 #include "CallITelephonyEventListener.h"
31 #include "CallSoundManager.h"
32 #include "CalllogManager.h"
33
34 class CallInfo;
35 class SettingsManager;
36
37 /**
38  * @class TelephonyManager
39  * @brief TelephonyManager is a singleton class used to intialize TAPI library.
40  * And register to telephony events, interact with TAPI library.
41  */
42 class TelephonyManager
43 {
44 public:
45         //Get singleton instance
46         static TelephonyManager* GetInstance(ITelephonyEventListener* pEventListener);
47         //Function to initiate (dial) an outgoing call.
48         ErrorCodes SetupMoCall(Tizen::Base::String& contactNumber, bool isEmergency);
49         //Function to end a call
50         result EndActiveCall(Tizen::Base::Long callHandle);
51         result EndDialingCall(Tizen::Base::String& contactNumber);
52         //Function to accept/reject an incoming call
53         result AnswerCall(int callHandle, bool acceptCall);
54         //Function to accept call with the given options
55         result AcceptCall(CallAnsweringOptions answerOptions,int callHandle);
56         //Function to end a conference call
57         result EndConferenceCall(void);
58         //Function to hold/retrieve a conference call
59         result HoldConferenceCall(bool holdCall);
60         //Function to join active and held call to conference
61         result JoinCall(void);
62         //Function to hold/unhold the call
63         result HoldCall(Tizen::Base::Long callHandle, bool holdCall);
64         //Function to swap the active and held call
65         result SwapCalls(void);
66         //Function to send DTMF strings
67         result SendCallDTMF(Tizen::Base::String& textToBeSent);
68         //Function to end a single call from the conference
69         result EndFromConference(int callHandle);
70         //Function to split a single call from the conference
71         result SplitFromConference(int callHandle);
72         //Function to set the mute status
73         result SetMuteStatus(bool setMute);
74         //Function to get the mute Status
75         bool IsCallMuted(void);
76         //Function to set the speaker status
77         result SetSpeakerStatus(bool setSpeaker);
78         //Function to get the speaker status
79         bool IsSpeakerOn(void);
80         //Function to check if split operation is allowed from the conference
81         bool IsSplitAllowed(void);
82         //Function to get the conference call info
83         CallInfo* GetConferenceCallInfoN(void);
84         //Get the current call list
85         Tizen::Base::Collection::IListT<CallInfo>* GetCallListN(void);
86         //Get the current call count
87         int GetCurrentCallCount(void);
88         //Start the alert in case of incoming call
89         void StartAlert(CallInfo& incomingCallInfo);
90         //Stop the alert in case of incoming call
91         void StopAlert(void);
92         //Main Callback function used while registering to TAPI
93         static void HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData);
94         //Dummy callback function used when nothing is to be done on response
95         static void HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
96         //callback function for dial operation
97         static void HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
98         //callback function for the join operation
99         static void HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
100         //callback function for the reject call operation
101         static void HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
102         //callback function for the swap calls operation
103         static void HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
104         //callback function for the End from conference operation
105         static void HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
106         //callback function for the split from conference operation
107         static void HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
108         //callback function for Ending conference call
109         static void HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
110         //Check if MOCall is emergency number and returns true. Otherwise, false.
111         bool CheckIfMOCallIsEmergency(const Tizen::Base::String& contactNumber, bool isSimInitialized);
112         //Check is modem and sim are initialised successfully and MO call can be made.
113         result CheckIfMOCallIsPossible();
114         //Gets the contact for the given phonenumber.returns null if not present.
115         Tizen::Social::Contact* GetContactN(const Tizen::Base::String& phoneNumber);
116         //This function make a synchronus API call to TAPI to fetch active/waiting incoming calls.
117         CallInfo* FetchIncomingCallHandleN(const Tizen::Base::String& callHandle, const Tizen::Base::String& contactNumber);
118         //This callback function is called by TAPI each time for every single call.
119         static void HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData);
120         //function used to process incoming call and decide whether to reject call based on call settings.
121         //Rejects the call and returns true, Else returns false.
122         bool CheckIncomingCallToBeRejected(CallInfo* pIncomingCallInfo);
123         //End all active
124         void EndAllCalls(void);
125         
126 protected:
127         //function to handle the idle callback(received when call is ended)
128         void HandleIdleCallBack(void* pData);
129         //function used to handle events for normal call disconnected.
130         bool HandleEndNormalActiveCall(CallInfo& endCallInfo);
131         //function to handle the active callback(received when call is connected)
132         void HandleActiveCallBack(void* pData);
133         //function to handle call connected successfully
134         void HandleCallConnected(unsigned int connectedCallHandle);
135         //function to handle the dial call callback
136         void HandleDialingCallBack(void* pData);
137         //function to handle ending of single participant in conference call.
138         bool HandleParticipantEndedFromConference(unsigned int participantCallHandle, CallInfo& conferenceCall);
139
140 private:
141         //create a singleton instance
142         static void CreateInstance(ITelephonyEventListener* pEventListener);
143         //used to destroy 'TelephonyManager' instance at application exit.
144         static void DestroyInstance(void);
145         //private destructor
146         virtual ~TelephonyManager(void);
147         TelephonyManager(ITelephonyEventListener* pEventListener);
148         TelephonyManager(TelephonyManager& manager);
149         TelephonyManager& operator =(TelephonyManager& manager);
150         //perform 2nd phase initialisation
151         result Initialize(void);
152         //initialise the TAPI library
153         result InitializeTelephonyLibrary(void);
154         //register for the TAPI events
155         int RegisterEvents(void);
156         //unregister from the TAPI events
157         void UnregisterEvents(void);
158         //internal function to hold an active call
159         result HoldActiveCall(CallInfo* pActiveCallInfo, bool holdCall);
160         //internal function to make a call
161         result DialOutgoingCall(Tizen::Base::String& contactNumber, bool isEmergency);
162         //internal function to handle waiting call options when single call is present
163         result AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle);
164         //internal function to handle waiting call options when multiple calls are present
165         result AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle);
166         //internal function to End Call
167         result EndCall(CallInfo& endCallInfo);
168         /**
169          * This function is internally used to fetch contact person details -
170          * display name & photo id from AddressBook for the given phone number.
171          *
172          * @param[in] phoneNumber - The substring of the phoneNumber to search
173          * @return E_SUCCESS, if found else E_FAILURE.
174          */
175         result FetchContactInfoForNumber(const Tizen::Base::String& phoneNumberStr);
176         //check if given contact number is valid and returns 'E_SUCCESS', else 'E_FAILURE'.
177         result CheckValidTelePhoneNumber(const Tizen::Base::String& contactNumber);
178         //Used to save ended call Log info to Logs database.
179         void SaveCallInfoToLogsDb(CallInfo& endCallInfo);
180
181 private:
182         static TelephonyManager* __pManager;
183
184         //Outgoing call Info
185         CallInfo* __pDialedCall;
186         //Incoming call Info
187         CallInfo* __pIncomingCall;
188         //Active Calls - only 2 active calls at any time
189         //can hold both Single or Conf. Calls
190         //mapping of "Call handle" to "CallInfo"
191         Tizen::Base::Collection::HashMapT<long, CallInfo>* __pActiveCallList;
192
193         //Listener for telephony events
194         ITelephonyEventListener* __pEventListener;
195
196         SettingsManager* __pSettingsManager;
197
198         //handle to Telephony API
199         TapiHandle* __pTapiHandle;
200         //used to connect to Address Book APIs.
201         Tizen::Social::Addressbook* __pAddressBook;
202         //used to store previously fetched contact.
203         Tizen::Social::Contact* __pCachedContact;
204         //mute status
205         bool __isMuted;
206         //Speaker Status
207         bool __isSpeakerOn;
208         SoundManager* __pSoundManager;
209         CallLogManager* __pCalllogMgr;
210 };
211
212 #endif // _PHN_TELEPHONY_MANAGER_H_