mirror of
https://github.com/openharmony/notification_notification_cangjie_wrapper.git
synced 2026-07-01 06:41:51 -04:00
@@ -21,6 +21,7 @@ import ohos.labels.APILevel
|
||||
import ohos.ffi.{Callback1Param, INVALID_CODE}
|
||||
import ohos.common_event_data.CCommonEventData
|
||||
import ohos.common_event_publish_data.CCommonEventPublishData
|
||||
import ohos.common_event_subscribe_info.CSubscribeInfo
|
||||
import ohos.business_exception.{BusinessException, AsyncCallback}
|
||||
public import ohos.common_event_data.CommonEventData
|
||||
public import ohos.common_event_publish_data.CommonEventPublishData
|
||||
@@ -75,12 +76,15 @@ public class CommonEventManager {
|
||||
syscap: "SystemCapability.Notification.CommonEvent"
|
||||
]
|
||||
public static func createSubscriber(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber {
|
||||
let ret = unsafe { CJ_CreateSubscriber(0) }
|
||||
if (ret == Int64(INVALID_CODE)) {
|
||||
var errorCode: Int32 = 0
|
||||
var info = CSubscribeInfo(subscribeInfo)
|
||||
let id = unsafe { FfiCommonEventManagerCreateSubscriber(inout info, inout errorCode) }
|
||||
info.free()
|
||||
if (errorCode == INVALID_CODE) {
|
||||
throw BusinessException(getErrorCode(ERROR_CES_UNINITIALIZED),
|
||||
"CommonEventManager: createSubscriber failed: ${getErrorMsg(ERROR_CES_UNINITIALIZED)}")
|
||||
}
|
||||
return CommonEventSubscriber(ret)
|
||||
return CommonEventSubscriber(id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,5 +34,7 @@ foreign {
|
||||
func CJ_Subscribe(id: Int64, funcId: Int64): Int32
|
||||
|
||||
func CJ_Unsubscribe(id: Int64): Int32
|
||||
|
||||
func FfiCommonEventManagerCreateSubscriber(info: CPointer<CSubscribeInfo>, errorCode: CPointer<Int32>): Int64
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ protected struct CSubscribeInfo {
|
||||
publisherPermission = LibC.mallocCString(info.publisherPermission)
|
||||
publisherDeviceId = LibC.mallocCString(info.publisherDeviceId)
|
||||
publisherBundleName = LibC.mallocCString(info.publisherBundleName)
|
||||
} catch(e: BusinessException) {
|
||||
} catch(e: Exception) {
|
||||
LibC.free(publisherPermission)
|
||||
LibC.free(publisherDeviceId)
|
||||
LibC.free(publisherBundleName)
|
||||
|
||||
Reference in New Issue
Block a user