Beta merge 2
[profile/ivi/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 "CallManager.h"
23
24 using namespace WrtDeviceApis::Commons;
25 using namespace TizenApis::Api::Call;
26 using namespace TizenApis::Api::Account;
27 using namespace DPL;
28
29 namespace TizenApis {
30 namespace Platform {
31 namespace Call {
32
33 CallManager::CallManager()
34 {
35         if (tel_init() == TAPI_API_SUCCESS)
36                 LogDebug("TAPI init success");
37 }
38
39 CallManager::~CallManager()
40 {
41         tel_deinit();
42 }
43
44 bool CallManager::isCallInProgress()
45 {
46         int ret;
47         call_state_e state;
48         bool result = false;
49
50         ret = call_get_voice_call_state(&state);
51
52         if (ret == CALL_ERROR_NONE) {
53                 switch (state) {
54                 case CALL_STATE_IDLE :
55                         result = false;
56                         break;
57                 case CALL_STATE_CONNECTING:
58                 case CALL_STATE_ACTIVE:
59                         result = true;
60                         break;
61                 }
62         } else {
63                 LogDebug("Call state changed cb error cause(" << ret << ")");
64         }
65
66         return result;
67
68 }
69
70 void CallManager::getCallService(const EventGetCallServicePtr& event)
71 {
72         EventRequestReceiver<EventGetCallService>::PostRequest(event);
73 }
74
75 void CallManager::OnRequestReceived(const EventGetCallServicePtr& event)
76 {
77         try {
78                 event->switchToManualAnswer();
79
80                 CallServiceFilterPtr filter(event->getFilter());
81                 if (filter->getServiceName().size() > 0) {
82                         ThrowMsg(UnsupportedException, "Not supported filter : serviceName");
83                 }
84
85                 if (filter->getProviderId().size() > 0) {
86                         ThrowMsg(UnsupportedException, "Not supported filter : providerId");
87                 }
88
89                 std::string typeId(filter->getServiceTypeId());
90                 StringArrayPtr tags(filter->getTags());
91
92                 if (typeId.compare("tizen.tel") != 0) {
93                         ThrowMsg(UnsupportedException, "Not supported value : serviceTypeId");
94                 }
95
96                 for (size_t cnt = 0; cnt < tags->size(); cnt++) {
97                         if (((*tags)[cnt]).compare("call") == 0
98                                 ||((*tags)[cnt]).compare("call.voice") == 0
99                                 || ((*tags)[cnt]).compare("call.video") == 0
100                                 || ((*tags)[cnt]).compare("call.emergency") == 0)  {
101                                 continue;
102                         } else {
103                                 ThrowMsg(UnsupportedException, "Not supported value : tags");
104                         }
105                 }
106
107                 AccountServicesArrayPtr accountServicesList(new AccountServicesArray());
108                 AccountServicesPtr callServices(new AccountServices());
109
110                 callServices->setServiceTypeId("tizen.tel");
111                 StringArrayPtr supportTags(new StringArray());
112                 supportTags->push_back("call.voice");
113                 supportTags->push_back("call.video");
114                 supportTags->push_back("call.emergency");
115                 callServices->setTags(*supportTags);
116
117                 accountServicesList->push_back(callServices);
118                 event->setResult(accountServicesList);
119
120                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
121         } catch (const UnsupportedException& ex) {
122                 LogError("Exception: " << ex.GetMessage());
123                 event->setExceptionCode(ExceptionCodes::UnsupportedException);
124                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
125         } catch (const PlatformException& ex) {
126                 LogError("Exception: " << ex.GetMessage());
127                 event->setExceptionCode(ExceptionCodes::PlatformException);
128                 EventRequestReceiver<EventGetCallService>::ManualAnswer(event);
129         }
130 }
131
132 }
133 }
134 }
135