[Cion] Add new APIs for Advanced Companion Framework (#3472)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Cion / Tizen.Applications / PeerInfo.cs
1 /*
2  * Copyright (c) 2021 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;
18
19 namespace Tizen.Applications
20 {
21     /// <summary>
22     /// A class to represent peer info.
23     /// </summary>
24     /// <since_tizen> 9 </since_tizen>
25     public class PeerInfo : IDisposable
26     {
27         private readonly string LogTag = "Tizen.Cion";
28         internal PeerInfoSafeHandle _handle;
29
30         internal PeerInfo(PeerInfoSafeHandle handle)
31         {
32             _handle = handle;
33         }
34
35         /// <summary>
36         /// Gets the device id.
37         /// </summary>
38         /// <since_tizen> 9 </since_tizen>
39         public string DeviceId
40         {
41             get
42             {
43                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetDeviceId(_handle, out string deviceId);
44                 if (ret != Interop.Cion.ErrorCode.None)
45                 {
46                     Log.Error(LogTag, "Failed to get device id.");
47                     return "";
48                 }
49                 return deviceId;
50             }
51         }
52
53         /// <summary>
54         /// Gets the device name.
55         /// </summary>
56         /// <since_tizen> 9 </since_tizen>
57         public string DeviceName
58         {
59             get
60             {
61                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetDeviceName(_handle, out string deviceName);
62                 if (ret != Interop.Cion.ErrorCode.None)
63                 {
64                     Log.Error(LogTag, "Failed to get device name.");
65                     return "";
66                 }
67                 return deviceName;
68             }
69         }
70
71         /// <summary>
72         /// Gets the device platform.
73         /// </summary>
74         /// <since_tizen> 9 </since_tizen>
75         public string DevicePlatform
76         {
77             get
78             {
79                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetDevicePlatform(_handle, out string devicePlatform);
80                 if (ret != Interop.Cion.ErrorCode.None)
81                 {
82                     Log.Error(LogTag, "Failed to get device platform.");
83                     return "";
84                 }
85                 return devicePlatform;
86             }
87         }
88
89         /// <summary>
90         /// Gets the device platform version.
91         /// </summary>
92         /// <since_tizen> 9 </since_tizen>
93         public string DevicePlatformVersion
94         {
95             get
96             {
97                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetDevicePlatformVersion(_handle, out string devicePlatformVersion);
98                 if (ret != Interop.Cion.ErrorCode.None)
99                 {
100                     Log.Error(LogTag, "Failed to get device platform version.");
101                     return "";
102                 }
103                 return devicePlatformVersion;
104             }
105         }
106
107         /// <summary>
108         /// Gets the device type.
109         /// </summary>
110         /// <since_tizen> 9 </since_tizen>
111         public string DeviceType
112         {
113             get
114             {
115                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetDeviceType(_handle, out string deviceType);
116                 if (ret != Interop.Cion.ErrorCode.None)
117                 {
118                     Log.Error(LogTag, "Failed to get device platform type.");
119                     return "";
120                 }
121                 return deviceType;
122             }
123         }
124
125         /// <summary>
126         /// Gets the application id.
127         /// </summary>
128         /// <since_tizen> 9 </since_tizen>
129         public string AppId
130         {
131             get
132             {
133                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetAppId(_handle, out string AppId);
134                 if (ret != Interop.Cion.ErrorCode.None)
135                 {
136                     Log.Error(LogTag, "Failed to get application id.");
137                     return "";
138                 }
139                 return AppId;
140             }
141         }
142
143         /// <summary>
144         /// Gets the application version.
145         /// </summary>
146         /// <since_tizen> 9 </since_tizen>
147         public string AppVersion
148         {
149             get
150             {
151                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetAppVersion(_handle, out string AppVersion);
152                 if (ret != Interop.Cion.ErrorCode.None)
153                 {
154                     Log.Error(LogTag, "Failed to get application version.");
155                     return "";
156                 }
157                 return AppVersion;
158             }
159         }
160
161         /// <summary>
162         /// Gets the UUID.
163         /// </summary>
164         /// <since_tizen> 9 </since_tizen>
165         public string UUID
166         {
167             get
168             {
169                 Interop.Cion.ErrorCode ret = Interop.CionPeerInfo.CionPeerInfoGetUuid(_handle, out string uuid);
170                 if (ret != Interop.Cion.ErrorCode.None)
171                 {
172                     Log.Error(LogTag, "Failed to get UUID.");
173                     return "";
174                 }
175                 return uuid;
176             }
177         }
178
179         #region IDisposable Support
180         private bool disposedValue = false;
181
182         /// <summary>
183         /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
184         /// </summary>
185         /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
186         /// <since_tizen> 9 </since_tizen>
187         protected virtual void Dispose(bool disposing)
188         {
189             if (!disposedValue)
190             {
191                 if (disposing)
192                 {
193                     _handle.Dispose();
194                 }
195                 disposedValue = true;
196             }
197         }
198
199         /// <summary>
200         /// Releases all resources used by the PeerInfo class.
201         /// </summary>
202         /// <since_tizen> 9 </since_tizen>
203         public void Dispose()
204         {
205             Dispose(true);
206             GC.SuppressFinalize(this);
207         }
208         #endregion
209     }
210 }