|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Telephony Multimedia Service |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <tms.h> |
|
19 #include <tmsstream.h> |
|
20 #include "tmscallproxy.h" |
|
21 #include "tmsstreamimpl.h" |
|
22 #include "tmsutility.h" |
|
23 #include "tmsipcallbodyimpl.h" |
|
24 |
|
25 using namespace TMS; |
|
26 |
|
27 TMSIPCallBodyImpl::TMSIPCallBodyImpl() |
|
28 { |
|
29 TRACE_PRN_FN_ENT; |
|
30 TRACE_PRN_FN_EXT; |
|
31 } |
|
32 |
|
33 TMSIPCallBodyImpl::~TMSIPCallBodyImpl() |
|
34 { |
|
35 TRACE_PRN_FN_ENT; |
|
36 if (iSession) |
|
37 { |
|
38 iSession->DeleteCall(); |
|
39 iSession->Close(); |
|
40 delete iSession; |
|
41 } |
|
42 TRACE_PRN_FN_EXT; |
|
43 } |
|
44 |
|
45 gint TMSIPCallBodyImpl::Create(TMSCallBody*& bodyimpl) |
|
46 { |
|
47 gint ret(TMS_RESULT_INSUFFICIENT_MEMORY); |
|
48 TMSIPCallBodyImpl* self = new TMSIPCallBodyImpl; |
|
49 |
|
50 TRACE_PRN_FN_ENT; |
|
51 if (self) |
|
52 { |
|
53 ret = self->PostConstruct(); |
|
54 if (ret != TMS_RESULT_SUCCESS) |
|
55 { |
|
56 delete self; |
|
57 self = NULL; |
|
58 } |
|
59 } |
|
60 bodyimpl = self; |
|
61 TRACE_PRN_FN_EXT; |
|
62 return ret; |
|
63 } |
|
64 |
|
65 gint TMSIPCallBodyImpl::PostConstruct() |
|
66 { |
|
67 gint ret(TMS_RESULT_SUCCESS); |
|
68 TRACE_PRN_FN_ENT; |
|
69 iSession = new TMSCallProxy(); |
|
70 |
|
71 if (iSession) |
|
72 { |
|
73 if (iSession->Connect() != TMS_RESULT_SUCCESS) |
|
74 { |
|
75 delete iSession; |
|
76 iSession = NULL; |
|
77 ret = TMS_RESULT_FATAL_ERROR; |
|
78 } |
|
79 else |
|
80 { |
|
81 ret = iSession->CreateCall(TMS_CALL_IP); |
|
82 if (ret != TMS_RESULT_SUCCESS && ret != TMS_RESULT_ALREADY_EXIST) |
|
83 { |
|
84 iSession->Close(); |
|
85 delete iSession; |
|
86 ret = TMS_RESULT_FATAL_ERROR; |
|
87 } |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 ret = TMS_RESULT_INSUFFICIENT_MEMORY; |
|
93 } |
|
94 TRACE_PRN_FN_EXT; |
|
95 return ret; |
|
96 } |
|
97 |
|
98 TMSCallType TMSIPCallBodyImpl::GetCallType() |
|
99 { |
|
100 TMSCallType ctype(TMS_CALL_IP); |
|
101 return ctype; |
|
102 } |
|
103 |
|
104 gint TMSIPCallBodyImpl::GetCallContextId(guint& ctxid) |
|
105 { |
|
106 gint ret(TMS_RESULT_FEATURE_NOT_SUPPORTED); |
|
107 ctxid = 0; |
|
108 return ret; |
|
109 } |
|
110 |
|
111 gint TMSIPCallBodyImpl::CreateStream(TMSStreamType type, TMSStream*& strm) |
|
112 { |
|
113 gint ret(TMS_RESULT_CALL_TYPE_NOT_SUPPORTED); |
|
114 |
|
115 if (strm) |
|
116 { |
|
117 return TMS_RESULT_INVALID_ARGUMENT; |
|
118 } |
|
119 |
|
120 switch (type) |
|
121 { |
|
122 case TMS_STREAM_UPLINK: |
|
123 case TMS_STREAM_DOWNLINK: |
|
124 ret = TMSStreamImpl::Create(TMS_CALL_IP, type, iSession, strm); |
|
125 if (ret == TMS_RESULT_SUCCESS) |
|
126 { |
|
127 ret = AddStreamToList(strm); |
|
128 } |
|
129 //TODO:Need longer term fix to not destory everything |
|
130 //if more the one stream is trying to be created. |
|
131 else if (ret == TMS_RESULT_ALREADY_EXIST) |
|
132 { |
|
133 break; |
|
134 } |
|
135 else |
|
136 { |
|
137 if (iSession) |
|
138 { |
|
139 //TODO: delete call only if no active sessions left |
|
140 iSession->DeleteCall(); |
|
141 iSession->Close(); |
|
142 delete iSession; |
|
143 iSession = NULL; |
|
144 } |
|
145 else |
|
146 { |
|
147 ret = TMS_RESULT_UNINITIALIZED_OBJECT; |
|
148 } |
|
149 } |
|
150 break; |
|
151 default: |
|
152 break; |
|
153 } |
|
154 TRACE_PRN_FN_EXT; |
|
155 return ret; |
|
156 } |
|
157 |
|
158 gint TMSIPCallBodyImpl::DeleteStream(TMSStream*& strm) |
|
159 { |
|
160 gint ret(TMS_RESULT_SUCCESS); |
|
161 TRACE_PRN_FN_ENT; |
|
162 ret = RemStreamFromList(strm); |
|
163 TRACE_PRN_FN_EXT; |
|
164 return ret; |
|
165 } |
|
166 |
|
167 gint TMSIPCallBodyImpl::AddStreamToList(TMSStream* strm) |
|
168 { |
|
169 gint ret(TMS_RESULT_SUCCESS); |
|
170 TRACE_PRN_FN_ENT; |
|
171 iStreamsVector.push_back(strm); |
|
172 TRACE_PRN_FN_EXT; |
|
173 return ret; |
|
174 } |
|
175 |
|
176 gint TMSIPCallBodyImpl::RemStreamFromList(TMSStream*& strm) |
|
177 { |
|
178 gint ret(TMS_RESULT_DOES_NOT_EXIST); |
|
179 gint nArraySize = (gint) iStreamsVector.size(); |
|
180 // get an iterator to the start of the array |
|
181 std::vector<TMSStream*>::iterator itStrm = iStreamsVector.begin(); |
|
182 |
|
183 // display the arrays' contents |
|
184 |
|
185 TRACE_PRN_FN_ENT; |
|
186 for (; itStrm < iStreamsVector.end(); itStrm++) |
|
187 { |
|
188 if (strm == *itStrm) |
|
189 { |
|
190 break; |
|
191 } |
|
192 } |
|
193 |
|
194 if (itStrm) |
|
195 { |
|
196 iStreamsVector.erase(itStrm); // Remove from array |
|
197 // Don't delete itStrm as it is now pointing to the next item on the list |
|
198 delete strm; // Free memory |
|
199 strm = NULL; |
|
200 ret = TMS_RESULT_SUCCESS; |
|
201 } |
|
202 TRACE_PRN_FN_EXT; |
|
203 return ret; |
|
204 } |
|
205 |
|
206 // End of file |