Esempio n. 1
0
        /// <summary>
        /// Registers a callback function to listen requests from the applications.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="addedEvent">The callback function pointer that is invoked when Add() is requested.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <remarks>
        /// Previous registered delegate function should be unregistered.
        /// </remarks>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
        public static void RegisterEventHandler(ShortcutAdded addedEvent)
        {
            if (shortcutAddCallback == null)
            {
                shortcutAddCallback = new Interop.Shortcut.AddCallback(AddCallback);

                Interop.Shortcut.ErrorCode err = Interop.Shortcut.SetShortcutAddCallback(shortcutAddCallback, IntPtr.Zero);
                if (err != Interop.Shortcut.ErrorCode.None)
                {
                    shortcutAddCallback = null;
                    throw ShortcutErrorFactory.GetException(err, "unable to register callback");
                }

                shortcutAdded = addedEvent;
            }
            else
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Unregisters a callback for the shortcut request.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="addedEvent">The callback function pointer that is used for RegisterCallback.</param>
        /// <feature>http://tizen.org/feature/shortcut</feature>
        /// <privilege>http://tizen.org/privilege/shortcut</privilege>
        /// <exception cref="ArgumentException">Thrown when an argument is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown in case the permission is denied.</exception>
        /// <exception cref="NotSupportedException">Thrown when the shortcut is not supported.</exception>
        public static void UnregisterEventHandler(ShortcutAdded addedEvent)
        {
            if (shortcutAdded != null && shortcutAdded.Equals(addedEvent))
            {
                shortcutAdded = null;

                if (shortcutAddCallback != null)
                {
                    Interop.Shortcut.UnsetShortcutAddCallback();
                    shortcutAddCallback = null;

                    int err = ErrorFacts.GetLastResult();
                    if (err != (int)Interop.Shortcut.ErrorCode.None)
                    {
                        throw ShortcutErrorFactory.GetException((Interop.Shortcut.ErrorCode)err, "unable to unregister callback");
                    }
                }
            }
            else
            {
                throw ShortcutErrorFactory.GetException(Interop.Shortcut.ErrorCode.InvalidParameter, null);
            }
        }