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>
43 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
45 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
49 int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle);
50 if (ret != (int)IoTConnectivityError.None)
52 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
53 throw IoTConnectivityErrorFactory.GetException(ret);
57 internal Attributes(IntPtr attributesHandleToClone)
59 int ret = Interop.IoTConnectivity.Common.Attributes.Clone(attributesHandleToClone, out _resourceAttributesHandle);
60 if (ret != (int)IoTConnectivityError.None)
62 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
63 throw IoTConnectivityErrorFactory.GetException(ret);
66 SetAttributes(attributesHandleToClone);
70 /// Destructor of the Attributes class.
78 /// Gets the number of keys
81 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
82 /// attributes.Add("brightness", 50);
83 /// var count = attributes.Count;
84 /// Console.WriteLine("There are {0} keys in the attribute object", count);
90 return _attributes.Count;
95 /// Contains all the attribute keys
98 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
99 /// { "state", "ON" },
102 /// var keys = attributes.Keys;
103 /// Console.WriteLine("Attribute contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
105 public ICollection<string> Keys
109 return _attributes.Keys;
114 /// Contains all the attribute values
117 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
118 /// { "state", "ON" },
121 /// var values = attributes.Values;
122 /// Console.WriteLine("Attribute contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
124 public ICollection<object> Values
128 return _attributes.Values;
133 /// Gets or sets the attribute with the specified key.
135 /// <param name="key">The key of the attribute to get or set.</param>
136 /// <returns>The element with the specified key.</returns>
138 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
139 /// attributes["state"] = "ON";
140 /// Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]);
142 public object this[string key]
146 if (_attributes.ContainsKey(key))
147 return _attributes[key];
159 /// Adds attribute key and value as a key value pair
161 /// <param name="item">The key value pair to add</param>
163 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
164 /// attributes.Add(new KeyValuePair<string, object> ("state", "ON"));
166 public void Add(KeyValuePair<string, object> item)
168 Add(item.Key, item.Value);
172 /// Adds an attribute
174 /// <param name="key">The key representing the attribute</param>
175 /// <param name="value">The value representing the attribute</param>
177 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
178 /// attributes.Add("brightness", 50);
180 public void Add(string key, object value)
185 ret = Interop.IoTConnectivity.Common.Attributes.AddInt(_resourceAttributesHandle, key, (int)value);
186 if (ret != (int)IoTConnectivityError.None)
188 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add int");
189 throw IoTConnectivityErrorFactory.GetException(ret);
192 else if (value is Attributes)
194 Attributes attribs = (Attributes)value;
195 ret = Interop.IoTConnectivity.Common.Attributes.AddAttributes(_resourceAttributesHandle, key, attribs._resourceAttributesHandle);
196 if (ret != (int)IoTConnectivityError.None)
198 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
199 throw IoTConnectivityErrorFactory.GetException(ret);
202 else if (value is string)
204 ret = Interop.IoTConnectivity.Common.Attributes.AddStr(_resourceAttributesHandle, key, (string)value);
205 if (ret != (int)IoTConnectivityError.None)
207 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add string");
208 throw IoTConnectivityErrorFactory.GetException(ret);
211 else if (value is double)
213 ret = Interop.IoTConnectivity.Common.Attributes.AddDouble(_resourceAttributesHandle, key, (double)value);
214 if (ret != (int)IoTConnectivityError.None)
216 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
217 throw IoTConnectivityErrorFactory.GetException(ret);
220 else if (value is bool)
222 ret = Interop.IoTConnectivity.Common.Attributes.AddBool(_resourceAttributesHandle, key, (bool)value);
223 if (ret != (int)IoTConnectivityError.None)
225 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
226 throw IoTConnectivityErrorFactory.GetException(ret);
229 else if (value is byte[])
231 byte[] val = value as byte[];
234 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get byte[] val");
235 throw new ArgumentException("Invalid Parameter");
237 ret = Interop.IoTConnectivity.Common.Attributes.AddByteStr(_resourceAttributesHandle, key, val, val.Length);
238 if (ret != (int)IoTConnectivityError.None)
240 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
241 throw IoTConnectivityErrorFactory.GetException(ret);
244 else if (value is IEnumerable)
246 IntPtr listHandle = List.GetListHandle(value);
247 ret = Interop.IoTConnectivity.Common.Attributes.AddList(_resourceAttributesHandle, key, listHandle);
248 if (ret != (int)IoTConnectivityError.None)
250 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add list");
251 throw IoTConnectivityErrorFactory.GetException(ret);
256 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Add");
257 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
259 _attributes.Add(key, value);
263 /// Clears attributes collection
265 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
266 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
267 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
269 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
270 /// attributes.Add("brightness", 50);
271 /// attributes.Clear();
275 foreach (string key in _attributes.Keys)
277 int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
278 if (ret != (int)IoTConnectivityError.None)
280 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear attributes");
281 throw IoTConnectivityErrorFactory.GetException(ret);
288 /// Checks whether the given key value pair exists in attributes collection
290 /// <param name="item">The status key value pair</param>
291 /// <returns>true if exists. Otherwise, false</returns>
293 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
294 /// { "state", "ON" },
297 /// if (attributes.Contains(new KeyValuePair<string, object> ("dim", 10))
298 /// Console.WriteLine("Attribute conatins pair ('dim', 10)");
300 public bool Contains(KeyValuePair<string, object> item)
302 return _attributes.Contains(item);
306 /// Checks whether the given key exists in attributes collection
308 /// <param name="key">The status key to look for</param>
309 /// <returns>true if exists. Otherwise, false</returns>
311 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
312 /// { "state", "ON" },
315 /// if (attributes.ContainsKey("dim"))
316 /// Console.WriteLine("Attribute conatins key : dim");
318 public bool ContainsKey(string key)
320 return _attributes.ContainsKey(key);
324 /// Copies the elements of the attributes to an array, starting at a particular index.
326 /// <param name="array">The destination array</param>
327 /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
329 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
330 /// { "state", "ON" },
333 /// KeyValuePair<string, object>[] dest = new KeyValuePair<string, object>[attributes.Count];
335 /// attributes.CopyTo(dest, index);
336 /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
338 public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
340 _attributes.CopyTo(array, arrayIndex);
344 /// Returns an enumerator that iterates through the collection.
346 /// <returns> An enumerator that can be used to iterate through the collection.</returns>
348 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
349 /// { "state", "ON" },
352 /// foreach (KeyValuePair<string, object> pair in attributes)
354 /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
357 public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
359 return _attributes.GetEnumerator();
363 /// Removes an attribute from collection
365 /// <param name="item">The attributes element to remove</param>
366 /// <returns>true if operation is success. Otherwise, false</returns>
367 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
368 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
369 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
371 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
372 /// { "state", "ON" },
375 /// if (attributes.Remove(new KeyValuePair<string, object>("dim", 10)))
376 /// Console.WriteLine("Remove was successful");
378 public bool Remove(KeyValuePair<string, object> item)
380 return Remove(item.Key);
384 /// Removes an attribute from collection using key
386 /// <param name="key">The attributes element to remove</param>
387 /// <returns>true if operation is successful, Otherwise, false</returns>
388 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
389 /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
390 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
392 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
393 /// { "state", "ON" },
396 /// if (attributes.Remove("state"))
397 /// Console.WriteLine("Remove was successful");
399 public bool Remove(string key)
401 bool isRemoved = _attributes.Remove(key);
404 int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
405 if (ret != (int)IoTConnectivityError.None)
407 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
408 throw IoTConnectivityErrorFactory.GetException(ret);
416 /// Gets the value associated with the specified key.
418 /// <param name="key">The key whose value to get.</param>
419 /// <param name="value"> The value associated with the specified key</param>
420 /// <returns> true if the attributes collection contains an element with the specified key; otherwise, false.</returns>
422 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
423 /// { "state", "ON" }
426 /// var isPresent = attributes.TryGetValue("state", out value);
428 /// Console.WriteLine("value : {0}", value);
430 public bool TryGetValue(string key, out object value)
432 return _attributes.TryGetValue(key, out value);
436 /// Returns an enumerator that iterates through the collection.
438 IEnumerator IEnumerable.GetEnumerator()
440 return _attributes.GetEnumerator();
444 /// Releases any unmanaged resources used by this object.
446 public void Dispose()
449 GC.SuppressFinalize(this);
453 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
455 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
456 protected virtual void Dispose(bool disposing)
463 // Free managed objects
466 Interop.IoTConnectivity.Common.Attributes.Destroy(_resourceAttributesHandle);
470 private void SetAttributes(IntPtr attributesHandle)
472 Interop.IoTConnectivity.Common.Attributes.AttributesCallback cb = (IntPtr attributes, string key, IntPtr userData) =>
474 Interop.IoTConnectivity.Common.DataType dataType;
475 int ret = Interop.IoTConnectivity.Common.Attributes.GetType(attributes, key, out dataType);
476 if (ret != (int)IoTConnectivityError.None)
478 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
479 throw IoTConnectivityErrorFactory.GetException(ret);
482 switch ((Interop.IoTConnectivity.Common.DataType)dataType)
484 case Interop.IoTConnectivity.Common.DataType.Int:
487 ret = Interop.IoTConnectivity.Common.Attributes.GetInt(attributes, key, out value);
488 if (ret != (int)IoTConnectivityError.None)
490 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
491 throw IoTConnectivityErrorFactory.GetException(ret);
496 case Interop.IoTConnectivity.Common.DataType.Bool:
499 ret = Interop.IoTConnectivity.Common.Attributes.GetBool(attributes, key, out value);
500 if (ret != (int)IoTConnectivityError.None)
502 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
503 throw IoTConnectivityErrorFactory.GetException(ret);
508 case Interop.IoTConnectivity.Common.DataType.Double:
511 ret = Interop.IoTConnectivity.Common.Attributes.GetDouble(attributes, key, out value);
512 if (ret != (int)IoTConnectivityError.None)
514 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
515 throw IoTConnectivityErrorFactory.GetException(ret);
520 case Interop.IoTConnectivity.Common.DataType.String:
523 ret = Interop.IoTConnectivity.Common.Attributes.GetStr(attributes, key, out value);
524 if (ret != (int)IoTConnectivityError.None)
526 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
527 throw IoTConnectivityErrorFactory.GetException(ret);
532 case Interop.IoTConnectivity.Common.DataType.ByteStr:
536 ret = Interop.IoTConnectivity.Common.Attributes.GetByteStr(attributes, key, out byteStrPtr, out byteStrSize);
537 if (ret != (int)IoTConnectivityError.None)
539 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
540 throw IoTConnectivityErrorFactory.GetException(ret);
542 byte[] byteStr = new byte[byteStrSize];
543 Marshal.Copy(byteStrPtr, byteStr, 0, byteStrSize);
547 case Interop.IoTConnectivity.Common.DataType.Null:
552 case Interop.IoTConnectivity.Common.DataType.List:
555 ret = Interop.IoTConnectivity.Common.Attributes.GetList(attributes, key, out listHandle);
556 if (ret != (int)IoTConnectivityError.None)
558 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
559 throw IoTConnectivityErrorFactory.GetException(ret);
561 Add(key, List.GetList(listHandle));
564 case Interop.IoTConnectivity.Common.DataType.Attributes:
566 IntPtr attribsHandle;
567 ret = Interop.IoTConnectivity.Common.Attributes.GetAttributes(attributes, key, out attribsHandle);
568 if (ret != (int)IoTConnectivityError.None)
570 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
571 throw IoTConnectivityErrorFactory.GetException(ret);
573 Add(key, new Attributes(attribsHandle));
583 int res = Interop.IoTConnectivity.Common.Attributes.Foreach(attributesHandle, cb, IntPtr.Zero);
584 if (res != (int)IoTConnectivityError.None)
586 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
587 throw IoTConnectivityErrorFactory.GetException(res);
592 internal static class List
594 internal static IntPtr GetListHandle(object list)
596 IntPtr listHandle = IntPtr.Zero;
600 if (list is IEnumerable<IEnumerable>)
602 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.List, out listHandle);
604 foreach (IEnumerable val in (IEnumerable<IEnumerable>)list)
606 IntPtr childList = GetListHandle(val);
607 ret = Interop.IoTConnectivity.Common.List.AddList(listHandle, childList, pos++);
608 if (ret != (int)IoTConnectivityError.None)
610 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
611 Interop.IoTConnectivity.Common.List.Destroy(childList);
612 throw IoTConnectivityErrorFactory.GetException(ret);
616 else if (list is IEnumerable<int>)
618 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Int, out listHandle);
620 foreach (int val in (IEnumerable<int>)list)
622 ret = Interop.IoTConnectivity.Common.List.AddInt(listHandle, val, pos++);
623 if (ret != (int)IoTConnectivityError.None)
625 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
626 throw IoTConnectivityErrorFactory.GetException(ret);
630 else if (list is IEnumerable<string>)
632 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.String, out listHandle);
634 foreach (string val in (IEnumerable<string>)list)
636 ret = Interop.IoTConnectivity.Common.List.AddStr(listHandle, val, pos++);
637 if (ret != (int)IoTConnectivityError.None)
639 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add str");
640 throw IoTConnectivityErrorFactory.GetException(ret);
644 else if (list is IEnumerable<double>)
646 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Double, out listHandle);
648 foreach (double val in (IEnumerable<double>)list)
650 ret = Interop.IoTConnectivity.Common.List.AddDouble(listHandle, val, pos++);
651 if (ret != (int)IoTConnectivityError.None)
653 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double");
654 throw IoTConnectivityErrorFactory.GetException(ret);
658 else if (list is IEnumerable<bool>)
660 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Bool, out listHandle);
662 foreach (bool val in (IEnumerable<bool>)list)
664 ret = Interop.IoTConnectivity.Common.List.AddBool(listHandle, val, pos++);
665 if (ret != (int)IoTConnectivityError.None)
667 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool");
668 throw IoTConnectivityErrorFactory.GetException(ret);
672 else if (list is IEnumerable<Attributes>)
674 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Attributes, out listHandle);
676 foreach (Attributes val in (IEnumerable<Attributes>)list)
678 ret = Interop.IoTConnectivity.Common.List.AddAttributes(listHandle, val._resourceAttributesHandle, pos++);
679 if (ret != (int)IoTConnectivityError.None)
681 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes");
682 throw IoTConnectivityErrorFactory.GetException(ret);
686 else if (list is IEnumerable<byte[]>)
688 ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.ByteStr, out listHandle);
690 foreach (byte[] val in (IEnumerable<byte[]>)list)
692 ret = Interop.IoTConnectivity.Common.List.AddByteStr(listHandle, val, val.Length, pos++);
693 if (ret != (int)IoTConnectivityError.None)
695 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add byte[]");
696 throw IoTConnectivityErrorFactory.GetException(ret);
702 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to GetListHandle");
703 throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter);
708 internal static object GetList(IntPtr listHandle)
712 int ret = Interop.IoTConnectivity.Common.List.GetType(listHandle, out type);
713 if (ret != (int)IoTConnectivityError.None)
715 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
716 throw IoTConnectivityErrorFactory.GetException(ret);
718 switch ((Interop.IoTConnectivity.Common.DataType)type)
720 case Interop.IoTConnectivity.Common.DataType.Int:
722 list = new List<int>();
723 Interop.IoTConnectivity.Common.List.IntCallback cb = (int pos, int value, IntPtr userData) =>
728 ret = Interop.IoTConnectivity.Common.List.ForeachInt(listHandle, cb, IntPtr.Zero);
731 case Interop.IoTConnectivity.Common.DataType.Bool:
733 list = new List<bool>();
734 Interop.IoTConnectivity.Common.List.BoolCallback cb = (int pos, bool value, IntPtr userData) =>
739 ret = Interop.IoTConnectivity.Common.List.ForeachBool(listHandle, cb, IntPtr.Zero);
742 case Interop.IoTConnectivity.Common.DataType.Double:
744 list = new List<double>();
745 Interop.IoTConnectivity.Common.List.DoubleCallback cb = (int pos, double value, IntPtr userData) =>
750 ret = Interop.IoTConnectivity.Common.List.ForeachDouble(listHandle, cb, IntPtr.Zero);
753 case Interop.IoTConnectivity.Common.DataType.String:
755 list = new List<string>();
756 Interop.IoTConnectivity.Common.List.StrCallback cb = (int pos, string value, IntPtr userData) =>
761 ret = Interop.IoTConnectivity.Common.List.ForeachStr(listHandle, cb, IntPtr.Zero);
764 case Interop.IoTConnectivity.Common.DataType.Attributes:
766 list = new List<Attributes>();
767 Interop.IoTConnectivity.Common.List.AttribsCallback cb = (int pos, IntPtr value, IntPtr userData) =>
769 list.Add(new Attributes(value));
772 ret = Interop.IoTConnectivity.Common.List.ForeachAttributes(listHandle, cb, IntPtr.Zero);
775 case Interop.IoTConnectivity.Common.DataType.ByteStr:
777 list = new List<byte[]>();
778 Interop.IoTConnectivity.Common.List.ByteStrCallback cb = (int pos, byte[] value, int len, IntPtr userData) =>
783 ret = Interop.IoTConnectivity.Common.List.ForeachByteStr(listHandle, cb, IntPtr.Zero);
786 case Interop.IoTConnectivity.Common.DataType.List:
788 list = new List<List<object>>();
789 Interop.IoTConnectivity.Common.List.ListCallback cb = (int pos, IntPtr value, IntPtr userData) =>
791 object childList = GetList(value);
792 if (childList != null)
796 ret = Interop.IoTConnectivity.Common.List.ForeachList(listHandle, cb, IntPtr.Zero);
802 if (ret != (int)IoTConnectivityError.None)
804 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes");
805 throw IoTConnectivityErrorFactory.GetException(ret);