[Tizen.Multimedia] Fix XML Doc warnings
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Vision / MediaVision / EngineConfiguration.cs
1 /*
2  * Copyright (c) 2016 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 using Tizen.System;
19 using System.Runtime.InteropServices;
20 using static Interop.MediaVision;
21
22 namespace Tizen.Multimedia.Vision
23 {
24     /// <summary>
25     /// A base class for configuration classes.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public abstract class EngineConfiguration : IDisposable
29     {
30         private IntPtr _handle = IntPtr.Zero;
31         private bool _disposed = false;
32
33         private const string _featurePath = "http://tizen.org/feature/vision.";
34
35         private bool IsSupportedEngineType(string type)
36         {
37             bool isSupported = false;
38
39             string featureType = _featurePath + type;
40
41             bool ret = Information.TryGetValue(featureType, out isSupported);
42
43             return (isSupported && ret) ? true : false;
44         }
45
46         private bool IsSupportedEngineType(string type1, string type2)
47         {
48             return (IsSupportedEngineType(type1) && IsSupportedEngineType(type2)) ? true : false;
49         }
50
51         internal EngineConfiguration(string engineType)
52         {
53             if (IsSupportedEngineType(engineType) == false)
54             {
55                 throw new NotSupportedException($"{engineType} : Not Supported");
56             }
57
58             EngineConfig.Create(out _handle).Validate("Failed to create media vision engine.");
59         }
60
61         internal EngineConfiguration(string engineType1, string engineType2)
62         {
63
64             if (IsSupportedEngineType(engineType1, engineType2) == false)
65             {
66                 throw new NotSupportedException($"{engineType1} or {engineType2} : Not Supported");
67             }
68
69             EngineConfig.Create(out _handle).Validate("Failed to create media vision engine.");
70         }
71
72         /// <summary>
73         /// Finalizes an instance of the EngineConfiguration class.
74         /// </summary>
75         ~EngineConfiguration()
76         {
77             Dispose(false);
78         }
79
80         internal static IntPtr GetHandle(EngineConfiguration config)
81         {
82             if (config == null)
83             {
84                 return IntPtr.Zero;
85             }
86
87             if (config._disposed)
88             {
89                 throw new ObjectDisposedException(config.GetType().Name);
90             }
91
92             return config._handle;
93         }
94
95         internal void Set(string key, double value)
96         {
97             EngineConfig.SetDouble(Handle, key, value).Validate("Failed to set attribute");
98         }
99
100         internal void Set(string key, int value)
101         {
102             EngineConfig.SetInt(Handle, key, value).Validate("Failed to set attribute");
103         }
104
105
106         internal void Set(string key, bool value)
107         {
108             EngineConfig.SetBool(Handle, key, value).Validate("Failed to set attribute");
109         }
110
111         internal void Set(string key, string value)
112         {
113             EngineConfig.SetString(Handle, key, value).Validate("Failed to set attribute");
114         }
115
116         internal int GetInt(string key)
117         {
118             int value = 0;
119             EngineConfig.GetInt(Handle, key, out value).Validate("Failed to get the value");
120             return value;
121         }
122
123         internal double GetDouble(string key)
124         {
125             double value = 0;
126             EngineConfig.GetDouble(Handle, key, out value).Validate("Failed to get the value");
127             return value;
128         }
129
130         internal bool GetBool(string key)
131         {
132             bool value = false;
133             EngineConfig.GetBool(Handle, key, out value).Validate("Failed to get the value");
134             return value;
135         }
136
137         internal string GetString(string key)
138         {
139             IntPtr ptr = IntPtr.Zero;
140
141             try
142             {
143                 EngineConfig.GetString(Handle, key, out ptr).Validate("Failed to get the value");
144                 return Marshal.PtrToStringAnsi(ptr);
145             }
146             finally
147             {
148                 LibcSupport.Free(ptr);
149             }
150         }
151
152         /// <summary>
153         /// Releases all resources used by the <see cref="EngineConfiguration"/> object.
154         /// </summary>
155         public void Dispose()
156         {
157             Dispose(true);
158             GC.SuppressFinalize(this);
159         }
160
161         /// <summary>
162         /// Releases the resources used by the <see cref="EngineConfiguration"/> object.
163         /// </summary>
164         /// <param name="disposing">
165         /// true to release both managed and unmanaged resources, otherwise false to release only unmanaged resources.
166         /// </param>
167         protected virtual void Dispose(bool disposing)
168         {
169             if (_disposed)
170             {
171                 return;
172             }
173
174             EngineConfig.Destroy(_handle);
175             _disposed = true;
176         }
177
178         internal IntPtr Handle
179         {
180             get
181             {
182                 if (_disposed)
183                 {
184                     throw new ObjectDisposedException(nameof(EngineConfiguration));
185                 }
186                 return _handle;
187             }
188         }
189     }
190 }