diff options
author | Hyihong Chae <hh.chae@samsung.com> | 2017-05-02 12:48:26 +0900 |
---|---|---|
committer | Hyihong Chae <hh.chae@samsung.com> | 2017-05-02 12:51:50 +0900 |
commit | b7488732c577a447accca3a4ebf7892066de5eb7 (patch) | |
tree | 594313e4ee667d5968fba9af5cb0b0725c63d9cc | |
parent | eedb7e4813408275ba8aa7d99da3ce426831eece (diff) | |
download | mtp-b7488732c577a447accca3a4ebf7892066de5eb7.tar.gz mtp-b7488732c577a447accca3a4ebf7892066de5eb7.tar.bz2 mtp-b7488732c577a447accca3a4ebf7892066de5eb7.zip |
[C# MTP] Add initial codes
Change-Id: Idc1e0c20ba2f8160bbdbbd4d8451f79a1aef697c
Signed-off-by: HyiHong Chae <hh.chae@samsung.com>
24 files changed, 2358 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c9a181 --- /dev/null +++ b/.gitignore @@ -0,0 +1,242 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/Tizen.Network.Mtp/Interop/Interop.Glib.cs b/Tizen.Network.Mtp/Interop/Interop.Glib.cs new file mode 100644 index 0000000..576a6e2 --- /dev/null +++ b/Tizen.Network.Mtp/Interop/Interop.Glib.cs @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 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; + +internal static partial class Interop +{ + internal static partial class Glib + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool GSourceFunc(IntPtr userData); + + [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)] + internal static extern uint IdleAdd(GSourceFunc d, IntPtr data); + } +} diff --git a/Tizen.Network.Mtp/Interop/Interop.Libc.cs b/Tizen.Network.Mtp/Interop/Interop.Libc.cs new file mode 100644 index 0000000..825599e --- /dev/null +++ b/Tizen.Network.Mtp/Interop/Interop.Libc.cs @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2016 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; + +internal static partial class Interop +{ + internal static partial class Libc + { + [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)] + internal static extern int Free(IntPtr ptr); + } +} diff --git a/Tizen.Network.Mtp/Interop/Interop.Libraries.cs b/Tizen.Network.Mtp/Interop/Interop.Libraries.cs new file mode 100644 index 0000000..ae75b1a --- /dev/null +++ b/Tizen.Network.Mtp/Interop/Interop.Libraries.cs @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 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. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Mtp = "libcapi-network-mtp.so.0"; + public const string Glib = "libglib-2.0.so.0"; + public const string Libc = "libc.so.6"; + } +} diff --git a/Tizen.Network.Mtp/Interop/Interop.Mtp.cs b/Tizen.Network.Mtp/Interop/Interop.Mtp.cs new file mode 100644 index 0000000..bd50253 --- /dev/null +++ b/Tizen.Network.Mtp/Interop/Interop.Mtp.cs @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016 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; + +internal static partial class Interop +{ + internal static partial class Mtp + { + //Callback for event + //mtp_event_cb + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void MptStateChangedCallback(int eventType, int eventParameter, IntPtr userData); + + //capi-network-mtp-1.3.16-2.3.armv7l.rpm + ////Mtp Manager + [DllImport(Libraries.Mtp, EntryPoint = "mtp_initialize")] + internal static extern int Initialize(); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_deinitialize")] + internal static extern int Deinitialize(); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_get_devices")] + internal static extern int GetDevices(out IntPtr devices, out int count); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_get_storages")] + internal static extern int GetStorages(int device, out IntPtr storages, out int count); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_get_object_handles")] + internal static extern int GetObjectHandles(int device, int storage, int fileType, int parentHandle, out IntPtr objectHandle, out int count); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_get_object")] + internal static extern bool GetObject(int device, int objectHandle, string fileDestinationPath); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_get_thumbnail")] + internal static extern int getThumbnail(int device, int objectHandle, string fileDestinationPath); + + [DllImport(Libraries.Mtp, EntryPoint = "mtp_add_mtp_event_cb")] + internal static extern int AddMtpStateChangedCallback(MptStateChangedCallback callback, IntPtr userData); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_remove_mtp_event_cb")] + internal static extern int RemoveMtpStateChangedCallback(MptStateChangedCallback callback); + + internal static class DeviceInfomation + { + [DllImport(Libraries.Mtp, EntryPoint = "mtp_deviceinfo_get_manufacturer_name")] + internal static extern int GetManufacturerName(int device, out IntPtr manufacturerName); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_deviceinfo_get_model_name")] + internal static extern int GetModelName(int device, out IntPtr modelName); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_deviceinfo_get_serial_number")] + internal static extern int GetSerialNumber(int device, out IntPtr serialNumber); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_deviceinfo_get_device_version")] + internal static extern int GetDeviceVersion(int device, out IntPtr deviceVersion); + } + + internal static class StorageInformation + { + [DllImport(Libraries.Mtp, EntryPoint = "mtp_storageinfo_get_description")] + internal static extern int GetDescription(int device, int storage, out IntPtr description); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_storageinfo_get_free_space")] + internal static extern int GetFreeSpace(int device, int storage, out UInt64 freeSpace); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_storageinfo_get_max_capacity")] + internal static extern int GetMaxCapacity(int device, int storage, out UInt64 maxCapacity); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_storageinfo_get_storage_type")] + internal static extern int GetStorageType(int device, int storage, out int storageType); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_storageinfo_get_volume_identifier")] + internal static extern int GetVolumeIdentifier(int device, int storage, out IntPtr volumeIdentifier); + } + + internal static class ObjectInformation + { + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_file_name")] + internal static extern int GetFileName(int device, int objectHandle, out IntPtr fileName); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_keywords")] + internal static extern int GetKeywords(int device, int objectHandle, out IntPtr keyWords); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_association_desc")] + internal static extern int GetAssociationDescription(int device, int objectHandle, out int associationDescription); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_association_type")] + internal static extern int GetAssociationType(int device, int objectHandle, out int associationType); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_size")] + internal static extern int GetSize(int device, int objectHandle, out int size); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_parent_object_handle")] + internal static extern int GetParentObjectHandle(int device, int objectHandle, out int parentObjectHandle); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_storage")] + internal static extern int GetStorage(int device, int objectHandle, out int stroage); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_date_created")] + internal static extern int GetDateCreated(int device, int objectHandle, out int dateCreated); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_date_modified")] + internal static extern int GetDateModified(int device, int objectHandle, out int dateModified); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_file_type")] + internal static extern int GetFileType(int device, int objectHandle, out int fileType); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_image_bit_depth")] + internal static extern int GetImageBitDepth(int device, int objectHandle, out int depth); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_image_pix_width")] + internal static extern int GetImagePixWidth(int device, int objectHandle, out int width); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_image_pix_height")] + internal static extern int GetImagePixHeight(int device, int objectHandle, out int height); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_thumbnail_size")] + internal static extern int GetThumbnailSize(int device, int objectHandle, out int size); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_thumbnail_file_type")] + internal static extern int GetThumbnailFileType(int device, int objectHandle, out int fileType); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_thumbnail_pix_height")] + internal static extern int GetThumbnailPixHeight(int device, int objectHandle, out int height); + [DllImport(Libraries.Mtp, EntryPoint = "mtp_objectinfo_get_thumbnail_pix_width")] + internal static extern int GetThumbnailPixWidth(int device, int objectHandle, out int width); + } + + } +} diff --git a/Tizen.Network.Mtp/Properties/AssemblyInfo.cs b/Tizen.Network.Mtp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5fb1cac --- /dev/null +++ b/Tizen.Network.Mtp/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Network.Mtp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tizen.Network.Mtp")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9515cdfb-6634-4cd7-9efb-cb71628e3d92")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp.csproj b/Tizen.Network.Mtp/Tizen.Network.Mtp.csproj new file mode 100644 index 0000000..a17234d --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp.csproj @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{9515CDFB-6634-4CD7-9EFB-CB71628E3D92}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tizen.Network.Mtp</RootNamespace> + <AssemblyName>Tizen.Network.Mtp</AssemblyName> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup> + <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier> + <TargetFrameworkVersion>v1.3</TargetFrameworkVersion> + <NuGetTargetMoniker>.NETStandard,Version=v1.3</NuGetTargetMoniker> + <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences> + <NoStdLib>true</NoStdLib> + <NoWarn>$(NoWarn);1701;1702</NoWarn> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Prefer32Bit>false</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Prefer32Bit>false</Prefer32Bit> + </PropertyGroup> + <PropertyGroup> + <SignAssembly>true</SignAssembly> + </PropertyGroup> + <PropertyGroup> + <AssemblyOriginatorKeyFile>Tizen.Network.Mtp.snk</AssemblyOriginatorKeyFile> + </PropertyGroup> + <ItemGroup> + <None Include="Tizen.Network.Mtp.nuspec" /> + <None Include="Tizen.Network.Mtp.project.json" /> + <None Include="Tizen.Network.Mtp.snk" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Interop\Interop.Glib.cs" /> + <Compile Include="Interop\Interop.Libc.cs" /> + <Compile Include="Interop\Interop.Libraries.cs" /> + <Compile Include="Interop\Interop.Mtp.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpDevice.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpEnumerations.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpErrorFactory.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpEventArgs.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpManager.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpManagerEvent.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpManagerImpl.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpObject.cs" /> + <Compile Include="Tizen.Network.Mtp\MtpStorage.cs" /> + </ItemGroup> + <ItemGroup /> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <PropertyGroup> + <!-- https://github.com/dotnet/corefxlab/tree/master/samples/NetCoreSample and + https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild + --> + <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two + properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and + to prevent it from outputting a warning (MSB3644). + --> + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories> + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths> + <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences> + </PropertyGroup> +</Project>
\ No newline at end of file diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp.nuspec b/Tizen.Network.Mtp/Tizen.Network.Mtp.nuspec new file mode 100644 index 0000000..9249c25 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp.nuspec @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<package> + <metadata> + <id>Tizen.Network.Mtp</id> + <version>$version$</version> + <authors>Samsung Electronics</authors> + <requireLicenseAcceptance>false</requireLicenseAcceptance> + <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl> + <projectUrl>https://www.tizen.org/</projectUrl> + <iconUrl>https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png</iconUrl> + <copyright>© Samsung Electronics Co., Ltd All Rights Reserved</copyright> + <description>Provides the Mtp API for Tizen.Net</description> + <dependencies> + <dependency id="Tizen" version="1.0.2" /> + </dependencies> + </metadata> + <files> + <file src="bin/$Configuration$/Tizen.Network.Mtp.dll" target="lib/netstandard1.3" /> + </files> +</package> diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp.project.json b/Tizen.Network.Mtp/Tizen.Network.Mtp.project.json new file mode 100644 index 0000000..066fd72 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp.project.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.1", + "Tizen": "1.0.3" + }, + "frameworks": { + "netstandard1.3": {} + } +}
\ No newline at end of file diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp.sln b/Tizen.Network.Mtp/Tizen.Network.Mtp.sln new file mode 100644 index 0000000..0bcbb64 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Network.Mtp", "Tizen.Network.Mtp.csproj", "{9515CDFB-6634-4CD7-9EFB-CB71628E3D92}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9515CDFB-6634-4CD7-9EFB-CB71628E3D92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9515CDFB-6634-4CD7-9EFB-CB71628E3D92}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9515CDFB-6634-4CD7-9EFB-CB71628E3D92}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9515CDFB-6634-4CD7-9EFB-CB71628E3D92}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp.snk b/Tizen.Network.Mtp/Tizen.Network.Mtp.snk Binary files differnew file mode 100644 index 0000000..c0eac28 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp.snk diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpDevice.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpDevice.cs new file mode 100644 index 0000000..fd62713 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpDevice.cs @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2016 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 +{ + /// <summary> + /// A class for Mtp Device informations. It allows applications to handle device informations. + /// </summary> + public class MtpDevice : IDisposable + { + private int _deviceHandle = -1; + private bool disposed = false; + private List<MtpStorage> _storageList = new List<MtpStorage>(); + + /// <summary> + /// The manufacturer name. + /// </summary> + public string ManufacturerName + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.DeviceInfomation.GetManufacturerName(_deviceHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get manufacturer name, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + /// <summary> + /// The model name. + /// </summary> + public string ModelName + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.DeviceInfomation.GetModelName(_deviceHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get model name, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + /// <summary> + /// The serial number. + /// </summary> + public string SerialNumber + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.DeviceInfomation.GetSerialNumber(_deviceHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get serial number, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + /// <summary> + /// The device version. + /// </summary> + public string DeviceVersion + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.DeviceInfomation.GetDeviceVersion(_deviceHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get device version, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + internal MtpDevice(int handle) + { + _deviceHandle = handle; + } + + ~MtpDevice() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + foreach (MtpStorage storage in _storageList) + { + storage.Dispose(); + _storageList.Remove(storage); + } + } + //Free unmanaged objects + disposed = true; + } + + internal int GetHandle() + { + return _deviceHandle; + } + + /// <summary> + /// Gets the list of storages. + /// </summary> + /// <returns>List of storage objects.</returns> + 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; + } + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEnumerations.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEnumerations.cs new file mode 100644 index 0000000..da66932 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEnumerations.cs @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2016 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; + +namespace Tizen.Network.Mtp +{ + /// <summary> + /// Enumeration for Mtp storage type. + /// </summary> + public enum MtpStorageType + { + /// <summary> + /// Undifined + /// </summary> + Undifined = 0, + /// <summary> + /// fixed ROM + /// </summary> + FixedRom = 1, + /// <summary> + /// removable ROM + /// </summary> + RemovableRom = 2, + /// <summary> + /// fixed RAM + /// </summary> + FixedRam = 3, + /// <summary> + /// removable RAM + /// </summary> + RemovableRam = 4 + } + + /// <summary> + /// Enumeration for Mtp file type. + /// </summary> + public enum MtpFileType + { + /// <summary> + /// Folder + /// </summary> + Folder = 0, + /// <summary> + /// Wav + /// </summary> + Wav = 1, + /// <summary> + /// Mp3 + /// </summary> + Mp3 = 2, + /// <summary> + /// Wma + /// </summary> + Wma = 3, + /// <summary> + /// Ogg + /// </summary> + Ogg = 4, + /// <summary> + /// Audible + /// </summary> + Audible = 5, + /// <summary> + /// Mp4 + /// </summary> + Mp4 = 6, + /// <summary> + /// UndefAudio + /// </summary> + UndefAudio = 7, + /// <summary> + /// Wmv + /// </summary> + Wmv = 8, + /// <summary> + /// Avi + /// </summary> + Avi = 9, + /// <summary> + /// Mpeg + /// </summary> + Mpeg = 10, + /// <summary> + /// Asf + /// </summary> + Asf = 11, + /// <summary> + /// Qt + /// </summary> + Qt = 12, + /// <summary> + /// UndefVideo + /// </summary> + UndefVideo = 13, + /// <summary> + /// Jpeg + /// </summary> + Jpeg = 14, + /// <summary> + /// Jfif + /// </summary> + Jfif = 15, + /// <summary> + /// Tiff + /// </summary> + Tiff = 16, + /// <summary> + /// Bmp + /// </summary> + Bmp = 17, + /// <summary> + /// Gif + /// </summary> + Gif = 18, + /// <summary> + /// Pict + /// </summary> + Pict = 19, + /// <summary> + /// Png + /// </summary> + Png = 20, + /// <summary> + /// Vcalendar1 + /// </summary> + Vcalendar1 = 21, + /// <summary> + /// Vcalendar2 + /// </summary> + Vcalendar2 = 22, + /// <summary> + /// Vcard2 + /// </summary> + Vcard2 = 23, + /// <summary> + /// Vcard3 + /// </summary> + Vcard3 = 24, + /// <summary> + /// WindowsImageFormat + /// </summary> + WindowsImageFormat = 25, + /// <summary> + /// WinExec + /// </summary> + WinExec = 26, + /// <summary> + /// Text + /// </summary> + Text = 27, + /// <summary> + /// Html + /// </summary> + Html = 28, + /// <summary> + /// Firmware + /// </summary> + Firmware = 29, + /// <summary> + /// Aac + /// </summary> + Aac = 30, + /// <summary> + /// Mediacard + /// </summary> + Mediacard = 31, + /// <summary> + /// Flac + /// </summary> + Flac = 32, + /// <summary> + /// Mp2 + /// </summary> + Mp2 = 33, + /// <summary> + /// M4a + /// </summary> + M4a = 34, + /// <summary> + /// Doc + /// </summary> + Doc = 35, + /// <summary> + /// Xml + /// </summary> + Xml = 36, + /// <summary> + /// Xls + /// </summary> + Xls = 37, + /// <summary> + /// Ppt + /// </summary> + Ppt = 38, + /// <summary> + /// Mht + /// </summary> + Mht = 39, + /// <summary> + /// Jp2 + /// </summary> + Jp2 = 40, + /// <summary> + /// Jpx + /// </summary> + Jpx = 41, + /// <summary> + /// Album + /// </summary> + Album = 42, + /// <summary> + /// Playlist + /// </summary> + Playlist = 43, + /// <summary> + /// Unknown + /// </summary> + Unknown = 44, + /// <summary> + /// All (Helper type) + /// </summary> + All = 45, + /// <summary> + /// All Image (Helper type) + /// </summary> + AllImage = 46 + } + + /// <summary> + /// Enumeration for Mtp Event type. + /// </summary> + public enum MtpEventType + { + /// <summary> + /// Unknown + /// </summary> + Unknown, + /// <summary> + /// Storage Added + /// </summary> + StorageAdded, + /// <summary> + /// Storage Removed + /// </summary> + StorageRemoved, + /// <summary> + /// Object Added + /// </summary> + ObjectAdded, + /// <summary> + /// Object Removed + /// </summary> + ObjectRemoved, + /// <summary> + /// Device Added + /// </summary> + DeviceAdded, + /// <summary> + /// Device Removed + /// </summary> + DeviceRemoved, + /// <summary> + /// Turned Off + /// </summary> + TurnedOff + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpErrorFactory.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpErrorFactory.cs new file mode 100644 index 0000000..bb0b98d --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpErrorFactory.cs @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2016 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 Tizen.Internals.Errors; + +namespace Tizen.Network.Mtp +{ + static internal class MtpErrorValue + { + internal const int Base = -0x01CC0000; + } + + /// <summary> + /// Enumeration for Mtp Error. + /// </summary> + public enum MtpError + { + None = ErrorCode.None, + IoError = ErrorCode.IoError, + InvalidParameterError = ErrorCode.InvalidParameter, + OutOfMemoryError = ErrorCode.OutOfMemory, + PermissionDeniedError = ErrorCode.PermissionDenied, + NotSupportedError = ErrorCode.NotSupported, + + CommunicationError = MtpErrorValue.Base | 0x01, + ControllerError = MtpErrorValue.Base | 0x02, + NoDeviceError = MtpErrorValue.Base | 0x03, + NotInitializedError = MtpErrorValue.Base | 0x04, + NotActivatedError = MtpErrorValue.Base | 0x05, + NotActivatedCommunicationError = MtpErrorValue.Base | 0x06, + PluginFailError = MtpErrorValue.Base | 0x07 + } + + internal static class MtpErrorFactory + { + static internal void ThrowMtpException(int e) + { + ThrowException(e, false); + } + + static internal void ThrowMtpException(int e, int handle) + { + ThrowException(e, (handle < 0)); + } + + static private void ThrowException(int e, bool isHandleNull) + { + MtpError err = (MtpError)e; + + if (isHandleNull) + { + throw new InvalidOperationException("Invalid instance (object may have been disposed or released)"); + } + + if (err == MtpError.InvalidParameterError) + { + throw new ArgumentException(err.ToString()); + } + else if (err == MtpError.NotSupportedError) + { + throw new NotSupportedException(); + } + else + { + throw new InvalidOperationException(err.ToString()); + } + } + + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEventArgs.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEventArgs.cs new file mode 100644 index 0000000..881347e --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpEventArgs.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016 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.Collections.Generic; + +namespace Tizen.Network.Mtp +{ + /// <summary> + /// An extended EventArgs class which contains Mtp event. + /// </summary> + public class MtpStateChangedEventArgs : EventArgs + { + private MtpEventType _type = MtpEventType.Unknown; + private int _eventParameter; + + internal MtpStateChangedEventArgs(MtpEventType type, int eventParameter) + { + _type = type; + _eventParameter = eventParameter; + } + + /// <summary> + /// The Mtp event type. + /// </summary> + public MtpEventType Type + { + get + { + return _type; + } + } + + /// <summary> + /// The event parameter. + /// </summary> + public int EventParameter + { + get + { + return _eventParameter; + } + } + } + +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManager.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManager.cs new file mode 100644 index 0000000..8cde515 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManager.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 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.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Network.Mtp +{ + /// <summary> + /// A class for MTP management. It allows applications to use MTP service. + /// </summary> + static public class MtpManager + { + /// <summary> + /// Gets the list of available Secure Element readers. + /// </summary> + /// <returns>List of SmartcardReader objects.</returns> + static public IEnumerable<MtpDevice> GetDevices() + { + try + { + return MtpManagerImpl.Instance.GetDevices(); + } + catch (TypeInitializationException e) + { + throw e.InnerException; + } + } + + /// <summary> + /// The Activation changed event. + /// </summary> + static public event EventHandler<MtpStateChangedEventArgs> MtpStateChanged + { + add + { + try + { + MtpManagerImpl.Instance.MtpStateChanged += value; + } + catch (TypeInitializationException e) + { + throw e.InnerException; + } + } + remove + { + try + { + MtpManagerImpl.Instance.MtpStateChanged -= value; + } + catch (TypeInitializationException e) + { + throw e.InnerException; + } + } + } + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerEvent.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerEvent.cs new file mode 100644 index 0000000..7b23311 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerEvent.cs @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016 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.Threading.Tasks; + +namespace Tizen.Network.Mtp +{ + internal static class EventHandlerExtension + { + internal static void SafeInvoke(this EventHandler evt, object sender, EventArgs e) + { + var handler = evt; + if (handler != null) + { + handler(sender, e); + } + } + internal static void SafeInvoke<T>(this EventHandler<T> evt, object sender, T e) where T : EventArgs + { + var handler = evt; + if (handler != null) + { + handler(sender, e); + } + } + } + + internal partial class MtpManagerImpl + { + private event EventHandler<MtpStateChangedEventArgs> _mtpStateChanged; + + private Interop.Mtp.MptStateChangedCallback _mtpStateChangedCallback; + + internal event EventHandler<MtpStateChangedEventArgs> MtpStateChanged + { + add + { + if (_mtpStateChanged == null) + { + RegisterMtpStateChangedEvent(); + } + _mtpStateChanged += value; + } + remove + { + _mtpStateChanged -= value; + if (_mtpStateChanged == null) + { + UnregisterMtpStateChangedEvent(); + } + } + } + + private void RegisterMtpStateChangedEvent() + { + _mtpStateChangedCallback = (int eventType, int eventParameter, IntPtr userData) => + { + MtpEventType _eventType = (MtpEventType)eventType; + int _eventParameter = eventParameter; + MtpStateChangedEventArgs e = new MtpStateChangedEventArgs(_eventType, _eventParameter); + _mtpStateChanged.SafeInvoke(null, e); + }; + + int ret = Interop.Mtp.AddMtpStateChangedCallback(_mtpStateChangedCallback, IntPtr.Zero); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to add mtp state changed callback, Error - " + (MtpError)ret); + } + } + + private void UnregisterMtpStateChangedEvent() + { + int ret = Interop.Mtp.RemoveMtpStateChangedCallback(_mtpStateChangedCallback); + + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to remove mtp state changed callback, Error - " + (MtpError)ret); + } + } + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerImpl.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerImpl.cs new file mode 100644 index 0000000..111bdb0 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpManagerImpl.cs @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2016 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.Collections.Generic; +using System.Runtime.InteropServices; +using System.Threading.Tasks; + +namespace Tizen.Network.Mtp +{ + static internal class Globals + { + internal const string LogTag = "Tizen.Network.Mtp"; + } + + internal partial class MtpManagerImpl : IDisposable + { + private static readonly MtpManagerImpl _instance = new MtpManagerImpl(); + private List<MtpDevice> _deviceList = new List<MtpDevice>(); + private bool disposed = false; + + internal static MtpManagerImpl Instance + { + get + { + return _instance; + } + } + + private MtpManagerImpl() + { + Initialize(); + } + + ~MtpManagerImpl() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + } + //Free unmanaged objects + Deinitialize(); + disposed = true; + } + + 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); + } + } + + private void Deinitialize() + { + int ret = Interop.Mtp.Deinitialize(); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to Deinitialize Mtp, Error - " + (MtpError)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; + } + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpObject.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpObject.cs new file mode 100644 index 0000000..d129cbf --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpObject.cs @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2016 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 +{ + /// <summary> + /// A class for Mtp Object informations. It allows applications to handle object informations. + /// </summary> + public class MtpObject : IDisposable + { + private int _deviceHandle = -1; + private int _objectHandle = -1; + private bool disposed = false; + + /// <summary> + /// The file name. + /// </summary> + 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); + } + } + + /// <summary> + /// The keywords. + /// </summary> + 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); + } + } + + /// <summary> + /// The association description. + /// </summary> + 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; + } + } + + /// <summary> + /// The association type. + /// </summary> + 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; + } + } + + /// <summary> + /// The size. + /// </summary> + 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; + } + } + + /// <summary> + //TODO /// The parent object handle. + /// </summary> + 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; + } + } + + /// <summary> + //TODO /// The storage. + /// </summary> + 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; + } + } + + /// <summary> + /// The date created + /// </summary> + 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; + } + } + + /// <summary> + /// The date modified. + /// </summary> + 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; + } + } + + /// <summary> + /// The file type. + /// </summary> + 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; + } + } + + /// <summary> + /// The image bit depth. + /// </summary> + 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; + } + } + + /// <summary> + /// The image pixel width. + /// </summary> + 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; + } + } + + /// <summary> + /// The image pixel height. + /// </summary> + 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; + } + } + + /// <summary> + /// The thumbnail size. + /// </summary> + 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; + } + } + + /// <summary> + /// The thumbnail file type. + /// </summary> + 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; + } + } + + /// <summary> + /// The thumbnail pixel width. + /// </summary> + 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; + } + } + + /// <summary> + /// The thumbnail pixel height. + /// </summary> + 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() + { + Dispose(false); + } + + 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; + } + + } +} diff --git a/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpStorage.cs b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpStorage.cs new file mode 100644 index 0000000..6cee673 --- /dev/null +++ b/Tizen.Network.Mtp/Tizen.Network.Mtp/MtpStorage.cs @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2016 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 +{ + /// <summary> + /// A class for Mtp Storage informations. It allows applications to handle storage informations. + /// </summary> + public class MtpStorage : IDisposable + { + private int _deviceHandle = -1; + private int _storageHandle = -1; + private bool disposed = false; + private List<int> _objectHandleList = new List<int>(); + private List<MtpObject> _objectList = new List<MtpObject>(); + //private int _objectHandle = 0; + + /// <summary> + /// The description. + /// </summary> + public string Description + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.StorageInformation.GetDescription(_deviceHandle, _storageHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get description, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + /// <summary> + /// The free space. + /// </summary> + public UInt64 FreeSpace + { + get + { + UInt64 freeSpace; + int ret = Interop.Mtp.StorageInformation.GetFreeSpace(_deviceHandle, _storageHandle, out freeSpace); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret); + } + return freeSpace; + } + } + + /// <summary> + /// The max capacity. + /// </summary> + public UInt64 MaxCapacity + { + get + { + UInt64 maxCapacity; + int ret = Interop.Mtp.StorageInformation.GetMaxCapacity(_deviceHandle, _storageHandle, out maxCapacity); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret); + } + return maxCapacity; + } + } + + /// <summary> + /// The storage type. + /// </summary> + public MtpStorageType StorageType + { + get + { + int storageType; + int ret = Interop.Mtp.StorageInformation.GetStorageType(_deviceHandle, _storageHandle, out storageType); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get free space, Error - " + (MtpError)ret); + } + return (MtpStorageType)storageType; + } + } + + /// <summary> + /// The volume identifier. + /// </summary> + public string VolumeIdentifier + { + get + { + IntPtr strPtr; + int ret = Interop.Mtp.StorageInformation.GetVolumeIdentifier(_deviceHandle, _storageHandle, out strPtr); + if (ret != (int)MtpError.None) + { + Log.Error(Globals.LogTag, "Failed to get volume identifier, Error - " + (MtpError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + + internal MtpStorage(int deviceHandle, int storageHandle) + { + _deviceHandle = deviceHandle; + _storageHandle = storageHandle; + } + + ~MtpStorage() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. +/* foreach (SmartcardChannel channel in _basicChannelList) + { + channel.Dispose(); + _basicChannelList.Remove(channel); + } + + foreach (SmartcardChannel channel in _logicalChannelList) + { + channel.Dispose(); + _logicalChannelList.Remove(channel); + } +*/ } + //Free unmanaged objects + disposed = true; + } + + internal int GetHandle() + { + return _storageHandle; + } + + /// <summary> + /// Gets the list of storages. + /// </summary> + /// <returns>List of storage objects.</returns> + public IEnumerable<MtpObject> GetObjectHandles(int parentHandle, MtpFileType fileType) + { + IntPtr objectPtr; + int count = 0; + + int ret = Interop.Mtp.GetObjectHandles(_deviceHandle, _storageHandle, parentHandle, (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; + } + } +} diff --git a/packaging/csapi-network-mtp.manifest b/packaging/csapi-network-mtp.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-network-mtp.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/packaging/csapi-network-mtp.spec b/packaging/csapi-network-mtp.spec new file mode 100644 index 0000000..77fda8d --- /dev/null +++ b/packaging/csapi-network-mtp.spec @@ -0,0 +1,44 @@ +Name: csapi-network-mtp +Summary: Tizen Mtp API for C# +Version: 1.0.0 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +AutoReqProv: no +ExcludeArch: aarch64 + +BuildRequires: dotnet-build-tools + +# C# API Requries +BuildRequires: csapi-tizen-nuget + +%define Assemblies Tizen.Network.Mtp + +%description +%{summary} + +%dotnet_import_sub_packages + +%prep +%setup -q +cp %{SOURCE1} . + +%build +for ASM in %{Assemblies}; do +%dotnet_build $ASM +%dotnet_pack $ASM/$ASM.nuspec %{version} +done + +%install +for ASM in %{Assemblies}; do +%dotnet_install $ASM +done + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_files} |