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 System.Runtime.InteropServices;
20 using System.Threading.Tasks;
22 namespace Tizen.Network.Smartcard
24 static internal class Globals
26 internal const string LogTag = "Tizen.Network.Smartcard";
29 internal class SmartcardManagerImpl : IDisposable
31 private static readonly SmartcardManagerImpl _instance = new SmartcardManagerImpl();
32 private List<SmartcardReader> _readerList = new List<SmartcardReader>();
33 private bool disposed = false;
35 internal static SmartcardManagerImpl Instance
43 private SmartcardManagerImpl()
48 ~SmartcardManagerImpl()
56 GC.SuppressFinalize(this);
59 private void Dispose(bool disposing)
66 // Free managed objects.
67 foreach (SmartcardReader reader in _readerList)
70 _readerList.Remove(reader);
73 //Free unmanaged objects
78 private void initialize()
80 int ret = Interop.Smartcard.Initialize();
81 if (ret != (int)SmartcardError.None)
83 Log.Error(Globals.LogTag, "Failed to initialize smartcard, Error - " + (SmartcardError)ret);
84 SmartcardErrorFactory.ThrowSmartcardException(ret);
88 private void deinitialize()
90 int ret = Interop.Smartcard.Deinitialize();
91 if (ret != (int)SmartcardError.None)
93 Log.Error(Globals.LogTag, "Failed to deinitialize smartcard, Error - " + (SmartcardError)ret);
97 internal IEnumerable<SmartcardReader> GetReaders()
102 int ret = Interop.Smartcard.GetReaders(out readerPtr, out len);
103 if (ret != (int)SmartcardError.None)
105 Log.Error(Globals.LogTag, "Failed to remove with AP, Error - " + (SmartcardError)ret);
106 SmartcardErrorFactory.ThrowSmartcardException(ret);
109 for (int i = 0; i < len; i++)
111 int readerID = Marshal.ReadInt32(readerPtr);
113 SmartcardReader readerItem = new SmartcardReader(readerID);
114 _readerList.Add(readerItem);
115 readerPtr += sizeof(int);