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