/*
-* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2021 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.
using System;
using System.Runtime.InteropServices;
using Tizen.Internals;
+using Tizen.Applications;
internal static partial class Interop
{
};
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate void NotificationCallback(IntPtr ctx, IntPtr data);
+ internal delegate void NotificationCallback(IntPtr ctx, IntPtr user_data);
+
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void DataRequestCallback(IntPtr data, string[] parameters, int params_size, IntPtr ctx, IntPtr user_data);
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_set_notification_cb")]
- internal static extern InspectionError SetNotificationCb(NotificationCallback callback, IntPtr data);
+ internal static extern InspectionError SetNotificationCb(NotificationCallback callback, IntPtr user_data);
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_unset_notification_cb")]
internal static extern InspectionError UnsetNotificationCb();
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_subscribe_event")]
+ internal static extern InspectionError SubscribeEvent(string event_name, string client_id);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_set_data_request_cb")]
+ internal static extern InspectionError SetDataRequestCb(DataRequestCallback callback, IntPtr user_data);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_unset_data_request_cb")]
+ internal static extern InspectionError UnsetDataRequestCb();
+
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_request_client_data")]
internal static extern InspectionError RequestClientData(string client_id, string[] parameters, int params_size, out IntPtr data);
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_get_data")]
+ internal static extern InspectionError GetData(IntPtr ctx, string[] parameters, int params_size, out IntPtr data);
+
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_data_read")]
internal static extern InspectionError DataRead(IntPtr data, IntPtr buf, uint count, int timeout_ms, out uint bytes_read);
- [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_data_destroy")]
- internal static extern void DataDestroy(IntPtr data);
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_data_write")]
+ internal static extern InspectionError DataWrite(IntPtr data, IntPtr buf, uint count, out uint bytes_written);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_send_event")]
+ internal static extern InspectionError SendEvent(string event_name, Bundle event_data);
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_get_client_id")]
- internal static extern InspectionError GetClientID(IntPtr ctx, out string client_id);
+ internal static extern InspectionError GetClientID(IntPtr ctx, out IntPtr client_id);
- [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_get_data")]
- internal static extern InspectionError GetData(IntPtr ctx, string[] parameters, int params_size, out IntPtr data);
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_get_event_name")]
+ internal static extern InspectionError GetEventName(IntPtr ctx, out IntPtr event_name);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_get_event_data")]
+ internal static extern InspectionError GetEventData(IntPtr ctx, out IntPtr event_data);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_request_bugreport")]
+ internal static extern InspectionError RequestBugreport(int pid);
+
+ [DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_data_destroy")]
+ internal static extern void DataDestroy(IntPtr data);
[DllImport(Libraries.Diagnostics, EntryPoint = "diagnostics_destroy")]
- internal static extern void Destroy(IntPtr data);
+ internal static extern void Destroy(IntPtr ctx);
}
}
--- /dev/null
+/*
+* Copyright (c) 2021 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 NativeApi = Interop.Inspections;
+
+namespace Tizen.Inspections
+{
+ /// <summary>
+ /// DataRequestReceivedEventArgs is an extended EventArgs class.
+ /// This class contains event arguments for the DataRequestReceived event from the Inspection class.
+ /// </summary>
+ public class DataRequestReceivedEventArgs : EventArgs
+ {
+ internal DataRequestReceivedEventArgs(InspectionData data, string[] parameters, InspectionContext ctx)
+ {
+ Data = data;
+ Parameters = parameters;
+ Context = ctx;
+ }
+
+ /// <summary>
+ /// The instance of InspectionData.
+ /// </summary>
+ public InspectionData Data { get; internal set; }
+
+ /// <summary>
+ /// An array of data request parameters.
+ /// </summary>
+ public string[] Parameters { get; internal set; }
+
+ /// <summary>
+ /// The instance of InspectionContext.
+ /// </summary>
+ public InspectionContext Context { get; internal set; }
+ }
+}
/*
-* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2021 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.
*/
using System;
+using System.Runtime.InteropServices;
+using Tizen;
+using Tizen.Applications;
using NativeApi = Interop.Inspections;
namespace Tizen.Inspections
public static class Inspector
{
private static NativeApi.NotificationCallback _notificationCallback;
+ private static NativeApi.DataRequestCallback _dataRequestCallback;
private static event EventHandler<EventReceivedEventArgs> _eventReceived;
+ private static event EventHandler<DataRequestReceivedEventArgs> _dataRequestReceived;
/// <summary>
/// Event to be invoked when new inspection context arrives.
}
/// <summary>
+ /// Event to be invoked when new inspection data request arrives.
+ /// </summary>
+ public static event EventHandler<DataRequestReceivedEventArgs> DataRequestReceived
+ {
+ add
+ {
+ if (_dataRequestReceived == null)
+ SetDataRequestCallback();
+ _dataRequestReceived += value;
+ }
+ remove
+ {
+ _dataRequestReceived -= value;
+ if (_dataRequestReceived == null)
+ UnsetDataRequestCallback();
+ }
+ }
+
+ /// <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);
+ }
+
+ /// <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);
+ }
+
+ /// <summary>
/// Requests other module (app or service) to provide inspection data.
/// </summary>
/// <param name="moduleID">An ID of module to request.</param>
return new InspectionData(data);
}
+ /// <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);
+ }
+
private static void SetNotificationCallback()
{
- _notificationCallback = (IntPtr ctx, IntPtr data) =>
+ _notificationCallback = (IntPtr ctx, IntPtr userData) =>
{
_eventReceived?.Invoke(null, new EventReceivedEventArgs(new InspectionContext(ctx)));
};
private static void UnsetNotificationCallback()
{
- NativeApi.UnsetNotificationCb();
+ var ret = NativeApi.UnsetNotificationCb();
+ if (ret != NativeApi.InspectionError.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ 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);
+ }
+
+ private static void UnsetDataRequestCallback()
+ {
+ var ret = NativeApi.UnsetDataRequestCb();
+ if (ret != NativeApi.InspectionError.None)
+ throw ExceptionFactory.CreateException(ret);
}
}
{
_handle = handle;
- var ret = NativeApi.GetClientID(handle, out string clientID);
+ IntPtr eventData = IntPtr.Zero;
+
+ var ret = NativeApi.GetClientID(handle, out IntPtr clientID);
if (ret != NativeApi.InspectionError.None)
throw ExceptionFactory.CreateException(ret);
- ModuleID = clientID;
+ 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));
+ }
}
/// <summary>
public string ModuleID { get; internal set; }
/// <summary>
+ /// Stores event name.
+ /// </summary>
+ public string EventName { get; internal set; }
+
+ /// <summary>
+ /// Stores event data.
+ /// </summary>
+ public Bundle EventData { get; internal set; }
+
+ /// <summary>
/// Dispose API for closing the internal resources.
/// </summary>
public void Dispose()
}
/// <summary>
+ /// Writes given number of bytes to inspection data.
+ /// </summary>
+ /// <param name="buffer">An array of bytes. This method copies count bytes from buffer to the current stream.</param>
+ /// <param name="offset">The zero-based byte offset in buffer at which to begin copying bytes to the current stream.</param>
+ /// <param name="count">The number of bytes to be written to the current stream.</param>
+ /// <returns>
+ /// The number of bytes written to the current stream.
+ /// </returns>
+ public int Write(byte[] buffer, int offset, int count)
+ {
+ return WriteUnsafe(buffer, offset, count);
+ }
+
+ private unsafe int WriteUnsafe(byte[] buffer, int offset, int count)
+ {
+ var length = Convert.ToUInt32(count);
+ uint bytes_written = 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.DataWrite(_handle, ptr, length, out bytes_written);
+ if (ret < NativeApi.InspectionError.None)
+ throw ExceptionFactory.CreateException(ret);
+ }
+
+ return (int)bytes_written;
+ }
+
+ /// <summary>
/// Dispose API for closing the internal resources.
/// </summary>
public void Dispose()