示例#1
0
ZFCompareResult ZFEnum::objectCompare(ZF_IN ZFObject *anotherObj)
{
    if(this == anotherObj)
    {
        return ZFCompareTheSame;
    }
    if(anotherObj == zfnull || anotherObj->classData() != this->classData())
    {
        return ZFCompareUncomparable;
    }

    zfself *another = ZFCastZFObjectUnchecked(zfself *, anotherObj);
    if(this->enumValue() == ZFEnumValueInvalid
        || another->enumValue() == ZFEnumValueInvalid)
    {
        return ZFCompareUncomparable;
    }
    zfint n = ZFCastStatic(zfint, this->enumValue()) - ZFCastStatic(zfint, another->enumValue());
    if(n < 0)
    {
        return ZFCompareSmaller;
    }
    else if(n == 0)
    {
        return ZFCompareTheSame;
    }
    else
    {
        return ZFCompareGreater;
    }
}
 virtual void nativeTimerDestroy(ZF_IN ZFTimer *timer,
                                 ZF_IN void *nativeTimer)
 {
     JNIEnv *jniEnv = JNIGetJNIEnv();
     jobject nativeTimerTmp = ZFCastStatic(jobject, nativeTimer);
     JNIUtilDeleteGlobalRef(jniEnv, nativeTimerTmp);
 }
zfindex ZFByteOrderDecodeGetSize(ZF_IN zfindex encodedByteSize)
{
    if(encodedByteSize % 2 != 0)
    {
        return zfindexMax;
    }
    return ZFCastStatic(zfindex, encodedByteSize / 2);
}
 virtual void timerStop(ZF_IN ZFTimer *timer)
 {
     JNIEnv *jniEnv = JNIGetJNIEnv();
     static jmethodID jmId = JNIUtilGetStaticMethodID(jniEnv, this->jclsOwner, zfTextA("native_timerStop"),
         JNIGetMethodSig(JNIType::S_void, JNIParamTypeContainer()
             .add(JNIType::S_object(ZFImpl_sys_Android_JNI_NAME_Object))
         ).c_str());
     JNIUtilCallStaticVoidMethod(jniEnv, this->jclsOwner, jmId, ZFCastStatic(jobject, timer->nativeTimer()));
 }
zfstring &ZFImpl_sys_Android_zfstringFromString(ZF_IN_OUT zfstring &s, ZF_IN jobject jstr)
{
    ZFSTRINGENCODING_SENSITIVE("use UTF8")
    JNIEnv *jniEnv = JNIGetJNIEnv();
    jstring nativeString = ZFCastStatic(jstring, jstr);
    const zfcharA *utf8 = JNIUtilGetStringUTFChars(jniEnv, nativeString, zfnull);
    if(utf8 != zfnull)
    {
        s += utf8;
    }
    JNIUtilReleaseStringUTFChars(jniEnv, nativeString, utf8);
    return s;
}
zfstring ZFImpl_sys_Android_objectInfo(ZF_IN jobject nativeObject)
{
    JNIEnv *jniEnv = JNIGetJNIEnv();
    jclass jcls = JNIUtilFindClass(jniEnv, JNIConvertClassNameForFindClass(ZFImpl_sys_Android_JNI_NAME_ZFAndroidLog).c_str());
    static jmethodID jmId = JNIUtilGetStaticMethodID(jniEnv, jcls, zfTextA("objectInfo"),
        JNIGetMethodSig(JNIType::S_object(ZFImpl_sys_Android_JNI_NAME_String), JNIParamTypeContainer()
            .add(JNIType::S_object(ZFImpl_sys_Android_JNI_NAME_Object))
        ).c_str());
    jstring tmp = ZFCastStatic(jstring, JNIUtilCallStaticObjectMethod(jniEnv, jcls, jmId, nativeObject));
    const char *utf = JNIUtilGetStringUTFChars(jniEnv, tmp, zfnull);
    zfstring ret = utf;
    JNIUtilReleaseStringUTFChars(jniEnv, tmp, utf);
    return ret;
}
zfstring ZFImpl_sys_Android_stackTrace(void)
{
    JNIEnv *jniEnv = JNIGetJNIEnv();
    jclass jcls = JNIUtilFindClass(jniEnv, JNIConvertClassNameForFindClass(ZFImpl_sys_Android_JNI_NAME_ZFAndroidLog).c_str());
    static jmethodID jmId = JNIUtilGetStaticMethodID(jniEnv, jcls, zfTextA("stackTrace"),
        JNIGetMethodSig(JNIType::S_object(ZFImpl_sys_Android_JNI_NAME_String), JNIParamTypeContainer()
        ).c_str());
    jstring jobjString = ZFCastStatic(jstring, JNIUtilCallStaticObjectMethod(jniEnv, jcls, jmId));
    const char *utf = JNIUtilGetStringUTFChars(jniEnv, jobjString, zfnull);
    zfstring ret;
    if(utf != zfnull)
    {
        ret = utf;
    }
    JNIUtilReleaseStringUTFChars(jniEnv, jobjString, utf);
    return ret;
}
 virtual void timerStart(ZF_IN ZFTimer *timer)
 {
     JNIEnv *jniEnv = JNIGetJNIEnv();
     static jmethodID jmId = JNIUtilGetStaticMethodID(jniEnv, this->jclsOwner, zfTextA("native_timerStart"),
         JNIGetMethodSig(JNIType::S_void, JNIParamTypeContainer()
             .add(JNIType::S_object(ZFImpl_sys_Android_JNI_NAME_Object))
             .add(JNIPointerJNIType)
             .add(JNIType::S_long)
             .add(JNIType::S_long)
             .add(JNIType::S_boolean)
         ).c_str());
     JNIUtilCallStaticVoidMethod(jniEnv, this->jclsOwner, jmId,
         ZFCastStatic(jobject, timer->nativeTimer()),
         JNIConvertZFObjectToJNIType(jniEnv, timer),
         timer->timerDelay(),
         timer->timerInterval(),
         timer->timerActivateInMainThread());
 }