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 /// <since_tizen> 3 </since_tizen>
54 /// <param name="list">
55 /// The List of Notification Id's for which the ChangeNotification event will be triggered
57 /// <feature>http://tizen.org/feature/network.telephony</feature>
58 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
59 /// <exception cref="InvalidOperationException">
60 /// This Exception can occur due to:
61 /// 1. Operation Not Supported
62 /// 2. Operation Failed
64 public void SetNotificationId(IEnumerable<ChangeNotificationEventArgs.Notification> list)
68 foreach (ChangeNotificationEventArgs.Notification n in list)
75 Tizen.Log.Error(Interop.Telephony.LogTag, "SetNotificationId Failed with Error " + e.ToString());
81 /// The Notification Id's for which the ChangeNotification event will not be triggered
83 /// <since_tizen> 3 </since_tizen>
84 /// <param name="list">
85 /// The List of Notification Id's for which the ChangeNotification event will be not be triggered
87 /// <feature>http://tizen.org/feature/network.telephony</feature>
88 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
89 /// <exception cref="InvalidOperationException">
90 /// This Exception can occur due to:
91 /// 1. Operation Not Supported
92 /// 2. Operation Failed
94 public void RemoveNotificationId(IEnumerable<ChangeNotificationEventArgs.Notification> list)
96 foreach (ChangeNotificationEventArgs.Notification n in list)
98 Interop.Telephony.TelephonyError error = Interop.Telephony.TelephonyUnsetNotiCb(_handle, n);
99 if (error != Interop.Telephony.TelephonyError.None)
101 throw ExceptionFactory.CreateException(error);
106 private void SetCallback(ChangeNotificationEventArgs.Notification n)
108 Interop.Telephony.NotificationCallback NotificationDelegate = (IntPtr handle, ChangeNotificationEventArgs.Notification notiId, IntPtr data, IntPtr userData) =>
110 SlotHandle simHandle = Manager.FindHandle(handle);
111 object notiData = null;
114 case ChangeNotificationEventArgs.Notification.SimStatus:
116 notiData = (Sim.State)Marshal.ReadInt32(data);
120 case ChangeNotificationEventArgs.Notification.SimCallForwardingIndicatorState:
122 notiData = ((Marshal.ReadInt32(data) == 0) ? false : true);
126 case ChangeNotificationEventArgs.Notification.NetworkServiceState:
128 notiData = (Network.ServiceState)Marshal.ReadInt32(data);
132 case ChangeNotificationEventArgs.Notification.NetworkCellid:
134 notiData = Marshal.ReadInt32(data);
138 case ChangeNotificationEventArgs.Notification.NetworkRoamingStatus:
140 notiData = (Marshal.ReadInt32(data) == 0) ? false : true;
144 case ChangeNotificationEventArgs.Notification.NetworkSignalstrengthLevel:
146 notiData = (Network.Rssi)Marshal.ReadInt32(data);
150 case ChangeNotificationEventArgs.Notification.NetworkNetworkName:
152 notiData = Marshal.PtrToStringAnsi(data);
156 case ChangeNotificationEventArgs.Notification.NetworkPsType:
158 notiData = (Network.PsType)Marshal.ReadInt32(data);
162 case ChangeNotificationEventArgs.Notification.NetworkDefaultDataSubscription:
164 notiData = (Network.DefaultDataSubscription)Marshal.ReadInt32(data);
168 case ChangeNotificationEventArgs.Notification.NetworkDefaultSubscription:
170 notiData = (Network.DefaultSubscription)Marshal.ReadInt32(data);
174 case ChangeNotificationEventArgs.Notification.NetworkLac:
176 notiData = Marshal.ReadInt32(data);
180 case ChangeNotificationEventArgs.Notification.NetworkTac:
182 notiData = Marshal.ReadInt32(data);
186 case ChangeNotificationEventArgs.Notification.NetworkSystemId:
188 notiData = Marshal.ReadInt32(data);
192 case ChangeNotificationEventArgs.Notification.NetworkId:
194 notiData = Marshal.ReadInt32(data);
198 case ChangeNotificationEventArgs.Notification.NetworkBsId:
200 notiData = Marshal.ReadInt32(data);
204 case ChangeNotificationEventArgs.Notification.NetworkBsLatitude:
206 notiData = Marshal.ReadInt32(data);
210 case ChangeNotificationEventArgs.Notification.NetworkBsLongitude:
212 notiData = Marshal.ReadInt32(data);
216 case ChangeNotificationEventArgs.Notification.VoiceCallStatusIdle:
218 notiData = (uint)Marshal.ReadInt32(data);
222 case ChangeNotificationEventArgs.Notification.VoiceCallStatusActive:
224 notiData = (uint)Marshal.ReadInt32(data);
228 case ChangeNotificationEventArgs.Notification.VoiceCallStatusHeld:
230 notiData = (uint)Marshal.ReadInt32(data);
234 case ChangeNotificationEventArgs.Notification.VoiceCallStatusDialing:
236 notiData = (uint)Marshal.ReadInt32(data);
240 case ChangeNotificationEventArgs.Notification.VoiceCallStatusAlerting:
242 notiData = (uint)Marshal.ReadInt32(data);
246 case ChangeNotificationEventArgs.Notification.VoiceCallStatusIncoming:
248 notiData = (uint)Marshal.ReadInt32(data);
252 case ChangeNotificationEventArgs.Notification.VideoCallStatusIdle:
254 notiData = (uint)Marshal.ReadInt32(data);
258 case ChangeNotificationEventArgs.Notification.VideoCallStatusActive:
260 notiData = (uint)Marshal.ReadInt32(data);
264 case ChangeNotificationEventArgs.Notification.VideoCallStatusDialing:
266 notiData = (uint)Marshal.ReadInt32(data);
270 case ChangeNotificationEventArgs.Notification.VideoCallStatusAlerting:
272 notiData = (uint)Marshal.ReadInt32(data);
276 case ChangeNotificationEventArgs.Notification.VideoCallStatusIncoming:
278 notiData = (uint)Marshal.ReadInt32(data);
282 case ChangeNotificationEventArgs.Notification.CallPreferredVoiceSubscription:
284 notiData = (CallPreferredVoiceSubscription)Marshal.ReadInt32(data);
290 ChangeNotificationEventArgs args = new ChangeNotificationEventArgs(notiId, notiData);
291 ChangeNotification?.Invoke(simHandle, args);
293 _changeNotificationList.Add(NotificationDelegate);
295 Interop.Telephony.TelephonyError error = Interop.Telephony.TelephonySetNotiCb(_handle, n, NotificationDelegate, IntPtr.Zero);
296 if (error != Interop.Telephony.TelephonyError.None)
298 Exception e = ExceptionFactory.CreateException(error);
299 // Check if error is Invalid Parameter then hide the error
300 if (e is ArgumentException)
302 e = new InvalidOperationException("Internal Error Occured");