Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / PhonebookStructs.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.Runtime.InteropServices;
18 using System.Text;
19 using System.Collections.Generic;
20
21 namespace Tizen.Tapi
22 {
23     [StructLayout(LayoutKind.Sequential)]
24     internal struct PhonebookRecordStruct
25     {
26         internal PhonebookType Type;
27         internal ushort Index;
28         internal ushort NextIndex;
29         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
30         internal string Name;
31         internal TextEncryptionType Dcs;
32         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
33         internal string Number;
34         internal SimTypeOfNumber Ton;
35         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
36         internal string Sne;
37         internal TextEncryptionType SneDcs;
38         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
39         internal string Anr1;
40         internal SimTypeOfNumber Anr1Ton;
41         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
42         internal string Anr2;
43         internal SimTypeOfNumber Anr2Ton;
44         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
45         internal string Anr3;
46         internal SimTypeOfNumber Anr3Ton;
47         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
48         internal string Email1;
49         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
50         internal string Email2;
51         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
52         internal string Email3;
53         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
54         internal string Email4;
55         internal ushort GroupIndex;
56         internal ushort PbControl;
57     }
58
59     [StructLayout(LayoutKind.Sequential)]
60     internal struct SimPhonebookListStruct
61     {
62         internal int Fdn;
63         internal int Adn;
64         internal int Sdn;
65         internal int Usim;
66         internal int Aas;
67         internal int Gas;
68     }
69
70     [StructLayout(LayoutKind.Sequential)]
71     internal struct SimPhonebookStatusStruct
72     {
73         internal int IsInitCompleted;
74         internal SimPhonebookListStruct PbList;
75     }
76
77     [StructLayout(LayoutKind.Sequential)]
78     internal struct PhonebookContactChangeInfoStruct
79     {
80         internal PhonebookType Type;
81         internal ushort Index;
82         internal PhonebookOperationType Operation;
83     }
84
85     [StructLayout(LayoutKind.Sequential)]
86     internal struct PhonebookStorageInfoStruct
87     {
88         internal PhonebookType Type;
89         internal ushort TotalRecord;
90         internal ushort UsedRecord;
91     }
92
93     [StructLayout(LayoutKind.Sequential)]
94     internal struct PhonebookMetaInfoStruct
95     {
96         internal PhonebookType Type;
97         internal ushort MinIndex;
98         internal ushort MaxIndex;
99         internal ushort NumMaxLength;
100         internal ushort TextMaxLength;
101         internal ushort UsedCount;
102     }
103
104     [StructLayout(LayoutKind.Sequential)]
105     internal struct FileTypeCapabilityInfo3GStruct
106     {
107         internal PhonebookFileType3G FileType;
108         internal ushort MaxIndex;
109         internal ushort MaxTextLen;
110         internal ushort UsedCount;
111     }
112
113     [StructLayout(LayoutKind.Sequential)]
114     internal struct PhonebookMetaInfo3GStruct
115     {
116         internal ushort FileTypeCount;
117         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 13, ArraySubType = UnmanagedType.LPStruct)]
118         internal FileTypeCapabilityInfo3GStruct[] FileTypeInfo;
119     }
120
121     internal static class PhonebookStructConversions
122     {
123         internal static SimPhonebookList ConvertSimPhonebookListStruct(SimPhonebookListStruct listStruct)
124         {
125             SimPhonebookList list = new SimPhonebookList();
126             list.PbFdn = listStruct.Fdn;
127             list.PbAdn = listStruct.Adn;
128             list.PbSdn = listStruct.Sdn;
129             list.PbUsim = listStruct.Usim;
130             list.PbAas = listStruct.Aas;
131             list.PbGas = listStruct.Gas;
132             return list;
133         }
134
135         internal static SimPhonebookStatus ConvertSimPhonebookStatusStruct(SimPhonebookStatusStruct statusStruct)
136         {
137             SimPhonebookStatus status = new SimPhonebookStatus();
138             if (statusStruct.IsInitCompleted == 1)
139             {
140                 status.InitStatus = true;
141             }
142
143             else if (statusStruct.IsInitCompleted == 0)
144             {
145                 status.InitStatus = false;
146             }
147
148             status.List = ConvertSimPhonebookListStruct(statusStruct.PbList);
149             return status;
150         }
151
152         internal static PhonebookStorageInfo ConvertPhonebookStorageStruct(PhonebookStorageInfoStruct storageStruct)
153         {
154             PhonebookStorageInfo storageInfo = new PhonebookStorageInfo();
155             storageInfo.PbType = storageStruct.Type;
156             storageInfo.PbTotalRecord = storageStruct.TotalRecord;
157             storageInfo.PbUsedRecord = storageStruct.UsedRecord;
158             return storageInfo;
159         }
160
161         internal static PhonebookMetaInfo ConvertPhonebookMetaInfoStruct(PhonebookMetaInfoStruct metaStruct)
162         {
163             PhonebookMetaInfo info = new PhonebookMetaInfo();
164             info.MetaType = metaStruct.Type;
165             info.MinIdx = metaStruct.MinIndex;
166             info.MaxIdx = metaStruct.MaxIndex;
167             info.NumMaxLength = metaStruct.NumMaxLength;
168             info.TextMaxLen = metaStruct.TextMaxLength;
169             info.UsedRecCount = metaStruct.UsedCount;
170             return info;
171         }
172
173         internal static FileTypeCapabilityInfo3G ConvertFileTypeCapabilityInfo3GStruct(FileTypeCapabilityInfo3GStruct infoStruct)
174         {
175             FileTypeCapabilityInfo3G info = new FileTypeCapabilityInfo3G();
176             info.Type = infoStruct.FileType;
177             info.MaxIdx = infoStruct.MaxIndex;
178             info.TextMaxLen = infoStruct.MaxTextLen;
179             info.UsedRecCount = infoStruct.UsedCount;
180             return info;
181         }
182
183         internal static PhonebookMetaInfo3G ConvertPhonebookMetaInfo3GStruct(PhonebookMetaInfo3GStruct infoStruct)
184         {
185             PhonebookMetaInfo3G info = new PhonebookMetaInfo3G();
186             info.FileCount = infoStruct.FileTypeCount;
187             List<FileTypeCapabilityInfo3G> capabilityList = new List<FileTypeCapabilityInfo3G>();
188             foreach (FileTypeCapabilityInfo3GStruct capabilityInfo in infoStruct.FileTypeInfo)
189             {
190                 capabilityList.Add(ConvertFileTypeCapabilityInfo3GStruct(capabilityInfo));
191             }
192
193             info.FileInfo = capabilityList;
194             return info;
195         }
196
197         internal static PhonebookContactChangeInfo ConvertPhonebookContactChangeStruct(PhonebookContactChangeInfoStruct infoStruct)
198         {
199             PhonebookContactChangeInfo info = new PhonebookContactChangeInfo();
200             info.PbType = infoStruct.Type;
201             info.ChangedIndex = infoStruct.Index;
202             info.OpType = infoStruct.Operation;
203             return info;
204         }
205
206         internal static PhonebookRecord ConvertPhonebookRecordStruct(PhonebookRecordStruct recordStruct)
207         {
208             PhonebookRecord record = new PhonebookRecord();
209             record.Type = recordStruct.Type;
210             record.Index = recordStruct.Index;
211             record.NextIndex = recordStruct.NextIndex;
212             record.Name = recordStruct.Name;
213             record.Dcs = recordStruct.Dcs;
214             record.Number = recordStruct.Number;
215             record.Ton = recordStruct.Ton;
216             record.Sne = recordStruct.Sne;
217             record.SneDcs = recordStruct.SneDcs;
218             record.Anr1 = recordStruct.Anr1;
219             record.Anr1Ton = recordStruct.Anr1Ton;
220             record.Anr2 = recordStruct.Anr2;
221             record.Anr2Ton = recordStruct.Anr2Ton;
222             record.Anr3 = recordStruct.Anr3;
223             record.Anr3Ton = recordStruct.Anr3Ton;
224             record.Email1 = recordStruct.Email1;
225             record.Email2 = recordStruct.Email2;
226             record.Email3 = recordStruct.Email3;
227             record.Email4 = recordStruct.Email4;
228             record.GroupIndex = recordStruct.GroupIndex;
229             record.PbControl = recordStruct.PbControl;
230             return record;
231         }
232     }
233
234     internal static class PhonebookClassConversions
235     {
236         internal static PhonebookRecordStruct ConvertPhonebookrecord(PhonebookRecord record)
237         {
238             PhonebookRecordStruct recordStruct = new PhonebookRecordStruct();
239             recordStruct.Type = record.Type;
240             recordStruct.Index = record.Index;
241             recordStruct.NextIndex = record.NextIndex;
242             recordStruct.Name = record.Name;
243             recordStruct.Dcs = record.Dcs;
244             recordStruct.Number = record.Number;
245             recordStruct.Ton = record.Ton;
246             recordStruct.Sne = record.Sne;
247             recordStruct.SneDcs = record.SneDcs;
248             recordStruct.Anr1 = record.Anr1;
249             recordStruct.Anr1Ton = record.Anr1Ton;
250             recordStruct.Anr2 = record.Anr2;
251             recordStruct.Anr2Ton = record.Anr2Ton;
252             recordStruct.Anr3 = record.Anr3;
253             recordStruct.Anr3Ton = record.Anr3Ton;
254             recordStruct.Email1 = record.Email1;
255             recordStruct.Email2 = record.Email2;
256             recordStruct.Email3 = record.Email3;
257             recordStruct.Email4 = record.Email4;
258             recordStruct.GroupIndex = record.GroupIndex;
259             recordStruct.PbControl = record.PbControl;
260             return recordStruct;
261         }
262     }
263 }