2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 #include <Commons/Exception.h>
19 #include <ITapiCall.h>
23 #include <dpl/log/log.h>
24 #include "CallService.h"
26 using namespace WrtDeviceApis::Commons;
27 using namespace TizenApis::Api::Call;
35 static void callAsyncCB(TelTapiEvent_t *event, void *userdata)
37 if (event == NULL || userdata == NULL) {
41 (static_cast<CallService*>(userdata))->changedEvent(static_cast<void*>(event));
45 CallService::CallService() : m_lockSendUSSD(false)
47 m_handles = handleListPtr(new handleList());
48 if (tel_init() == TAPI_API_SUCCESS) {
49 LogDebug("TAPI init success");
50 std::string widget("org.tizen.widget");
51 tel_register_app_name((char*)(widget.c_str()));
55 CallService::~CallService()
57 deregisterCallEvent();
61 void CallService::registerCallEvent()
63 TapiResult_t api_err = TAPI_API_SUCCESS;
64 unsigned int handle = 0;
66 int call_event_list[] =
68 TAPI_EVENT_SS_USSD_CNF,
71 int num_event = sizeof(call_event_list)/sizeof(int);
72 for (int index = 0 ; index < num_event; index++) {
73 api_err = (TapiResult_t)tel_register_event(call_event_list[index], &handle, (TelAppCallback)&callAsyncCB, this);
74 m_handles->push_back(handle);
76 LogDebug("register TAPI event count[" << m_handles->size() << "]");
79 void CallService::deregisterCallEvent()
81 std::vector<unsigned int>::iterator it = m_handles->begin();
83 for (;it < m_handles->end();) {
84 tel_deregister_event((*it));
85 it = CallService::m_handles->erase(it);
88 LogDebug("The handle of TAPI event is removed. (" << m_handles->size() << ")");
91 void CallService::launchDialer(const EventLaunchDialerPtr& event)
93 EventRequestReceiver<EventLaunchDialer>::PostRequest(event);
96 void CallService::sendUSSD(const EventSendUSSDPtr& event)
98 EventRequestReceiver<EventSendUSSD>::PostRequest(event);
101 StringListPtr CallService::getVoicemailNumbers()
103 StringListPtr numberList = StringListPtr(new StringList());
104 TelSimMailboxNumbers_s mbox;
106 if (tel_get_sim_mailbox_info(&mbox) != TAPI_API_SUCCESS) {
110 if (mbox.voice_line1.bUsed != 0) {
111 std::string DiallingNum1(mbox.voice_line1.DiallingNum);
112 if (DiallingNum1.size() > 0)
113 numberList->push_back(DiallingNum1);
116 if (mbox.voice_line2.bUsed != 0) {
117 std::string DiallingNum2(mbox.voice_line2.DiallingNum);
118 if (DiallingNum2.size() > 0)
119 numberList->push_back(DiallingNum2);
122 if (mbox.video.bUsed != 0) {
123 std::string DiallingNum3(mbox.video.DiallingNum);
124 if (DiallingNum3.size() > 0)
125 numberList->push_back(DiallingNum3);
128 if (mbox.fax.bUsed != 0) {
129 std::string DiallingNum4(mbox.fax.DiallingNum);
130 if (DiallingNum4.size() > 0)
131 numberList->push_back(DiallingNum4);
134 if (mbox.email.bUsed != 0) {
135 std::string DiallingNum5(mbox.email.DiallingNum);
136 if (DiallingNum5.size() > 0)
137 numberList->push_back(DiallingNum5);
140 LogDebug("return voicemail Numbers count [" << numberList->size() << "]");
145 StringListPtr CallService::getSubscriberNumbers()
147 StringListPtr numberList = StringListPtr(new StringList());
148 TelSimSubscriberInfo_t msisdn;
150 if (tel_get_sim_msisdn(&msisdn) != TAPI_API_SUCCESS) {
154 std::string sub1(msisdn.num);
156 numberList->push_back(sub1);
158 LogDebug("return subscriber count [" << numberList->size() << "]");
162 StringListPtr CallService::getEmergencyNumbers()
164 StringListPtr eccNumber = StringListPtr(new StringList());
165 TelSimCardType_t cardType;
166 TelSimEccData_t eccData;
169 if (tel_get_sim_type(&cardType) != TAPI_API_SUCCESS) {
173 if (tel_get_sim_ecc(&eccData, &eccCount) != TAPI_API_SUCCESS) {
177 LogDebug("eccCount [" << eccCount << "] cardType[" << cardType <<"]");
180 if (cardType == TAPI_SIM_CARD_TYPE_GSM) {
181 std::string ecc1 (eccData.EccInfo.szEcc1);
182 std::string ecc2 (eccData.EccInfo.szEcc2);
183 std::string ecc3 (eccData.EccInfo.szEcc3);
184 std::string ecc4 (eccData.EccInfo.szEcc4);
185 std::string ecc5 (eccData.EccInfo.szEcc5);
188 eccNumber->push_back(ecc1);
190 eccNumber->push_back(ecc2);
192 eccNumber->push_back(ecc3);
194 eccNumber->push_back(ecc4);
196 eccNumber->push_back(ecc5);
197 } else if (cardType == TAPI_SIM_CARD_TYPE_USIM) {
198 for (int cnt = 0; cnt < eccCount; cnt++) {
199 std::string ecc (eccData.UeccInfo[cnt].szEcc);
201 eccNumber->push_back(ecc);
206 LogDebug("return ecc count [" << eccNumber->size() << "]");
210 void CallService::OnRequestReceived(const EventLaunchDialerPtr& event)
213 event->switchToManualAnswer();
215 std::string remoteParty("tel://");
216 remoteParty.append(event->getRemoteParty());
217 remoteParty.append(event->getExtension());
220 service_create(&service);
222 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
223 service_set_package(service, "com.samsung.phone"); //org.tizen.phone
225 service_set_uri(service, remoteParty.c_str());
227 if (service == NULL) {
228 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Unknown exception");
231 int result = service_send_launch_request (service, NULL, NULL);
233 if (result != SERVICE_ERROR_NONE) {
235 case SERVICE_ERROR_INVALID_PARAMETER:
236 LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER");
237 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
239 case SERVICE_ERROR_OUT_OF_MEMORY:
240 LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY");
241 event->setExceptionCode(ExceptionCodes::PlatformException);
243 case SERVICE_ERROR_APP_NOT_FOUND:
244 LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND");
245 event->setExceptionCode(ExceptionCodes::NotFoundException);
248 LogDebug("service_send_launch_request returns UNKNOWN ERROR!!!");
249 event->setExceptionCode(ExceptionCodes::UnknownException);
253 LogDebug("service_send_launch_request successful");
256 EventRequestReceiver<EventLaunchDialer>::ManualAnswer(event);
257 service_destroy(service);
258 } catch (const PlatformException& ex) {
259 LogError("Exception: " << ex.GetMessage());
260 event->setExceptionCode(ExceptionCodes::PlatformException);
261 EventRequestReceiver<EventLaunchDialer>::ManualAnswer(event);
265 void CallService::OnRequestReceived(const EventSendUSSDPtr& event)
268 event->switchToManualAnswer();
269 if (m_lockSendUSSD == false) {
270 m_lockSendUSSD = true;
271 m_EventSendUSSDPtr = event;
273 event->setExceptionCode(ExceptionCodes::PlatformException);
274 EventRequestReceiver<EventSendUSSD>::ManualAnswer(event);
280 TelSsUssdMsgInfo_t ussdInfo;
282 std::string cmd(m_EventSendUSSDPtr->getCommand());
284 ussdInfo.UssdStringLength = (int)cmd.size();
285 if (ussdInfo.UssdStringLength >= TAPI_SS_USSD_DATA_SIZE_MAX) {
286 ussdInfo.UssdStringLength = TAPI_SS_USSD_DATA_SIZE_MAX - 1;
288 cmd.copy(ussdInfo.szUssdString, (size_t)(ussdInfo.UssdStringLength), 0);
290 int ret = tel_send_ss_ussd_request(&ussdInfo, &reqId);
292 if (ret != TAPI_API_SUCCESS) {
293 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Platform exception");
296 } catch (const PlatformException& ex) {
297 LogError("Exception: " << ex.GetMessage());
298 m_EventSendUSSDPtr->setExceptionCode(ExceptionCodes::PlatformException);
299 EventRequestReceiver<EventSendUSSD>::ManualAnswer(m_EventSendUSSDPtr);
300 m_lockSendUSSD = false;
304 void CallService::changedEvent(void *data)
306 TelTapiEvent_t *tapiEvent = (TelTapiEvent_t *)data;
308 switch (tapiEvent->EventClass) {
309 case TAPI_EVENT_CLASS_SS:
311 switch(tapiEvent->EventType) {
312 case TAPI_EVENT_SS_USSD_CNF:
314 TelSsUssdMsgIndInfo_t ussdRecord;
315 std::string result("");
317 if (tapiEvent->pData != NULL) {
318 memcpy(&ussdRecord, (TelSsUssdMsgIndInfo_t *)tapiEvent->pData, sizeof(TelSsUssdMsgInfo_t));
319 result.append(ussdRecord.UssdInfo.szUssdString, ussdRecord.UssdInfo.UssdStringLength);
320 m_EventSendUSSDPtr->setResult(result);
322 m_EventSendUSSDPtr->setExceptionCode(ExceptionCodes::PlatformException);
325 deregisterCallEvent();
326 EventRequestReceiver<EventSendUSSD>::ManualAnswer(m_EventSendUSSDPtr);
327 m_lockSendUSSD = false;