Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / CallStructs.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 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20
21 namespace Tizen.Tapi
22 {
23     [StructLayout(LayoutKind.Sequential)]
24     internal struct CallIdleStatusNotiStruct
25     {
26         internal uint Id;
27         internal CallEndCause Cause;
28     }
29
30     [StructLayout(LayoutKind.Sequential)]
31     internal struct CallIncomingInfoStruct
32     {
33         internal uint Handle;
34         internal CallType Type;
35         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TapiUtility.CallDialNumberMaxLen)]
36         internal string CallerNumber;
37         internal CallerName NameData;
38         internal CallCliMode CliMode;
39         internal CallNoCliCause CliCause;
40         internal int IsForwarded;
41         internal CallActiveLine ActiveLine;
42     }
43
44     [StructLayout(LayoutKind.Sequential)]
45     internal struct CallerName
46     {
47         internal CallNameMode NameMode;
48         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TapiUtility.CallNameMaxSize)]
49         internal string Name;
50     }
51
52     [StructLayout(LayoutKind.Sequential)]
53     internal struct CallRecordLineControlStruct
54     {
55         internal byte PolarityIncluded;
56         internal byte ToggleMode;
57         internal byte ReversePolarity;
58         internal byte PowerDenialTime;
59     }
60
61     [StructLayout(LayoutKind.Explicit)]
62     internal struct CallRecordDataStruct
63     {
64         [MarshalAs(UnmanagedType.LPStr)]
65         [FieldOffset(0)]
66         internal IntPtr Name;
67         [MarshalAs(UnmanagedType.LPStr)]
68         [FieldOffset(0)]
69         internal IntPtr Number;
70         [FieldOffset(0)]
71         internal CallRecordLineControlStruct LineCtrl;
72     }
73
74     [StructLayout(LayoutKind.Sequential)]
75     internal struct CallRecordStruct
76     {
77         internal uint Id;
78         internal CallRecordType Type;
79         internal CallRecordDataStruct Data;
80     }
81
82     [StructLayout(LayoutKind.Explicit)]
83     internal struct CallSignalStruct
84     {
85         [FieldOffset(0)]
86         internal CallToneSignal SignalTone;
87         [FieldOffset(0)]
88         internal CallIsdnAlertSignal IsdnAlert;
89         [FieldOffset(0)]
90         internal CallIs54bAlertSignal Is54bAlert;
91     }
92
93     [StructLayout(LayoutKind.Sequential)]
94     internal struct CallSignalInfoStruct
95     {
96         internal CallAlertSignal SignalType;
97         internal CallAlertPitch PitchType;
98         internal CallSignalStruct CallSignal;
99     }
100
101     [StructLayout(LayoutKind.Sequential)]
102     internal struct CallInformationStruct
103     {
104         internal CallType Type;
105         internal EmergencyType EType;
106         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TapiUtility.CallDialNumberMaxLen)]
107         internal string PhoneNumber;
108     }
109
110     [StructLayout(LayoutKind.Sequential)]
111     internal struct CallBurstDtmfStruct
112     {
113         [MarshalAs(UnmanagedType.LPStr)]
114         internal string Dtmf;
115         internal CallDtmfPulseWidth Width;
116         internal CallDtmfDigitInterval Interval;
117     }
118
119     [StructLayout(LayoutKind.Sequential)]
120     internal struct CallStatusStruct
121     {
122         internal int CallHandle;
123         internal int BMoCall;
124         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TapiUtility.CallDialNumberMaxLen)]
125         internal string PhoneNumber;
126         internal CallType Type;
127         internal CallState State;
128         internal int BConferenceState;
129         internal int BVolteCall;
130     }
131
132     [StructLayout(LayoutKind.Sequential)]
133     internal struct CallDeflectDestStruct
134     {
135         internal IntPtr DestinationNumber;
136     }
137
138     [StructLayout(LayoutKind.Sequential)]
139     internal struct CallVolumeRecordStruct
140     {
141         internal SoundDevice Device;
142         internal SoundType Type;
143         internal SoundVolume Volume;
144     }
145
146     [StructLayout(LayoutKind.Sequential)]
147     internal struct CallSoundPathStruct
148     {
149         internal SoundPath Path;
150         internal ExtraVolume ExVolume;
151     }
152
153     [StructLayout(LayoutKind.Sequential)]
154     internal struct CallUpgradeDowngradeNotiStruct
155     {
156         internal int CallHandle;
157         internal CallConfigType ConfigType;
158     }
159
160     [StructLayout(LayoutKind.Sequential)]
161     internal struct CallOperationsStruct
162     {
163         internal uint id;
164     }
165
166     [StructLayout(LayoutKind.Sequential)]
167     internal struct CallEndStruct
168     {
169         internal CallEndType type;
170         internal uint id;
171     }
172
173     [StructLayout(LayoutKind.Sequential)]
174     internal struct CallVolumeStruct
175     {
176         internal uint number;
177         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20, ArraySubType = UnmanagedType.LPStruct)]
178         internal CallVolumeRecordStruct[] recordList;
179     }
180
181     [StructLayout(LayoutKind.Sequential)]
182     internal struct CallMuteStatusStruct
183     {
184         internal SoundMutePath Path;
185         internal SoundMuteStatus Status;
186     }
187
188     [StructLayout(LayoutKind.Sequential)]
189     internal struct CallPrivacyModeStruct
190     {
191         internal CallPrivacyMode Mode;
192     }
193
194     internal static class CallStructConversions
195     {
196         internal static CallIdleStatusNotificationData ConvertCallIdleStatusNoti(CallIdleStatusNotiStruct idleStatusNoti)
197         {
198             CallIdleStatusNotificationData idleStatusNotiData = new CallIdleStatusNotificationData();
199             idleStatusNotiData.Id = idleStatusNoti.Id;
200             idleStatusNotiData.Cause = idleStatusNoti.Cause;
201             return idleStatusNotiData;
202         }
203
204         internal static CallIncomingInfo ConvertIncomingCallInfo(CallIncomingInfoStruct incomingInfo)
205         {
206             CallIncomingInfo callIncoming = new CallIncomingInfo();
207             callIncoming.Handle = incomingInfo.Handle;
208             callIncoming.Type = incomingInfo.Type;
209             callIncoming.Number = incomingInfo.CallerNumber;
210             CallerNameInfo nameData = new CallerNameInfo();
211             nameData.Mode = incomingInfo.NameData.NameMode;
212             nameData.NameData = incomingInfo.NameData.Name;
213
214             callIncoming.Name = nameData;
215             callIncoming.Cli = incomingInfo.CliMode;
216             callIncoming.Cause = incomingInfo.CliCause;
217             if (incomingInfo.IsForwarded == 1)
218             {
219                 callIncoming.IsFwded = true;
220             }
221
222             else if (incomingInfo.IsForwarded == 0)
223             {
224                 callIncoming.IsFwded = false;
225             }
226
227             callIncoming.Line = incomingInfo.ActiveLine;
228
229             return callIncoming;
230         }
231
232         internal static CallRecord ConvertCallRecordStruct(CallRecordStruct record)
233         {
234             CallRecord recordData = new CallRecord();
235             recordData.Id = record.Id;
236             recordData.Type = record.Type;
237             if (record.Type == CallRecordType.Name)
238             {
239                 recordData.Name = Marshal.PtrToStringAnsi(record.Data.Name);
240             }
241
242             else if (record.Type == CallRecordType.Number)
243             {
244                 recordData.Number = Marshal.PtrToStringAnsi(record.Data.Number);
245             }
246
247             else if (record.Type == CallRecordType.LineControl)
248             {
249                 CallRecordLineControl lineCtrl = new CallRecordLineControl();
250                 lineCtrl.PolarityInc = record.Data.LineCtrl.PolarityIncluded;
251                 lineCtrl.Toggle = record.Data.LineCtrl.ToggleMode;
252                 lineCtrl.ReversePol = record.Data.LineCtrl.ReversePolarity;
253                 lineCtrl.PowerTime = record.Data.LineCtrl.PowerDenialTime;
254                 recordData.LineCtrl = lineCtrl;
255             }
256
257             return recordData;
258         }
259
260         internal static CallSignalNotification ConvertCallSignalInfo(CallSignalInfoStruct signalInfo)
261         {
262             CallSignalNotification signalNoti = new CallSignalNotification();
263             signalNoti.Signal = signalInfo.SignalType;
264             signalNoti.Pitch = signalInfo.PitchType;
265             if (signalInfo.SignalType == CallAlertSignal.Tone)
266             {
267                 signalNoti.Tone = signalInfo.CallSignal.SignalTone;
268             }
269
270             else if (signalInfo.SignalType == CallAlertSignal.IsdnAlert)
271             {
272                 signalNoti.Isdn = signalInfo.CallSignal.IsdnAlert;
273             }
274
275             else if (signalInfo.SignalType == CallAlertSignal.Is54bAlert)
276             {
277                 signalNoti.Is54b = signalInfo.CallSignal.Is54bAlert;
278             }
279
280             return signalNoti;
281         }
282
283         internal static CallUpgradeDowngradeRequestNoti ConvertCallUpgradeNoti(CallUpgradeDowngradeNotiStruct notiStruct)
284         {
285             CallUpgradeDowngradeRequestNoti requestNoti = new CallUpgradeDowngradeRequestNoti();
286             requestNoti.Handle = notiStruct.CallHandle;
287             requestNoti.Type = notiStruct.ConfigType;
288             return requestNoti;
289         }
290
291         internal static CallStatus ConvertStatusStruct(CallStatusStruct statusStruct)
292         {
293             CallStatus statusData = new CallStatus();
294             statusData.CallHandle = statusStruct.CallHandle;
295             statusData.IsMoCall = Convert.ToBoolean(statusStruct.BMoCall);
296             statusData.PhoneNumber = statusStruct.PhoneNumber;
297             statusData.Type = statusStruct.Type;
298             statusData.State = statusStruct.State;
299             statusData.IsConferenceState = Convert.ToBoolean(statusStruct.BConferenceState);
300             statusData.IsVolteCall = Convert.ToBoolean(statusStruct.BVolteCall);
301             return statusData;
302         }
303
304         internal static CallVolumeInfo ConvertVolumeStruct(CallVolumeStruct volumeStruct)
305         {
306             List<CallVolumeRecord> records = new List<CallVolumeRecord>();
307             foreach(CallVolumeRecordStruct record in volumeStruct.recordList)
308             {
309                 records.Add(new CallVolumeRecord(record.Device, record.Type, record.Volume));
310             }
311
312             CallVolumeInfo volumeInfo = new CallVolumeInfo(volumeStruct.number, records);
313             return volumeInfo;
314         }
315     }
316
317     internal static class CallClassConversions
318     {
319         internal static CallInformationStruct ConvertCallInformationToStruct(CallInformation info)
320         {
321             CallInformationStruct callInfoStruct = new CallInformationStruct();
322             callInfoStruct.Type = info.Type;
323             callInfoStruct.EType = info.EType;
324             callInfoStruct.PhoneNumber = info.PhoneNumber;
325             return callInfoStruct;
326         }
327
328         internal static CallBurstDtmfStruct ConvertCallBurstToStruct(CallBurstDtmfData data)
329         {
330             CallBurstDtmfStruct callBurstStruct = new CallBurstDtmfStruct();
331             callBurstStruct.Dtmf = data.Dtmf;
332             callBurstStruct.Width = data.Width;
333             callBurstStruct.Interval = data.Interval;
334             return callBurstStruct;
335         }
336
337         internal static CallDeflectDestStruct ConvertByteDestinationToStruct(byte[] number)
338         {
339             CallDeflectDestStruct callDeflectStruct = new CallDeflectDestStruct();
340             callDeflectStruct.DestinationNumber = Marshal.AllocHGlobal(83);
341             Marshal.Copy(number, 0, callDeflectStruct.DestinationNumber, Math.Min(83, number.Length));
342             return callDeflectStruct;
343         }
344
345         internal static CallVolumeRecordStruct ConvertVolumeRecordToStruct(CallVolumeRecord record)
346         {
347             CallVolumeRecordStruct volumeStruct = new CallVolumeRecordStruct();
348             volumeStruct.Device = record.Device;
349             volumeStruct.Type = record.Type;
350             volumeStruct.Volume = record.Volume;
351             return volumeStruct;
352         }
353
354         internal static CallSoundPathStruct ConvertSoundPathToStruct(CallSoundPathInfo info)
355         {
356             CallSoundPathStruct pathStruct = new CallSoundPathStruct();
357             pathStruct.Path = info.Path;
358             pathStruct.ExVolume = info.ExVolume;
359             return pathStruct;
360         }
361     }
362 }