merge wrt-plugins-tizen_0.2.0-3
[platform/framework/web/wrt-plugins-tizen.git] / src / platform / Tizen / Call / CallManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <cassert>
18 #include <Commons/Exception.h>
19 #include <call.h>
20 #include <dpl/log/log.h>
21 #include <API/Account/AccountServices.h>
22 #include <API/Call/CallDefine.h>
23 #include "CallManager.h"
24
25 using namespace WrtDeviceApis::Commons;
26 using namespace TizenApis::Api::Call;
27 using namespace TizenApis::Api::Account;
28 using namespace DPL;
29
30 namespace TizenApis {
31 namespace Platform {
32 namespace Call {
33
34 CallManager::CallManager()
35 {
36         if (tel_init() == TAPI_API_SUCCESS)
37                 LogDebug("TAPI init success");
38 }
39
40 CallManager::~CallManager()
41 {
42         tel_deinit();
43 }
44
45 bool CallManager::isCallInProgress()
46 {
47         int ret;
48         call_state_e state;
49         bool result = false;
50
51         ret = call_get_voice_call_state(&state);
52
53         if (ret == CALL_ERROR_NONE) {
54                 switch (state) {
55                 case CALL_STATE_IDLE :
56                         result = false;
57                         break;
58                 case CALL_STATE_CONNECTING:
59                 case CALL_STATE_ACTIVE:
60                         result = true;
61                         break;
62                 }
63         } else {
64                 LogDebug("Call state changed cb error cause(" << ret << ")");
65         }
66
67         return result;
68
69 }
70
71 void CallManager::getCallService(const EventGetCallServicePtr& event)
72 {
73         EventRequestReceiver<EventGetCallService>::PostRequest(event);
74 }
75
76 void CallManager::OnRequestReceived(const EventGetCallServicePtr& event)
77 {
78         try {
79                 event->switchToManualAnswer();
80
81                 CallServiceFilterPtr filter(event->getFilter());
82                 if (filter->getServiceName().size() > 0) {
83                         ThrowMsg(UnsupportedException, "Not supported filter : serviceName");
84                 }
85
86                 if (filter->getProviderId().size() > 0) {
87                         ThrowMsg(UnsupportedException, "Not supported filter : providerId");
88                 }
89
90                 std::string typeId(filter->getCallType());
91                 StringArrayPtr tags(filter->getTags());
92
93                 if (typeId.compare(STR_TIZEN_TEL) != 0
94                         && typeId.compare(STR_TIZEN_XMPP) != 0
95                         && typeId.compare(STR_TIZEN_SIP) != 0
96                         && typeId.compare("") != 0) {
97                         ThrowMsg(InvalidArgumentException, "Invalid value : ServiceTypeId");
98                 }
99
100                 size_t cnt = 0;
101                 for (; cnt < tags->size(); cnt++) {
102                         if (((*tags)[cnt]).compare(STR_CALL) != 0
103                                 &&((*tags)[cnt]).compare(STR_CALL_VOICE) != 0
104                                 && ((*tags)[cnt]).compare(STR_CALL_VIDEO) != 0
105                                 && ((*tags)[cnt]).compare(STR_CALL_EMERGENCY) != 0)  {
106                                 ThrowMsg(InvalidArgumentException, "Invalid value : tags");
107                         }
108                 }
109
110                 AccountServicesArrayPtr accountServicesList(new AccountServicesArray());
111                 AccountServicesPtr callServices(new AccountServices());
112
113                 if (typeId.compare(STR_TIZEN_XMPP) == 0
114                         || typeId.compare(STR_TIZEN_SIP) == 0) {
115                         event->setResult(accountServicesList);
116                         EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
117                 }
118
119                 callServices->setServiceTypeId(STR_TIZEN_TEL);
120                 StringArrayPtr supportTags(new StringArray());
121                 supportTags->push_back(STR_CALL_VOICE);
122                 supportTags->push_back(STR_CALL_VIDEO);
123                 supportTags->push_back(STR_CALL_EMERGENCY);
124                 callServices->setTags(*supportTags);
125                 callServices->setApplicationId(STR_TIZEN_DIALER);
126
127                 accountServicesList->push_back(callServices);
128                 event->setResult(accountServicesList);
129
130                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
131         } catch (const InvalidArgumentException& ex) {
132                 LogError("Exception: " << ex.GetMessage());
133                 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
134                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
135         } catch (const PlatformException& ex) {
136                 LogError("Exception: " << ex.GetMessage());
137                 event->setExceptionCode(ExceptionCodes::PlatformException);
138                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
139         }
140 }
141
142 }
143 }
144 }
145