[TCSACR-81][ADD] Added new property to get account handle
[platform/core/csapi/tizenfx.git] / src / Tizen.Account.AccountManager / Interop / Interop.AccountService.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19 using Tizen.Account.AccountManager;
20
21 /// <summary>
22 /// Interop for Account class APIs.
23 /// </summary>
24 /// <since_tizen> 3 </since_tizen>
25 internal static partial class Interop
26 {
27     /// <summary>
28     /// Interop for Account class APIs.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     internal static partial class AccountService
32     {
33         [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_to_db_by_id", CallingConvention = CallingConvention.Cdecl)]
34         internal static extern int UpdateAccountToDBById(SafeAccountHandle handle, int id);
35
36         [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_to_db_by_user_name", CallingConvention = CallingConvention.Cdecl)]
37         internal static extern int UpdateAccountToDBByUserName(IntPtr handle, string userName, string packageName);
38
39         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_account_id", CallingConvention = CallingConvention.Cdecl)]
40         internal static extern int QueryAccountById(int accountId, ref SafeAccountHandle handle);
41
42         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_user_name", CallingConvention = CallingConvention.Cdecl)]
43         internal static extern int QueryAccountByUserName(Interop.Account.AccountCallback callback, string userName, IntPtr userData);
44
45         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_package_name", CallingConvention = CallingConvention.Cdecl)]
46         internal static extern int QueryAccountByPackageName(Interop.Account.AccountCallback callback, string packageName, IntPtr userData);
47
48         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_capability_by_account_id", CallingConvention = CallingConvention.Cdecl)]
49         internal static extern int QueryAccountCapabilityById(Interop.Account.AccountCapabilityCallback callback, int accoutId, IntPtr data);
50
51         [DllImport(Libraries.AccountSvc, EntryPoint = "account_update_sync_status_by_id", CallingConvention = CallingConvention.Cdecl)]
52         internal static extern int UpdateAccountSyncStatusById(int accoutId, int status);
53
54         [DllImport(Libraries.AccountSvc, EntryPoint = "account_insert_to_db", CallingConvention = CallingConvention.Cdecl)]
55         internal static extern int AddAccount(SafeAccountHandle handle, out int accountId);
56
57         [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_id", CallingConvention = CallingConvention.Cdecl)]
58         internal static extern int DeleteAccountById(int accountId);
59
60         [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_user_name", CallingConvention = CallingConvention.Cdecl)]
61         internal static extern int DeleteAccountByUser(string userName, string packageName);
62
63         [DllImport(Libraries.AccountSvc, EntryPoint = "account_delete_from_db_by_package_name", CallingConvention = CallingConvention.Cdecl)]
64         internal static extern int DeleteAccountByPackage(string packageName);
65
66         [DllImport(Libraries.AccountSvc, EntryPoint = "account_get_total_count_from_db", CallingConvention = CallingConvention.Cdecl)]
67         internal static extern int GetAccountCount(out int count);
68
69         [DllImport(Libraries.AccountSvc, EntryPoint = "account_foreach_account_from_db")]
70         internal static extern int AccountForeachAccountFromDb(Interop.Account.AccountCallback callback, IntPtr userData);
71
72         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_capability")]
73         internal static extern int GetAccountByCapability(Interop.Account.AccountCallback callback, string capabilityType, int value, IntPtr userData);
74
75         [DllImport(Libraries.AccountSvc, EntryPoint = "account_query_account_by_capability_type")]
76         internal static extern int GetAccountByCapabilityType(Interop.Account.AccountCallback callback, string capabilityType, IntPtr userData);
77
78         [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_foreach_account_type_from_db")]
79         internal static extern int GetAllAccountproviders(Interop.AccountProvider.AccountProviderCallback callback, IntPtr userData);
80
81         [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_by_provider_feature")]
82         internal static extern int GetAccountProviderByFeature(Interop.AccountProvider.AccountProviderCallback callback, string key, IntPtr userData);
83
84         [DllImport(Libraries.AccountSvc, EntryPoint = "account_type_query_by_app_id")]
85         internal static extern int GetAccountProviderByAppId(string appId, out IntPtr handle);
86
87         [DllImport(Libraries.AccountSvc, EntryPoint = "account_subscribe_create")]
88         internal static extern int CreateAccountSubscriber(out Interop.AccountService.SafeAccountSubscriberHandle handle);
89
90         [DllImport(Libraries.AccountSvc, EntryPoint = "account_subscribe_notification")]
91         internal static extern int RegisterSubscriber(Interop.AccountService.SafeAccountSubscriberHandle handle, Interop.AccountService.SubscribeCallback callback, IntPtr userData);
92
93         [DllImport(Libraries.AccountSvc, EntryPoint = "account_unsubscribe_notification")]
94         internal static extern int UnregisterSubscriber(Interop.AccountService.SafeAccountSubscriberHandle handle);
95
96         //Callbacks
97         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
98         internal delegate bool SubscribeCallback(string eventType, int accountId, IntPtr userData);
99
100         internal sealed class SafeAccountSubscriberHandle : SafeHandle
101         {
102             public SafeAccountSubscriberHandle()
103                 : base(IntPtr.Zero, true)
104             {
105             }
106
107             public override bool IsInvalid
108             {
109                 get { return this.handle == IntPtr.Zero; }
110             }
111
112             protected override bool ReleaseHandle()
113             {
114                 this.SetHandle(IntPtr.Zero);
115                 return true;
116             }
117         }
118     }
119 }