mirror of
https://github.com/openharmony/notification_notification_cangjie_wrapper.git
synced 2026-07-01 06:41:51 -04:00
@@ -22,6 +22,7 @@ ohos_cangjie_shared_library("ohos.common_event_publish_data") {
|
||||
]
|
||||
|
||||
cj_external_deps = [
|
||||
"cangjie_ark_interop:ohos.business_exception",
|
||||
"cangjie_ark_interop:ohos.ffi",
|
||||
"cangjie_ark_interop:ohos.labels",
|
||||
]
|
||||
|
||||
@@ -21,6 +21,7 @@ import std.collection.HashMap
|
||||
import ohos.labels.APILevel
|
||||
import ohos.value_type.{ValueType, CArrParameters, CParameters, createCpCString, createCArrParam}
|
||||
import ohos.ffi.{CArrString, CTypeResource}
|
||||
import ohos.business_exception.BusinessException
|
||||
|
||||
/**
|
||||
* The CommonEventPublishData module provides APIs for defining common event content and attributes.
|
||||
@@ -131,6 +132,10 @@ protected struct CCommonEventPublishData {
|
||||
let isOrdered: Bool
|
||||
let isSticky: Bool
|
||||
var parameters: CArrParameters = CArrParameters(CPointer<CParameters>(), 0)
|
||||
|
||||
/**
|
||||
* @throws { BusinessException } 1500009 - Error obtaining system parameters.
|
||||
*/
|
||||
protected init(c: CommonEventPublishData) {
|
||||
unsafe {
|
||||
try {
|
||||
@@ -150,7 +155,7 @@ protected struct CCommonEventPublishData {
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
free()
|
||||
throw e
|
||||
throw BusinessException(1500009, "Error obtaining system parameters.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ protected struct CSubscribeInfo {
|
||||
var publisherDeviceId: CString = CString(CPointer<UInt8>())
|
||||
var publisherBundleName: CString = CString(CPointer<UInt8>())
|
||||
|
||||
/**
|
||||
* @throws { BusinessException } 1500009 - Error obtaining system parameters.
|
||||
*/
|
||||
protected init(info: CommonEventSubscribeInfo) {
|
||||
priority = info.priority
|
||||
userId = info.userId
|
||||
@@ -47,7 +50,7 @@ protected struct CSubscribeInfo {
|
||||
LibC.free(publisherPermission)
|
||||
LibC.free(publisherDeviceId)
|
||||
LibC.free(publisherBundleName)
|
||||
throw e
|
||||
throw BusinessException(1500009, "Error obtaining system parameters.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,13 +66,16 @@ protected struct CParameters {
|
||||
let value: CPointer<Unit>
|
||||
let size: Int64
|
||||
|
||||
/**
|
||||
* @throws { BusinessException } 1500009 - Error obtaining system parameters.
|
||||
*/
|
||||
init(p: Parameters) {
|
||||
this.key = unsafe { LibC.mallocCString(p.key) }
|
||||
(valueType, this.value, this.size) = try {
|
||||
getValue(p.value)
|
||||
} catch (e: Exception) {
|
||||
unsafe { LibC.free(this.key) }
|
||||
throw e
|
||||
throw BusinessException(1500009, "Error obtaining system parameters.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +129,9 @@ protected struct CArrParameters {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws { BusinessException } 1500009 - Error obtaining system parameters.
|
||||
*/
|
||||
unsafe protected func createCArrParam(parameters: HashMap<String, ValueType>): CArrParameters {
|
||||
let cp = safeMalloc<CParameters>(count: parameters.size)
|
||||
let ptr = CArrParameters(cp, parameters.size)
|
||||
@@ -136,7 +142,7 @@ unsafe protected func createCArrParam(parameters: HashMap<String, ValueType>): C
|
||||
} catch (e: Exception) {
|
||||
freeCArrParam(ptr.head, count)
|
||||
LibC.free(cp)
|
||||
throw e
|
||||
throw BusinessException(1500009, "Error obtaining system parameters.")
|
||||
}
|
||||
ptr.head.write(count, value)
|
||||
count++
|
||||
@@ -164,6 +170,9 @@ unsafe func createArrPtr<T>(value: Array<T>): CPointer<Unit> where T <: CType {
|
||||
return CPointer<Unit>(ptr)
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws { BusinessException } 1500009 - Error obtaining system parameters.
|
||||
*/
|
||||
unsafe protected func createCpCString(value: Array<String>): CPointer<CString> {
|
||||
let ptr = safeMalloc<CString>(count: value.size)
|
||||
for (i in 0..value.size) {
|
||||
@@ -172,7 +181,7 @@ unsafe protected func createCpCString(value: Array<String>): CPointer<CString> {
|
||||
} catch (e: Exception) {
|
||||
freeCpCString(ptr, i)
|
||||
LibC.free(ptr)
|
||||
throw e
|
||||
throw BusinessException(1500009, "Error obtaining system parameters.")
|
||||
}
|
||||
}
|
||||
return ptr
|
||||
|
||||
Reference in New Issue
Block a user