From f0fc278b0e463c13715fd971995ff32961c8f264 Mon Sep 17 00:00:00 2001 From: lyj_love_code Date: Mon, 8 Aug 2022 10:36:21 +0800 Subject: [PATCH] add hiappevent js api Signed-off-by: lyj_love_code --- api/@ohos.hiAppEvent.d.ts | 204 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/api/@ohos.hiAppEvent.d.ts b/api/@ohos.hiAppEvent.d.ts index 6c03a9d019..2d694a38b5 100644 --- a/api/@ohos.hiAppEvent.d.ts +++ b/api/@ohos.hiAppEvent.d.ts @@ -132,6 +132,7 @@ declare namespace hiAppEvent { * write application event. * * @since 7 + * @deprecated since 9 * @syscap SystemCapability.HiviewDFX.HiAppEvent * @static * @param {string} eventName application event name. @@ -177,6 +178,209 @@ declare namespace hiAppEvent { */ maxStorage?: string; } + + /** + * Definition of written application event information. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + interface AppEventInfo { + /** + * The domain of the event. + */ + domain: string; + + /** + * The name of the event. + */ + name: string; + + /** + * The type of the event. + */ + eventType: EventType; + + /** + * The params of the event. + */ + params: object; + } + + /** + * write application event. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @static + * @param {AppEventInfo} info application event information to be written. + * @param {AsyncCallback} [callback] callback function. + * @return {void | Promise} no callback return Promise otherwise return void. + */ + function write(info: AppEventInfo): Promise; + function write(info: AppEventInfo, callback: AsyncCallback): void; + + /** + * Definition of the read event package. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + interface AppEventPackage { + /** + * The id of the package. + */ + packageId: number; + + /** + * The number of events contained in the package. + */ + row: number; + + /** + * The total size of events contained in the package. + */ + size: number; + + /** + * The events data contained in the package. + */ + data: string[]; + } + + /** + * Definition of event holder object, which is used to read the event data monitored by the watcher. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + class AppEventPackageHolder { + /** + * Constructor for AppEventPackageHolder. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @param {string} watcherName name of the watcher to read. + */ + constructor(watcherName: string); + + /** + * Set the threshold size per read. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @param {number} size threshold size. + */ + setSize(size: number): void; + + /** + * Read the event data monitored by the watcher. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @return {AppEventPackage} the read event package. + */ + takeNext(): AppEventPackage; + } + + /** + * Definition of the condition for triggering callback when the watcher monitors event data. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + interface TriggerCondition { + /** + * The number of write events that trigger callback. + */ + row?: number; + + /** + * The size of write events that trigger callback. + */ + size?: number; + + /** + * The interval for triggering callback. + */ + timeOut?: number; + } + + /** + * Definition of event filter object, which is used to filter events monitored by the watcher. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + interface AppEventFilter { + /** + * The name of the event domain to be monitored by the watcher. + */ + domain: string; + + /** + * The types of the events to be monitored by the watcher. + */ + eventTypes?: EventType[]; + } + + /** + * Definition of event watcher object, which is used to monitor written event data. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + */ + interface Watcher { + /** + * The name of watcher. + */ + name: string; + + /** + * The condition for triggering callback. + */ + triggerCondition?: TriggerCondition; + + /** + * The event filters for monitoring events. + */ + appEventFilters?: AppEventFilter[]; + + /** + * The callback function of watcher. + */ + onTrigger?: (curRow: number, curSize:number, holder:AppEventPackageHolder) => void; + } + + /** + * Add event watcher. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @static + * @param {Watcher} watcher watcher object for monitoring events. + * @return {AppEventPackageHolder} holder object, which is used to read the monitoring data of the watcher. + */ + function addWatcher(watcher: Watcher): AppEventPackageHolder; + + /** + * Remove event watcher. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @static + * @param {Watcher} watcher watcher object for monitoring events. + */ + function removeWatcher(watcher: Watcher): void; + + /** + * Clear all local logging data of the application. + * + * @since 9 + * @syscap SystemCapability.HiviewDFX.HiAppEvent + * @static + */ + function clearData(): void; } export default hiAppEvent; \ No newline at end of file -- Gitee