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 static Interop.MediaVision;
21 namespace Tizen.Multimedia
24 /// This class represents an abstract EngineConfiguration class.\n
25 /// It provides dictionary functionality. It means that it is possible to set (key, value) pairs to this class \n
26 /// and use them to transfer these values to the engine part underlying Media Vision API. \n
27 /// Information on which attributes can be set is provided together with concrete engines.
29 public abstract class EngineConfiguration : IDisposable
31 internal IntPtr _engineHandle = IntPtr.Zero;
32 private readonly IDictionary<string, object> _config = new Dictionary<string, object>();
33 private bool _disposed = false;
36 /// Constructor of the EngineConfig class.
38 internal EngineConfiguration()
40 int ret = Interop.MediaVision.EngineConfig.Create(out _engineHandle);
41 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to create media vision engine.");
45 /// Destructor of the EngineConfig class.
47 ~EngineConfiguration()
52 internal void Add<T>(string key, T value)
54 object val = (object)value;
56 if (!_config.ContainsKey(key))
58 _config.Add(key, val);
63 if (typeof(T) == typeof(double))
65 ret = Interop.MediaVision.EngineConfig.SetDouble(_engineHandle, key, (double)val);
67 else if (typeof(T) == typeof(int))
69 ret = Interop.MediaVision.EngineConfig.SetInt(_engineHandle, key, (int)val);
71 else if (typeof(T) == typeof(bool))
73 ret = Interop.MediaVision.EngineConfig.SetBool(_engineHandle, key, (bool)val);
75 else if (typeof(T) == typeof(string))
77 ret = Interop.MediaVision.EngineConfig.SetString(_engineHandle, key, (string)val);
80 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to add attribute");
85 internal object Get(string key)
87 if (_config.ContainsKey(key))
93 Log.Error(MediaVisionLog.Tag, "Attribute was not set");
101 GC.SuppressFinalize(this);
104 protected virtual void Dispose(bool disposing)
113 // Free managed objects
116 Interop.MediaVision.EngineConfig.Destroy(_engineHandle);