|
1 /* |
|
2 * Copyright (c) 2005-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "CCall.h" |
|
21 #include <stdio.h> |
|
22 |
|
23 /* |
|
24 * Constructor |
|
25 * |
|
26 * Takes in a TCall structure passed in via the RPC framework |
|
27 */ |
|
28 CCall::CCall( const TCall& aCall ) |
|
29 : iCall(aCall) |
|
30 { |
|
31 } |
|
32 |
|
33 /* |
|
34 * Destructor |
|
35 */ |
|
36 CCall::~CCall() |
|
37 { |
|
38 } |
|
39 |
|
40 /* |
|
41 * CallID |
|
42 * |
|
43 * Retrieve the call id |
|
44 */ |
|
45 bool CCall::CallID( int& aCallID ) const |
|
46 { |
|
47 bool ret = false; |
|
48 if( iCall.iCallID >= 0 ) |
|
49 { |
|
50 aCallID = iCall.iCallID; |
|
51 ret = true; |
|
52 } |
|
53 return ret; |
|
54 } |
|
55 |
|
56 /* |
|
57 * Params |
|
58 * |
|
59 * Retrieve the number of parameters in the call |
|
60 */ |
|
61 bool CCall::Params( int& aNumParams) const |
|
62 { |
|
63 bool ret = false; |
|
64 if( iCall.iParams.iParams_len >= 0 ) |
|
65 { |
|
66 aNumParams = iCall.iParams.iParams_len; |
|
67 ret = true; |
|
68 } |
|
69 return ret; |
|
70 } |
|
71 |
|
72 /* |
|
73 * Name |
|
74 * |
|
75 * Retrieve the name of a parameter at a specific index |
|
76 */ |
|
77 bool CCall::Name( int anIndex, string& aName ) const |
|
78 { |
|
79 bool ret = false; |
|
80 if( anIndex >= 0 && anIndex < iCall.iParams.iParams_len ) |
|
81 { |
|
82 if( Check(iCall.iParams.iParams_val[anIndex].iName, MAXPARAMNAMELENGTH) ) |
|
83 { |
|
84 aName.assign( iCall.iParams.iParams_val[anIndex].iName ); |
|
85 ret = true; |
|
86 } |
|
87 } |
|
88 return ret; |
|
89 } |
|
90 |
|
91 /* |
|
92 * Value |
|
93 * |
|
94 * Retrieve the value of a parameter at a specific index |
|
95 */ |
|
96 bool CCall::Value( int anIndex, string& aValue ) const |
|
97 { |
|
98 bool ret = false; |
|
99 if( anIndex >= 0 && anIndex < iCall.iParams.iParams_len ) |
|
100 { |
|
101 if( Check(iCall.iParams.iParams_val[anIndex].iValue, MAXPARAMVALUELENGTH) ) |
|
102 { |
|
103 aValue.assign( iCall.iParams.iParams_val[anIndex].iValue ); |
|
104 ret = true; |
|
105 } |
|
106 } |
|
107 return ret; |
|
108 } |
|
109 |
|
110 /* |
|
111 * Check |
|
112 * |
|
113 * Check a string value is within the defined boundaries |
|
114 */ |
|
115 bool CCall::Check( const string& aValue, const unsigned int aMaxLength ) const |
|
116 { |
|
117 bool ret = false; |
|
118 if( aValue.size() > 0 && aValue.size() <= aMaxLength ) |
|
119 { |
|
120 ret = true; |
|
121 } |
|
122 return ret; |
|
123 } |
|
124 |
|
125 /* |
|
126 * Get |
|
127 * |
|
128 * Find the index into the array matching the specified parameter name |
|
129 */ |
|
130 int CCall::GetIndex(const string &aName) const |
|
131 { |
|
132 // search through each param to find a matching (case insensitive) name & return the index |
|
133 for (unsigned int i =0; i < iCall.iParams.iParams_len; i++) |
|
134 { |
|
135 if (!_stricmp(aName.c_str(), iCall.iParams.iParams_val[i].iName)) |
|
136 return i; |
|
137 } |
|
138 return -1; |
|
139 } |
|
140 |
|
141 /* |
|
142 * Get |
|
143 * |
|
144 * Retrieve the value of the specified parameter |
|
145 */ |
|
146 bool CCall::Get(const string &aName, string &aValue) const |
|
147 { |
|
148 // find a matching index & copy value |
|
149 int index = GetIndex(aName); |
|
150 if (index < 0) |
|
151 return false; |
|
152 |
|
153 aValue.assign(iCall.iParams.iParams_val[index].iValue); |
|
154 return true; |
|
155 } |
|
156 |
|
157 bool CCall::Get(const string &aName, int &aValue) const |
|
158 { |
|
159 // get value as string |
|
160 string value; |
|
161 if (!Get(aName, value)) |
|
162 return false; |
|
163 |
|
164 // convert value to int |
|
165 if (sscanf(value.c_str(), "0x%x", &aValue) != 1 && |
|
166 sscanf(value.c_str(), "%d", &aValue) != 1) |
|
167 { |
|
168 return false; |
|
169 } |
|
170 |
|
171 return true; |
|
172 } |
|
173 |
|
174 bool CCall::Get(const string &aName, bool &aValue) const |
|
175 { |
|
176 // get value as string |
|
177 string value; |
|
178 if (!Get(aName, value)) |
|
179 return false; |
|
180 |
|
181 // convert value to bool |
|
182 if (!_stricmp(value.c_str(), "true")) |
|
183 return true; |
|
184 else if (!_stricmp(value.c_str(), "false")) |
|
185 return false; |
|
186 |
|
187 aValue = false; |
|
188 return false; |
|
189 } |
|
190 |
|
191 /* |
|
192 * Dump |
|
193 * |
|
194 * Dump the contents to stdout (useful debugging aid) |
|
195 * - Deliberately uses the public APIs |
|
196 */ |
|
197 void CCall::Dump() const |
|
198 { |
|
199 // call id |
|
200 int callId = 0; |
|
201 if (CallID(callId)) |
|
202 printf("callId = %d\n", callId); |
|
203 else |
|
204 { |
|
205 printf("Error! callId is indeterminate\n"); |
|
206 return; |
|
207 } |
|
208 |
|
209 // num params |
|
210 int numParams = 0; |
|
211 if (Params(numParams)) |
|
212 printf("numParams = %d\n", numParams); |
|
213 else |
|
214 { |
|
215 printf("Error! numParams is indeterminate\n"); |
|
216 return; |
|
217 } |
|
218 |
|
219 // params |
|
220 for (int i=0 ; i < numParams ; i++) |
|
221 { |
|
222 // param name |
|
223 string paramName; |
|
224 if (Name(i, paramName)) |
|
225 printf(" arg; \"%s\" = ", paramName.c_str()); |
|
226 else |
|
227 printf("Error! paramName is indeterminate\n"); |
|
228 |
|
229 // param value |
|
230 string paramValue; |
|
231 if (Value(i, paramValue)) |
|
232 printf("\"%s\"\n", paramValue.c_str()); |
|
233 else |
|
234 printf("\nError! paramValue is indeterminate\n"); |
|
235 } |
|
236 } |
|
237 |