|
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 <tmsdtmfobsrvr.h> |
|
20 #include "tmsutility.h" |
|
21 #include "tmsproxy.h" |
|
22 #include "tmsdtmfbodyimpl.h" |
|
23 |
|
24 using namespace TMS; |
|
25 |
|
26 TMSDTMFBodyImpl::TMSDTMFBodyImpl() : |
|
27 iObserver(NULL), |
|
28 iProxy(NULL), |
|
29 iParent(NULL), |
|
30 iString(NULL) |
|
31 { |
|
32 TRACE_PRN_FN_ENT; |
|
33 TRACE_PRN_FN_EXT; |
|
34 } |
|
35 |
|
36 TMSDTMFBodyImpl::~TMSDTMFBodyImpl() |
|
37 { |
|
38 TRACE_PRN_FN_ENT; |
|
39 if (iProxy) |
|
40 { |
|
41 iProxy->Close(); |
|
42 } |
|
43 delete iProxy; |
|
44 |
|
45 if (iString) |
|
46 { |
|
47 g_string_free(iString, TRUE); |
|
48 } |
|
49 iObserver = NULL; |
|
50 iParent = NULL; |
|
51 iUserData = NULL; |
|
52 TRACE_PRN_FN_EXT; |
|
53 } |
|
54 |
|
55 gint TMSDTMFBodyImpl::Create(TMSStreamType streamtype, TMSDTMF& parent, |
|
56 TMSDTMFBody*& bodyimpl) |
|
57 { |
|
58 gint ret(TMS_RESULT_INSUFFICIENT_MEMORY); |
|
59 TMSDTMFBodyImpl* self = new TMSDTMFBodyImpl(); |
|
60 if (self) |
|
61 { |
|
62 ret = self->PostConstruct(streamtype, parent); |
|
63 if (ret != TMS_RESULT_SUCCESS) |
|
64 { |
|
65 delete self; |
|
66 self = NULL; |
|
67 } |
|
68 } |
|
69 bodyimpl = self; |
|
70 return ret; |
|
71 } |
|
72 |
|
73 gint TMSDTMFBodyImpl::PostConstruct(TMSStreamType streamtype, TMSDTMF& parent) |
|
74 { |
|
75 gint ret(TMS_RESULT_SUCCESS); |
|
76 iClientId = 1; |
|
77 iParent = &parent; |
|
78 iStreamType = streamtype; |
|
79 iProxy = new TMSProxy(); |
|
80 if (!iProxy) |
|
81 { |
|
82 ret = TMS_RESULT_INSUFFICIENT_MEMORY; |
|
83 } |
|
84 else |
|
85 { |
|
86 if (iProxy->Connect() == TMS_RESULT_SUCCESS) |
|
87 { |
|
88 ret = iProxy->InitDTMFPlayer(iStreamType); |
|
89 } |
|
90 else |
|
91 { |
|
92 delete iProxy; |
|
93 iProxy = NULL; |
|
94 ret = TMS_RESULT_FATAL_ERROR; |
|
95 } |
|
96 } |
|
97 RET_REASON_IF_ERR(ret); |
|
98 return ret; |
|
99 } |
|
100 |
|
101 gint TMSDTMFBodyImpl::AddObserver(TMSDTMFObserver& obsrvr, gpointer user_data) |
|
102 { |
|
103 gint ret(TMS_RESULT_SUCCESS); |
|
104 if (!iObserver) |
|
105 { |
|
106 iObserver = &obsrvr; |
|
107 iUserData = user_data; |
|
108 if (iProxy) |
|
109 { |
|
110 ret = iProxy->SetMsgQueueNotifier(EMsgQueueDTMFType, iObserver, |
|
111 iParent, iClientId); |
|
112 } |
|
113 else |
|
114 { |
|
115 ret = TMS_RESULT_DOES_NOT_EXIST; |
|
116 } |
|
117 } |
|
118 else |
|
119 { |
|
120 ret = TMS_RESULT_ALREADY_EXIST; |
|
121 } |
|
122 return ret; |
|
123 } |
|
124 |
|
125 gint TMSDTMFBodyImpl::RemoveObserver(TMSDTMFObserver& obsrvr) |
|
126 { |
|
127 gint ret(TMS_RESULT_SUCCESS); |
|
128 if (iProxy && (&obsrvr == iObserver)) |
|
129 { |
|
130 ret = iProxy->RemoveMsgQueueNotifier(EMsgQueueDTMFType, iObserver); |
|
131 iObserver = NULL; |
|
132 } |
|
133 else |
|
134 { |
|
135 ret = TMS_RESULT_DOES_NOT_EXIST; |
|
136 } |
|
137 return ret; |
|
138 } |
|
139 |
|
140 gint TMSDTMFBodyImpl::Start() |
|
141 { |
|
142 gint ret(TMS_RESULT_SUCCESS); |
|
143 if (iProxy && iString) |
|
144 { |
|
145 if (iString->len) |
|
146 { |
|
147 ret = iProxy->StartDTMF(iStreamType, iString); |
|
148 } |
|
149 else |
|
150 { |
|
151 ret = TMS_RESULT_INVALID_ARGUMENT; |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 ret = TMS_RESULT_UNINITIALIZED_OBJECT; |
|
157 } |
|
158 return ret; |
|
159 } |
|
160 |
|
161 gint TMSDTMFBodyImpl::Stop() |
|
162 { |
|
163 gint ret(TMS_RESULT_SUCCESS); |
|
164 if (iProxy) |
|
165 { |
|
166 ret = iProxy->StopDTMF(iStreamType); |
|
167 } |
|
168 else |
|
169 { |
|
170 ret = TMS_RESULT_UNINITIALIZED_OBJECT; |
|
171 } |
|
172 return ret; |
|
173 } |
|
174 |
|
175 gint TMSDTMFBodyImpl::SetTone(GString* string) |
|
176 { |
|
177 __ASSERT_ALWAYS(string, PANIC(TMS_RESULT_NULL_ARGUMENT)); |
|
178 |
|
179 gint ret(TMS_RESULT_SUCCESS); |
|
180 if (iString) |
|
181 { |
|
182 if (iString->len) |
|
183 { |
|
184 g_string_free(iString, TRUE); |
|
185 } |
|
186 } |
|
187 |
|
188 iString = g_string_new_len(string->str, string->len); |
|
189 return ret; |
|
190 } |
|
191 |
|
192 gint TMSDTMFBodyImpl::ContinueDTMFStringSending(gboolean sending) |
|
193 { |
|
194 gint ret(TMS_RESULT_SUCCESS); |
|
195 if (iProxy) |
|
196 { |
|
197 ret = iProxy->ContinueDTMFStringSending(sending); |
|
198 } |
|
199 else |
|
200 { |
|
201 ret = TMS_RESULT_DOES_NOT_EXIST; |
|
202 } |
|
203 return ret; |
|
204 } |
|
205 |