summaryrefslogtreecommitdiff
path: root/Tizen.Applications.NotificationEventListener/Interop/Interop.NotificationEventListener.cs
blob: 1e8b41323f472aa8b4626cc23160c5bc7248ae87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
 * Copyright (c) 2017 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 Tizen.Applications;
using Tizen.Applications.NotificationEventListener;

internal static partial class Interop
{
    internal static class NotificationEventListener
    {
        internal delegate void ChangedCallback(IntPtr userData, NotificationType type, IntPtr operationList, int num);

        internal enum ErrorCode
        {
            None = Tizen.Internals.Errors.ErrorCode.None,
            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
            OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
            IoError = Tizen.Internals.Errors.ErrorCode.IoError,
            DbError = -0x01140000 | 0x01,
            AlreadyExists = -0x01140000 | 0x02,
            DBusError = -0x01140000 | 0x03,
            DoesnotExist = -0x01140000 | 0x04,
            ServiceError = -0x01140000 | 0x05,
            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
            InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation
        }

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_free")]
        internal static extern ErrorCode Destroy(IntPtr handle);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_id")]
        internal static extern ErrorCode GetID(NotificationSafeHandle handle, out int groupId, out int privateId);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_pkgname")]
        internal static extern ErrorCode GetAppIdReferenceType(NotificationSafeHandle handle, out IntPtr appid);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_text")]
        internal static extern ErrorCode GetTextReferenceType(NotificationSafeHandle handle, NotificationText type, out IntPtr text);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_image")]
        internal static extern ErrorCode GetImageReferenceType(NotificationSafeHandle handle, NotificationImage type, out IntPtr text);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_insert_time")]
        internal static extern ErrorCode GetInsertTime(NotificationSafeHandle handle, out int time);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_time")]
        internal static extern ErrorCode GetTime(NotificationSafeHandle handle, out int time);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_sound")]
        internal static extern ErrorCode GetSoundReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_vibration")]
        internal static extern ErrorCode GetVibrationReferenceType(NotificationSafeHandle handle, out AccessoryOption type, out IntPtr path);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_led")]
        internal static extern ErrorCode GetLed(NotificationSafeHandle handle, out AccessoryOption type, out int color);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_led_time_period")]
        internal static extern ErrorCode GetLedTime(NotificationSafeHandle handle, out int onMilliSeconds, out int offMilliSeconds);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_tag")]
        internal static extern ErrorCode GetTagReferenceType(NotificationSafeHandle handle, out IntPtr tag);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_display_applist")]
        internal static extern ErrorCode GetStyleList(NotificationSafeHandle handle, out int styleList);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_auto_remove")]
        internal static extern ErrorCode GetAutoRemove(NotificationSafeHandle handle, out bool autoRemove);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_text_input_max_length")]
        internal static extern ErrorCode GetPlaceHolderLength(NotificationSafeHandle handle, out int max);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_launch_option")]
        internal static extern ErrorCode GetAppControl(NotificationSafeHandle handle, LaunchOption type, out SafeAppControlHandle appControlHandle);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_event_handler")]
        internal static extern ErrorCode GetEventHandler(NotificationSafeHandle handle, int type, out SafeAppControlHandle appControlHandle);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_register_detailed_changed_cb")]
        internal static extern ErrorCode SetChangedCallback(ChangedCallback callback, IntPtr userData);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_unregister_detailed_changed_cb")]
        internal static extern ErrorCode UnsetChangedCallback(ChangedCallback callback);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_op_get_data")]
        internal static extern ErrorCode GetOperationData(IntPtr operationList, NotificationOperationDataType type, out IntPtr userData);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_list_get_data")]
        internal static extern IntPtr GetData(IntPtr notificationList);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_list_get_next")]
        internal static extern IntPtr GetNext(IntPtr notificationList);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_delete_by_priv_id")]
        internal static extern ErrorCode Delete(string appId, NotificationType type, int uniqueNumber);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_clear")]
        internal static extern ErrorCode DeleteAll(int type);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_list")]
        internal static extern ErrorCode GetList(NotificationType type, int count, out IntPtr notification);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_send_event_by_priv_id")]
        internal static extern ErrorCode SendEvent(int uniqueNumber, int evnetType);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_layout")]
        internal static extern ErrorCode GetLayout(NotificationSafeHandle handle, out NotificationLayout type);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_type")]
        internal static extern ErrorCode GetType(NotificationSafeHandle handle, out NotificationType type);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_ongoing_value_type")]
        internal static extern ErrorCode GetOngoingType(NotificationSafeHandle handle, out ProgressCategory category);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_size")]
        internal static extern ErrorCode GetProgressSize(NotificationSafeHandle handle, out double value);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_progress")]
        internal static extern ErrorCode GetProgress(NotificationSafeHandle handle, out double value);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_property")]
        internal static extern ErrorCode GetProperties(NotificationSafeHandle handle, out int flags);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_extention_data")]
        internal static extern ErrorCode GetExtender(NotificationSafeHandle handle, string key, out SafeBundleHandle value);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_clone")]
        internal static extern ErrorCode GetClone(IntPtr handle, out IntPtr value);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_free_list")]
        internal static extern ErrorCode NotificationListFree(IntPtr list);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_args")]
        internal static extern ErrorCode GetExtentionBundle(NotificationSafeHandle handle, out IntPtr args, out IntPtr groupArgs);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_hide_timeout")]
        internal static extern ErrorCode GetHideTimeout(NotificationSafeHandle handle, out int timeout);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_delete_timeout")]
        internal static extern ErrorCode GetDeleteTimeout(NotificationSafeHandle handle, out int timeout);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_event_flag")]
        internal static extern ErrorCode GetEventFlag(NotificationSafeHandle handle, out bool eventFlag);

        [DllImport(Libraries.NotificationEventListener, EntryPoint = "notification_get_default_button")]
        internal static extern ErrorCode GetDefaultButton(NotificationSafeHandle handle, out int index);

        internal static ErrorCode GetAppId(NotificationSafeHandle handle, out string appid)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetAppIdReferenceType(handle, out ptr);

            if (ptr == IntPtr.Zero)
            {
                appid = null;
            }
            else
            {
                appid = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal static ErrorCode GetText(NotificationSafeHandle handle, NotificationText type, out string text)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetTextReferenceType(handle, type, out ptr);

            if (ptr == IntPtr.Zero)
            {
                text = null;
            }
            else
            {
                text = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal static ErrorCode GetImage(NotificationSafeHandle handle, NotificationImage type, out string text)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetImageReferenceType(handle, type, out ptr);

            if (ptr == IntPtr.Zero)
            {
                text = null;
            }
            else
            {
                text = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal static ErrorCode GetSound(NotificationSafeHandle handle, out AccessoryOption type, out string path)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetSoundReferenceType(handle, out type, out ptr);

            if (ptr == IntPtr.Zero)
            {
                path = null;
            }
            else
            {
                path = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal static ErrorCode GetVibration(NotificationSafeHandle handle, out AccessoryOption type, out string path)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetVibrationReferenceType(handle, out type, out ptr);

            if (ptr == IntPtr.Zero)
            {
                path = null;
            }
            else
            {
                path = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal static ErrorCode GetTag(NotificationSafeHandle handle, out string tag)
        {
            ErrorCode err;
            IntPtr ptr;
            err = GetTagReferenceType(handle, out ptr);

            if (ptr == IntPtr.Zero)
            {
                tag = null;
            }
            else
            {
                tag = Marshal.PtrToStringAnsi(ptr);
            }

            return err;
        }

        internal sealed class NotificationSafeHandle : SafeHandle
        {
            public NotificationSafeHandle()
                : base(IntPtr.Zero, true)
            {
            }

            internal NotificationSafeHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
            {
                SetHandle(existingHandle);
            }

            public override bool IsInvalid
            {
                get { return this.handle == IntPtr.Zero; }
            }

            protected override bool ReleaseHandle()
            {
                NotificationEventListener.Destroy(this.handle);
                this.SetHandle(IntPtr.Zero);
                return true;
            }
        }
    }
}