2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
21 namespace Tizen.Telephony
24 /// This Class provides API's that provides functionality related to slot handle.
26 public class SlotHandle
28 internal IntPtr _handle;
29 private List<Interop.Telephony.NotificationCallback> _changeNotificationList = new List<Interop.Telephony.NotificationCallback>();
31 internal SlotHandle(IntPtr handle)
37 /// Event Handler for Receiving the Telephony State Changes
38 /// this event will be triggered for the NotificationId's given in the SetNotificationId API
40 public event EventHandler<ChangeNotificationEventArgs> ChangeNotification;
42 internal IntPtr Handle
51 /// The Notification Id's for which the ChangeNotification event will be triggered
53 /// <param name="list">
54 /// The List of Notification Id's for which the ChangeNotification event will be triggered
56 /// <exception cref="InvalidOperationException">
57 /// This Exception can occur due to:
58 /// 1. Operation Not Supported
59 /// 2. Operation Failed
61 public void SetNotificationId(List<ChangeNotificationEventArgs.Notification> list)
65 foreach (ChangeNotificationEventArgs.Notification n in list)
72 Tizen.Log.Error(Interop.Telephony.LogTag, "SetNotificationId Failed with Error " + e.ToString());
78 /// The Notification Id's for which the ChangeNotification event will not be triggered
80 /// <param name="list">
81 /// The List of Notification Id's for which the ChangeNotification event will be not be triggered
83 /// <exception cref="InvalidOperationException">
84 /// This Exception can occur due to:
85 /// 1. Operation Not Supported
86 /// 2. Operation Failed
88 public void RemoveNotificationId(List<ChangeNotificationEventArgs.Notification> list)
90 foreach (ChangeNotificationEventArgs.Notification n in list)
92 Interop.Telephony.TelephonyError error = Interop.Telephony.TelephonyUnsetNotiCb(_handle, n);
93 if (error != Interop.Telephony.TelephonyError.None)
95 throw ExceptionFactory.CreateException(error);
100 private void SetCallback(ChangeNotificationEventArgs.Notification n)
102 Interop.Telephony.NotificationCallback NotificationDelegate = (IntPtr handle, ChangeNotificationEventArgs.Notification notiId, IntPtr data, IntPtr userData) =>
104 SlotHandle simHandle = Manager.FindHandle(handle);
105 object notiData = null;
108 case ChangeNotificationEventArgs.Notification.SimStatus:
110 notiData = (Sim.State)Marshal.ReadInt32(data);
114 case ChangeNotificationEventArgs.Notification.SimCallForwardingIndicatorState:
116 notiData = ((Marshal.ReadInt32(data) == 0) ? false : true);
120 case ChangeNotificationEventArgs.Notification.NetworkServiceState:
122 notiData = (Network.ServiceState)Marshal.ReadInt32(data);
126 case ChangeNotificationEventArgs.Notification.NetworkCellid:
128 notiData = Marshal.ReadInt32(data);
132 case ChangeNotificationEventArgs.Notification.NetworkRoamingStatus:
134 notiData = (Marshal.ReadInt32(data) == 0) ? false : true;
138 case ChangeNotificationEventArgs.Notification.NetworkSignalstrengthLevel:
140 notiData = (Network.Rssi)Marshal.ReadInt32(data);
144 case ChangeNotificationEventArgs.Notification.NetworkNetworkName:
146 notiData = Marshal.PtrToStringAnsi(data);
150 case ChangeNotificationEventArgs.Notification.NetworkPsType:
152 notiData = (Network.PsType)Marshal.ReadInt32(data);
156 case ChangeNotificationEventArgs.Notification.NetworkDefaultDataSubscription:
158 notiData = (Network.DefaultDataSubscription)Marshal.ReadInt32(data);
162 case ChangeNotificationEventArgs.Notification.NetworkDefaultSubscription:
164 notiData = (Network.DefaultSubscription)Marshal.ReadInt32(data);
168 case ChangeNotificationEventArgs.Notification.NetworkLac:
170 notiData = Marshal.ReadInt32(data);
174 case ChangeNotificationEventArgs.Notification.NetworkTac:
176 notiData = Marshal.ReadInt32(data);
180 case ChangeNotificationEventArgs.Notification.NetworkSystemId:
182 notiData = Marshal.ReadInt32(data);
186 case ChangeNotificationEventArgs.Notification.NetworkId:
188 notiData = Marshal.ReadInt32(data);
192 case ChangeNotificationEventArgs.Notification.NetworkBsId:
194 notiData = Marshal.ReadInt32(data);
198 case ChangeNotificationEventArgs.Notification.NetworkBsLatitude:
200 notiData = Marshal.ReadInt32(data);
204 case ChangeNotificationEventArgs.Notification.NetworkBsLongitude:
206 notiData = Marshal.ReadInt32(data);
210 case ChangeNotificationEventArgs.Notification.VoiceCallStatusIdle:
212 notiData = (uint)Marshal.ReadInt32(data);
216 case ChangeNotificationEventArgs.Notification.VoiceCallStatusActive:
218 notiData = (uint)Marshal.ReadInt32(data);
222 case ChangeNotificationEventArgs.Notification.VoiceCallStatusHeld:
224 notiData = (uint)Marshal.ReadInt32(data);
228 case ChangeNotificationEventArgs.Notification.VoiceCallStatusDialing:
230 notiData = (uint)Marshal.ReadInt32(data);
234 case ChangeNotificationEventArgs.Notification.VoiceCallStatusAlerting:
236 notiData = (uint)Marshal.ReadInt32(data);
240 case ChangeNotificationEventArgs.Notification.VoiceCallStatusIncoming:
242 notiData = (uint)Marshal.ReadInt32(data);
246 case ChangeNotificationEventArgs.Notification.VideoCallStatusIdle:
248 notiData = (uint)Marshal.ReadInt32(data);
252 case ChangeNotificationEventArgs.Notification.VideoCallStatusActive:
254 notiData = (uint)Marshal.ReadInt32(data);
258 case ChangeNotificationEventArgs.Notification.VideoCallStatusDialing:
260 notiData = (uint)Marshal.ReadInt32(data);
264 case ChangeNotificationEventArgs.Notification.VideoCallStatusAlerting:
266 notiData = (uint)Marshal.ReadInt32(data);
270 case ChangeNotificationEventArgs.Notification.VideoCallStatusIncoming:
272 notiData = (uint)Marshal.ReadInt32(data);
276 case ChangeNotificationEventArgs.Notification.CallPreferredVoiceSubscription:
278 notiData = (CallPreferredVoiceSubscription)Marshal.ReadInt32(data);
284 ChangeNotificationEventArgs args = new ChangeNotificationEventArgs(notiId, notiData);
285 ChangeNotification?.Invoke(simHandle, args);
287 _changeNotificationList.Add(NotificationDelegate);
289 Interop.Telephony.TelephonyError error = Interop.Telephony.TelephonySetNotiCb(_handle, n, NotificationDelegate, IntPtr.Zero);
290 if (error != Interop.Telephony.TelephonyError.None)
292 Exception e = ExceptionFactory.CreateException(error);
293 // Check if error is Invalid Parameter then hide the error
294 if (e is ArgumentException)
296 e = new InvalidOperationException("Internal Error Occured");