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.
19 using System.Runtime.InteropServices;
20 using static Interop.MediaVision;
22 namespace Tizen.Multimedia.Vision
25 /// A base class for configuration classes.
27 /// <since_tizen> 3 </since_tizen>
28 public abstract class EngineConfiguration : IDisposable
30 private IntPtr _handle = IntPtr.Zero;
31 private bool _disposed = false;
33 private const string _featurePath = "http://tizen.org/feature/vision.";
35 private bool IsSupportedEngineType(string type)
37 bool isSupported = false;
39 string featureType = _featurePath + type;
41 bool ret = Information.TryGetValue(featureType, out isSupported);
43 return (isSupported && ret) ? true : false;
46 private bool IsSupportedEngineType(string type1, string type2)
48 return (IsSupportedEngineType(type1) && IsSupportedEngineType(type2)) ? true : false;
51 internal EngineConfiguration(string engineType)
53 if (IsSupportedEngineType(engineType) == false)
55 throw new NotSupportedException($"{engineType} : Not Supported");
58 EngineConfig.Create(out _handle).Validate("Failed to create media vision engine.");
61 internal EngineConfiguration(string engineType1, string engineType2)
64 if (IsSupportedEngineType(engineType1, engineType2) == false)
66 throw new NotSupportedException($"{engineType1} or {engineType2} : Not Supported");
69 EngineConfig.Create(out _handle).Validate("Failed to create media vision engine.");
72 ~EngineConfiguration()
77 internal static IntPtr GetHandle(EngineConfiguration config)
86 throw new ObjectDisposedException(config.GetType().Name);
89 return config._handle;
92 internal void Set(string key, double value)
94 EngineConfig.SetDouble(Handle, key, value).Validate("Failed to set attribute");
97 internal void Set(string key, int value)
99 EngineConfig.SetInt(Handle, key, value).Validate("Failed to set attribute");
103 internal void Set(string key, bool value)
105 EngineConfig.SetBool(Handle, key, value).Validate("Failed to set attribute");
108 internal void Set(string key, string value)
110 EngineConfig.SetString(Handle, key, value).Validate("Failed to set attribute");
113 internal int GetInt(string key)
116 EngineConfig.GetInt(Handle, key, out value).Validate("Failed to get the value");
120 internal double GetDouble(string key)
123 EngineConfig.GetDouble(Handle, key, out value).Validate("Failed to get the value");
127 internal bool GetBool(string key)
130 EngineConfig.GetBool(Handle, key, out value).Validate("Failed to get the value");
134 internal string GetString(string key)
136 IntPtr ptr = IntPtr.Zero;
140 EngineConfig.GetString(Handle, key, out ptr).Validate("Failed to get the value");
141 return Marshal.PtrToStringAnsi(ptr);
145 LibcSupport.Free(ptr);
150 /// Releases all resources used by the <see cref="EngineConfiguration"/> object.
152 public void Dispose()
155 GC.SuppressFinalize(this);
159 /// Releases the resources used by the <see cref="EngineConfiguration"/> object.
161 /// <param name="disposing">
162 /// true to release both managed and unmanaged resources, otherwise false to release only unmanaged resources.
164 protected virtual void Dispose(bool disposing)
171 EngineConfig.Destroy(_handle);
175 internal IntPtr Handle
181 throw new ObjectDisposedException(nameof(EngineConfiguration));