/* * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Runtime.InteropServices; using System.Collections.Generic; namespace Tizen.Network.Mtp { /// /// A class for Mtp Object information. It allows applications to handle object information. /// /// 4 public class MtpObject : IDisposable { private int _deviceHandle = -1; private int _objectHandle = -1; private bool disposed = false; /// /// Gets the filename of the object information. /// /// File name of object. /// 4 public string FileName { get { IntPtr strPtr; int ret = Interop.Mtp.ObjectInformation.GetFileName(_deviceHandle, _objectHandle, out strPtr); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get file name, Error - " + (MtpError)ret); return ""; } return Marshal.PtrToStringAnsi(strPtr); } } /// /// Gets the keywords of the object information. /// /// Keywords of object. /// 4 public string Keywords { get { IntPtr strPtr; int ret = Interop.Mtp.ObjectInformation.GetKeywords(_deviceHandle, _objectHandle, out strPtr); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get keywords, Error - " + (MtpError)ret); return ""; } return Marshal.PtrToStringAnsi(strPtr); } } /// /// Gets the association description of the object information. /// /// Association description of object. /// 4 public int AssociationDescription { get { int value; int ret = Interop.Mtp.ObjectInformation.GetAssociationDescription(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get association decription, Error - " + (MtpError)ret); } return value; } } /// /// Gets the association type of the object information. /// /// Association type of object. /// 4 public int AssociationType { get { int value; int ret = Interop.Mtp.ObjectInformation.GetAssociationType(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get association type, Error - " + (MtpError)ret); } return value; } } /// /// Gets the size of the object information. /// /// Size of object. /// 4 public int Size { get { int value; int ret = Interop.Mtp.ObjectInformation.GetSize(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get size, Error - " + (MtpError)ret); } return value; } } /// /// Gets the parent object handle of the object information. /// /// Handle of Parent object. /// 4 public int ParentObjectHandle { get { int value; int ret = Interop.Mtp.ObjectInformation.GetParentObjectHandle(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get parent object handle, Error - " + (MtpError)ret); } return value; } } /// /// Gets the mtp storage of the object information. /// /// Storage of object. /// 4 public int Storage { get { int value; int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get storage, Error - " + (MtpError)ret); } return value; } } /// /// Gets the object created time of the object information. /// /// Date created of object. /// 4 public int DateCreated { get { int value; int ret = Interop.Mtp.ObjectInformation.GetDateCreated(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get date created, Error - " + (MtpError)ret); } return value; } } /// /// Gets the object modified time of the object information. /// /// Date modified of object. /// 4 public int DateModified { get { int value; int ret = Interop.Mtp.ObjectInformation.GetDateModified(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get date modified, Error - " + (MtpError)ret); } return value; } } /// /// Gets the file type of the object information. /// /// File type of object. /// 4 public MtpFileType FileType { get { int value; int ret = Interop.Mtp.ObjectInformation.GetStorage(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get file type, Error - " + (MtpError)ret); } return (MtpFileType)value; } } /// /// Gets the image bit depth of the object information. /// /// Bit depth of image. /// 4 public int ImageBitDepth { get { int value; int ret = Interop.Mtp.ObjectInformation.GetImageBitDepth(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get image bit depth, Error - " + (MtpError)ret); } return value; } } /// /// Gets the image pixel width of the object information. /// /// Pixel width of image. /// 4 public int ImagePixelWidth { get { int value; int ret = Interop.Mtp.ObjectInformation.GetImagePixWidth(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get image pixel width, Error - " + (MtpError)ret); } return value; } } /// /// Gets the image pixel height of the object information. /// /// Pixel height of image. /// 4 public int ImagePixelHeight { get { int value; int ret = Interop.Mtp.ObjectInformation.GetImagePixHeight(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get image pixel height, Error - " + (MtpError)ret); } return value; } } /// /// Gets the thumbnail size of the object information. /// /// Size of thumbnail. /// 4 public int ThumbnailSize { get { int value; int ret = Interop.Mtp.ObjectInformation.GetThumbnailSize(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get thumbnail size, Error - " + (MtpError)ret); } return value; } } /// /// Gets the thumbnail file type of the object information. /// /// File type of thumbnail. /// 4 public int ThumbnailFileType { get { int value; int ret = Interop.Mtp.ObjectInformation.GetThumbnailFileType(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get thumbnail file type, Error - " + (MtpError)ret); } return value; } } /// /// Gets the thumbnail pixel width of the object information. /// /// Pixel width of thumbnail. /// 4 public int ThumbnailPixelWidth { get { int value; int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixWidth(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get thumbnail pixel width, Error - " + (MtpError)ret); } return value; } } /// /// Gets the thumbnail pixel height of the object information. /// /// Pixel height of thumbnail. /// 4 public int ThumbnailPixelHeight { get { int value; int ret = Interop.Mtp.ObjectInformation.GetThumbnailPixHeight(_deviceHandle, _objectHandle, out value); if (ret != (int)MtpError.None) { Log.Error(Globals.LogTag, "Failed to get thumbnail pixel height, Error - " + (MtpError)ret); } return value; } } internal MtpObject(int deviceHandle, int objectHandle) { _deviceHandle = deviceHandle; _objectHandle = objectHandle; } /// /// MtpObject destructor. /// ~MtpObject() { Dispose(false); } /// /// Dispose /// /// 4 public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if (disposed) return; if (disposing) { // Free managed objects. } //Free unmanaged objects disposed = true; } internal int GetHandle() { return _objectHandle; } } }