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