diff --git a/frameworks/extension/src/ani/ani_common_event_utils.cpp b/frameworks/extension/src/ani/ani_common_event_utils.cpp index 17f6dea9c5e38c7988b98b0114cc08c70c419188..6738dc6412b3ec092c19ccf166bdfa5a27bf7061 100644 --- a/frameworks/extension/src/ani/ani_common_event_utils.cpp +++ b/frameworks/extension/src/ani/ani_common_event_utils.cpp @@ -17,12 +17,14 @@ #include "ani_common_want.h" #include "event_log_wrapper.h" +#include + namespace OHOS { namespace EventManagerFwkAni { using namespace OHOS::EventFwk; using namespace OHOS::AppExecFwk; -#define SETTER_METHOD_NAME(property) "" #property +using namespace arkts::ani_signature; void AniCommonEventUtils::CreateNewObjectByClass( ani_env* env, const char* className, ani_class& cls, ani_object& ani_data) @@ -94,6 +96,7 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( ani_env* env, ani_object& ani_data, const CommonEventData& commonEventData) { EVENT_LOGD("called"); + ani_class cls = nullptr; CreateNewObjectByClass(env, "commonEvent.commonEventData.CommonEventDataImpl", cls, ani_data); if ((ani_data == nullptr) || (cls == nullptr)) { @@ -105,26 +108,26 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( // set event [string] env->String_NewUTF8( commonEventData.GetWant().GetAction().c_str(), commonEventData.GetWant().GetAction().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(event), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("event").c_str(), string); // set bundleName [string] env->String_NewUTF8( commonEventData.GetWant().GetBundle().c_str(), commonEventData.GetWant().GetBundle().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(bundleName), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("bundleName").c_str(), string); // set data [string] env->String_NewUTF8(commonEventData.GetData().c_str(), commonEventData.GetData().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(data), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("data").c_str(), string); // set code [number] ani_object codeObject; CreateAniIntObject(env, codeObject, commonEventData.GetCode()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(code), codeObject); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("code").c_str(), codeObject); // set parameters [Record] ani_ref wantParamRef = WrapWantParams(env, commonEventData.GetWant().GetParams()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(parameters), wantParamRef); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("parameters").c_str(), wantParamRef); } } // namespace EventManagerFwkAni -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp b/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp index 2d7a166538be212866ff7009270e3fc679e9e9f5..c046ece975aaf09fcbf79484bdc1b74e93c988ab 100644 --- a/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp +++ b/interfaces/kits/ani/common_event/src/ani_common_event_utils.cpp @@ -17,12 +17,14 @@ #include "ani_common_want.h" #include "event_log_wrapper.h" +#include + namespace OHOS { namespace EventManagerFwkAni { using namespace OHOS::EventFwk; using namespace OHOS::AppExecFwk; -#define SETTER_METHOD_NAME(property) "" #property +using namespace arkts::ani_signature; void AniCommonEventUtils::GetStdString(ani_env* env, ani_string str, std::string& result) { @@ -358,36 +360,36 @@ void AniCommonEventUtils::GetCommonEventSubscribeInfoToEts( // set events [Array] ani_object eventsParamRef = GetAniStringArray(env, subscriber->GetSubscribeInfo().GetMatchingSkills().GetEvents()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(events), eventsParamRef); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("events").c_str(), eventsParamRef); ani_string string = nullptr; // set publisherPermission [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetPermission().c_str(), subscriber->GetSubscribeInfo().GetPermission().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherPermission), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherPermission").c_str(), string); // set publisherDeviceId [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetDeviceId().c_str(), subscriber->GetSubscribeInfo().GetDeviceId().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherDeviceId), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherDeviceId").c_str(), string); // set publisherBundleName [string] status = env->String_NewUTF8( subscriber->GetSubscribeInfo().GetPublisherBundleName().c_str(), subscriber->GetSubscribeInfo().GetPublisherBundleName().size(), &string); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(publisherBundleName), string); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("publisherBundleName").c_str(), string); // set userId [int] ani_object userIdObject; CreateAniIntObject(env, userIdObject, subscriber->GetSubscribeInfo().GetUserId()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(userId), userIdObject); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("userId").c_str(), userIdObject); // set priority [int] ani_object priorityObject; CreateAniIntObject(env, priorityObject, subscriber->GetSubscribeInfo().GetPriority()); - CallSetter(env, cls, infoObject, SETTER_METHOD_NAME(priority), priorityObject); + CallSetter(env, cls, infoObject, Builder::BuildSetterName("priority").c_str(), priorityObject); } ani_object AniCommonEventUtils::GetAniStringArray(ani_env *env, std::vector strs) @@ -560,26 +562,26 @@ void AniCommonEventUtils::ConvertCommonEventDataToEts( // set event [string] env->String_NewUTF8( commonEventData.GetWant().GetAction().c_str(), commonEventData.GetWant().GetAction().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(event), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("event").c_str(), string); // set bundleName [string] env->String_NewUTF8( commonEventData.GetWant().GetBundle().c_str(), commonEventData.GetWant().GetBundle().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(bundleName), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("bundleName").c_str(), string); // set data [string] env->String_NewUTF8(commonEventData.GetData().c_str(), commonEventData.GetData().size(), &string); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(data), string); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("data").c_str(), string); // set code [int] ani_object codeObject; CreateAniIntObject(env, codeObject, commonEventData.GetCode()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(code), codeObject); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("code").c_str(), codeObject); // set parameters [Record] ani_ref wantParamRef = WrapWantParams(env, commonEventData.GetWant().GetParams()); - CallSetter(env, cls, ani_data, SETTER_METHOD_NAME(parameters), wantParamRef); + CallSetter(env, cls, ani_data, Builder::BuildSetterName("parameters").c_str(), wantParamRef); } } // namespace EventManagerFwkAni -} // namespace OHOS \ No newline at end of file +} // namespace OHOS