Add check box for notification (#5342)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.NotificationEventListener / Interop / Interop.NotificationEventListener.cs
1 /*
2  * Copyright (c) 2017 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.Collections.Generic;
19 using System.Runtime.InteropServices;
20
21 using Tizen.Applications;
22 using Tizen.Applications.NotificationEventListener;
23
24 internal static partial class Interop
25 {
26     internal static class NotificationEventListener
27     {
28         internal delegate void ChangedCallback(IntPtr userData, NotificationType type, IntPtr operationList, int num);
29
30         internal enum ErrorCode
31         {
32             None = Tizen.Internals.Errors.ErrorCode.None,
33             InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
34             OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
35             IoError = Tizen.Internals.Errors.ErrorCode.IoError,
36             DbError = -0x01140000 | 0x01,
37             AlreadyExists = -0x01140000 | 0x02,
38             DBusError = -0x01140000 | 0x03,
39             DoesnotExist = -0x01140000 | 0x04,
40             ServiceError = -0x01140000 | 0x05,
41             PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
42             InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation
43         }
44
45         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_free")]
46         internal static extern ErrorCode Destroy(IntPtr handle);
47
48         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_id")]
49         internal static extern ErrorCode GetID(NotificationSafeHandle handle, out int groupId, out int privateId);
50
51         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_pkgname")]
52         internal static extern ErrorCode GetAppIdReferenceType(NotificationSafeHandle handle, out IntPtr appid);
53
54         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_text")]
55         internal static extern ErrorCode GetTextReferenceType(NotificationSafeHandle handle, NotificationText type, out IntPtr text);
56
57         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_image")]
58         internal static extern ErrorCode GetImageReferenceType(NotificationSafeHandle handle, NotificationImage type, out IntPtr text);
59
60         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_insert_time")]
61         internal static extern ErrorCode GetInsertTime(NotificationSafeHandle handle, out int time);
62
63         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_time")]
64         internal static extern ErrorCode GetTime(NotificationSafeHandle handle, out int time);
65
66         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_sound")]
67         internal static extern ErrorCode GetSoundReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);
68
69         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_vibration")]
70         internal static extern ErrorCode GetVibrationReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);
71
72         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_led")]
73         internal static extern ErrorCode GetLed(NotificationSafeHandle handle, out AccessoryOption type, out int color);
74
75         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_led_time_period")]
76         internal static extern ErrorCode GetLedTime(NotificationSafeHandle handle, out int onMilliSeconds, out int offMilliSeconds);
77
78         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_tag")]
79         internal static extern ErrorCode GetTagReferenceType(NotificationSafeHandle handle, out IntPtr tag);
80
81         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_display_applist")]
82         internal static extern ErrorCode GetStyleList(NotificationSafeHandle handle, out int styleList);
83
84         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_auto_remove")]
85         internal static extern ErrorCode GetAutoRemove(NotificationSafeHandle handle, out bool autoRemove);
86
87         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_text_input_max_length")]
88         internal static extern ErrorCode GetPlaceHolderLength(NotificationSafeHandle handle, out int max);
89
90         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_launch_option")]
91         internal static extern ErrorCode GetAppControl(NotificationSafeHandle handle, LaunchOption type, out SafeAppControlHandle appControlHandle);
92
93         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_event_handler")]
94         internal static extern ErrorCode GetEventHandler(NotificationSafeHandle handle, int type, out SafeAppControlHandle appControlHandle);
95
96         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_register_detailed_changed_cb")]
97         internal static extern ErrorCode SetChangedCallback(ChangedCallback callback, IntPtr userData);
98
99         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_unregister_detailed_changed_cb")]
100         internal static extern ErrorCode UnsetChangedCallback(ChangedCallback callback);
101
102         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_op_get_data")]
103         internal static extern ErrorCode GetOperationData(IntPtr operationList, NotificationOperationDataType type, out IntPtr userData);
104
105         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_list_get_data")]
106         internal static extern IntPtr GetData(IntPtr notificationList);
107
108         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_list_get_next")]
109         internal static extern IntPtr GetNext(IntPtr notificationList);
110
111         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_delete_by_priv_id")]
112         internal static extern ErrorCode Delete(string appId, NotificationType type, int uniqueNumber);
113
114         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_clear")]
115         internal static extern ErrorCode DeleteAll(int type);
116
117         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_list")]
118         internal static extern ErrorCode GetList(NotificationType type, int count, out IntPtr notification);
119
120         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_send_event_by_priv_id")]
121         internal static extern ErrorCode SendEvent(int uniqueNumber, int evnetType);
122
123         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_layout")]
124         internal static extern ErrorCode GetLayout(NotificationSafeHandle handle, out NotificationLayout type);
125
126         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_type")]
127         internal static extern ErrorCode GetType(NotificationSafeHandle handle, out NotificationType type);
128
129         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_ongoing_value_type")]
130         internal static extern ErrorCode GetOngoingType(NotificationSafeHandle handle, out ProgressCategory category);
131
132         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_size")]
133         internal static extern ErrorCode GetProgressSize(NotificationSafeHandle handle, out double value);
134
135         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_progress")]
136         internal static extern ErrorCode GetProgress(NotificationSafeHandle handle, out double value);
137
138         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_property")]
139         internal static extern ErrorCode GetProperties(NotificationSafeHandle handle, out int flags);
140
141         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_extension_data")]
142         internal static extern ErrorCode GetExtender(NotificationSafeHandle handle, string key, out SafeBundleHandle value);
143
144         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_clone")]
145         internal static extern ErrorCode GetClone(IntPtr handle, out IntPtr value);
146
147         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_free_list")]
148         internal static extern ErrorCode NotificationListFree(IntPtr list);
149
150         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_args")]
151         internal static extern ErrorCode GetExtensionBundle(NotificationSafeHandle handle, out IntPtr args, out IntPtr groupArgs);
152
153         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_hide_timeout")]
154         internal static extern ErrorCode GetHideTimeout(NotificationSafeHandle handle, out int timeout);
155
156         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_delete_timeout")]
157         internal static extern ErrorCode GetDeleteTimeout(NotificationSafeHandle handle, out int timeout);
158
159         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_event_flag")]
160         internal static extern ErrorCode GetEventFlag(NotificationSafeHandle handle, out bool eventFlag);
161
162         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_default_button")]
163         internal static extern ErrorCode GetDefaultButton(NotificationSafeHandle handle, out int index);
164
165         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_extension_event_handler")]
166         internal static extern ErrorCode GetExtensionAction(NotificationSafeHandle handle, UserEventType type, out SafeAppControlHandle appcontrol);
167
168         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_load")]
169         internal static extern IntPtr LoadNotification(string appID, int uniqueID);
170
171         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_all_count")]
172         internal static extern ErrorCode GetAllCount(NotificationType type, out int count);
173
174         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_set_check_box_checked")]
175         internal static extern ErrorCode SetCheckedValue(NotificationSafeHandle handle, bool checkedValue);
176
177         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_check_box")]
178         internal static extern ErrorCode GetCheckBox(NotificationSafeHandle handle, out bool flag, out bool checkedValue);
179
180         [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_send_event")]
181         internal static extern ErrorCode SendEventWithNotification(NotificationSafeHandle handle, int evnetType);
182
183
184
185         internal static ErrorCode GetAppId(NotificationSafeHandle handle, out string appid)
186         {
187             ErrorCode err;
188             IntPtr ptr;
189             err = GetAppIdReferenceType(handle, out ptr);
190
191             if (ptr == IntPtr.Zero)
192             {
193                 appid = null;
194             }
195             else
196             {
197                 appid = Marshal.PtrToStringAnsi(ptr);
198             }
199
200             return err;
201         }
202
203         internal static ErrorCode GetText(NotificationSafeHandle handle, NotificationText type, out string text)
204         {
205             ErrorCode err;
206             IntPtr ptr;
207             err = GetTextReferenceType(handle, type, out ptr);
208
209             if (ptr == IntPtr.Zero)
210             {
211                 text = null;
212             }
213             else
214             {
215                 text = Marshal.PtrToStringAnsi(ptr);
216             }
217
218             return err;
219         }
220
221         internal static ErrorCode GetImage(NotificationSafeHandle handle, NotificationImage type, out string text)
222         {
223             ErrorCode err;
224             IntPtr ptr;
225             err = GetImageReferenceType(handle, type, out ptr);
226
227             if (ptr == IntPtr.Zero)
228             {
229                 text = null;
230             }
231             else
232             {
233                 text = Marshal.PtrToStringAnsi(ptr);
234             }
235
236             return err;
237         }
238
239         internal static ErrorCode GetSound(NotificationSafeHandle handle, out AccessoryOption type, out string path)
240         {
241             ErrorCode err;
242             IntPtr ptr;
243             err = GetSoundReferenceType(handle, out type, out ptr);
244
245             if (ptr == IntPtr.Zero)
246             {
247                 path = null;
248             }
249             else
250             {
251                 path = Marshal.PtrToStringAnsi(ptr);
252             }
253
254             return err;
255         }
256
257         internal static ErrorCode GetVibration(NotificationSafeHandle handle, out AccessoryOption type, out string path)
258         {
259             ErrorCode err;
260             IntPtr ptr;
261             err = GetVibrationReferenceType(handle, out type, out ptr);
262
263             if (ptr == IntPtr.Zero)
264             {
265                 path = null;
266             }
267             else
268             {
269                 path = Marshal.PtrToStringAnsi(ptr);
270             }
271
272             return err;
273         }
274
275         internal static ErrorCode GetTag(NotificationSafeHandle handle, out string tag)
276         {
277             ErrorCode err;
278             IntPtr ptr;
279             err = GetTagReferenceType(handle, out ptr);
280
281             if (ptr == IntPtr.Zero)
282             {
283                 tag = null;
284             }
285             else
286             {
287                 tag = Marshal.PtrToStringAnsi(ptr);
288             }
289
290             return err;
291         }
292
293         internal sealed class NotificationSafeHandle : SafeHandle
294         {
295             public NotificationSafeHandle()
296                 : base(IntPtr.Zero, true)
297             {
298             }
299
300             internal NotificationSafeHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
301             {
302                 SetHandle(existingHandle);
303             }
304
305             public override bool IsInvalid
306             {
307                 get { return this.handle == IntPtr.Zero; }
308             }
309
310             protected override bool ReleaseHandle()
311             {
312                 NotificationEventListener.Destroy(this.handle);
313                 this.SetHandle(IntPtr.Zero);
314                 return true;
315             }
316         }
317     }
318 }