Fixed issues, Modified spec to use xbuild, doxygen comments
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / Attributes.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9 using System;
10 using System.Collections;
11 using System.Collections.Generic;
12 using System.Runtime.InteropServices;
13
14 namespace Tizen.Network.IoTConnectivity
15 {
16     /// <summary>
17     /// This class represents current attributes of a resource.
18     /// </summary>
19     public class Attributes : IDictionary<string, object>, IDisposable
20     {
21         internal IntPtr _resourceAttributesHandle = IntPtr.Zero;
22         private readonly IDictionary<string, object> _attributes = new Dictionary<string, object>();
23         private bool _disposed = false;
24
25         /// <summary>
26         /// Constructor
27         /// </summary>
28         public Attributes()
29         {
30             int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle);
31             if (ret != (int)IoTConnectivityError.None)
32             {
33                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
34                 throw IoTConnectivityErrorFactory.GetException(ret);
35             }
36         }
37
38         internal Attributes(IntPtr attributesHandleToClone)
39         {
40             int ret = Interop.IoTConnectivity.Common.Attributes.Clone(attributesHandleToClone, out _resourceAttributesHandle);
41             if (ret != (int)IoTConnectivityError.None)
42             {
43                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
44                 throw IoTConnectivityErrorFactory.GetException(ret);
45             }
46
47             SetAttributes(attributesHandleToClone);
48         }
49
50         ~Attributes()
51         {
52             Dispose(false);
53         }
54
55         /// <summary>
56         /// Gets the number of status elements
57         /// </summary>
58         public int Count
59         {
60             get
61             {
62                 return _attributes.Count;
63             }
64         }
65
66         /// <summary>
67         /// Represents whether Attributes is readonly
68         /// </summary>
69         public bool IsReadOnly
70         {
71             get
72             {
73                 return _attributes.IsReadOnly;
74             }
75         }
76
77         /// <summary>
78         /// Contains all the status keys
79         /// </summary>
80         public ICollection<string> Keys
81         {
82             get
83             {
84                 return _attributes.Keys;
85             }
86         }
87
88         /// <summary>
89         /// Contains all the status values
90         /// </summary>
91         public ICollection<object> Values
92         {
93             get
94             {
95                 return _attributes.Values;
96             }
97         }
98
99         /// <summary>
100         /// Gets or sets the status with the specified key.
101         /// </summary>
102         /// <param name="key">The key of the status to get or set.</param>
103         /// <returns>The element with the specified key.</returns>
104         public object this[string key]
105         {
106             get
107             {
108                 return _attributes[key];
109             }
110
111             set
112             {
113                 Add(key, value);
114             }
115         }
116
117         /// <summary>
118         /// Adds status key and value as a key value pair
119         /// </summary>
120         /// <param name="item">The item to add</param>
121         public void Add(KeyValuePair<string, object> item)
122         {
123             Add(item.Key, item.Value);
124         }
125
126         /// <summary>
127         /// Adds status element
128         /// </summary>
129         /// <param name="key">The key representing the attributes</param>
130         /// <param name="value">The value representing the attributes</param>
131         public void Add(string key, object value)
132         {
133             int ret = 0;
134             if (value is int)
135             {
136                 ret = Interop.IoTConnectivity.Common.Attributes.AddInt(_resourceAttributesHandle, key, (int)value);
137                 if (ret != (int)IoTConnectivityError.None)
138                 {
139                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add int");
140                     throw IoTConnectivityErrorFactory.GetException(ret);
141                 }
142             }
143             else if (value is Attributes)
144             {
145                 Attributes attribs = (Attributes)value;
146                 ret = Interop.IoTConnectivity.Common.Attributes.AddAttributes(_resourceAttributesHandle, key, attribs._resourceAttributesHandle);
147                 if (ret != (int)IoTConnectivityError.None)
148                 {
149                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
150                     throw IoTConnectivityErrorFactory.GetException(ret);
151                 }
152             }
153             else if (value is string)
154             {
155                 ret = Interop.IoTConnectivity.Common.Attributes.AddStr(_resourceAttributesHandle, key, (string)value);
156                 if (ret != (int)IoTConnectivityError.None)
157                 {
158                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add string");
159                     throw IoTConnectivityErrorFactory.GetException(ret);
160                 }
161             }
162             else if (value is double)
163             {
164                 ret = Interop.IoTConnectivity.Common.Attributes.AddDouble(_resourceAttributesHandle, key, (double)value);
165                 if (ret != (int)IoTConnectivityError.None)
166                 {
167                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
168                     throw IoTConnectivityErrorFactory.GetException(ret);
169                 }
170             }
171             else if (value is bool)
172             {
173                 ret = Interop.IoTConnectivity.Common.Attributes.AddBool(_resourceAttributesHandle, key, (bool)value);
174                 if (ret != (int)IoTConnectivityError.None)
175                 {
176                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
177                     throw IoTConnectivityErrorFactory.GetException(ret);
178                 }
179             }
180             else if (value is byte[])
181             {
182                 byte[] val = value as byte[];
183                 if (val == null)
184                 {
185                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get byte[] val");
186                     throw new ArgumentException("Invalid Parameter");
187                 }
188                 ret = Interop.IoTConnectivity.Common.Attributes.AddByteStr(_resourceAttributesHandle, key, val, val.Length);
189                 if (ret != (int)IoTConnectivityError.None)
190                 {
191                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
192                     throw IoTConnectivityErrorFactory.GetException(ret);
193                 }
194             }
195             else if (value is IEnumerable)
196             {
197                 IntPtr listHandle = List.GetListHandle(value);
198                 ret = Interop.IoTConnectivity.Common.Attributes.AddList(_resourceAttributesHandle, key, listHandle);
199                 if (ret != (int)IoTConnectivityError.None)
200                 {
201                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add list");
202                     throw IoTConnectivityErrorFactory.GetException(ret);
203                 }
204             }
205             else
206             {
207                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Add");
208                 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
209             }
210             _attributes.Add(key, value);
211         }
212
213         /// <summary>
214         /// Clears attributes collection
215         /// </summary>
216         public void Clear()
217         {
218             foreach (string key in _attributes.Keys)
219             {
220                 int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
221                 if (ret != (int)IoTConnectivityError.None)
222                 {
223                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear attributes");
224                     throw IoTConnectivityErrorFactory.GetException(ret);
225                 }
226             }
227             _attributes.Clear();
228         }
229
230         /// <summary>
231         /// Checks the given key value pair exists in attributes collection
232         /// </summary>
233         /// <param name="item">The status key value pair</param>
234         /// <returns>true if exists. Otherwise, false</returns>
235         public bool Contains(KeyValuePair<string, object> item)
236         {
237             return _attributes.Contains(item);
238         }
239
240         /// <summary>
241         /// Checks the given key exists in attributes collection
242         /// </summary>
243         /// <param name="key">The status key</param>
244         /// <returns>true if exists. Otherwise, false</returns>
245         public bool ContainsKey(string key)
246         {
247             return _attributes.ContainsKey(key);
248         }
249
250         /// <summary>
251         /// Copies the elements of the attributes to an Array, starting at a particular index.
252         /// </summary>
253         /// <param name="array">The destination array</param>
254         /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
255         public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
256         {
257             _attributes.CopyTo(array, arrayIndex);
258         }
259
260         /// <summary>
261         ///   Returns an enumerator that iterates through the collection.
262         /// </summary>
263         /// <returns> An enumerator that can be used to iterate through the collection.</returns>
264         public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
265         {
266             return _attributes.GetEnumerator();
267         }
268
269         /// <summary>
270         /// Removes a attributes element from collection
271         /// </summary>
272         /// <param name="item">The attributes element to remove</param>
273         /// <returns>true if operation is success. Otherwise, false</returns>
274         public bool Remove(KeyValuePair<string, object> item)
275         {
276             int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, item.Key);
277             if (ret != (int)IoTConnectivityError.None)
278             {
279                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
280                 throw IoTConnectivityErrorFactory.GetException(ret);
281             }
282
283             return _attributes.Remove(item);
284         }
285
286         /// <summary>
287         ///  Removes a attributes element from collection using key
288         /// </summary>
289         /// <param name="key">The attributes element to remove</param>
290         /// <returns>true if operation is success. Otherwise, false</returns>
291         public bool Remove(string key)
292         {
293             int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
294             if (ret != (int)IoTConnectivityError.None)
295             {
296                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
297                 throw IoTConnectivityErrorFactory.GetException(ret);
298             }
299
300             return _attributes.Remove(key);
301         }
302
303         /// <summary>
304         /// Gets the value associated with the specified key.
305         /// </summary>
306         /// <param name="key">The key whose value to get.</param>
307         /// <param name="value"> The value associated with the specified key</param>
308         /// <returns> true if the attributes collection contains an element with the specified key; otherwise, false.</returns>
309         public bool TryGetValue(string key, out object value)
310         {
311             return _attributes.TryGetValue(key, out value);
312         }
313
314         IEnumerator IEnumerable.GetEnumerator()
315         {
316             return _attributes.GetEnumerator();
317         }
318
319         public void Dispose()
320         {
321             Dispose(true);
322             GC.SuppressFinalize(this);
323         }
324
325         protected virtual void Dispose(bool disposing)
326         {
327             if (_disposed)
328                 return;
329
330             if (disposing)
331             {
332                 // Free managed objects
333             }
334
335             Interop.IoTConnectivity.Common.Attributes.Destroy(_resourceAttributesHandle);
336             _disposed = true;
337         }
338
339         private void SetAttributes(IntPtr attributesHandle)
340         {
341             Interop.IoTConnectivity.Common.Attributes.AttributesCallback cb = (IntPtr attributes, string key, IntPtr userData) =>
342             {
343                 Interop.IoTConnectivity.Common.DataType dataType;
344                 int ret = Interop.IoTConnectivity.Common.Attributes.GetType(attributes, key, out dataType);
345                 if (ret != (int)IoTConnectivityError.None)
346                 {
347                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
348                     throw IoTConnectivityErrorFactory.GetException(ret);
349                 }
350
351                 switch ((Interop.IoTConnectivity.Common.DataType)dataType)
352                 {
353                     case Interop.IoTConnectivity.Common.DataType.Int:
354                         {
355                             int value;
356                             ret = Interop.IoTConnectivity.Common.Attributes.GetInt(attributes, key, out value);
357                             if (ret != (int)IoTConnectivityError.None)
358                             {
359                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
360                                 throw IoTConnectivityErrorFactory.GetException(ret);
361                             }
362                             Add(key, value);
363                             break;
364                         }
365                     case Interop.IoTConnectivity.Common.DataType.Bool:
366                         {
367                             bool value;
368                             ret = Interop.IoTConnectivity.Common.Attributes.GetBool(attributes, key, out value);
369                             if (ret != (int)IoTConnectivityError.None)
370                             {
371                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
372                                 throw IoTConnectivityErrorFactory.GetException(ret);
373                             }
374                             Add(key, value);
375                             break;
376                         }
377                     case Interop.IoTConnectivity.Common.DataType.Double:
378                         {
379                             double value;
380                             ret = Interop.IoTConnectivity.Common.Attributes.GetDouble(attributes, key, out value);
381                             if (ret != (int)IoTConnectivityError.None)
382                             {
383                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
384                                 throw IoTConnectivityErrorFactory.GetException(ret);
385                             }
386                             Add(key, value);
387                             break;
388                         }
389                     case Interop.IoTConnectivity.Common.DataType.String:
390                         {
391                             string value;
392                             ret = Interop.IoTConnectivity.Common.Attributes.GetStr(attributes, key, out value);
393                             if (ret != (int)IoTConnectivityError.None)
394                             {
395                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
396                                 throw IoTConnectivityErrorFactory.GetException(ret);
397                             }
398                             Add(key, value);
399                             break;
400                         }
401                     case Interop.IoTConnectivity.Common.DataType.ByteStr:
402                         {
403                             IntPtr byteStrPtr;
404                             int byteStrSize;
405                             ret = Interop.IoTConnectivity.Common.Attributes.GetByteStr(attributes, key, out byteStrPtr, out byteStrSize);
406                             if (ret != (int)IoTConnectivityError.None)
407                             {
408                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
409                                 throw IoTConnectivityErrorFactory.GetException(ret);
410                             }
411                             byte[] byteStr = new byte[byteStrSize];
412                             Marshal.Copy(byteStrPtr, byteStr, 0, byteStrSize);
413                             Add(key, byteStr);
414                             break;
415                         }
416                     case Interop.IoTConnectivity.Common.DataType.Null:
417                         {
418                             Add(key, null);
419                             break;
420                         }
421                     case Interop.IoTConnectivity.Common.DataType.List:
422                         {
423                             IntPtr listHandle;
424                             ret = Interop.IoTConnectivity.Common.Attributes.GetList(attributes, key, out listHandle);
425                             if (ret != (int)IoTConnectivityError.None)
426                             {
427                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
428                                 throw IoTConnectivityErrorFactory.GetException(ret);
429                             }
430                             Add(key, List.GetList(listHandle));
431                             break;
432                         }
433                     case Interop.IoTConnectivity.Common.DataType.Attributes:
434                         {
435                             IntPtr attribsHandle;
436                             ret = Interop.IoTConnectivity.Common.Attributes.GetAttributes(attributes, key, out attribsHandle);
437                             if (ret != (int)IoTConnectivityError.None)
438                             {
439                                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
440                                 throw IoTConnectivityErrorFactory.GetException(ret);
441                             }
442                             Add(key, new Attributes(attribsHandle));
443                             break;
444                         }
445                     default:
446                         break;
447                 }
448
449                 return true;
450             };
451
452             int res = Interop.IoTConnectivity.Common.Attributes.Foreach(attributesHandle, cb, IntPtr.Zero);
453             if (res != (int)IoTConnectivityError.None)
454             {
455                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
456                 throw IoTConnectivityErrorFactory.GetException(res);
457             }
458         }
459     }
460
461     internal static class List
462     {
463         internal static IntPtr GetListHandle(object list)
464         {
465             IntPtr listHandle = IntPtr.Zero;
466             int ret;
467             int pos = 0;
468
469             if (list is IEnumerable<IEnumerable>)
470             {
471                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.List, out listHandle);
472                 pos = 0;
473                 foreach (IEnumerable val in (IEnumerable<IEnumerable>)list)
474                 {
475                     IntPtr childList = GetListHandle(val);
476                     ret = Interop.IoTConnectivity.Common.List.AddList(listHandle, childList, pos++);
477                     if (ret != (int)IoTConnectivityError.None)
478                     {
479                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
480                         Interop.IoTConnectivity.Common.List.Destroy(childList);
481                         throw IoTConnectivityErrorFactory.GetException(ret);
482                     }
483                 }
484             }
485             else if (list is IEnumerable<int>)
486             {
487                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Int, out listHandle);
488                 pos = 0;
489                 foreach (int val in (IEnumerable<int>)list)
490                 {
491                     ret = Interop.IoTConnectivity.Common.List.AddInt(listHandle, val, pos++);
492                     if (ret != (int)IoTConnectivityError.None)
493                     {
494                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
495                         throw IoTConnectivityErrorFactory.GetException(ret);
496                     }
497                 }
498             }
499             else if (list is IEnumerable<string>)
500             {
501                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.String, out listHandle);
502                 pos = 0;
503                 foreach (string val in (IEnumerable<string>)list)
504                 {
505                     ret = Interop.IoTConnectivity.Common.List.AddStr(listHandle, val, pos++);
506                     if (ret != (int)IoTConnectivityError.None)
507                     {
508                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add str");
509                         throw IoTConnectivityErrorFactory.GetException(ret);
510                     }
511                 }
512             }
513             else if (list is IEnumerable<double>)
514             {
515                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Double, out listHandle);
516                 pos = 0;
517                 foreach (double val in (IEnumerable<double>)list)
518                 {
519                     ret = Interop.IoTConnectivity.Common.List.AddDouble(listHandle, val, pos++);
520                     if (ret != (int)IoTConnectivityError.None)
521                     {
522                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
523                         throw IoTConnectivityErrorFactory.GetException(ret);
524                     }
525                 }
526             }
527             else if (list is IEnumerable<bool>)
528             {
529                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Bool, out listHandle);
530                 pos = 0;
531                 foreach (bool val in (IEnumerable<bool>)list)
532                 {
533                     ret = Interop.IoTConnectivity.Common.List.AddBool(listHandle, val, pos++);
534                     if (ret != (int)IoTConnectivityError.None)
535                     {
536                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
537                         throw IoTConnectivityErrorFactory.GetException(ret);
538                     }
539                 }
540             }
541             else if (list is IEnumerable<Attributes>)
542             {
543                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Attributes, out listHandle);
544                 pos = 0;
545                 foreach (Attributes val in (IEnumerable<Attributes>)list)
546                 {
547                     ret = Interop.IoTConnectivity.Common.List.AddAttributes(listHandle, val._resourceAttributesHandle, pos++);
548                     if (ret != (int)IoTConnectivityError.None)
549                     {
550                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
551                         throw IoTConnectivityErrorFactory.GetException(ret);
552                     }
553                 }
554             }
555             else if (list is IEnumerable<byte[]>)
556             {
557                 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.ByteStr, out listHandle);
558                 pos = 0;
559                 foreach (byte[] val in (IEnumerable<byte[]>)list)
560                 {
561                     ret = Interop.IoTConnectivity.Common.List.AddByteStr(listHandle, val, val.Length, pos++);
562                     if (ret != (int)IoTConnectivityError.None)
563                     {
564                         Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add byte[]");
565                         throw IoTConnectivityErrorFactory.GetException(ret);
566                     }
567                 }
568             }
569             else
570             {
571                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to GetListHandle");
572                 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
573             }
574             return listHandle;
575         }
576
577         internal static object GetList(IntPtr listHandle)
578         {
579             IList list = null;
580             int type;
581             int ret = Interop.IoTConnectivity.Common.List.GetType(listHandle, out type);
582             if (ret != (int)IoTConnectivityError.None)
583             {
584                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
585                 throw IoTConnectivityErrorFactory.GetException(ret);
586             }
587             switch ((Interop.IoTConnectivity.Common.DataType)type)
588             {
589                 case Interop.IoTConnectivity.Common.DataType.Int:
590                     {
591                         list = new List<int>();
592                         Interop.IoTConnectivity.Common.List.IntCallback cb = (int pos, int value, IntPtr userData) =>
593                         {
594                             list.Add(value);
595                             return true;
596                         };
597                         ret = Interop.IoTConnectivity.Common.List.ForeachInt(listHandle, cb, IntPtr.Zero);
598                         break;
599                     }
600                 case Interop.IoTConnectivity.Common.DataType.Bool:
601                     {
602                         list = new List<bool>();
603                         Interop.IoTConnectivity.Common.List.BoolCallback cb = (int pos, bool value, IntPtr userData) =>
604                         {
605                             list.Add(value);
606                             return true;
607                         };
608                         ret = Interop.IoTConnectivity.Common.List.ForeachBool(listHandle, cb, IntPtr.Zero);
609                         break;
610                     }
611                 case Interop.IoTConnectivity.Common.DataType.Double:
612                     {
613                         list = new List<double>();
614                         Interop.IoTConnectivity.Common.List.DoubleCallback cb = (int pos, double value, IntPtr userData) =>
615                         {
616                             list.Add(value);
617                             return true;
618                         };
619                         ret = Interop.IoTConnectivity.Common.List.ForeachDouble(listHandle, cb, IntPtr.Zero);
620                         break;
621                     }
622                 case Interop.IoTConnectivity.Common.DataType.String:
623                     {
624                         list = new List<string>();
625                         Interop.IoTConnectivity.Common.List.StrCallback cb = (int pos, string value, IntPtr userData) =>
626                         {
627                             list.Add(value);
628                             return true;
629                         };
630                         ret = Interop.IoTConnectivity.Common.List.ForeachStr(listHandle, cb, IntPtr.Zero);
631                         break;
632                     }
633                 case Interop.IoTConnectivity.Common.DataType.Attributes:
634                     {
635                         list = new List<Attributes>();
636                         Interop.IoTConnectivity.Common.List.AttribsCallback cb = (int pos, IntPtr value, IntPtr userData) =>
637                         {
638                             list.Add(new Attributes(value));
639                             return true;
640                         };
641                         ret = Interop.IoTConnectivity.Common.List.ForeachAttributes(listHandle, cb, IntPtr.Zero);
642                         break;
643                     }
644                 case Interop.IoTConnectivity.Common.DataType.ByteStr:
645                     {
646                         list = new List<byte[]>();
647                         Interop.IoTConnectivity.Common.List.ByteStrCallback cb = (int pos, byte[] value, int len, IntPtr userData) =>
648                         {
649                             list.Add(value);
650                             return true;
651                         };
652                         ret = Interop.IoTConnectivity.Common.List.ForeachByteStr(listHandle, cb, IntPtr.Zero);
653                         break;
654                     }
655                 case Interop.IoTConnectivity.Common.DataType.List:
656                     {
657                         list = new List<List<object>>();
658                         Interop.IoTConnectivity.Common.List.ListCallback cb = (int pos, IntPtr value, IntPtr userData) =>
659                         {
660                             object childList = GetList(value);
661                             list.Add(childList);
662                             return true;
663                         };
664                         ret = Interop.IoTConnectivity.Common.List.ForeachList(listHandle, cb, IntPtr.Zero);
665                         break;
666                     }
667                 default:
668                     break;
669             }
670             if (ret != (int)IoTConnectivityError.None)
671             {
672                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
673                 throw IoTConnectivityErrorFactory.GetException(ret);
674             }
675             return list;
676         }
677     }
678 }