Beispiel #1
0
        /// <summary>
        /// The InspectionContext class constructor.
        /// </summary>
        /// <param name="handle">Inspection context received in the EventReceived event.</param>
        internal InspectionContext(IntPtr handle)
        {
            _handle = handle;

            IntPtr eventData = IntPtr.Zero;

            var ret = NativeApi.GetClientID(handle, out IntPtr clientID);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            ModuleID = Marshal.PtrToStringAnsi(clientID);

            ret = NativeApi.GetEventName(handle, out IntPtr eventName);
            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            EventName = Marshal.PtrToStringAnsi(eventName);

            ret = NativeApi.GetEventData(handle, out eventData);
            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            if (eventData != IntPtr.Zero)
            {
                EventData = new Bundle(new SafeBundleHandle(eventData, false));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Subscribes to inspection event sent by other module.
        /// </summary>
        /// <param name="eventName">Event name.</param>
        /// <param name="moduleID">An ID of the event sender module.</param>
        /// <remarks>
        /// This function is permitted only to an app signed by platform level certificates.
        /// </remarks>
        public static void SubscribeEvent(string eventName, string moduleID)
        {
            var ret = NativeApi.SubscribeEvent(eventName, moduleID);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #3
0
        private static void UnsetDataRequestCallback()
        {
            var ret = NativeApi.UnsetDataRequestCb();

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Requests bugreport creation.
        /// </summary>
        /// <privilege>http://tizen.org/privilege/bugreport.admin</privilege>
        /// <privlevel>platform</privlevel>
        /// <param name="pid">An ID of a process that should be livedumped. When pid is 0, system-wide bugreport is created.</param>
        public static void RequestBugreport(int pid)
        {
            var ret = NativeApi.RequestBugreport(pid);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sends inspection event.
        /// </summary>
        /// <param name="eventName">Event name.</param>
        /// <param name="eventData">Event data.</param>
        /// <remarks>
        /// This function is permitted only to an app signed by platform level certificates.
        /// </remarks>
        public static void SendEvent(string eventName, Bundle eventData)
        {
            var ret = NativeApi.SendEvent(eventName, eventData);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Dispose API for closing the internal resources.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (_handle != IntPtr.Zero)
         {
             NativeApi.DataDestroy(_handle);
             _handle = IntPtr.Zero;
         }
         _disposed = true;
     }
 }
Beispiel #7
0
        /// <summary>
        /// The InspectionContext class constructor.
        /// </summary>
        /// <param name="handle">Inspection context received in the EventReceived event.</param>
        internal InspectionContext(IntPtr handle)
        {
            _handle = handle;

            var ret = NativeApi.GetClientID(handle, out string clientID);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            ModuleID = clientID;
        }
Beispiel #8
0
        private static void SetNotificationCallback()
        {
            _notificationCallback = (IntPtr ctx, IntPtr data) =>
            {
                _eventReceived?.Invoke(null, new EventReceivedEventArgs(new InspectionContext(ctx)));
            };

            var ret = NativeApi.SetNotificationCb(_notificationCallback, IntPtr.Zero);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Requests other module (app or service) to provide inspection data.
        /// </summary>
        /// <param name="moduleID">An ID of module to request.</param>
        /// <param name="parameters">Array of request parameters passed to the module.</param>
        /// <returns>
        /// The instance of InspectionData.
        /// </returns>
        /// <remarks>
        /// This function is permitted only to an app signed by platform level certificates.
        /// </remarks>
        public static InspectionData RequestInspectableData(string moduleID, string[] parameters)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var ret = NativeApi.RequestClientData(moduleID, parameters, parameters.Length, out IntPtr data);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            return(new InspectionData(data));
        }
Beispiel #10
0
        /// <summary>
        /// Gets data from the context based on given parameters.
        /// </summary>
        /// <param name="parameters">Array of parameters.</param>
        /// <returns>
        /// The instance of InspectionData.
        /// </returns>
        /// <remarks>
        /// This function is permitted only to an app signed by platform level certificates.
        /// </remarks>
        public InspectionData GetInspectableData(string[] parameters)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var ret = NativeApi.GetData(_handle, parameters, parameters.Length, out IntPtr data);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }

            return(new InspectionData(data));
        }
Beispiel #11
0
        private static void SetDataRequestCallback()
        {
            _dataRequestCallback = (IntPtr data, string[] parameters, int paramsSize, IntPtr ctx, IntPtr userData) =>
            {
                InspectionContext context = ctx != IntPtr.Zero ? new InspectionContext(ctx) : null;

                _dataRequestReceived?.Invoke(null, new DataRequestReceivedEventArgs(new InspectionData(data), parameters, context));
            };

            var ret = NativeApi.SetDataRequestCb(_dataRequestCallback, IntPtr.Zero);

            if (ret != NativeApi.InspectionError.None)
            {
                throw ExceptionFactory.CreateException(ret);
            }
        }
Beispiel #12
0
        private unsafe int ReadUnsafe(byte[] buffer, int offset, int count, int timeout)
        {
            var  length     = Convert.ToUInt32(count);
            uint bytes_read = 0;

            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (offset + count > buffer.Length)
            {
                throw new ArgumentException("The sum of offset and count is larger than the buffer length");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));

                fixed(byte *p = &buffer[offset])
                {
                    IntPtr ptr = (IntPtr)p;
                    var    ret = NativeApi.DataRead(_handle, ptr, length, timeout, out bytes_read);

                    if (ret < NativeApi.InspectionError.None)
                    {
                        throw ExceptionFactory.CreateException(ret);
                    }
                }

                return((int)bytes_read);
        }
Beispiel #13
0
 private static void UnsetNotificationCallback()
 {
     NativeApi.UnsetNotificationCb();
 }