diff --git a/interop/src/cpp/DeserializerBase.h b/interop/src/cpp/DeserializerBase.h index 68965f3fc6880ec0b9add554478e6a7759fa98e6..87ac95187279260631b70b25fcc2e8257fb0fa8a 100644 --- a/interop/src/cpp/DeserializerBase.h +++ b/interop/src/cpp/DeserializerBase.h @@ -102,44 +102,6 @@ inline const char *getUnitName(int value) } } -inline void parseDimension(const InteropString &string, InteropLength *result) -{ - char *suffixPtr = nullptr; - float value = std::strtof(string.chars, &suffixPtr); - - if (!suffixPtr || suffixPtr == string.chars) - { - // not a numeric value - result->unit = -1; - return; - } - result->value = value; - if (suffixPtr[0] == '\0' || (suffixPtr[0] == 'v' && suffixPtr[1] == 'p')) - { - result->unit = 1; - } - else if (suffixPtr[0] == '%') - { - result->unit = 3; - } - else if (suffixPtr[0] == 'p' && suffixPtr[1] == 'x') - { - result->unit = 0; - } - else if (suffixPtr[0] == 'l' && suffixPtr[1] == 'p' && suffixPtr[2] == 'x') - { - result->unit = 4; - } - else if (suffixPtr[0] == 'f' && suffixPtr[1] == 'p') - { - result->unit = 2; - } - else - { - result->unit = -1; - } -} - template inline void convertor(T value) = delete; @@ -508,38 +470,6 @@ public: return InteropBuffer { resource, (void*)data, length }; } - // TODO: produce them with prefix in generator. - InteropLength readLength() - { - InteropLength result = {}; - result.unit = 1; - result.type = readInt8(); - switch (result.type) - { - case INTEROP_RUNTIME_OBJECT: - { - result.resource = readInt32(); - break; - } - case INTEROP_RUNTIME_STRING: - { - InteropString string = readString(); - parseDimension(string, &result); - break; - } - case INTEROP_RUNTIME_NUMBER: - { - result.value = readFloat32(); - break; - } - default: - { - INTEROP_FATAL("Fatal error"); - } - } - return result; - } - InteropString readString() { InteropString result; @@ -663,16 +593,4 @@ inline void WriteToString(std::string *result, const InteropNumber *value) result->append("}"); } -template <> -inline void WriteToString(std::string *result, const InteropLength *value) -{ - result->append("{"); - result->append(".type=" + std::to_string(value->type)); - result->append(", .value="); - WriteToString(result, value->value); - result->append(", .unit=" + std::to_string(value->unit)); - result->append(", .resource=" + std::to_string(value->resource)); - result->append("}"); -} - #endif // _DESERIALIZER_BASE_H_ diff --git a/interop/src/cpp/SerializerBase.h b/interop/src/cpp/SerializerBase.h index dbf2b51bd0a7ee18ab9a2533d130f085bede59c9..630a68162b393868e7344d39a8fd271fb6e8455b 100644 --- a/interop/src/cpp/SerializerBase.h +++ b/interop/src/cpp/SerializerBase.h @@ -205,36 +205,6 @@ public: writeInt8(value); } - void writeLength(InteropLength value) { - InteropRuntimeType tag = (InteropRuntimeType) value.type; - writeInt8(tag); - switch (tag) { - case INTEROP_RUNTIME_NUMBER: - writeFloat32(value.value); - break; - case INTEROP_RUNTIME_OBJECT: - writeInt32(value.resource); - break; - case INTEROP_RUNTIME_STRING: { - char buf[64]; - std::string suffix; - switch (value.unit) { - case 0: suffix = "px"; break; - case 1: suffix = "vp"; break; - case 2: suffix = "fp"; break; - case 3: suffix = "%"; break; - case 4: suffix = "lpx"; break; - } - snprintf(buf, 64, "%.8f%s", value.value, suffix.c_str()); - InteropString str = { buf, (InteropInt32) strlen(buf) }; - writeString(str); - break; - } - default: - break; - } - } - void writeCallbackResource(const InteropCallbackResource resource) { writeInt32(resource.resourceId); writePointer(reinterpret_cast(resource.hold)); diff --git a/interop/src/cpp/ani/convertors-ani.h b/interop/src/cpp/ani/convertors-ani.h index a277ee71a2eedbabe88d447303ce0fea064c01d4..23d842897755cfb62f12447cc8b4b64093d84706 100644 --- a/interop/src/cpp/ani/convertors-ani.h +++ b/interop/src/cpp/ani/convertors-ani.h @@ -292,73 +292,6 @@ template <> struct InteropTypeConverter { KInteropNumber converted) {} }; -template<> -struct InteropTypeConverter { - using InteropType = ani_ref; - static KLength convertFrom(ani_env* env, InteropType value) { - static ani_class double_class = nullptr; - static ani_class int_class = nullptr; - static ani_class string_class = nullptr; - static ani_class resource_class = nullptr; - if (!double_class) { - CHECK_ANI_FATAL(env->FindClass("Lstd/core/Double;", &double_class)); - } - if (!int_class) { - CHECK_ANI_FATAL(env->FindClass("Lstd/core/Int;", &int_class)); - } - if (!string_class) { - CHECK_ANI_FATAL(env->FindClass("Lstd/core/String;", &string_class)); - } - if (!resource_class) { - CHECK_ANI_FATAL(env->FindClass("L@ohos/arkui/generated/resource/Resource;", &resource_class)); - } - - const ani_object valueObj = reinterpret_cast(value); - - ani_boolean isInstanceOf; - CHECK_ANI_FATAL(env->Object_InstanceOf(valueObj, double_class, &isInstanceOf)); - if (isInstanceOf) { - static ani_method double_p = nullptr; - if (!double_p) CHECK_ANI_FATAL(env->Class_FindMethod(double_class, "unboxed", ":D", &double_p)); - ani_double result; - CHECK_ANI_FATAL(env->Object_CallMethod_Double(valueObj, double_p, &result)); - return KLength{ 1, (KFloat) result, 1, 0 }; - } - - CHECK_ANI_FATAL(env->Object_InstanceOf(valueObj, int_class, &isInstanceOf)); - if (isInstanceOf) { - static ani_method int_p = nullptr; - if (!int_p) CHECK_ANI_FATAL(env->Class_FindMethod(int_class, "unboxed", ":I", &int_p)); - ani_int result; - CHECK_ANI_FATAL(env->Object_CallMethod_Int(valueObj, int_p, &result)); - return KLength{ 1, (KFloat) result, 1, 0 }; - } - - CHECK_ANI_FATAL(env->Object_InstanceOf(valueObj, string_class, &isInstanceOf)); - if (isInstanceOf) { - KStringPtr ptr = InteropTypeConverter::convertFrom(env, reinterpret_cast(value)); - KLength length { 0 }; - parseKLength(ptr, &length); - length.type = 2; - length.resource = 0; - return length; - } - - CHECK_ANI_FATAL(env->Object_InstanceOf(valueObj, resource_class, &isInstanceOf)); - if (isInstanceOf) { - static ani_method resource_p = nullptr; - if (!resource_p) CHECK_ANI_FATAL(env->Class_FindMethod(resource_class, "id",":D", &resource_p)); - ani_double result; - CHECK_ANI_FATAL(env->Object_CallMethod_Double(valueObj, resource_p, &result)); - return KLength{ 3, 0, 1, (KInt) result }; - } - - return KLength( { 0, 0, 0, 0}); - } - static InteropType convertTo(ani_env* env, KLength value) = delete; - static void release(ani_env* env, InteropType value, const KLength& converted) {} -}; - template inline typename InteropTypeConverter::InteropType makeResult(ani_env* env, Type value) { return InteropTypeConverter::convertTo(env, value); diff --git a/interop/src/cpp/ets/convertors-ets.h b/interop/src/cpp/ets/convertors-ets.h index 126bd44dbf6f2f4f22e4401726e81a84997a268b..987fe3c4bf6f055bcbcd22c5ed79fa473940b279 100644 --- a/interop/src/cpp/ets/convertors-ets.h +++ b/interop/src/cpp/ets/convertors-ets.h @@ -241,40 +241,6 @@ template <> struct InteropTypeConverter { static void release(EtsEnv *env, InteropType value, KInteropNumber converted) {} }; -template<> -struct InteropTypeConverter { - using InteropType = ets_object; - static KLength convertFrom(EtsEnv* env, InteropType value) { - const static ets_class double_class = reinterpret_cast(env->NewGlobalRef(env->FindClass("std/core/Double"))); - const static ets_class int_class = reinterpret_cast(env->NewGlobalRef(env->FindClass("std/core/Int"))); - const static ets_class string_class = reinterpret_cast(env->NewGlobalRef(env->FindClass("std/core/String"))); - const static ets_class resource_class = reinterpret_cast( - env->NewGlobalRef(env->FindClass("@ohos/arkui/generated/resource/Resource"))); - - if (env->IsInstanceOf(value, double_class)) { - const static ets_method double_p = env->Getp_method(double_class, "unboxed", ":D"); - return KLength{ 1, (KFloat)env->CallDoubleMethod(value, double_p), 1, 0 }; - } else if (env->IsInstanceOf(value, int_class)) { - const static ets_method int_p = env->Getp_method(int_class, "unboxed", ":I"); - return KLength{ 1, (KFloat)env->CallIntMethod(value, int_p), 1, 0 }; - } else if (env->IsInstanceOf(value, string_class)) { - KStringPtr ptr = InteropTypeConverter::convertFrom(env, reinterpret_cast(value)); - KLength length { 0 }; - parseKLength(ptr, &length); - length.type = 2; - length.resource = 0; - return length; - } else if (env->IsInstanceOf(value, resource_class)) { - const static ets_method resource_p = env->Getp_method(resource_class, "id", ":D"); - return KLength{ 3, 0, 1, (KInt)env->CallDoubleMethod(value, resource_p) }; - } else { - return KLength( { 0, 0, 0, 0}); - } - } - static InteropType convertTo(EtsEnv* env, KLength value) = delete; - static void release(EtsEnv* env, InteropType value, const KLength& converted) {} -}; - template inline typename InteropTypeConverter::InteropType makeResult(EtsEnv* env, Type value) { return InteropTypeConverter::convertTo(env, value); diff --git a/interop/src/cpp/interop-types.h b/interop/src/cpp/interop-types.h index 66867520874a0d1e000c915cdab577d1c531d138..b556a216d275657ecedaf03aecea1826bae374b2 100644 --- a/interop/src/cpp/interop-types.h +++ b/interop/src/cpp/interop-types.h @@ -79,15 +79,6 @@ typedef struct InteropNumber { }; } InteropNumber; -// Binary layout of InteropLength must match that of KLength. -typedef struct InteropLength -{ - InteropInt8 type; - InteropFloat32 value; - InteropInt32 unit; - InteropInt32 resource; -} InteropLength; - typedef struct InteropCustomObject { char kind[20]; InteropInt32 id; diff --git a/interop/src/cpp/jni/convertors-jni.h b/interop/src/cpp/jni/convertors-jni.h index 58a02c99e15e09add347da8ee961eca0828c3f68..e29a546192b35b5f42ef3c88dc296e796d969013 100644 --- a/interop/src/cpp/jni/convertors-jni.h +++ b/interop/src/cpp/jni/convertors-jni.h @@ -293,31 +293,6 @@ struct SlowInteropTypeConverter { static void release(JNIEnv* env, InteropType value, KInteropNumber converted) {} }; -template<> -struct InteropTypeConverter { - using InteropType = jstring; - static KLength convertFrom(JNIEnv* env, InteropType value) { - KLength result { 0 }; - - if (value == nullptr) { - result.type = -1; // ARK_RUNTIME_UNEXPECTED - return result; - } - jboolean isCopy; - const char* str_value = env->GetStringUTFChars(value, &isCopy); - int len = env->GetStringLength(value); - KStringPtr kStr(str_value, len, false); - parseKLength(kStr, &result); - env->ReleaseStringUTFChars(value, str_value); - result.type = 2; // ARK_RUNTIME_STRING - result.resource = 0; - - return result; - } - static InteropType convertTo(JNIEnv* env, KLength value) = delete; - static inline void release(JNIEnv* env, InteropType value, KLength converted) {} -}; - template inline Type getArgument(JNIEnv* env, typename InteropTypeConverter::InteropType arg) { return InteropTypeConverter::convertFrom(env, arg); diff --git a/interop/src/cpp/napi/convertors-napi.h b/interop/src/cpp/napi/convertors-napi.h index 90e9a1fc061257effde15084729c5b14d7529eaa..0b95e82ed7b0ab50dd9d22b593d721aeec7509e0 100644 --- a/interop/src/cpp/napi/convertors-napi.h +++ b/interop/src/cpp/napi/convertors-napi.h @@ -480,48 +480,6 @@ inline KSerializerBuffer getArgument(const CallbackInfo& info return getArgument(info.Env(), info[index]); } -template <> -inline KLength getArgument(const CallbackInfo& info, int index) { - KLength result { 0 }; - NAPI_ASSERT_INDEX(info, index, result); - auto value = info[index]; - napi_valuetype type; - auto status = napi_typeof(info.Env(), value, &type); - if (status != 0) return result; - switch (type) { - case napi_number: { - result.value = getFloat32(info.Env(), value); - result.unit = 1; - result.type = 0; - break; - } - case napi_string: { - KStringPtr string = getString(info.Env(), value); - parseKLength(string, &result); - result.type = 1; - result.resource = 0; - break; - } - case napi_object: { - result.value = 0; - result.unit = 1; - result.type = 2; - napi_value field; - napi_status status = napi_get_named_property(info.Env(), value, "id", &field); - if (status == 0) { - status = napi_get_value_int32(info.Env(), field, &result.resource); - if (status != 0) result.resource = 0; - } else { - result.resource = 0; - } - break; - } - default: - INTEROP_FATAL("Error, unexpected KLength type"); - } - return result; -} - template <> inline KInteropBuffer getArgument(const CallbackInfo& info, int index) { diff --git a/interop/src/cpp/types/koala-types.h b/interop/src/cpp/types/koala-types.h index 78438e8c99b8a06b045de0b6f7a524b2167b74b0..e7beb9112d0f4d7747bf9b82b2f6553fafc876e3 100644 --- a/interop/src/cpp/types/koala-types.h +++ b/interop/src/cpp/types/koala-types.h @@ -218,60 +218,6 @@ struct KInteropReturnBuffer { void (*dispose)(KNativePointer data, KInt length); }; -struct KLength { - KByte type; - KFloat value; - KInt unit; - KInt resource; - InteropLength toCType() { - InteropLength result; - result.type = this->type; - result.value = this->value; - result.unit = this->unit; - result.resource = this->resource; - return result; - } -}; - -inline void parseKLength(const KStringPtrImpl &string, KLength *result) -{ - char *suffixPtr = nullptr; - - float value = std::strtof(string.c_str(), &suffixPtr); - - if (!suffixPtr || suffixPtr == string.c_str()) - { - // not a numeric value - result->unit = -1; - return; - } - result->value = value; - if (suffixPtr[0] == '\0' || (suffixPtr[0] == 'v' && suffixPtr[1] == 'p')) - { - result->unit = 1; - } - else if (suffixPtr[0] == '%') - { - result->unit = 3; - } - else if (suffixPtr[0] == 'p' && suffixPtr[1] == 'x') - { - result->unit = 0; - } - else if (suffixPtr[0] == 'l' && suffixPtr[1] == 'p' && suffixPtr[2] == 'x') - { - result->unit = 4; - } - else if (suffixPtr[0] == 'f' && suffixPtr[1] == 'p') - { - result->unit = 2; - } - else - { - result->unit = -1; - } -} - typedef _InteropVMContext *KVMContext; // BEWARE: this MUST never be used in user code, only in very rare service code.