mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
refactor(native): rename C API auth_* -> craft_* in JNI bridge
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
|
||||
namespace {
|
||||
|
||||
AuthHandle from_jlong(jlong ptr) {
|
||||
return reinterpret_cast<AuthHandle>(static_cast<uintptr_t>(ptr));
|
||||
CraftHandle from_jlong(jlong ptr) {
|
||||
return reinterpret_cast<CraftHandle>(static_cast<uintptr_t>(ptr));
|
||||
}
|
||||
|
||||
jobject make_auth_result(JNIEnv* env, const AuthResult& r) {
|
||||
// craft_result mapper to Java AuthResult (rename for consistency)
|
||||
jobject make_craft_result(JNIEnv* env, const CraftResult& r) {
|
||||
jclass cls = env->FindClass("cn/craftlabs/auth/AuthResult");
|
||||
if (!cls) {
|
||||
return nullptr;
|
||||
@@ -88,7 +89,7 @@ extern "C" {
|
||||
JNIEXPORT jlong JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeInitialize(
|
||||
JNIEnv* env, jclass, jstring configJson) {
|
||||
const char* utf = configJson ? env->GetStringUTFChars(configJson, nullptr) : nullptr;
|
||||
AuthHandle h = auth_initialize(utf ? utf : "{}");
|
||||
CraftHandle h = craft_initialize(utf ? utf : "{}");
|
||||
if (configJson && utf) {
|
||||
env->ReleaseStringUTFChars(configJson, utf);
|
||||
}
|
||||
@@ -98,37 +99,37 @@ JNIEXPORT jlong JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeIniti
|
||||
JNIEXPORT void JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeDestroy(JNIEnv*,
|
||||
jclass,
|
||||
jlong handle) {
|
||||
auth_destroy(from_jlong(handle));
|
||||
craft_destroy(from_jlong(handle));
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeActivate(
|
||||
JNIEnv* env, jclass, jlong handle, jstring licenseKey) {
|
||||
const char* utf = licenseKey ? env->GetStringUTFChars(licenseKey, nullptr) : "";
|
||||
AuthResult r = auth_activate(from_jlong(handle), utf ? utf : "");
|
||||
CraftResult r = craft_activate(from_jlong(handle), utf ? utf : "");
|
||||
if (licenseKey && utf) {
|
||||
env->ReleaseStringUTFChars(licenseKey, utf);
|
||||
}
|
||||
return make_auth_result(env, r);
|
||||
return make_craft_result(env, r);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeCheckLicense(
|
||||
JNIEnv* env, jclass, jlong handle) {
|
||||
AuthResult r = auth_check_license(from_jlong(handle));
|
||||
return make_auth_result(env, r);
|
||||
CraftResult r = craft_check_license(from_jlong(handle));
|
||||
return make_craft_result(env, r);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeGetLicenseInfo(
|
||||
JNIEnv* env, jclass, jlong handle) {
|
||||
LicenseInfo* info = auth_get_license_info(from_jlong(handle));
|
||||
LicenseInfo* info = craft_get_license_info(from_jlong(handle));
|
||||
jobject jinfo = make_license_info(env, info);
|
||||
auth_free_license_info(info);
|
||||
craft_free_license_info(info);
|
||||
return jinfo;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeHasFeature(
|
||||
JNIEnv* env, jclass, jlong handle, jstring featureName) {
|
||||
const char* utf = featureName ? env->GetStringUTFChars(featureName, nullptr) : "";
|
||||
int v = auth_has_feature(from_jlong(handle), utf ? utf : "");
|
||||
int v = craft_has_feature(from_jlong(handle), utf ? utf : "");
|
||||
if (featureName && utf) {
|
||||
env->ReleaseStringUTFChars(featureName, utf);
|
||||
}
|
||||
@@ -138,14 +139,14 @@ JNIEXPORT jboolean JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeHa
|
||||
JNIEXPORT jobject JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeRelease(JNIEnv* env,
|
||||
jclass,
|
||||
jlong handle) {
|
||||
AuthResult r = auth_release(from_jlong(handle));
|
||||
return make_auth_result(env, r);
|
||||
CraftResult r = craft_release(from_jlong(handle));
|
||||
return make_craft_result(env, r);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_cn_craftlabs_auth_internal_NativeBridge_nativeHeartbeat(
|
||||
JNIEnv* env, jclass, jlong handle) {
|
||||
AuthResult r = auth_heartbeat(from_jlong(handle));
|
||||
return make_auth_result(env, r);
|
||||
CraftResult r = craft_heartbeat(from_jlong(handle));
|
||||
return make_craft_result(env, r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user