1 /// Copyright 2016 by Samsung Electronics, Inc.,
4 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 using System.Collections;
22 using System.Collections.Generic;
23 using System.Runtime.InteropServices;
25 namespace Tizen.Network.IoTConnectivity
28 /// This class represents current attributes of a resource.
29 /// It provides API to manage attributes.
30 /// This class is accessed by using a constructor to create a new instance of this object.
32 public class Attributes : IDictionary<string, object>, IDisposable
34 internal IntPtr _resourceAttributesHandle = IntPtr.Zero;
35 private readonly IDictionary<string, object> _attributes = new Dictionary<string, object>();
36 private bool _disposed = false;
39 /// The Attributes constructor
41 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
42 /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory</exception>
44 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
48 int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle);
49 if (ret != (int)IoTConnectivityError.None)
51 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
52 throw IoTConnectivityErrorFactory.GetException(ret);
56 internal Attributes(IntPtr attributesHandleToClone)
58 int ret = Interop.IoTConnectivity.Common.Attributes.Clone(attributesHandleToClone, out _resourceAttributesHandle);
59 if (ret != (int)IoTConnectivityError.None)
61 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
62 throw IoTConnectivityErrorFactory.GetException(ret);
65 SetAttributes(_resourceAttributesHandle);
69 /// Destructor of the Attributes class.
77 /// Gets the number of keys
80 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
81 /// attributes.Add("brightness", 50);
82 /// var count = attributes.Count;
83 /// Console.WriteLine("There are {0} keys in the attribute object", count);
89 return _attributes.Count;
94 /// Represents whether attribute is readonly
97 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
98 /// { "state", "ON" },
101 /// if (attributes.IsReadOnly)
102 /// Console.WriteLine("Read only attribute");
104 public bool IsReadOnly
108 return _attributes.IsReadOnly;
113 /// Contains all the attribute keys
116 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
117 /// { "state", "ON" },
120 /// var keys = attributes.Keys;
121 /// Console.WriteLine("Attribute contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
123 public ICollection<string> Keys
127 return _attributes.Keys;
132 /// Contains all the attribute values
135 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
136 /// { "state", "ON" },
139 /// var values = attributes.Values;
140 /// Console.WriteLine("Attribute contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
142 public ICollection<object> Values
146 return _attributes.Values;
151 /// Gets or sets the attribute with the specified key.
153 /// <param name="key">The key of the attribute to get or set.</param>
154 /// <returns>The element with the specified key.</returns>
156 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
157 /// attributes["state"] = "ON";
158 /// Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]);
160 public object this[string key]
164 if (_attributes.ContainsKey(key))
165 return _attributes[key];
177 /// Adds attribute key and value as a key value pair
179 /// <param name="item">The key value pair to add</param>
181 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
182 /// attributes.Add(new KeyValuePair<string, object> ("state", "ON"));
184 public void Add(KeyValuePair<string, object> item)
186 Add(item.Key, item.Value);
190 /// Adds an attribute
192 /// <param name="key">The key representing the attribute</param>
193 /// <param name="value">The value representing the attribute</param>
195 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
196 /// attributes.Add("brightness", 50);
198 public void Add(string key, object value)
203 ret = Interop.IoTConnectivity.Common.Attributes.AddInt(_resourceAttributesHandle, key, (int)value);
204 if (ret != (int)IoTConnectivityError.None)
206 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add int");
207 throw IoTConnectivityErrorFactory.GetException(ret);
210 else if (value is Attributes)
212 Attributes attribs = (Attributes)value;
213 ret = Interop.IoTConnectivity.Common.Attributes.AddAttributes(_resourceAttributesHandle, key, attribs._resourceAttributesHandle);
214 if (ret != (int)IoTConnectivityError.None)
216 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
217 throw IoTConnectivityErrorFactory.GetException(ret);
220 else if (value is string)
222 ret = Interop.IoTConnectivity.Common.Attributes.AddStr(_resourceAttributesHandle, key, (string)value);
223 if (ret != (int)IoTConnectivityError.None)
225 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add string");
226 throw IoTConnectivityErrorFactory.GetException(ret);
229 else if (value is double)
231 ret = Interop.IoTConnectivity.Common.Attributes.AddDouble(_resourceAttributesHandle, key, (double)value);
232 if (ret != (int)IoTConnectivityError.None)
234 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
235 throw IoTConnectivityErrorFactory.GetException(ret);
238 else if (value is bool)
240 ret = Interop.IoTConnectivity.Common.Attributes.AddBool(_resourceAttributesHandle, key, (bool)value);
241 if (ret != (int)IoTConnectivityError.None)
243 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
244 throw IoTConnectivityErrorFactory.GetException(ret);
247 else if (value is byte[])
249 byte[] val = value as byte[];
252 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get byte[] val");
253 throw new ArgumentException("Invalid Parameter");
255 ret = Interop.IoTConnectivity.Common.Attributes.AddByteStr(_resourceAttributesHandle, key, val, val.Length);
256 if (ret != (int)IoTConnectivityError.None)
258 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
259 throw IoTConnectivityErrorFactory.GetException(ret);
262 else if (value is IEnumerable)
264 IntPtr listHandle = List.GetListHandle(value);
265 ret = Interop.IoTConnectivity.Common.Attributes.AddList(_resourceAttributesHandle, key, listHandle);
266 if (ret != (int)IoTConnectivityError.None)
268 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add list");
269 throw IoTConnectivityErrorFactory.GetException(ret);
274 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Add");
275 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
277 _attributes.Add(key, value);
281 /// Clears attributes collection
283 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
284 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
286 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
287 /// attributes.Add("brightness", 50);
288 /// attributes.Clear();
292 foreach (string key in _attributes.Keys)
294 int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
295 if (ret != (int)IoTConnectivityError.None)
297 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear attributes");
298 throw IoTConnectivityErrorFactory.GetException(ret);
305 /// Checks whether the given key value pair exists in attributes collection
307 /// <param name="item">The status key value pair</param>
308 /// <returns>true if exists. Otherwise, false</returns>
310 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
311 /// { "state", "ON" },
314 /// if (attributes.Contains(new KeyValuePair<string, object> ("dim", 10))
315 /// Console.WriteLine("Attribute conatins pair ('dim', 10)");
317 public bool Contains(KeyValuePair<string, object> item)
319 return _attributes.Contains(item);
323 /// Checks whether the given key exists in attributes collection
325 /// <param name="key">The status key to look for</param>
326 /// <returns>true if exists. Otherwise, false</returns>
328 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
329 /// { "state", "ON" },
332 /// if (attributes.ContainsKey("dim"))
333 /// Console.WriteLine("Attribute conatins key : dim");
335 public bool ContainsKey(string key)
337 return _attributes.ContainsKey(key);
341 /// Copies the elements of the attributes to an array, starting at a particular index.
343 /// <param name="array">The destination array</param>
344 /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
346 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
347 /// { "state", "ON" },
350 /// KeyValuePair<string, object>[] dest = new KeyValuePair<string, object>[attributes.Count];
352 /// attributes.CopyTo(dest, index);
353 /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
355 public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
357 _attributes.CopyTo(array, arrayIndex);
361 /// Returns an enumerator that iterates through the collection.
363 /// <returns> An enumerator that can be used to iterate through the collection.</returns>
365 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
366 /// { "state", "ON" },
369 /// foreach (KeyValuePair<string, object> pair in attributes)
371 /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
374 public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
376 return _attributes.GetEnumerator();
380 /// Removes an attribute from collection
382 /// <param name="item">The attributes element to remove</param>
383 /// <returns>true if operation is success. Otherwise, false</returns>
384 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
385 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
386 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
388 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
389 /// { "state", "ON" },
392 /// if (attributes.Remove(new KeyValuePair<string, object>("dim", 10)))
393 /// Console.WriteLine("Remove was successful");
395 public bool Remove(KeyValuePair<string, object> item)
397 return Remove(item.Key);
401 /// Removes an attribute from collection using key
403 /// <param name="key">The attributes element to remove</param>
404 /// <returns>true if operation is successful, Otherwise, false</returns>
405 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
406 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
407 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
409 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
410 /// { "state", "ON" },
413 /// if (attributes.Remove("state"))
414 /// Console.WriteLine("Remove was successful");
416 public bool Remove(string key)
418 int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
419 if (ret != (int)IoTConnectivityError.None)
421 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
422 throw IoTConnectivityErrorFactory.GetException(ret);
425 bool isRemoved = _attributes.Remove(key);
431 /// Gets the value associated with the specified key.
433 /// <param name="key">The key whose value to get.</param>
434 /// <param name="value"> The value associated with the specified key</param>
435 /// <returns> true if the attributes collection contains an element with the specified key; otherwise, false.</returns>
437 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
438 /// { "state", "ON" }
441 /// var isPresent = attributes.TryGetValue("state", out value);
443 /// Console.WriteLine("value : {0}", value);
445 public bool TryGetValue(string key, out object value)
447 return _attributes.TryGetValue(key, out value);
451 /// Returns an enumerator that iterates through the collection.
453 IEnumerator IEnumerable.GetEnumerator()
455 return _attributes.GetEnumerator();
459 /// Releases any unmanaged resources used by this object.
461 public void Dispose()
464 GC.SuppressFinalize(this);
468 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
470 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
471 protected virtual void Dispose(bool disposing)
478 // Free managed objects
481 Interop.IoTConnectivity.Common.Attributes.Destroy(_resourceAttributesHandle);
485 private void SetAttributes(IntPtr attributesHandle)
487 Interop.IoTConnectivity.Common.Attributes.AttributesCallback cb = (IntPtr attributes, string key, IntPtr userData) =>
489 Interop.IoTConnectivity.Common.DataType dataType;
490 int ret = Interop.IoTConnectivity.Common.Attributes.GetType(attributes, key, out dataType);
491 if (ret != (int)IoTConnectivityError.None)
493 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
494 throw IoTConnectivityErrorFactory.GetException(ret);
497 switch ((Interop.IoTConnectivity.Common.DataType)dataType)
499 case Interop.IoTConnectivity.Common.DataType.Int:
502 ret = Interop.IoTConnectivity.Common.Attributes.GetInt(attributes, key, out value);
503 if (ret != (int)IoTConnectivityError.None)
505 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
506 throw IoTConnectivityErrorFactory.GetException(ret);
508 _attributes.Add(key, value);
511 case Interop.IoTConnectivity.Common.DataType.Bool:
514 ret = Interop.IoTConnectivity.Common.Attributes.GetBool(attributes, key, out value);
515 if (ret != (int)IoTConnectivityError.None)
517 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
518 throw IoTConnectivityErrorFactory.GetException(ret);
520 _attributes.Add(key, value);
523 case Interop.IoTConnectivity.Common.DataType.Double:
526 ret = Interop.IoTConnectivity.Common.Attributes.GetDouble(attributes, key, out value);
527 if (ret != (int)IoTConnectivityError.None)
529 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
530 throw IoTConnectivityErrorFactory.GetException(ret);
532 _attributes.Add(key, value);
535 case Interop.IoTConnectivity.Common.DataType.String:
539 ret = Interop.IoTConnectivity.Common.Attributes.GetStr(attributes, key, out value);
540 if (ret != (int)IoTConnectivityError.None)
542 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
543 throw IoTConnectivityErrorFactory.GetException(ret);
545 Str = (value != IntPtr.Zero) ? Marshal.PtrToStringAnsi(value) : string.Empty;
546 _attributes.Add(key, Str);
549 case Interop.IoTConnectivity.Common.DataType.ByteStr:
553 ret = Interop.IoTConnectivity.Common.Attributes.GetByteStr(attributes, key, out byteStrPtr, out byteStrSize);
554 if (ret != (int)IoTConnectivityError.None)
556 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
557 throw IoTConnectivityErrorFactory.GetException(ret);
559 byte[] byteStr = new byte[byteStrSize];
560 Marshal.Copy(byteStrPtr, byteStr, 0, byteStrSize);
561 _attributes.Add(key, byteStr);
564 case Interop.IoTConnectivity.Common.DataType.Null:
566 _attributes.Add(key, null);
569 case Interop.IoTConnectivity.Common.DataType.List:
572 ret = Interop.IoTConnectivity.Common.Attributes.GetList(attributes, key, out listHandle);
573 if (ret != (int)IoTConnectivityError.None)
575 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
576 throw IoTConnectivityErrorFactory.GetException(ret);
578 _attributes.Add(key, List.GetList(listHandle));
581 case Interop.IoTConnectivity.Common.DataType.Attributes:
583 IntPtr attribsHandle;
584 ret = Interop.IoTConnectivity.Common.Attributes.GetAttributes(attributes, key, out attribsHandle);
585 if (ret != (int)IoTConnectivityError.None)
587 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
588 throw IoTConnectivityErrorFactory.GetException(ret);
590 _attributes.Add(key, new Attributes(attribsHandle));
600 int res = Interop.IoTConnectivity.Common.Attributes.Foreach(attributesHandle, cb, IntPtr.Zero);
601 if (res != (int)IoTConnectivityError.None)
603 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
604 throw IoTConnectivityErrorFactory.GetException(res);
609 internal static class List
611 internal static IntPtr GetListHandle(object list)
613 IntPtr listHandle = IntPtr.Zero;
617 if (list is IEnumerable<IEnumerable>)
619 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.List, out listHandle);
621 foreach (IEnumerable val in (IEnumerable<IEnumerable>)list)
623 IntPtr childList = GetListHandle(val);
624 ret = Interop.IoTConnectivity.Common.List.AddList(listHandle, childList, pos++);
625 if (ret != (int)IoTConnectivityError.None)
627 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
628 Interop.IoTConnectivity.Common.List.Destroy(childList);
629 throw IoTConnectivityErrorFactory.GetException(ret);
633 else if (list is IEnumerable<int>)
635 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Int, out listHandle);
637 foreach (int val in (IEnumerable<int>)list)
639 ret = Interop.IoTConnectivity.Common.List.AddInt(listHandle, val, pos++);
640 if (ret != (int)IoTConnectivityError.None)
642 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
643 throw IoTConnectivityErrorFactory.GetException(ret);
647 else if (list is IEnumerable<string>)
649 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.String, out listHandle);
651 foreach (string val in (IEnumerable<string>)list)
653 ret = Interop.IoTConnectivity.Common.List.AddStr(listHandle, val, pos++);
654 if (ret != (int)IoTConnectivityError.None)
656 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add str");
657 throw IoTConnectivityErrorFactory.GetException(ret);
661 else if (list is IEnumerable<double>)
663 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Double, out listHandle);
665 foreach (double val in (IEnumerable<double>)list)
667 ret = Interop.IoTConnectivity.Common.List.AddDouble(listHandle, val, pos++);
668 if (ret != (int)IoTConnectivityError.None)
670 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
671 throw IoTConnectivityErrorFactory.GetException(ret);
675 else if (list is IEnumerable<bool>)
677 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Bool, out listHandle);
679 foreach (bool val in (IEnumerable<bool>)list)
681 ret = Interop.IoTConnectivity.Common.List.AddBool(listHandle, val, pos++);
682 if (ret != (int)IoTConnectivityError.None)
684 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
685 throw IoTConnectivityErrorFactory.GetException(ret);
689 else if (list is IEnumerable<Attributes>)
691 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Attributes, out listHandle);
693 foreach (Attributes val in (IEnumerable<Attributes>)list)
695 ret = Interop.IoTConnectivity.Common.List.AddAttributes(listHandle, val._resourceAttributesHandle, pos++);
696 if (ret != (int)IoTConnectivityError.None)
698 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
699 throw IoTConnectivityErrorFactory.GetException(ret);
703 else if (list is IEnumerable<byte[]>)
705 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.ByteStr, out listHandle);
707 foreach (byte[] val in (IEnumerable<byte[]>)list)
709 ret = Interop.IoTConnectivity.Common.List.AddByteStr(listHandle, val, val.Length, pos++);
710 if (ret != (int)IoTConnectivityError.None)
712 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add byte[]");
713 throw IoTConnectivityErrorFactory.GetException(ret);
719 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to GetListHandle");
720 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
725 internal static object GetList(IntPtr listHandle)
729 int ret = Interop.IoTConnectivity.Common.List.GetType(listHandle, out type);
730 if (ret != (int)IoTConnectivityError.None)
732 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
733 throw IoTConnectivityErrorFactory.GetException(ret);
735 switch ((Interop.IoTConnectivity.Common.DataType)type)
737 case Interop.IoTConnectivity.Common.DataType.Int:
739 list = new List<int>();
740 Interop.IoTConnectivity.Common.List.IntCallback cb = (int pos, int value, IntPtr userData) =>
745 ret = Interop.IoTConnectivity.Common.List.ForeachInt(listHandle, cb, IntPtr.Zero);
748 case Interop.IoTConnectivity.Common.DataType.Bool:
750 list = new List<bool>();
751 Interop.IoTConnectivity.Common.List.BoolCallback cb = (int pos, bool value, IntPtr userData) =>
756 ret = Interop.IoTConnectivity.Common.List.ForeachBool(listHandle, cb, IntPtr.Zero);
759 case Interop.IoTConnectivity.Common.DataType.Double:
761 list = new List<double>();
762 Interop.IoTConnectivity.Common.List.DoubleCallback cb = (int pos, double value, IntPtr userData) =>
767 ret = Interop.IoTConnectivity.Common.List.ForeachDouble(listHandle, cb, IntPtr.Zero);
770 case Interop.IoTConnectivity.Common.DataType.String:
772 list = new List<string>();
773 Interop.IoTConnectivity.Common.List.StrCallback cb = (int pos, string value, IntPtr userData) =>
778 ret = Interop.IoTConnectivity.Common.List.ForeachStr(listHandle, cb, IntPtr.Zero);
781 case Interop.IoTConnectivity.Common.DataType.Attributes:
783 list = new List<Attributes>();
784 Interop.IoTConnectivity.Common.List.AttribsCallback cb = (int pos, IntPtr value, IntPtr userData) =>
786 list.Add(new Attributes(value));
789 ret = Interop.IoTConnectivity.Common.List.ForeachAttributes(listHandle, cb, IntPtr.Zero);
792 case Interop.IoTConnectivity.Common.DataType.ByteStr:
794 list = new List<byte[]>();
795 Interop.IoTConnectivity.Common.List.ByteStrCallback cb = (int pos, byte[] value, int len, IntPtr userData) =>
800 ret = Interop.IoTConnectivity.Common.List.ForeachByteStr(listHandle, cb, IntPtr.Zero);
803 case Interop.IoTConnectivity.Common.DataType.List:
805 list = new List<List<object>>();
806 Interop.IoTConnectivity.Common.List.ListCallback cb = (int pos, IntPtr value, IntPtr userData) =>
808 object childList = GetList(value);
809 if (childList != null)
813 ret = Interop.IoTConnectivity.Common.List.ForeachList(listHandle, cb, IntPtr.Zero);
819 if (ret != (int)IoTConnectivityError.None)
821 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
822 throw IoTConnectivityErrorFactory.GetException(ret);