Skip to content

Commit

Permalink
Add QueryEntitlementToken
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed Jan 19, 2024
1 parent efee12b commit 20944c1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ isn't quite there yet. At the time of writing, the following are implemented.
### Ecom interface

- Catalog offers (query/count/copy)
- Entitlements (query/count/copy)
- Entitlements (query/count/copy), entitlement token

If there's something missing that you need, please do open an issue. PRs
are very welcome.
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/com/bearwaves/eos4j/EOSEcom.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public Entitlement copyEntitlementByNameAndIndex(CopyEntitlementByNameAndIndexOp
return EOSEcomNative.copyEntitlementByNameAndIndex(handle, options);
}

public void queryEntitlementToken(QueryEntitlementTokenOptions options, OnQueryEntitlementTokenCallback callback) {
EOSEcomNative.queryEntitlementToken(handle, options, callback);
}

public static class CatalogOffer extends EOSHandle {
public final int serverIndex;
public final String catalogNamespace;
Expand Down Expand Up @@ -141,6 +145,8 @@ public void release() {
}
}

// Options structs

public static class QueryOffersOptions {
public final EOS.EpicAccountId localUserId;
public final String overrideCatalogNamespace;
Expand Down Expand Up @@ -241,11 +247,23 @@ public CopyEntitlementByNameAndIndexOptions(EOS.EpicAccountId localUserId, Strin
}
}

public static class QueryEntitlementTokenOptions {
public final EOS.EpicAccountId localUserId;
public final String[] entitlementNames;

public QueryEntitlementTokenOptions(EOS.EpicAccountId localUserId, String[] entitlementNames) {
this.localUserId = localUserId;
this.entitlementNames = entitlementNames;
}
}

// Callback structs

public static class QueryOffersCallbackInfo {
public final int resultCode;
public final EOS.EpicAccountId localUserId;

public QueryOffersCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) {
QueryOffersCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) {
this.resultCode = resultCode;
this.localUserId = localUserId;
}
Expand All @@ -255,17 +273,35 @@ public static class QueryEntitlementsCallbackInfo {
public final int resultCode;
public final EOS.EpicAccountId localUserId;

public QueryEntitlementsCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) {
QueryEntitlementsCallbackInfo(int resultCode, EOS.EpicAccountId localUserId) {
this.resultCode = resultCode;
this.localUserId = localUserId;
}
}

public static class QueryEntitlementTokenCallbackInfo {
public final int resultCode;
public final EOS.EpicAccountId localUserId;
public final String entitlementToken;

QueryEntitlementTokenCallbackInfo(int resultCode, EOS.EpicAccountId localUserId, String entitlementToken) {
this.resultCode = resultCode;
this.localUserId = localUserId;
this.entitlementToken = entitlementToken;
}
}

// Callback interfaces

public interface OnQueryOffersCompleteCallback {
void run(QueryOffersCallbackInfo data);
}

public interface OnQueryEntitlementsCallback {
void run(QueryEntitlementsCallbackInfo data);
}

public interface OnQueryEntitlementTokenCallback {
void run(QueryEntitlementTokenCallbackInfo data);
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/bearwaves/eos4j/EOSEcomNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,45 @@ static native EOSEcom.Entitlement copyEntitlementByNameAndIndex(
static native void releaseEntitlement(long handle); /*
EOS_Ecom_Entitlement_Release(reinterpret_cast<EOS_Ecom_Entitlement*>(handle));
*/

static native void queryEntitlementToken(
long handle,
EOSEcom.QueryEntitlementTokenOptions options,
EOSEcom.OnQueryEntitlementTokenCallback callback
); /*
jobject local_user_id_obj = EOS4J::javaObjectFromObjectField(env, options, "localUserId", "Lcom/bearwaves/eos4j/EOS$EpicAccountId;");
auto local_user_id = EOS4J::javaLongFromObjectField(env, local_user_id_obj, "ptr");
std::vector<EOS4J::JavaString> entitlement_names = EOS4J::javaStringVectorFromObjectField(env, options, "entitlementNames");
const char* entitlements[entitlement_names.size()];
for (size_t i = 0; i < entitlement_names.size(); i++) {
entitlements[i] = entitlement_names.at(i).c_str();
}
EOS_Ecom_QueryEntitlementTokenOptions query_options;
memset(&query_options, 0, sizeof(query_options));
query_options.ApiVersion = EOS_ECOM_QUERYENTITLEMENTTOKEN_API_LATEST;
query_options.LocalUserId = reinterpret_cast<EOS_EpicAccountId>(local_user_id);
query_options.EntitlementNames = reinterpret_cast<EOS_Ecom_EntitlementName*>(entitlements);
query_options.EntitlementNameCount = entitlement_names.size();
auto callback_adapter = std::make_unique<EOS4J::CallbackAdapter>(env, callback);
EOS_Ecom_QueryEntitlementToken(reinterpret_cast<EOS_HEcom>(handle), &query_options, callback_adapter.release(), [](const EOS_Ecom_QueryEntitlementTokenCallbackInfo* data) -> void {
std::unique_ptr<EOS4J::CallbackAdapter> callback_adapter{reinterpret_cast<EOS4J::CallbackAdapter*>(data->ClientData)};
callback_adapter->attach([&](JNIEnv* env, jobject callback) -> void {
jclass eaid_cls = env->FindClass("com/bearwaves/eos4j/EOS$EpicAccountId");
jmethodID eaid_ctor = env->GetMethodID(eaid_cls, "<init>", "(J)V");
auto local_user_id = env->NewObject(eaid_cls, eaid_ctor, data->LocalUserId);
jclass callback_info_class = env->FindClass("com/bearwaves/eos4j/EOSEcom$QueryEntitlementTokenCallbackInfo");
jmethodID callback_info_ctor = env->GetMethodID(callback_info_class, "<init>", "(ILcom/bearwaves/eos4j/EOS$EpicAccountId;Ljava/lang/String;)V");
auto callback_info = env->NewObject(callback_info_class, callback_info_ctor, static_cast<int>(data->ResultCode), local_user_id, env->NewStringUTF(data->EntitlementToken));
jclass cls = env->GetObjectClass(callback);
jmethodID mid = env->GetMethodID(cls, "run", "(Lcom/bearwaves/eos4j/EOSEcom$QueryEntitlementTokenCallbackInfo;)V");
env->CallVoidMethod(callback, mid, callback_info);
});
});
*/
}

0 comments on commit 20944c1

Please sign in to comment.