コード例 #1
0
        private void RegisterLifecycleEvent()
        {
            if (!s_lifecycleEventRefCnt.ContainsKey(Id))
            {
                s_lifecycleEventRefCnt[Id] = 0;
            }

            if (_created != null || _paused != null || _resumed != null || _destroyed != null)
            {
                return;
            }

            if (s_lifecycleEventRefCnt[Id] == 0)
            {
                if (_onLifecycleCallback == null)
                {
                    _onLifecycleCallback = new Interop.WidgetService.LifecycleCallback(OnLifecycleEvent);
                }

                Interop.WidgetService.ErrorCode err = Interop.WidgetService.SetLifecycleEvent(Id, _onLifecycleCallback, IntPtr.Zero);
                switch (err)
                {
                case Interop.WidgetService.ErrorCode.InvalidParameter:
                    throw new InvalidOperationException("Invalid parameter at unmanaged code");

                case Interop.WidgetService.ErrorCode.PermissionDenied:
                    throw new UnauthorizedAccessException();
                }
            }

            s_lifecycleEventRefCnt[Id]++;
            s_eventObjects.Add(this);
            Log.Debug(LogTag, "register lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
        }
コード例 #2
0
        private void UnregisterLifecycleEvent()
        {
            if (!s_lifecycleEventRefCnt.ContainsKey(Id))
            {
                return;
            }

            if (s_lifecycleEventRefCnt[Id] <= 0)
            {
                return;
            }

            if (_created != null || _paused != null || _resumed != null || _destroyed != null)
            {
                return;
            }

            if (s_lifecycleEventRefCnt[Id] == 1)
            {
                Interop.WidgetService.ErrorCode err = Interop.WidgetService.UnsetLifecycleEvent(Id, IntPtr.Zero);

                switch (err)
                {
                case Interop.WidgetService.ErrorCode.InvalidParameter:
                    throw new InvalidOperationException("Invalid parameter at unmanaged code");

                case Interop.WidgetService.ErrorCode.PermissionDenied:
                    throw new UnauthorizedAccessException();

                case Interop.WidgetService.ErrorCode.NotExist:
                    throw new InvalidOperationException("Event handler is not exist");

                case Interop.WidgetService.ErrorCode.NotSupported:
                    throw new NotSupportedException();
                }
                _onLifecycleCallback = null;
            }

            s_eventObjects.Remove(this);
            s_lifecycleEventRefCnt[Id]--;
            Log.Debug(LogTag, "unregister lifecycle cb " + Id + " [" + s_lifecycleEventRefCnt[Id] + "]");
        }