private IntPtr _handle = IntPtr.Zero;
private bool _disposed = false;
private CameraState _state = CameraState.None;
- private CameraDeviceManager _cameraDeviceManager;
/// <summary>
/// Initializes a new instance of the <see cref="Camera"/> class.
try
{
- _cameraDeviceManager = new CameraDeviceManager();
- var deviceInfo = _cameraDeviceManager.GetDeviceInformation();
- Log.Info(CameraLog.Tag, deviceInfo.ToString());
+ using (var cameraDeviceManager = new CameraDeviceManager())
+ {
+ var deviceInfo = cameraDeviceManager.GetDeviceInformation();
+ if (!deviceInfo.Any())
+ {
+ throw new InvalidOperationException("There's no available camera device.");
+ }
- cameraDeviceType = deviceInfo.First().Type;
+ cameraDeviceType = deviceInfo.First().Type;
+ }
}
catch (NotSupportedException e)
{
- Tizen.Log.Info(CameraLog.Tag,
+ Log.Info(CameraLog.Tag,
$"CameraDeviceManager is not supported. {e.Message}. Not error.");
}
using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.ComponentModel;
using Native = Interop.CameraDeviceManager;
/// <returns></returns>
/// <since_tizen> 9 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
- public ReadOnlyCollection<CameraDeviceInformation> GetDeviceInformation()
+ public IEnumerable<CameraDeviceInformation> GetDeviceInformation()
{
var deviceList = new Native.CameraDeviceListStruct();
return GetDeviceInformation(deviceList);
}
- internal static ReadOnlyCollection<CameraDeviceInformation> GetDeviceInformation(Native.CameraDeviceListStruct list)
+ internal static IEnumerable<CameraDeviceInformation> GetDeviceInformation(Native.CameraDeviceListStruct list)
{
- var devices = list.device;
+ if (list.count == 0)
+ {
+ return Enumerable.Empty<CameraDeviceInformation>();
+ }
+
var deviceList = new List<CameraDeviceInformation>();
for (int i = 0 ; i < list.count ; i++)
{
- var deviceInfo = GetDeviceInformation(devices[i]);
- deviceList.Add(deviceInfo);
-
- Log.Info(CameraLog.Tag, deviceInfo.ToString());
+ deviceList.Add(GetDeviceInformation(list.device[i]));
}
- return new ReadOnlyCollection<CameraDeviceInformation>(deviceList);
+ return deviceList.AsReadOnly();
}
internal static CameraDeviceInformation GetDeviceInformation(Native.CameraDeviceStruct device) =>
}
}
- private int connectionCallbackId = 0;
+ private int _connectionCallbackId = -1;
private void RegisterDeviceConnectionChangedCallback()
{
Log.Debug(CameraLog.Tag, "Enter");
_deviceConnectionChanged?.Invoke(this, new CameraDeviceConnectionChangedEventArgs(ref device, status));
};
- Native.SetDeviceConnectionChangedCallback(Handle, _deviceConnectionChangedCallback, IntPtr.Zero, out connectionCallbackId).
+ Native.SetDeviceConnectionChangedCallback(Handle, _deviceConnectionChangedCallback, IntPtr.Zero, out _connectionCallbackId).
ThrowIfFailed("Failed to set device connection changed callback");
+
+ Log.Debug(CameraLog.Tag, $"Leave. callbackId[{_connectionCallbackId}]");
}
private void UnregisterDeviceConnectionChangedCallback()
{
- Log.Debug(CameraLog.Tag, "Enter");
+ Log.Debug(CameraLog.Tag, $"Enter. callbackId[{_connectionCallbackId}]");
- Native.UnsetDeviceConnectionChangedCallback(Handle, connectionCallbackId).
- ThrowIfFailed("Failed to unset device connection changed callback");
+ if (_connectionCallbackId >= 0)
+ {
+ Native.UnsetDeviceConnectionChangedCallback(Handle, _connectionCallbackId).
+ ThrowIfFailed("Failed to unset device connection changed callback");
+ }
}
#region Dispose support
{
if (_disposed)
{
- Log.Error(CameraLog.Tag, "Camera handle is disposed.");
+ Log.Error(CameraLog.Tag, "CameraDeviceManager handle is disposed.");
throw new ObjectDisposedException(nameof(Camera));
}
}
Name = name ?? throw new ArgumentNullException(nameof(name), "name is null");
Id = id ?? throw new ArgumentNullException(nameof(id), "id is null");
NumberOfExtraStream = numberOfExtraStream;
+
+ Log.Debug(CameraLog.Tag, this.ToString());
}
/// <summary>