2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
22 namespace Tizen.Convergence
25 /// The class encapsulates a D2D convergence compliant device information
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class InternalDevice : IDisposable
30 internal const string DeviceIdKey = "device_id";
31 internal const string DeviceNameKey = "device_name";
32 internal const string DeviceTypeKey = "device_type";
33 internal Interop.Internal.ConvDeviceHandle _deviceHandle;
34 internal List<InternalService> _services = new List<InternalService>();
37 /// The Unique ID of the device
39 public string Id { get;}
42 /// Name of the device
44 public string Name { get;}
47 /// The profile of the device
49 public string Type { get; }
52 /// List of services supported by the device
54 public IEnumerable<InternalService> Services
62 internal InternalDevice(IntPtr deviceHandle)
64 int ret = Interop.Internal.ConvDevice.Clone(deviceHandle, out _deviceHandle);
65 if (ret != (int)ConvErrorCode.None)
67 Log.Error(ErrorFactory.LogTag, "Failed to clone device");
68 throw ErrorFactory.GetException(ret);
71 IntPtr stringPtr = IntPtr.Zero;
72 ret = Interop.Internal.ConvDevice.GetPropertyString(_deviceHandle, DeviceIdKey, out stringPtr);
73 if (ret == (int)ConvErrorCode.None)
75 Id = Marshal.PtrToStringAnsi(stringPtr);
76 Interop.Libc.Free(stringPtr);
79 ret = Interop.Internal.ConvDevice.GetPropertyString(_deviceHandle, DeviceNameKey, out stringPtr);
80 if (ret == (int)ConvErrorCode.None)
82 Name = Marshal.PtrToStringAnsi(stringPtr);
83 Interop.Libc.Free(stringPtr);
86 ret = Interop.Internal.ConvDevice.GetPropertyString(_deviceHandle, DeviceTypeKey, out stringPtr);
87 if (ret != (int)ConvErrorCode.None)
89 Type = Marshal.PtrToStringAnsi(stringPtr);
90 Interop.Libc.Free(stringPtr);
93 Log.Debug(ErrorFactory.LogTag, "Device ID ,Name, and Type:[" + Id +"," + Name +"," + Type +"]");
95 Interop.Internal.ConvDevice.ConvServiceForeachCallback cb = (IntPtr serviceHandle, IntPtr userData) =>
97 _services.Add(InternalService.GetService(serviceHandle));
100 ret = Interop.Internal.ConvDevice.ForeachService(_deviceHandle, cb, IntPtr.Zero);
101 if (ret != (int)ConvErrorCode.None)
103 Log.Error(ErrorFactory.LogTag, "Failed to get device services");
104 throw ErrorFactory.GetException(ret);
109 /// The dispose method
111 public void Dispose()
113 _deviceHandle.Dispose();