private void Initialize()
        {
            int ret = Interop.Mtp.Initialize();

            if (ret != (int)MtpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to Initialize Mtp, Error - " + (MtpError)ret);
                MtpErrorFactory.ThrowMtpException(ret);
            }
        }
        internal IEnumerable <MtpDevice> GetDevices()
        {
            IntPtr devicePtr;
            int    count = 0;

            int ret = Interop.Mtp.GetDevices(out devicePtr, out count);

            if (ret != (int)MtpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get device list, Error - " + (MtpError)ret);
                MtpErrorFactory.ThrowMtpException(ret);
            }

            for (int i = 0; i < count; i++)
            {
                int deviceID = Marshal.ReadInt32(devicePtr);

                MtpDevice deviceItem = new MtpDevice(deviceID);
                _deviceList.Add(deviceItem);
                devicePtr += sizeof(int);
            }

            return(_deviceList);
        }
Exemple #3
0
        /// <summary>
        /// Gets the list of storages.
        /// </summary>
        /// <returns>List of storage objects.</returns>
        /// <feature>http://tizen.org/feature/network.mtp</feature>
        /// <exception cref="NotSupportedException">Thrown when Mtp is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
        /// <since_tizen> 4 </since_tizen>
        public IEnumerable <MtpStorage> GetStorages()
        {
            IntPtr storagePtr;
            int    count = 0;

            int ret = Interop.Mtp.GetStorages(_deviceHandle, out storagePtr, out count);

            if (ret != (int)MtpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get storage list, Error - " + (MtpError)ret);
                MtpErrorFactory.ThrowMtpException(ret);
            }

            for (int i = 0; i < count; i++)
            {
                int storageID = Marshal.ReadInt32(storagePtr);

                MtpStorage storageItem = new MtpStorage(_deviceHandle, storageID);
                _storageList.Add(storageItem);
                storagePtr += sizeof(int);
            }

            return(_storageList);
        }
Exemple #4
0
        /// <summary>
        /// Gets the list of objects.
        /// </summary>
        /// <param name="parentObject">The parent object handle. If parentHandle is 0, it means "root folder" of mtp storage.</param>
        /// <param name="fileType">The file type what you want.</param>
        /// <returns>List of objects.</returns>
        /// <feature>http://tizen.org/feature/network.mtp</feature>
        /// <remarks>
        /// http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.
        /// http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
        /// </remarks>
        /// <exception cref="NotSupportedException">Thrown when Mtp is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when method is failed due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
        /// <since_tizen> 4 </since_tizen>
        public IEnumerable <MtpObject> GetObjectList(MtpObject parentObject, MtpFileType fileType)
        {
            IntPtr objectPtr;
            int    count = 0;

            int ret = Interop.Mtp.GetObjectHandles(_deviceHandle, _storageHandle, parentObject.GetHandle(), (int)fileType, out objectPtr, out count);

            if (ret != (int)MtpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get object handle lists, Error - " + (MtpError)ret);
                MtpErrorFactory.ThrowMtpException(ret);
            }

            for (int i = 0; i < count; i++)
            {
                int objectID = Marshal.ReadInt32(objectPtr);

                MtpObject objectItem = new MtpObject(_deviceHandle, objectID);
                _objectList.Add(objectItem);
                objectPtr += sizeof(int);
            }

            return(_objectList);
        }