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 <API/Call/CallDefine.h>
25 #include "CallService.h"
27 using namespace WrtDeviceApis::Commons;
28 using namespace TizenApis::Api::Call;
36 static void callAsyncCB(TelTapiEvent_t *event, void *userdata)
38 if (event == NULL || userdata == NULL) {
42 (static_cast<CallService*>(userdata))->changedEvent(static_cast<void*>(event));
46 CallService::CallService() : m_lockSendUSSD(false)
48 m_handles = handleListPtr(new handleList());
49 if (tel_init() == TAPI_API_SUCCESS) {
50 LogDebug("TAPI init success");
51 std::string widget("org.tizen.widget");
52 tel_register_app_name((char*)(widget.c_str()));
56 CallService::~CallService()
58 deregisterCallEvent();
62 void CallService::registerCallEvent()
64 TapiResult_t api_err = TAPI_API_SUCCESS;
65 unsigned int handle = 0;
67 int call_event_list[] =
69 TAPI_EVENT_SS_USSD_CNF,
72 int num_event = sizeof(call_event_list)/sizeof(int);
73 for (int index = 0 ; index < num_event; index++) {
74 api_err = (TapiResult_t)tel_register_event(call_event_list[index], &handle, (TelAppCallback)&callAsyncCB, this);
75 m_handles->push_back(handle);
77 LogDebug("register TAPI event count[" << m_handles->size() << "]");
80 void CallService::deregisterCallEvent()
82 std::vector<unsigned int>::iterator it = m_handles->begin();
84 for (;it < m_handles->end();) {
85 tel_deregister_event((*it));
86 it = CallService::m_handles->erase(it);
89 LogDebug("The handle of TAPI event is removed. (" << m_handles->size() << ")");
92 void CallService::launchDialer(const EventLaunchDialerPtr& event)
94 EventRequestReceiver<EventLaunchDialer>::PostRequest(event);
97 void CallService::sendUSSD(const EventSendUSSDPtr& event)
99 EventRequestReceiver<EventSendUSSD>::PostRequest(event);
102 StringListPtr CallService::getVoicemailNumbers()
104 StringListPtr numberList = StringListPtr(new StringList());
105 TelSimMailboxNumbers_s mbox;
107 if (tel_get_sim_mailbox_info(&mbox) != TAPI_API_SUCCESS) {
111 if (mbox.voice_line1.bUsed != 0) {
112 std::string DiallingNum1(mbox.voice_line1.DiallingNum);
113 if (DiallingNum1.size() > 0)
114 numberList->push_back(DiallingNum1);
117 if (mbox.voice_line2.bUsed != 0) {
118 std::string DiallingNum2(mbox.voice_line2.DiallingNum);
119 if (DiallingNum2.size() > 0)
120 numberList->push_back(DiallingNum2);
123 if (mbox.video.bUsed != 0) {
124 std::string DiallingNum3(mbox.video.DiallingNum);
125 if (DiallingNum3.size() > 0)
126 numberList->push_back(DiallingNum3);
129 if (mbox.fax.bUsed != 0) {
130 std::string DiallingNum4(mbox.fax.DiallingNum);
131 if (DiallingNum4.size() > 0)
132 numberList->push_back(DiallingNum4);
135 if (mbox.email.bUsed != 0) {
136 std::string DiallingNum5(mbox.email.DiallingNum);
137 if (DiallingNum5.size() > 0)
138 numberList->push_back(DiallingNum5);
141 LogDebug("return voicemail Numbers count [" << numberList->size() << "]");
146 StringListPtr CallService::getSubscriberNumbers()
148 StringListPtr numberList = StringListPtr(new StringList());
149 TelSimSubscriberInfo_t msisdn;
151 if (tel_get_sim_msisdn(&msisdn) != TAPI_API_SUCCESS) {
155 std::string sub1(msisdn.num);
157 numberList->push_back(sub1);
159 LogDebug("return subscriber count [" << numberList->size() << "]");
163 StringListPtr CallService::getEmergencyNumbers()
165 StringListPtr eccNumber = StringListPtr(new StringList());
166 TelSimCardType_t cardType;
167 TelSimEccData_t eccData;
170 if (tel_get_sim_type(&cardType) != TAPI_API_SUCCESS) {
174 if (tel_get_sim_ecc(&eccData, &eccCount) != TAPI_API_SUCCESS) {
178 LogDebug("eccCount [" << eccCount << "] cardType[" << cardType <<"]");
181 if (cardType == TAPI_SIM_CARD_TYPE_GSM) {
182 std::string ecc1 (eccData.EccInfo.szEcc1);
183 std::string ecc2 (eccData.EccInfo.szEcc2);
184 std::string ecc3 (eccData.EccInfo.szEcc3);
185 std::string ecc4 (eccData.EccInfo.szEcc4);
186 std::string ecc5 (eccData.EccInfo.szEcc5);
189 eccNumber->push_back(ecc1);
191 eccNumber->push_back(ecc2);
193 eccNumber->push_back(ecc3);
195 eccNumber->push_back(ecc4);
197 eccNumber->push_back(ecc5);
198 } else if (cardType == TAPI_SIM_CARD_TYPE_USIM) {
199 for (int cnt = 0; cnt < eccCount; cnt++) {
200 std::string ecc (eccData.UeccInfo[cnt].szEcc);
202 eccNumber->push_back(ecc);
207 LogDebug("return ecc count [" << eccNumber->size() << "]");
211 void CallService::OnRequestReceived(const EventLaunchDialerPtr& event)
214 event->switchToManualAnswer();
216 std::string remoteParty(STR_TEL_URI);
217 remoteParty.append(event->getRemoteParty());
218 remoteParty.append(event->getExtension());
221 service_create(&service);
223 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
224 service_set_package(service, event->getAppId().c_str());
226 service_set_uri(service, remoteParty.c_str());
228 if (service == NULL) {
229 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Unknown exception");
232 int result = service_send_launch_request (service, NULL, NULL);
234 if (result != SERVICE_ERROR_NONE) {
236 case SERVICE_ERROR_INVALID_PARAMETER:
237 LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER");
238 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
240 case SERVICE_ERROR_OUT_OF_MEMORY:
241 LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY");
242 event->setExceptionCode(ExceptionCodes::PlatformException);
244 case SERVICE_ERROR_APP_NOT_FOUND:
245 LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND");
246 event->setExceptionCode(ExceptionCodes::NotFoundException);
249 LogDebug("service_send_launch_request returns UNKNOWN ERROR!!!");
250 event->setExceptionCode(ExceptionCodes::UnknownException);
254 LogDebug("service_send_launch_request successful");
257 EventRequestReceiver<EventLaunchDialer>::ManualAnswer(event);
258 service_destroy(service);
259 } catch (const PlatformException& ex) {
260 LogError("Exception: " << ex.GetMessage());
261 event->setExceptionCode(ExceptionCodes::PlatformException);
262 EventRequestReceiver<EventLaunchDialer>::ManualAnswer(event);
266 void CallService::OnRequestReceived(const EventSendUSSDPtr& event)
269 event->switchToManualAnswer();
270 if (m_lockSendUSSD == false) {
271 m_lockSendUSSD = true;
272 m_EventSendUSSDPtr = event;
274 event->setExceptionCode(ExceptionCodes::PlatformException);
275 EventRequestReceiver<EventSendUSSD>::ManualAnswer(event);
281 TelSsUssdMsgInfo_t ussdInfo;
283 std::string cmd(m_EventSendUSSDPtr->getCommand());
285 ussdInfo.UssdStringLength = (int)cmd.size();
286 if (ussdInfo.UssdStringLength >= TAPI_SS_USSD_DATA_SIZE_MAX) {
287 ussdInfo.UssdStringLength = TAPI_SS_USSD_DATA_SIZE_MAX - 1;
289 cmd.copy(ussdInfo.szUssdString, (size_t)(ussdInfo.UssdStringLength), 0);
291 int ret = tel_send_ss_ussd_request(&ussdInfo, &reqId);
293 if (ret != TAPI_API_SUCCESS) {
294 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Platform exception");
297 } catch (const PlatformException& ex) {
298 LogError("Exception: " << ex.GetMessage());
299 m_EventSendUSSDPtr->setExceptionCode(ExceptionCodes::PlatformException);
300 EventRequestReceiver<EventSendUSSD>::ManualAnswer(m_EventSendUSSDPtr);
301 m_lockSendUSSD = false;
305 void CallService::changedEvent(void *data)
307 TelTapiEvent_t *tapiEvent = (TelTapiEvent_t *)data;
309 switch (tapiEvent->EventClass) {
310 case TAPI_EVENT_CLASS_SS:
312 switch(tapiEvent->EventType) {
313 case TAPI_EVENT_SS_USSD_CNF:
315 TelSsUssdMsgIndInfo_t ussdRecord;
316 std::string result("");
318 if (tapiEvent->pData != NULL) {
319 memcpy(&ussdRecord, (TelSsUssdMsgIndInfo_t *)tapiEvent->pData, sizeof(TelSsUssdMsgInfo_t));
320 result.append(ussdRecord.UssdInfo.szUssdString, ussdRecord.UssdInfo.UssdStringLength);
321 m_EventSendUSSDPtr->setResult(result);
323 m_EventSendUSSDPtr->setExceptionCode(ExceptionCodes::PlatformException);
326 deregisterCallEvent();
327 EventRequestReceiver<EventSendUSSD>::ManualAnswer(m_EventSendUSSDPtr);
328 m_lockSendUSSD = false;