Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / TapiUtility.cs
1 /*
2  * Copyright (c) 2016 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 using System;
18
19 namespace Tizen.Tapi
20 {
21     internal enum TapiError
22     {
23         Success = 0,
24         InvalidInput = -1,
25         InvalidPtr = -2,
26         NotSupported = -3,
27         Depricated = -4,
28         SystemOutOfMemory = -5,
29         SystemRpcLinkDown = -6,
30         ServiceNotReady = -7,
31         ServerFailure = -8,
32         OemPluginFailure = -9,
33         TransportLayerFailure = -10,
34         InvalidDataLength = -11,
35         RequestMaxInProgress = -12,
36         OfflineModeError = -13,
37         EventClassUnknown = -14,
38         EventUnknown = -15,
39         RegistrationOpFailed = -16,
40         OperationFailed = -17,
41         InvalidOperation = -18,
42         AccessDenied = -19,
43         SystemRpcLinkNotEst = -100,
44         ApiNotSupported = -101,
45         ServerLayerFailure = -102,
46         InvalidCallId = -200,
47         CallContextOverflow = -201,
48         CouldNotGetCallContext = -202,
49         ContextSearchRetNonCallContext = -203,
50         CouldNotDestroyContext = -204,
51         InvalidLineId = -205,
52         InvalidCallHandle = -206,
53         InvalidCallState = -207,
54         CallPreCondFailed = -208,
55         CallSameReqPending = -209,
56         ModemPoweredOff = -300,
57         ModemAlreadyOn = -301,
58         ModemAlreadyOff = -302,
59         NetTextDeviceNotReady = -400,
60         NetTextScaAddrNotSet = -401,
61         NetTextInvalidDataLength = -402,
62         NetTextScaAddressNotSet = -403,
63         SimCardError = -500,
64         SimNotFound = -501,
65         SimNotInitialized = -502,
66         SimLocked = -503,
67         SimPermBlocked = -504,
68         SimServiceDisabled = -505,
69         SatInvalidCommandId = -600,
70         SatCommandTypeMismatch = -601,
71         SatEventNotRequiredByUsim = -602,
72         NetworkInvalidContext = -700,
73         NetworkPlmnNotAllowed = -701,
74         NetworkRoamingNotAllowed = -702,
75         MiscReturnNull = -800,
76         MiscvalidityError = -801,
77         MiscInputParamError = -802,
78         MiscOutParamNull = -803
79     }
80
81     internal static class TapiUtility
82     {
83         internal const string LogTag = "Tizen.Tapi";
84         internal const int MaxVersionLen = 32;
85         internal const int MiscProdCodeMaxLen = 32;
86         internal const int ModelIdMaxLen = 17;
87         internal const int MiscPrlEriVersionMaxLen = 17;
88         internal const int MiscMeSnMaxLen = 32;
89         internal const int MiscMeDeviceNameMaxLen = 32;
90         internal const int CallDialNumberMaxLen = 83;
91         internal const int CallNameMaxSize = 97;
92
93         internal static string ConvertNotiToString(Notification noti)
94         {
95             switch(noti)
96             {
97                 case Notification.IdleVoiceCall:
98                     return "org.tizen.telephony.Call:VoiceCallStatusIdle";
99                 case Notification.ActiveVoiceCall:
100                     return "org.tizen.telephony.Call:VoiceCallStatusActive";
101                 case Notification.HeldVoiceCall:
102                     return "org.tizen.telephony.Call:VoiceCallStatusHeld";
103                 case Notification.DialingVoiceCall:
104                     return "org.tizen.telephony.Call:VoiceCallStatusDialing";
105                 case Notification.AlertVoiceCall:
106                     return "org.tizen.telephony.Call:VoiceCallStatusAlert";
107                 case Notification.IncomingVoiceCall:
108                     return "org.tizen.telephony.Call:VoiceCallStatusIncoming";
109                 case Notification.IdleVideoCall:
110                     return "org.tizen.telephony.Call:VideoCallStatusIdle";
111                 case Notification.ActiveVideoCall:
112                     return "org.tizen.telephony.Call:VideoCallStatusActive";
113                 case Notification.DialingVideoCall:
114                     return "org.tizen.telephony.Call:VideoCallStatusDialing";
115                 case Notification.AlertVideoCall:
116                     return "org.tizen.telephony.Call:VideoCallStatusAlert";
117                 case Notification.IncomingVideoCall:
118                     return "org.tizen.telephony.Call:VideoCallStatusIncoming";
119                 case Notification.WaitingCallInfo:
120                     return "org.tizen.telephony.Call:Waiting";
121                 case Notification.ForwardCallInfo:
122                     return "org.tizen.telephony.Call:Forwarded";
123                 case Notification.BarredIncomingCallInfo:
124                     return "org.tizen.telephony.Call:BarredIncoming";
125                 case Notification.BarredOutgoingCallInfo:
126                     return "org.tizen.telephony.Call:BarredOutgoing";
127                 case Notification.DeflectCallInfo:
128                     return "org.tizen.telephony.Call:Deflected";
129                 case Notification.ClirCallInfo:
130                     return "org.tizen.telephony.Call:ClirSuppressionReject";
131                 case Notification.ForwardUnconditionalCallInfo:
132                     return "org.tizen.telephony.Call:ForwardUnconditional";
133                 case Notification.ForwardConditionalCallInfo:
134                     return "org.tizen.telephony.Call:ForwardConditional";
135                 case Notification.ForwardedCallInfo:
136                     return "org.tizen.telephony.Call:ForwardedCall";
137                 case Notification.DeflectedCallInfo:
138                     return "org.tizen.telephony.Call:DeflectedCall";
139                 case Notification.TransferredCallInfo:
140                     return "org.tizen.telephony.Call:TransferedCall";
141                 case Notification.HeldCallInfo:
142                     return "org.tizen.telephony.Call:CallHeld";
143                 case Notification.ActiveCallInfo:
144                     return "org.tizen.telephony.Call:CallActive";
145                 case Notification.JoinedCallInfo:
146                     return "org.tizen.telephony.Call:CallJoined";
147                 case Notification.TransferAlertCallInfo:
148                     return "org.tizen.telephony.Call:TransferAlert";
149                 case Notification.CfCheckMessageCallInfo:
150                     return "org.tizen.telephony.Call:CfCheckMessage";
151                 case Notification.RecCallInfo:
152                     return "org.tizen.telephony.Call:CallInfoRec";
153                 case Notification.FallbackCallInfo:
154                     return "org.tizen.telephony.Call:CallFallback";
155                 case Notification.PrivacyModeCall:
156                     return "org.tizen.telephony.Call:CallPrivacyMode";
157                 case Notification.OtaspCall:
158                     return "org.tizen.telephony.Call:CallOtaspStatus";
159                 case Notification.OtapaCall:
160                     return "org.tizen.telephony.Call:CallOtapaStatus";
161                 case Notification.CallSignalInfo:
162                     return "org.tizen.telephony.Call:CallSignalInfo";
163                 case Notification.CallSoundPath:
164                     return "org.tizen.telephony.Call:CallSoundPath";
165                 case Notification.CallSoundRingbackTone:
166                     return "org.tizen.telephony.Call:CallSoundRingbackTone";
167                 case Notification.CallSoundWbamr:
168                     return "org.tizen.telephony.Call:CallSoundWbamr";
169                 case Notification.CallSoundNoiceReduction:
170                     return "org.tizen.telephony.Call:CallSoundNoiseReduction";
171                 case Notification.CallSoundClock:
172                     return "org.tizen.telephony.Call:CallSoundClockStatus";
173                 case Notification.CallPreferredVoiceSubscription:
174                     return "org.tizen.telephony.Call:CallPreferredVoiceSubscription";
175                 case Notification.CallModifiableInfo:
176                     return "org.tizen.telephony.Call:Modifiable";
177                 case Notification.CallupgradeRequested:
178                     return "org.tizen.telephony.Call:CallUpgradeRequested";
179                 case Notification.CallDowngraded:
180                     return "org.tizen.telephony.Call:CallDowngraded";
181                 case Notification.ModemPower:
182                     return "org.tizen.telephony.Modem:Power";
183                 case Notification.SimStatus:
184                     return "org.tizen.telephony.Sim:Status";
185                 case Notification.SimRefreshed:
186                     return "org.tizen.telephony.Sim:Refreshed";
187                 case Notification.SapStatus:
188                     return "org.tizen.telephony.Sap:Status";
189                 case Notification.SapDisconnect:
190                     return "org.tizen.telephony.Sap:Disconnect";
191                 case Notification.SatSetupMenu:
192                     return "org.tizen.telephony.SAT:SetupMenu";
193                 case Notification.SatDisplayText:
194                     return "org.tizen.telephony.SAT:DisplayText";
195                 case Notification.SatSelectItem:
196                     return "org.tizen.telephony.SAT:SelectItem";
197                 case Notification.SatGetInKey:
198                     return "org.tizen.telephony.SAT:GetInkey";
199                 case Notification.SatGetInput:
200                     return "org.tizen.telephony.SAT:GetInput";
201                 case Notification.SatRefresh:
202                     return "org.tizen.telephony.SAT:Refresh";
203                 case Notification.SatSendSms:
204                     return "org.tizen.telephony.SAT:SendSMS";
205                 case Notification.SatSetupEventList:
206                     return "org.tizen.telephony.SAT:SetupEventList";
207                 case Notification.SatSendDtmf:
208                     return "org.tizen.telephony.SAT:SendDtmf";
209                 case Notification.SatEndProactiveSession:
210                     return "org.tizen.telephony.SAT:EndProactiveSession";
211                 case Notification.SatCallControlResult:
212                     return "org.tizen.telephony.SAT:CallControlResult";
213                 case Notification.SatMoSmControlResult:
214                     return "org.tizen.telephony.SAT:MoSmControlResult";
215                 case Notification.SatSetupCall:
216                     return "org.tizen.telephony.SAT:SetupCall";
217                 case Notification.SatSendSs:
218                     return "org.tizen.telephony.SAT:SendSS";
219                 case Notification.SatSetupUssd:
220                     return "org.tizen.telephony.SAT:SetupUSSD";
221                 case Notification.PhonebookStatus:
222                     return "org.tizen.telephony.Phonebook:Status";
223                 case Notification.PhonebookContactChange:
224                     return "org.tizen.telephony.Phonebook:ContactChange";
225                 case Notification.NetworkRegistrationStatus:
226                     return "org.tizen.telephony.Network:RegistrationStatus";
227                 case Notification.NetworkCellInfo:
228                     return "org.tizen.telephony.Network:CellInfo";
229                 case Notification.NetworkChange:
230                     return "org.tizen.telephony.Network:Change";
231                 case Notification.NetworkTimeInfo:
232                     return "org.tizen.telephony.Network:TimeInfo";
233                 case Notification.NetworkIdentity:
234                     return "org.tizen.telephony.Network:Identity";
235                 case Notification.NetworkSignalStrength:
236                     return "org.tizen.telephony.Network:SignalStrength";
237                 case Notification.NetworkEmergencyCallbackMode:
238                     return "org.tizen.telephony.Network:EmergencyCallbackMode";
239                 case Notification.NetworkDefaultDataSubscription:
240                     return "org.tizen.telephony.Network:DefaultDataSubscription";
241                 case Notification.NetworkDefaultSubscription:
242                     return "org.tizen.telephony.Network:DefaultSubscription";
243                 case Notification.NetworkCellId:
244                     return "org.tizen.telephony.Network:CellId";
245                 case Notification.NetworkLac:
246                     return "org.tizen.telephony.Network:Lac";
247                 case Notification.NetworkTac:
248                     return "org.tizen.telephony.Network:Tac";
249                 case Notification.NetworkSystemId:
250                     return "org.tizen.telephony.Network:SystemId";
251                 case Notification.NetworkNetworkId:
252                     return "org.tizen.telephony.Network:NetworkId";
253                 case Notification.NetworkBsId:
254                     return "org.tizen.telephony.Network:BsId";
255                 case Notification.NetworkBsLatitude:
256                     return "org.tizen.telephony.Network:BsLatitude";
257                 case Notification.NetworkBsLongitude:
258                     return "org.tizen.telephony.Network:BsLongitude";
259                 case Notification.NetworkVolteStatus:
260                     return "org.tizen.telephony.Network:VolteStatus";
261                 case Notification.NetworkEpdgStatus:
262                     return "org.tizen.telephony.Network:EpdgStatus";
263                 case Notification.SsUssd:
264                     return "org.tizen.telephony.Ss:NotifyUSSD";
265                 case Notification.SsReleaseComplete:
266                     return "org.tizen.telephony.Ss:ReleaseComplete";
267                 case Notification.SsNotifyForwarding:
268                     return "org.tizen.telephony.Ss:NotifyForwarding";
269                 case Notification.SsNotifyBarring:
270                     return "org.tizen.telephony.Ss:NotifyBarring";
271                 case Notification.SsNotifyWaiting:
272                     return "org.tizen.telephony.Ss:NotifyWaiting";
273                 case Notification.SsNotifyInfo:
274                     return "org.tizen.telephony.Ss:NotifySsInfo";
275                 case Notification.SmsIncomingMsg:
276                     return "org.tizen.telephony.sms:IncommingMsg";
277                 case Notification.SmsIncomingCbMsg:
278                     return "org.tizen.telephony.sms:IncommingCbMsg";
279                 case Notification.SmsIncomingEtwsMsg:
280                     return "org.tizen.telephony.sms:IncommingEtwsMsg";
281                 case Notification.SmsMemoryStatus:
282                     return "org.tizen.telephony.sms:MemoryStatus";
283                 case Notification.SmsReady:
284                     return "org.tizen.telephony.sms:SmsReady";
285                 case Notification.OemData:
286                     return "org.tizen.telephony.OEM:OemData";
287                 default:
288                     return null;
289             }
290         }
291
292         internal static string ConvertPropToString(Property prop)
293         {
294             switch(prop)
295             {
296                 case Property.ModemPower:
297                     return "org.tizen.telephony.Modem:power";
298                 case Property.ModemDongleStatus:
299                     return "org.tizen.telephony.Modem:dongle_status";
300                 case Property.ModemDongleLogin:
301                     return "org.tizen.telephony.Modem:dongle_login";
302                 case Property.SimCallForwardState:
303                     return "org.tizen.telephony.Sim:cf_state";
304                 case Property.NetworkLac:
305                     return "org.tizen.telephony.Network:lac";
306                 case Property.NetworkTac:
307                     return "org.tizen.telephony.Network:tac";
308                 case Property.NetworkPlmn:
309                     return "org.tizen.telephony.Network:plmn";
310                 case Property.NetworkCellId:
311                     return ".tizen.telephony.Network:cell_id";
312                 case Property.NetworkPhysicalCellId:
313                     return "org.tizen.telephony.Network:physical_cell_id";
314                 case Property.NetworkServiceType:
315                     return "org.tizen.telephony.Network:service_type";
316                 case Property.NetworkAct:
317                     return "org.tizen.telephony.Network:access_technology";
318                 case Property.NetworkPsType:
319                     return "org.tizen.telephony.Network:ps_type";
320                 case Property.NetworkCircuitStatus:
321                     return "org.tizen.telephony.Network:circuit_status";
322                 case Property.NetworkPacketStatus:
323                     return "org.tizen.telephony.Network:packet_status";
324                 case Property.NetworkRoamingStatus:
325                     return "org.tizen.telephony.Network:roaming_status";
326                 case Property.NetworkNameOption:
327                     return "org.tizen.telephony.Network:name_option";
328                 case Property.NetworkName:
329                     return "org.tizen.telephony.Network:network_name";
330                 case Property.NetworkSpnName:
331                     return "org.tizen.telephony.Network:spn_name";
332                 case Property.NetworkSignalDbm:
333                     return "org.tizen.telephony.Network:sig_dbm";
334                 case Property.NetworkSignalLevel:
335                     return "org.tizen.telephony.Network:sig_level";
336                 case Property.NetworkImsVoiceStatus:
337                     return "org.tizen.telephony.Network:ims_voice_status";
338                 case Property.NetworkVolteEnable:
339                     return "org.tizen.telephony.Network:volte_enable";
340                 case Property.NetworkLteBand:
341                     return "org.tizen.telephony.Network:lte_band_type";
342                 default:
343                     return null;
344             }
345         }
346
347         internal static void ThrowTapiException(int exception, IntPtr handle)
348         {
349             ThrowException(exception, (handle == IntPtr.Zero), "");
350         }
351
352         internal static void ThrowTapiException(int exception, IntPtr handle, string message)
353         {
354             ThrowException(exception, (handle == IntPtr.Zero), message);
355         }
356
357         private static void ThrowException(int exception, bool isHandleNull, string message)
358         {
359             TapiError _error = (TapiError)exception;
360             switch (_error)
361             {
362                 case TapiError.NotSupported:
363                     throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.telephony");
364                 case TapiError.AccessDenied:
365                     throw new UnauthorizedAccessException("Permission denied " + message);
366                 case TapiError.SystemOutOfMemory:
367                     throw new OutOfMemoryException("System out of memory");
368                 case TapiError.InvalidPtr:
369                     if (isHandleNull)
370                     {
371                         throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
372                     }
373                     else
374                         throw new ArgumentException("Invalid parameter");
375                 case TapiError.InvalidInput:
376                     throw new ArgumentException("Invalid parameter");
377                 default:
378                     throw new InvalidOperationException(_error.ToString());
379             }
380         }
381     }
382 }