diff --git a/packages/in_app_purchase/CHANGELOG.md b/packages/in_app_purchase/CHANGELOG.md index 28a2d4ee4..f5046e7b5 100644 --- a/packages/in_app_purchase/CHANGELOG.md +++ b/packages/in_app_purchase/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.2.0 +* Migrate from platform channels to Dart FFI using the pigeon C++ FFI generator (git ref 1e63f1b5). * Apply clang-format-16 formatting. ## 0.1.9 diff --git a/packages/in_app_purchase/README.md b/packages/in_app_purchase/README.md index 879bba61f..1fa09e2c2 100644 --- a/packages/in_app_purchase/README.md +++ b/packages/in_app_purchase/README.md @@ -35,7 +35,7 @@ This package is not an _endorsed_ implementation of `in_app_purchase`. Therefore ```yaml dependencies: in_app_purchase: ^3.3.0 - in_app_purchase_tizen: ^0.1.9 + in_app_purchase_tizen: ^0.2.0 ``` Then you can import `in_app_purchase` and `in_app_purchase_tizen` in your Dart code: diff --git a/packages/in_app_purchase/example/integration_test/in_app_purchase_test.dart b/packages/in_app_purchase/example/integration_test/in_app_purchase_test.dart index 7a6f2cd7a..257f5bb89 100644 --- a/packages/in_app_purchase/example/integration_test/in_app_purchase_test.dart +++ b/packages/in_app_purchase/example/integration_test/in_app_purchase_test.dart @@ -2,8 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; +import 'package:in_app_purchase_tizen/in_app_purchase_tizen.dart'; import 'package:integration_test/integration_test.dart'; void main() { @@ -13,4 +16,51 @@ void main() { final InAppPurchase iapInstance = InAppPurchase.instance; expect(iapInstance, isNotNull); }); + + test('FFI host API smoke test', () async { + final InAppPurchase iap = InAppPurchase.instance; + final InAppPurchaseTizenPlatformAddition addition = iap + .getPlatformAddition(); + addition.setRequestParameters(appId: 'test', pageSize: 15, pageNum: 1, securityKey: 'test'); + + Object? asyncError; + bool? available; + try { + available = await iap.isAvailable().timeout(const Duration(seconds: 15)); + } catch (error) { + asyncError = error; + } + expect( + asyncError, + isNot(isA()), + reason: 'isAvailable() never completed: FFI reply never arrived', + ); + final asyncErrorText = '$asyncError'; + expect(asyncErrorText, isNot(contains('Failed to lookup symbol'))); + expect(asyncErrorText, isNot(contains('has not been set up'))); + expect(asyncErrorText, isNot(contains('BinaryMessenger is not supported'))); + if (available == null && asyncError == null) { + fail('isAvailable() produced neither a value nor an error'); + } + + Object? queryError; + ProductDetailsResponse? response; + try { + response = await iap.queryProductDetails({}).timeout(const Duration(seconds: 30)); + } catch (error) { + queryError = error; + } + expect( + queryError, + isNot(isA()), + reason: 'queryProductDetails() never completed: FFI reply never arrived', + ); + final queryErrorText = '$queryError'; + expect(queryErrorText, isNot(contains('Failed to lookup symbol'))); + expect(queryErrorText, isNot(contains('has not been set up'))); + expect(queryErrorText, isNot(contains('BinaryMessenger is not supported'))); + if (response == null && queryError == null) { + fail('queryProductDetails() produced neither a value nor an error'); + } + }); } diff --git a/packages/in_app_purchase/lib/src/billing_manager.dart b/packages/in_app_purchase/lib/src/billing_manager.dart index ffe0d5c2c..aded93d1e 100644 --- a/packages/in_app_purchase/lib/src/billing_manager.dart +++ b/packages/in_app_purchase/lib/src/billing_manager.dart @@ -38,6 +38,11 @@ class BillingManager { /// Interface for calling host-side code. final InAppPurchaseApi _hostApi; + /// Resets pending native replies left over from a previous Dart isolate. + void initialize() { + _hostApi.initialize(); + } + /// get country code Future getCountryCode() async { return _hostApi.getCountryCode(); diff --git a/packages/in_app_purchase/lib/src/in_app_purchase_tizen_platform.dart b/packages/in_app_purchase/lib/src/in_app_purchase_tizen_platform.dart index 7d94dc1af..64829344d 100644 --- a/packages/in_app_purchase/lib/src/in_app_purchase_tizen_platform.dart +++ b/packages/in_app_purchase/lib/src/in_app_purchase_tizen_platform.dart @@ -34,6 +34,10 @@ class InAppPurchaseTizenPlatform extends InAppPurchasePlatform { // Register the platform-specific implementation of the idiomatic // InAppPurchase API. InAppPurchasePlatform.instance = InAppPurchaseTizenPlatform(); + + if (RootIsolateToken.instance != null) { + billingManager.initialize(); + } } static final StreamController> _purchaseUpdatedController = diff --git a/packages/in_app_purchase/lib/src/messages.g.dart b/packages/in_app_purchase/lib/src/messages.g.dart index 65a263b7a..fde539078 100644 --- a/packages/in_app_purchase/lib/src/messages.g.dart +++ b/packages/in_app_purchase/lib/src/messages.g.dart @@ -1,18 +1,221 @@ -// Autogenerated from Pigeon (v22.7.4), do not edit directly. +// Autogenerated from Pigeon (v29.0.11), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers +// ignore_for_file: unused_import, unused_shown_name +// ignore_for_file: type=lint +import 'dart:ffi' as ffi; import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; +import 'dart:io' show File, Platform; +import 'dart:typed_data' show ByteData, Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; +import 'package:ffi/ffi.dart' as pkg_ffi; import 'package:flutter/services.dart'; +import 'package:meta/meta.dart' show immutable, protected, visibleForTesting; +import 'messages.g.ffi.dart' as pigeon_ffi; + +Object? _extractReplyValueOrThrow( + List? replyList, + String channelName, { + required bool isNullValid, +}) { + if (replyList == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); + } else if (replyList.length > 1) { + throw PlatformException( + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], + ); + } else if (!isNullValid && (replyList.isNotEmpty && replyList[0] == null)) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } + return replyList.firstOrNull; +} + +ffi.Pointer _encodeFfiRequest(ByteData? message) { + if (message == null) { + return ffi.nullptr; + } + final Uint8List bytes = message.buffer.asUint8List(message.offsetInBytes, message.lengthInBytes); + final ffi.Pointer data = pkg_ffi.calloc(bytes.length); + data.asTypedList(bytes.length).setAll(0, bytes); + final ffi.Pointer buffer = pkg_ffi + .calloc(); + buffer.ref.data = data; + buffer.ref.length = bytes.length; + return buffer; +} + +void _freeFfiRequest(ffi.Pointer buffer) { + if (buffer == ffi.nullptr) { + return; + } + pkg_ffi.calloc.free(buffer.ref.data); + pkg_ffi.calloc.free(buffer); +} + +List? _decodeFfiReply( + MessageCodec codec, + ffi.Pointer buffer, +) { + if (buffer == ffi.nullptr || buffer.ref.data == ffi.nullptr) { + return null; + } + final Uint8List bytes = Uint8List.fromList(buffer.ref.data.asTypedList(buffer.ref.length)); + return codec.decodeMessage(ByteData.sublistView(bytes)) as List?; +} + +ffi.DynamicLibrary _openPigeonNativeLibrary() { + try { + return (() { + final String libraryPath = File('/proc/self/maps') + .readAsLinesSync() + .map((String line) { + final int index = line.indexOf('/'); + return index == -1 ? '' : line.substring(index); + }) + .firstWhere((String path) => path.endsWith('/libflutter_plugins.so')); + return ffi.DynamicLibrary.open(libraryPath); + })(); + } catch (error) { + throw StateError( + 'Pigeon FFI: failed to open the native library. The plugin shared ' + 'library may not be loaded yet. Avoid constructing FFI bindings ' + 'during plugin registration; construct them lazily on first use. ' + 'Original error: $error', + ); + } +} + +late final ffi.DynamicLibrary _pigeonNativeLibrary = _openPigeonNativeLibrary(); + +ffi.Pointer _pigeonFfiLookup(String symbolName) { + return _pigeonNativeLibrary.lookup(symbolName); +} + +final pigeon_ffi.InAppPurchaseTizenFfiBindings _pigeonVar_defaultFfiBindings = + pigeon_ffi.InAppPurchaseTizenFfiBindings.fromLookup(_pigeonFfiLookup); + +typedef _PigeonFfiReplyCallbackNative = + ffi.Void Function(ffi.Int64 replyId, ffi.Pointer reply); + +class _PigeonFfiAsyncReply { + _PigeonFfiAsyncReply({ + required this.ffiBindings, + required this.codec, + required this.channelName, + required this.isNullValid, + required this.complete, + required this.completeError, + }); + + final pigeon_ffi.InAppPurchaseTizenFfiBindings ffiBindings; + final MessageCodec codec; + final String channelName; + final bool isNullValid; + final void Function(Object? value) complete; + final void Function(Object error, StackTrace stackTrace) completeError; +} + +final Map _pigeonFfiAsyncReplies = {}; +int _pigeonNextFfiAsyncReplyId = 1; -PlatformException _createConnectionError(String channelName) { - return PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel: "$channelName".', - ); +final ffi.NativeCallable<_PigeonFfiReplyCallbackNative> _pigeonFfiReplyCallback = + ffi.NativeCallable<_PigeonFfiReplyCallbackNative>.listener(_handlePigeonFfiReply) + ..keepIsolateAlive = false; + +// Cache the callback for reuse; only unfinished requests keep the isolate alive. +void _updatePigeonFfiReplyCallbackKeepAlive() { + _pigeonFfiReplyCallback.keepIsolateAlive = _pigeonFfiAsyncReplies.isNotEmpty; +} + +void _handlePigeonFfiReply(int replyId, ffi.Pointer reply) { + final _PigeonFfiAsyncReply? asyncReply = _pigeonFfiAsyncReplies.remove(replyId); + try { + if (asyncReply != null) { + final List? replyList = _decodeFfiReply(asyncReply.codec, reply); + final Object? replyValue = _extractReplyValueOrThrow( + replyList, + asyncReply.channelName, + isNullValid: asyncReply.isNullValid, + ); + asyncReply.complete(replyValue); + } + } catch (error, stackTrace) { + asyncReply?.completeError(error, stackTrace); + } finally { + if (reply != ffi.nullptr) { + (asyncReply?.ffiBindings ?? _pigeonVar_defaultFfiBindings).pigeon_free_buffer(reply); + } + _updatePigeonFfiReplyCallbackKeepAlive(); + } +} + +bool _deepEquals(Object? a, Object? b) { + if (identical(a, b)) { + return true; + } + if (a is double && b is double) { + if (a.isNaN && b.isNaN) { + return true; + } + return a == b; + } + if (a is List && b is List) { + return a.length == b.length && + a.indexed.every(((int, dynamic) item) => _deepEquals(item.$2, b[item.$1])); + } + if (a is Map && b is Map) { + if (a.length != b.length) { + return false; + } + for (final MapEntry entryA in a.entries) { + bool found = false; + for (final MapEntry entryB in b.entries) { + if (_deepEquals(entryA.key, entryB.key)) { + if (_deepEquals(entryA.value, entryB.value)) { + found = true; + break; + } else { + return false; + } + } + } + if (!found) { + return false; + } + } + return true; + } + return a == b; +} + +int _deepHash(Object? value) { + if (value is List) { + return Object.hashAll(value.map(_deepHash)); + } + if (value is Map) { + int result = 0; + for (final MapEntry entry in value.entries) { + result += (_deepHash(entry.key) * 31) ^ _deepHash(entry.value); + } + return result; + } + if (value is double && value.isNaN) { + // Normalize NaN to a consistent hash. + return 0x7FF8000000000000.hashCode; + } + if (value is double && value == 0.0) { + // Normalize -0.0 to 0.0 so they have the same hash code. + return 0.0.hashCode; + } + return value.hashCode; } /// Dart wrapper around [`ProductsListApiResult`] in (https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html). @@ -47,10 +250,14 @@ class ProductsListApiResult { /// ItemDetails in JSON format List?> itemDetails; - Object encode() { + List _toList() { return [cpStatus, cpResult, totalCount, checkValue, itemDetails]; } + Object encode() { + return _toList(); + } + static ProductsListApiResult decode(Object result) { result as List; return ProductsListApiResult( @@ -58,9 +265,34 @@ class ProductsListApiResult { cpResult: result[1] as String?, totalCount: result[2]! as int, checkValue: result[3]! as String, - itemDetails: (result[4] as List?)!.cast?>(), + itemDetails: (result[4]! as List).cast?>(), ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! ProductsListApiResult || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(cpStatus, other.cpStatus) && + _deepEquals(cpResult, other.cpResult) && + _deepEquals(totalCount, other.totalCount) && + _deepEquals(checkValue, other.checkValue) && + _deepEquals(itemDetails, other.itemDetails); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'ProductsListApiResult(cpStatus: $cpStatus, cpResult: $cpResult, totalCount: $totalCount, checkValue: $checkValue, itemDetails: $itemDetails)'; + } } /// Dart wrapper around [`GetUserPurchaseListAPIResult`] in (https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html). @@ -94,10 +326,14 @@ class GetUserPurchaseListAPIResult { /// InvoiceDetailsin JSON format. List?> invoiceDetails; - Object encode() { + List _toList() { return [cpStatus, cpResult, totalCount, checkValue, invoiceDetails]; } + Object encode() { + return _toList(); + } + static GetUserPurchaseListAPIResult decode(Object result) { result as List; return GetUserPurchaseListAPIResult( @@ -105,9 +341,34 @@ class GetUserPurchaseListAPIResult { cpResult: result[1] as String?, totalCount: result[2]! as int, checkValue: result[3]! as String, - invoiceDetails: (result[4] as List?)!.cast?>(), + invoiceDetails: (result[4]! as List).cast?>(), ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! GetUserPurchaseListAPIResult || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(cpStatus, other.cpStatus) && + _deepEquals(cpResult, other.cpResult) && + _deepEquals(totalCount, other.totalCount) && + _deepEquals(checkValue, other.checkValue) && + _deepEquals(invoiceDetails, other.invoiceDetails); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'GetUserPurchaseListAPIResult(cpStatus: $cpStatus, cpResult: $cpResult, totalCount: $totalCount, checkValue: $checkValue, invoiceDetails: $invoiceDetails)'; + } } /// Dart wrapper around [`BillingBuyData`](https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html#BillingBuyData). @@ -122,17 +383,42 @@ class BillingBuyData { /// The payment information. It is same with paymentDetails param of buyItem. Map payDetails; - Object encode() { + List _toList() { return [payResult, payDetails]; } + Object encode() { + return _toList(); + } + static BillingBuyData decode(Object result) { result as List; return BillingBuyData( payResult: result[0]! as String, - payDetails: (result[1] as Map?)!.cast(), + payDetails: (result[1]! as Map).cast(), ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! BillingBuyData || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(payResult, other.payResult) && _deepEquals(payDetails, other.payDetails); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'BillingBuyData(payResult: $payResult, payDetails: $payDetails)'; + } } /// Dart wrapper around [`VerifyInvoiceAPIResult`] in (https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html). @@ -159,10 +445,14 @@ class VerifyInvoiceAPIResult { /// Invoice ID that you want to verify whether a purchase was successful. String invoiceId; - Object encode() { + List _toList() { return [cpStatus, cpResult, appId, invoiceId]; } + Object encode() { + return _toList(); + } + static VerifyInvoiceAPIResult decode(Object result) { result as List; return VerifyInvoiceAPIResult( @@ -172,6 +462,30 @@ class VerifyInvoiceAPIResult { invoiceId: result[3]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! VerifyInvoiceAPIResult || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(cpStatus, other.cpStatus) && + _deepEquals(cpResult, other.cpResult) && + _deepEquals(appId, other.appId) && + _deepEquals(invoiceId, other.invoiceId); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'VerifyInvoiceAPIResult(cpStatus: $cpStatus, cpResult: $cpResult, appId: $appId, invoiceId: $invoiceId)'; + } } /// Dart wrapper around [`ServiceAvailableAPIResult`] in (https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html). @@ -193,10 +507,14 @@ class ServiceAvailableAPIResult { /// It will be null, if disconnect to billing server. String serviceYn; - Object encode() { + List _toList() { return [status, result, serviceYn]; } + Object encode() { + return _toList(); + } + static ServiceAvailableAPIResult decode(Object result) { result as List; return ServiceAvailableAPIResult( @@ -205,6 +523,29 @@ class ServiceAvailableAPIResult { serviceYn: result[2]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! ServiceAvailableAPIResult || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(status, other.status) && + _deepEquals(result, other.result) && + _deepEquals(serviceYn, other.serviceYn); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'ServiceAvailableAPIResult(status: $status, result: $result, serviceYn: $serviceYn)'; + } } class ProductMessage { @@ -233,10 +574,14 @@ class ProductMessage { /// It is a Base64 hash generated by applying the HMAC SHA256 algorithm on a concatenated string of parameters using the DPI security key. String checkValue; - Object encode() { + List _toList() { return [appId, countryCode, pageSize, pageNum, checkValue]; } + Object encode() { + return _toList(); + } + static ProductMessage decode(Object result) { result as List; return ProductMessage( @@ -247,6 +592,31 @@ class ProductMessage { checkValue: result[4]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! ProductMessage || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(appId, other.appId) && + _deepEquals(countryCode, other.countryCode) && + _deepEquals(pageSize, other.pageSize) && + _deepEquals(pageNum, other.pageNum) && + _deepEquals(checkValue, other.checkValue); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'ProductMessage(appId: $appId, countryCode: $countryCode, pageSize: $pageSize, pageNum: $pageNum, checkValue: $checkValue)'; + } } class PurchaseMessage { @@ -274,10 +644,14 @@ class PurchaseMessage { /// ItemType, MUST use 2 as value ("all items") String checkValue; - Object encode() { + List _toList() { return [appId, customId, countryCode, pageNum, checkValue]; } + Object encode() { + return _toList(); + } + static PurchaseMessage decode(Object result) { result as List; return PurchaseMessage( @@ -288,6 +662,31 @@ class PurchaseMessage { checkValue: result[4]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! PurchaseMessage || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(appId, other.appId) && + _deepEquals(customId, other.customId) && + _deepEquals(countryCode, other.countryCode) && + _deepEquals(pageNum, other.pageNum) && + _deepEquals(checkValue, other.checkValue); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'PurchaseMessage(appId: $appId, customId: $customId, countryCode: $countryCode, pageNum: $pageNum, checkValue: $checkValue)'; + } } class OrderDetails { @@ -309,10 +708,14 @@ class OrderDetails { String orderCustomId; - Object encode() { + List _toList() { return [orderItemId, orderTitle, orderTotal, orderCurrencyId, orderCustomId]; } + Object encode() { + return _toList(); + } + static OrderDetails decode(Object result) { result as List; return OrderDetails( @@ -323,6 +726,31 @@ class OrderDetails { orderCustomId: result[4]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! OrderDetails || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(orderItemId, other.orderItemId) && + _deepEquals(orderTitle, other.orderTitle) && + _deepEquals(orderTotal, other.orderTotal) && + _deepEquals(orderCurrencyId, other.orderCurrencyId) && + _deepEquals(orderCustomId, other.orderCustomId); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'OrderDetails(orderItemId: $orderItemId, orderTitle: $orderTitle, orderTotal: $orderTotal, orderCurrencyId: $orderCurrencyId, orderCustomId: $orderCustomId)'; + } } class BuyInfoMessage { @@ -334,14 +762,39 @@ class BuyInfoMessage { /// Payment parameters. OrderDetails payDetials; - Object encode() { + List _toList() { return [appId, payDetials]; } + Object encode() { + return _toList(); + } + static BuyInfoMessage decode(Object result) { result as List; return BuyInfoMessage(appId: result[0]! as String, payDetials: result[1]! as OrderDetails); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! BuyInfoMessage || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(appId, other.appId) && _deepEquals(payDetials, other.payDetials); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'BuyInfoMessage(appId: $appId, payDetials: $payDetials)'; + } } class InvoiceMessage { @@ -364,10 +817,14 @@ class InvoiceMessage { /// TV country code. String countryCode; - Object encode() { + List _toList() { return [appId, customId, invoiceId, countryCode]; } + Object encode() { + return _toList(); + } + static InvoiceMessage decode(Object result) { result as List; return InvoiceMessage( @@ -377,6 +834,30 @@ class InvoiceMessage { countryCode: result[3]! as String, ); } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! InvoiceMessage || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return _deepEquals(appId, other.appId) && + _deepEquals(customId, other.customId) && + _deepEquals(invoiceId, other.invoiceId) && + _deepEquals(countryCode, other.countryCode); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => _deepHash([runtimeType, ..._toList()]); + + @override + String toString() { + return 'InvoiceMessage(appId: $appId, customId: $customId, invoiceId: $invoiceId, countryCode: $countryCode)'; + } } class _PigeonCodec extends StandardMessageCodec { @@ -451,216 +932,307 @@ class _PigeonCodec extends StandardMessageCodec { } class InAppPurchaseApi { - /// Constructor for [InAppPurchaseApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - InAppPurchaseApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) - : pigeonVar_binaryMessenger = binaryMessenger, - pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty - ? '.$messageChannelSuffix' - : ''; - final BinaryMessenger? pigeonVar_binaryMessenger; + /// Constructor for [InAppPurchaseApi]. + InAppPurchaseApi({ + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + pigeon_ffi.InAppPurchaseTizenFfiBindings? ffiBindings, + }) : pigeonVar_ffiBindings = ffiBindings ?? _pigeonVar_defaultFfiBindings { + if (binaryMessenger != null) { + throw ArgumentError.value( + binaryMessenger, + 'binaryMessenger', + 'BinaryMessenger is not supported by FFI HostApi.', + ); + } + if (messageChannelSuffix.isNotEmpty) { + throw ArgumentError.value( + messageChannelSuffix, + 'messageChannelSuffix', + 'messageChannelSuffix is not supported by FFI HostApi.', + ); + } + } + + static final pigeon_ffi.InAppPurchaseTizenFfiBindings _pigeonVar_defaultFfiBindings = + pigeon_ffi.InAppPurchaseTizenFfiBindings.fromLookup(_pigeonFfiLookup); + + final pigeon_ffi.InAppPurchaseTizenFfiBindings pigeonVar_ffiBindings; static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - final String pigeonVar_messageChannelSuffix; + Future initialize() async { + final ffi.Pointer pigeonVar_request = ffi.nullptr; + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_initialize'; + ffi.Pointer pigeonVar_response = ffi.nullptr; + try { + pigeonVar_response = pigeonVar_ffiBindings.pigeon_in_app_purchase_api_initialize( + pigeonVar_request, + ); + final List? pigeonVar_replyList = _decodeFfiReply( + pigeonChannelCodec, + pigeonVar_response, + ); + _extractReplyValueOrThrow(pigeonVar_replyList, pigeonVar_channelName, isNullValid: true); + } finally { + _freeFfiRequest(pigeonVar_request); + if (pigeonVar_response != ffi.nullptr) { + pigeonVar_ffiBindings.pigeon_free_buffer(pigeonVar_response); + } + } + } /// Retrieves the list of products registered on the Billing (DPI) server. Future getProductsList(ProductMessage product) async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.getProductsList$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, + final ByteData? pigeonVar_requestMessage = pigeonChannelCodec.encodeMessage([product]); + final ffi.Pointer pigeonVar_request = _encodeFfiRequest( + pigeonVar_requestMessage, ); - final List? pigeonVar_replyList = - await pigeonVar_channel.send([product]) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_get_products_list'; + final Completer pigeonVar_completer = Completer(); + final int pigeonVar_replyId = _pigeonNextFfiAsyncReplyId++; + _pigeonFfiAsyncReplies[pigeonVar_replyId] = _PigeonFfiAsyncReply( + ffiBindings: pigeonVar_ffiBindings, + codec: pigeonChannelCodec, + channelName: pigeonVar_channelName, + isNullValid: false, + complete: (Object? pigeonVar_replyValue) { + pigeonVar_completer.complete(pigeonVar_replyValue! as ProductsListApiResult); + }, + completeError: (Object error, StackTrace stackTrace) { + pigeonVar_completer.completeError(error, stackTrace); + }, + ); + try { + _updatePigeonFfiReplyCallbackKeepAlive(); + pigeonVar_ffiBindings.pigeon_in_app_purchase_api_get_products_list( + pigeonVar_request, + pigeonVar_replyId, + _pigeonFfiReplyCallback.nativeFunction, ); - } else { - return (pigeonVar_replyList[0] as ProductsListApiResult?)!; + } catch (error, stackTrace) { + _pigeonFfiAsyncReplies.remove(pigeonVar_replyId); + if (!pigeonVar_completer.isCompleted) { + pigeonVar_completer.completeError(error, stackTrace); + } + } finally { + _freeFfiRequest(pigeonVar_request); + _updatePigeonFfiReplyCallbackKeepAlive(); } + return await pigeonVar_completer.future; } /// Retrieves the user's purchase list. Future getUserPurchaseList(PurchaseMessage purchase) async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.getUserPurchaseList$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, + final ByteData? pigeonVar_requestMessage = pigeonChannelCodec.encodeMessage([ + purchase, + ]); + final ffi.Pointer pigeonVar_request = _encodeFfiRequest( + pigeonVar_requestMessage, ); - final List? pigeonVar_replyList = - await pigeonVar_channel.send([purchase]) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_get_user_purchase_list'; + final Completer pigeonVar_completer = + Completer(); + final int pigeonVar_replyId = _pigeonNextFfiAsyncReplyId++; + _pigeonFfiAsyncReplies[pigeonVar_replyId] = _PigeonFfiAsyncReply( + ffiBindings: pigeonVar_ffiBindings, + codec: pigeonChannelCodec, + channelName: pigeonVar_channelName, + isNullValid: false, + complete: (Object? pigeonVar_replyValue) { + pigeonVar_completer.complete(pigeonVar_replyValue! as GetUserPurchaseListAPIResult); + }, + completeError: (Object error, StackTrace stackTrace) { + pigeonVar_completer.completeError(error, stackTrace); + }, + ); + try { + _updatePigeonFfiReplyCallbackKeepAlive(); + pigeonVar_ffiBindings.pigeon_in_app_purchase_api_get_user_purchase_list( + pigeonVar_request, + pigeonVar_replyId, + _pigeonFfiReplyCallback.nativeFunction, ); - } else { - return (pigeonVar_replyList[0] as GetUserPurchaseListAPIResult?)!; + } catch (error, stackTrace) { + _pigeonFfiAsyncReplies.remove(pigeonVar_replyId); + if (!pigeonVar_completer.isCompleted) { + pigeonVar_completer.completeError(error, stackTrace); + } + } finally { + _freeFfiRequest(pigeonVar_request); + _updatePigeonFfiReplyCallbackKeepAlive(); } + return await pigeonVar_completer.future; } /// Enables implementing the Samsung Checkout Client module within the application. /// After authenticating the purchase information through the application, the user can proceed to purchase payment. Future buyItem(BuyInfoMessage buyInfo) async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.buyItem$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, + final ByteData? pigeonVar_requestMessage = pigeonChannelCodec.encodeMessage([buyInfo]); + final ffi.Pointer pigeonVar_request = _encodeFfiRequest( + pigeonVar_requestMessage, ); - final List? pigeonVar_replyList = - await pigeonVar_channel.send([buyInfo]) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_buy_item'; + final Completer pigeonVar_completer = Completer(); + final int pigeonVar_replyId = _pigeonNextFfiAsyncReplyId++; + _pigeonFfiAsyncReplies[pigeonVar_replyId] = _PigeonFfiAsyncReply( + ffiBindings: pigeonVar_ffiBindings, + codec: pigeonChannelCodec, + channelName: pigeonVar_channelName, + isNullValid: false, + complete: (Object? pigeonVar_replyValue) { + pigeonVar_completer.complete(pigeonVar_replyValue! as BillingBuyData); + }, + completeError: (Object error, StackTrace stackTrace) { + pigeonVar_completer.completeError(error, stackTrace); + }, + ); + try { + _updatePigeonFfiReplyCallbackKeepAlive(); + pigeonVar_ffiBindings.pigeon_in_app_purchase_api_buy_item( + pigeonVar_request, + pigeonVar_replyId, + _pigeonFfiReplyCallback.nativeFunction, ); - } else { - return (pigeonVar_replyList[0] as BillingBuyData?)!; + } catch (error, stackTrace) { + _pigeonFfiAsyncReplies.remove(pigeonVar_replyId); + if (!pigeonVar_completer.isCompleted) { + pigeonVar_completer.completeError(error, stackTrace); + } + } finally { + _freeFfiRequest(pigeonVar_request); + _updatePigeonFfiReplyCallbackKeepAlive(); } + return await pigeonVar_completer.future; } /// Checks whether a purchase, corresponding to a specific "InvoiceID", was successful. Future verifyInvoice(InvoiceMessage invoice) async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.verifyInvoice$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, + final ByteData? pigeonVar_requestMessage = pigeonChannelCodec.encodeMessage([invoice]); + final ffi.Pointer pigeonVar_request = _encodeFfiRequest( + pigeonVar_requestMessage, ); - final List? pigeonVar_replyList = - await pigeonVar_channel.send([invoice]) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_verify_invoice'; + final Completer pigeonVar_completer = + Completer(); + final int pigeonVar_replyId = _pigeonNextFfiAsyncReplyId++; + _pigeonFfiAsyncReplies[pigeonVar_replyId] = _PigeonFfiAsyncReply( + ffiBindings: pigeonVar_ffiBindings, + codec: pigeonChannelCodec, + channelName: pigeonVar_channelName, + isNullValid: false, + complete: (Object? pigeonVar_replyValue) { + pigeonVar_completer.complete(pigeonVar_replyValue! as VerifyInvoiceAPIResult); + }, + completeError: (Object error, StackTrace stackTrace) { + pigeonVar_completer.completeError(error, stackTrace); + }, + ); + try { + _updatePigeonFfiReplyCallbackKeepAlive(); + pigeonVar_ffiBindings.pigeon_in_app_purchase_api_verify_invoice( + pigeonVar_request, + pigeonVar_replyId, + _pigeonFfiReplyCallback.nativeFunction, ); - } else { - return (pigeonVar_replyList[0] as VerifyInvoiceAPIResult?)!; + } catch (error, stackTrace) { + _pigeonFfiAsyncReplies.remove(pigeonVar_replyId); + if (!pigeonVar_completer.isCompleted) { + pigeonVar_completer.completeError(error, stackTrace); + } + } finally { + _freeFfiRequest(pigeonVar_request); + _updatePigeonFfiReplyCallbackKeepAlive(); } + return await pigeonVar_completer.future; } /// Checks whether the Billing server is available. Future isServiceAvailable() async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.isServiceAvailable$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, + final ffi.Pointer pigeonVar_request = ffi.nullptr; + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_is_service_available'; + final Completer pigeonVar_completer = Completer(); + final int pigeonVar_replyId = _pigeonNextFfiAsyncReplyId++; + _pigeonFfiAsyncReplies[pigeonVar_replyId] = _PigeonFfiAsyncReply( + ffiBindings: pigeonVar_ffiBindings, + codec: pigeonChannelCodec, + channelName: pigeonVar_channelName, + isNullValid: false, + complete: (Object? pigeonVar_replyValue) { + pigeonVar_completer.complete(pigeonVar_replyValue! as bool); + }, + completeError: (Object error, StackTrace stackTrace) { + pigeonVar_completer.completeError(error, stackTrace); + }, ); - final List? pigeonVar_replyList = await pigeonVar_channel.send(null) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + try { + _updatePigeonFfiReplyCallbackKeepAlive(); + pigeonVar_ffiBindings.pigeon_in_app_purchase_api_is_service_available( + pigeonVar_request, + pigeonVar_replyId, + _pigeonFfiReplyCallback.nativeFunction, ); - } else { - return (pigeonVar_replyList[0] as bool?)!; + } catch (error, stackTrace) { + _pigeonFfiAsyncReplies.remove(pigeonVar_replyId); + if (!pigeonVar_completer.isCompleted) { + pigeonVar_completer.completeError(error, stackTrace); + } + } finally { + _freeFfiRequest(pigeonVar_request); + _updatePigeonFfiReplyCallbackKeepAlive(); } + return await pigeonVar_completer.future; } Future getCustomId() async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.getCustomId$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel.send(null) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], + final ffi.Pointer pigeonVar_request = ffi.nullptr; + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_get_custom_id'; + ffi.Pointer pigeonVar_response = ffi.nullptr; + try { + pigeonVar_response = pigeonVar_ffiBindings.pigeon_in_app_purchase_api_get_custom_id( + pigeonVar_request, ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final List? pigeonVar_replyList = _decodeFfiReply( + pigeonChannelCodec, + pigeonVar_response, ); - } else { - return (pigeonVar_replyList[0] as String?)!; + final Object? pigeonVar_replyValue = _extractReplyValueOrThrow( + pigeonVar_replyList, + pigeonVar_channelName, + isNullValid: false, + ); + return pigeonVar_replyValue! as String; + } finally { + _freeFfiRequest(pigeonVar_request); + if (pigeonVar_response != ffi.nullptr) { + pigeonVar_ffiBindings.pigeon_free_buffer(pigeonVar_response); + } } } Future getCountryCode() async { - final String pigeonVar_channelName = - 'dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.getCountryCode$pigeonVar_messageChannelSuffix'; - final BasicMessageChannel pigeonVar_channel = BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = await pigeonVar_channel.send(null) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], + final ffi.Pointer pigeonVar_request = ffi.nullptr; + final String pigeonVar_channelName = 'pigeon_in_app_purchase_api_get_country_code'; + ffi.Pointer pigeonVar_response = ffi.nullptr; + try { + pigeonVar_response = pigeonVar_ffiBindings.pigeon_in_app_purchase_api_get_country_code( + pigeonVar_request, ); - } else if (pigeonVar_replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', + final List? pigeonVar_replyList = _decodeFfiReply( + pigeonChannelCodec, + pigeonVar_response, ); - } else { - return (pigeonVar_replyList[0] as String?)!; + final Object? pigeonVar_replyValue = _extractReplyValueOrThrow( + pigeonVar_replyList, + pigeonVar_channelName, + isNullValid: false, + ); + return pigeonVar_replyValue! as String; + } finally { + _freeFfiRequest(pigeonVar_request); + if (pigeonVar_response != ffi.nullptr) { + pigeonVar_ffiBindings.pigeon_free_buffer(pigeonVar_response); + } } } } diff --git a/packages/in_app_purchase/lib/src/messages.g.ffi.dart b/packages/in_app_purchase/lib/src/messages.g.ffi.dart new file mode 100644 index 000000000..5e58c30d9 --- /dev/null +++ b/packages/in_app_purchase/lib/src/messages.g.ffi.dart @@ -0,0 +1,206 @@ +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint, unused_import, unused_element, deprecated_member_use_from_same_package +import 'dart:ffi' as ffi; + +/// Generated bindings for Pigeon C++ FFI APIs. +class InAppPurchaseTizenFfiBindings { + /// Holds the symbol lookup function. + final ffi.Pointer Function(String symbolName) _lookup; + + /// The symbols are looked up in [dynamicLibrary]. + InAppPurchaseTizenFfiBindings(ffi.DynamicLibrary dynamicLibrary) + : _lookup = dynamicLibrary.lookup; + + /// The symbols are looked up with [lookup]. + InAppPurchaseTizenFfiBindings.fromLookup( + ffi.Pointer Function(String symbolName) lookup, + ) : _lookup = lookup; + + void pigeon_free_buffer(ffi.Pointer buffer) { + return _pigeon_free_buffer(buffer); + } + + late final _pigeon_free_bufferPtr = + _lookup)>>( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_free_buffer', + ); + late final _pigeon_free_buffer = _pigeon_free_bufferPtr + .asFunction)>(); + + void pigeon_in_app_purchase_api_buy_item( + ffi.Pointer request, + int reply_id, + PigeonFfiReplyCallback on_reply, + ) { + return _pigeon_in_app_purchase_api_buy_item(request, reply_id, on_reply); + } + + late final _pigeon_in_app_purchase_api_buy_itemPtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int64, PigeonFfiReplyCallback) + > + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_buy_item', + ); + late final _pigeon_in_app_purchase_api_buy_item = _pigeon_in_app_purchase_api_buy_itemPtr + .asFunction, int, PigeonFfiReplyCallback)>(); + + ffi.Pointer pigeon_in_app_purchase_api_get_country_code( + ffi.Pointer request, + ) { + return _pigeon_in_app_purchase_api_get_country_code(request); + } + + late final _pigeon_in_app_purchase_api_get_country_codePtr = + _lookup< + ffi.NativeFunction Function(ffi.Pointer)> + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_country_code', + ); + late final _pigeon_in_app_purchase_api_get_country_code = + _pigeon_in_app_purchase_api_get_country_codePtr + .asFunction Function(ffi.Pointer)>(); + + ffi.Pointer pigeon_in_app_purchase_api_get_custom_id( + ffi.Pointer request, + ) { + return _pigeon_in_app_purchase_api_get_custom_id(request); + } + + late final _pigeon_in_app_purchase_api_get_custom_idPtr = + _lookup< + ffi.NativeFunction Function(ffi.Pointer)> + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_custom_id', + ); + late final _pigeon_in_app_purchase_api_get_custom_id = + _pigeon_in_app_purchase_api_get_custom_idPtr + .asFunction Function(ffi.Pointer)>(); + + void pigeon_in_app_purchase_api_get_products_list( + ffi.Pointer request, + int reply_id, + PigeonFfiReplyCallback on_reply, + ) { + return _pigeon_in_app_purchase_api_get_products_list(request, reply_id, on_reply); + } + + late final _pigeon_in_app_purchase_api_get_products_listPtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int64, PigeonFfiReplyCallback) + > + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_products_list', + ); + late final _pigeon_in_app_purchase_api_get_products_list = + _pigeon_in_app_purchase_api_get_products_listPtr + .asFunction, int, PigeonFfiReplyCallback)>(); + + void pigeon_in_app_purchase_api_get_user_purchase_list( + ffi.Pointer request, + int reply_id, + PigeonFfiReplyCallback on_reply, + ) { + return _pigeon_in_app_purchase_api_get_user_purchase_list(request, reply_id, on_reply); + } + + late final _pigeon_in_app_purchase_api_get_user_purchase_listPtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int64, PigeonFfiReplyCallback) + > + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_user_purchase_list', + ); + late final _pigeon_in_app_purchase_api_get_user_purchase_list = + _pigeon_in_app_purchase_api_get_user_purchase_listPtr + .asFunction, int, PigeonFfiReplyCallback)>(); + + ffi.Pointer pigeon_in_app_purchase_api_initialize( + ffi.Pointer request, + ) { + return _pigeon_in_app_purchase_api_initialize(request); + } + + late final _pigeon_in_app_purchase_api_initializePtr = + _lookup< + ffi.NativeFunction Function(ffi.Pointer)> + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_initialize', + ); + late final _pigeon_in_app_purchase_api_initialize = _pigeon_in_app_purchase_api_initializePtr + .asFunction Function(ffi.Pointer)>(); + + void pigeon_in_app_purchase_api_is_service_available( + ffi.Pointer request, + int reply_id, + PigeonFfiReplyCallback on_reply, + ) { + return _pigeon_in_app_purchase_api_is_service_available(request, reply_id, on_reply); + } + + late final _pigeon_in_app_purchase_api_is_service_availablePtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int64, PigeonFfiReplyCallback) + > + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_is_service_available', + ); + late final _pigeon_in_app_purchase_api_is_service_available = + _pigeon_in_app_purchase_api_is_service_availablePtr + .asFunction, int, PigeonFfiReplyCallback)>(); + + void pigeon_in_app_purchase_api_verify_invoice( + ffi.Pointer request, + int reply_id, + PigeonFfiReplyCallback on_reply, + ) { + return _pigeon_in_app_purchase_api_verify_invoice(request, reply_id, on_reply); + } + + late final _pigeon_in_app_purchase_api_verify_invoicePtr = + _lookup< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int64, PigeonFfiReplyCallback) + > + >( + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_verify_invoice', + ); + late final _pigeon_in_app_purchase_api_verify_invoice = + _pigeon_in_app_purchase_api_verify_invoicePtr + .asFunction, int, PigeonFfiReplyCallback)>(); +} + +final class PigeonFfiBuffer extends ffi.Struct { + external ffi.Pointer data; + + @ffi.Size() + external int length; + + static ffi.Pointer $allocate( + ffi.Allocator $allocator, { + required ffi.Pointer data, + required int length, + }) => $allocator() + ..ref.data = data + ..ref.length = length; +} + +typedef PigeonFfiDoneCallback = ffi.Pointer>; +typedef PigeonFfiDoneCallbackFunction = ffi.Void Function(ffi.Int64 sink_id); +typedef DartPigeonFfiDoneCallbackFunction = void Function(int sink_id); +typedef PigeonFfiEventCallback = ffi.Pointer>; +typedef PigeonFfiEventCallbackFunction = + ffi.Void Function(ffi.Int64 sink_id, ffi.Pointer event); +typedef DartPigeonFfiEventCallbackFunction = + void Function(int sink_id, ffi.Pointer event); +typedef PigeonFfiReplyCallback = ffi.Pointer>; +typedef PigeonFfiReplyCallbackFunction = + ffi.Void Function(ffi.Int64 reply_id, ffi.Pointer reply); +typedef DartPigeonFfiReplyCallbackFunction = + void Function(int reply_id, ffi.Pointer reply); diff --git a/packages/in_app_purchase/pigeons/messages.dart b/packages/in_app_purchase/pigeons/messages.dart index a0fd77175..73a390e29 100644 --- a/packages/in_app_purchase/pigeons/messages.dart +++ b/packages/in_app_purchase/pigeons/messages.dart @@ -7,9 +7,31 @@ import 'package:pigeon/pigeon.dart'; @ConfigurePigeon( PigeonOptions( dartOut: 'lib/src/messages.g.dart', - cppOptions: CppOptions(namespace: 'in_app_purchase_tizen'), + dartFfiOut: 'lib/src/messages.g.ffi.dart', + configDirectory: 'tool/pigeon', + dartOptions: DartOptions( + ffiOptions: DartFfiOptions( + bindingClassName: 'InAppPurchaseTizenFfiBindings', + nativeLibraryExpression: r''' +(() { + final String libraryPath = File('/proc/self/maps') + .readAsLinesSync() + .map((String line) { + final int index = line.indexOf('/'); + return index == -1 ? '' : line.substring(index); + }) + .firstWhere( + (String path) => path.endsWith('/libflutter_plugins.so'), + ); + return ffi.DynamicLibrary.open(libraryPath); +})()''', + ), + ), + cppOptions: CppOptions(namespace: 'in_app_purchase_tizen', useStdVisit: false), cppHeaderOut: 'tizen/src/messages.h', cppSourceOut: 'tizen/src/messages.cc', + cppFfiHeaderOut: 'tizen/src/messages_ffi.h', + cppFfiSourceOut: 'tizen/src/messages_ffi.cc', ), ) /// Dart wrapper around [`ProductsListApiResult`] in (https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html). @@ -245,6 +267,8 @@ class InvoiceMessage { @HostApi() abstract class InAppPurchaseApi { + void initialize(); + /// Retrieves the list of products registered on the Billing (DPI) server. @async ProductsListApiResult getProductsList(ProductMessage product); diff --git a/packages/in_app_purchase/pubspec.yaml b/packages/in_app_purchase/pubspec.yaml index 94b873174..00672ad95 100644 --- a/packages/in_app_purchase/pubspec.yaml +++ b/packages/in_app_purchase/pubspec.yaml @@ -2,7 +2,7 @@ name: in_app_purchase_tizen description: Tizen implementation of the in_app_purchase plugin for Samsung Smart TV. homepage: https://github.com/flutter-tizen/plugins repository: https://github.com/flutter-tizen/plugins/tree/main/packages/in_app_purchase -version: 0.1.9 +version: 0.2.0 environment: sdk: ^3.10.0 @@ -19,10 +19,17 @@ flutter: dependencies: crypto: ^3.0.2 + ffi: ^2.0.0 flutter: sdk: flutter in_app_purchase_platform_interface: ^1.4.0 + meta: ^1.8.0 dev_dependencies: build_runner: ^2.0.0 - pigeon: ^22.4.2 + ffigen: ^22.0.0 + pigeon: + git: + url: https://github.com/gin7773/flutter-packages.git + ref: 1e63f1b5852a868d1b072de460752fe95e724600 + path: packages/pigeon diff --git a/packages/in_app_purchase/tizen/src/billing_manager.cc b/packages/in_app_purchase/tizen/src/billing_manager.cc index 5c574ebcd..87dc432bc 100644 --- a/packages/in_app_purchase/tizen/src/billing_manager.cc +++ b/packages/in_app_purchase/tizen/src/billing_manager.cc @@ -166,6 +166,15 @@ bool BillingManager::VerifyInvoice( return true; } +void BillingManager::ResetPendingCallbacks() { + std::lock_guard lock(mutex_); + is_available_callback_ = nullptr; + buy_item_callback_ = nullptr; + get_product_list_callback_ = nullptr; + get_purchase_list_callback_ = nullptr; + verify_invoice_callback_ = nullptr; +} + void BillingManager::OnAvailable(const char *detail_result, void *user_data) { LOG_INFO("[BillingManager] Billing server detail_result: %s", detail_result); @@ -187,8 +196,7 @@ void BillingManager::OnAvailable(const char *detail_result, void *user_data) { else self->is_available_callback_(false); } else { - self->is_available_callback_( - FlutterError("Invalid argument", "is_available_callback_ is null !")); + LOG_ERROR("[BillingManager] is_available_callback_ is null !"); } self->is_available_callback_ = nullptr; } @@ -258,8 +266,7 @@ void BillingManager::OnProducts(const char *detail_result, void *user_data) { check_value, item_details); self->get_product_list_callback_(products_list); } else { - self->get_product_list_callback_(FlutterError( - "Invalid argument", "get_product_list_callback_ is null !")); + LOG_ERROR("[BillingManager] get_product_list_callback_ is null !"); } self->get_product_list_callback_ = nullptr; } @@ -356,8 +363,7 @@ void BillingManager::OnPurchase(const char *detail_result, void *user_data) { cp_status, &cp_result, total_count, check_value, invoice_details); self->get_purchase_list_callback_(purchase_list); } else { - self->get_purchase_list_callback_(FlutterError( - "Invalid argument", "get_purchase_list_callback_ is null !")); + LOG_ERROR("[BillingManager] get_purchase_list_callback_ is null !"); } self->get_purchase_list_callback_ = nullptr; } @@ -401,8 +407,7 @@ bool BillingManager::OnBuyItem(const char *pay_result, const char *detail_info, BillingBuyData buy_data(pay_res, pay_details); self->buy_item_callback_(buy_data); } else { - self->buy_item_callback_( - FlutterError("Invalid argument", "buy_item_callback_ is null !")); + LOG_ERROR("[BillingManager] buy_item_callback_ is null !"); } self->buy_item_callback_ = nullptr; return true; @@ -433,8 +438,7 @@ void BillingManager::OnVerify(const char *detail_result, void *user_data) { invoice_id); self->verify_invoice_callback_(verify_invoice); } else { - self->verify_invoice_callback_( - FlutterError("Invalid argument", "verify_invoice_callback_ is null !")); + LOG_ERROR("[BillingManager] verify_invoice_callback_ is null !"); } self->verify_invoice_callback_ = nullptr; } diff --git a/packages/in_app_purchase/tizen/src/billing_manager.h b/packages/in_app_purchase/tizen/src/billing_manager.h index a0a9f94e7..092cd0f16 100644 --- a/packages/in_app_purchase/tizen/src/billing_manager.h +++ b/packages/in_app_purchase/tizen/src/billing_manager.h @@ -73,6 +73,7 @@ class BillingManager { bool VerifyInvoice(const char *app_id, const char *custom_id, const char *invoice_id, const char *country_code, FunctionResult result); + void ResetPendingCallbacks(); std::optional GetCustomId(); std::optional GetCountryCode(); diff --git a/packages/in_app_purchase/tizen/src/in_app_purchase_tizen_plugin.cc b/packages/in_app_purchase/tizen/src/in_app_purchase_tizen_plugin.cc index 75e80aa40..0be59cbc6 100644 --- a/packages/in_app_purchase/tizen/src/in_app_purchase_tizen_plugin.cc +++ b/packages/in_app_purchase/tizen/src/in_app_purchase_tizen_plugin.cc @@ -4,21 +4,84 @@ #include "in_app_purchase_tizen_plugin.h" -#include #include -#include +#include +#include +#include #include +#include #include +#include #include "billing_manager.h" #include "log.h" #include "messages.h" +#include "messages_ffi.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" namespace in_app_purchase_tizen { +namespace { + +class MainContextDispatcher : public PigeonFfiSyncDispatcher { + public: + MainContextDispatcher() + : thread_id_(std::this_thread::get_id()), + main_context_(g_main_context_ref_thread_default()) {} + + ~MainContextDispatcher() override { g_main_context_unref(main_context_); } + + PigeonFfiBuffer *RunSync(std::function task) override { + if (std::this_thread::get_id() == thread_id_) { + return task(); + } + + struct TaskState { + std::function task; + PigeonFfiBuffer *result = nullptr; + std::mutex mutex; + std::condition_variable condition; + bool done = false; + }; + TaskState state{std::move(task)}; + GSource *source = g_idle_source_new(); + g_source_set_priority(source, G_PRIORITY_DEFAULT); + g_source_set_callback( + source, + [](gpointer data) -> gboolean { + auto *state = static_cast(data); + PigeonFfiBuffer *result = state->task(); + { + std::lock_guard lock(state->mutex); + state->result = result; + state->done = true; + state->condition.notify_one(); + } + return G_SOURCE_REMOVE; + }, + &state, nullptr); + g_source_attach(source, main_context_); + g_source_unref(source); + + std::unique_lock lock(state.mutex); + state.condition.wait(lock, [&state] { return state.done; }); + return state.result; + } + + private: + std::thread::id thread_id_; + GMainContext *main_context_; +}; + +MainContextDispatcher *GetMainContextDispatcher() { + static MainContextDispatcher *dispatcher = new MainContextDispatcher(); + return dispatcher; +} + +} // namespace + class InAppPurchaseTizenPlugin : public flutter::Plugin, public InAppPurchaseApi { public: @@ -27,6 +90,7 @@ class InAppPurchaseTizenPlugin : public flutter::Plugin, InAppPurchaseTizenPlugin(flutter::PluginRegistrar *plugin_registrar); virtual ~InAppPurchaseTizenPlugin() { Dispose(); } + std::optional Initialize() override; void GetProductsList(const ProductMessage &product, std::function reply)> result) override; @@ -52,12 +116,15 @@ class InAppPurchaseTizenPlugin : public flutter::Plugin, }; InAppPurchaseTizenPlugin::InAppPurchaseTizenPlugin( - flutter::PluginRegistrar *plugin_registrar) { + flutter::PluginRegistrar * /*plugin_registrar*/) { billing_ = std::make_unique(); - InAppPurchaseTizenPlugin::SetUp(plugin_registrar->messenger(), this); + SetUpInAppPurchaseApiFfi(this, GetMainContextDispatcher()); } -void InAppPurchaseTizenPlugin::Dispose() { billing_ = nullptr; } +void InAppPurchaseTizenPlugin::Dispose() { + TearDownInAppPurchaseApiFfi(); + billing_ = nullptr; +} void InAppPurchaseTizenPlugin::RegisterWithRegistrar( flutter::PluginRegistrar *plugin_registrar) { @@ -65,6 +132,11 @@ void InAppPurchaseTizenPlugin::RegisterWithRegistrar( plugin_registrar->AddPlugin(std::move(plugin)); } +std::optional InAppPurchaseTizenPlugin::Initialize() { + billing_->ResetPendingCallbacks(); + return std::nullopt; +} + void InAppPurchaseTizenPlugin::GetProductsList( const ProductMessage &product, std::function reply)> result) { diff --git a/packages/in_app_purchase/tizen/src/messages.cc b/packages/in_app_purchase/tizen/src/messages.cc index 9c04a6f2f..371efb5c9 100644 --- a/packages/in_app_purchase/tizen/src/messages.cc +++ b/packages/in_app_purchase/tizen/src/messages.cc @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v22.7.4), do not edit directly. +// Autogenerated from Pigeon (v29.0.11), do not edit directly. // See also: https://pub.dev/packages/pigeon #undef _HAS_EXCEPTIONS @@ -10,16 +10,19 @@ #include #include +#include +#include #include #include +#include #include namespace in_app_purchase_tizen { -using flutter::BasicMessageChannel; -using flutter::CustomEncodableValue; -using flutter::EncodableList; -using flutter::EncodableMap; -using flutter::EncodableValue; +using ::flutter::BasicMessageChannel; +using ::flutter::CustomEncodableValue; +using ::flutter::EncodableList; +using ::flutter::EncodableMap; +using ::flutter::EncodableValue; FlutterError CreateConnectionError(const std::string channel_name) { return FlutterError( @@ -28,6 +31,345 @@ FlutterError CreateConnectionError(const std::string channel_name) { EncodableValue("")); } +namespace { +template +bool PigeonInternalDeepEquals(const T& a, const T& b); + +bool PigeonInternalDeepEquals(const double& a, const double& b); + +template +bool PigeonInternalDeepEquals(const std::vector& a, const std::vector& b); + +template +bool PigeonInternalDeepEquals(const std::map& a, const std::map& b); + +template +bool PigeonInternalDeepEquals(const std::optional& a, + const std::optional& b); + +template +bool PigeonInternalDeepEquals(const std::unique_ptr& a, + const std::unique_ptr& b); + +bool PigeonInternalDeepEquals(const ::flutter::EncodableValue& a, + const ::flutter::EncodableValue& b); + +template +bool PigeonInternalDeepEquals(const T& a, const T& b) { + return a == b; +} + +template +bool PigeonInternalDeepEquals(const std::vector& a, + const std::vector& b) { + if (a.size() != b.size()) { + return false; + } + for (size_t i = 0; i < a.size(); ++i) { + if (!PigeonInternalDeepEquals(a[i], b[i])) { + return false; + } + } + return true; +} + +template +bool PigeonInternalDeepEquals(const std::map& a, + const std::map& b) { + if (a.size() != b.size()) { + return false; + } + for (const auto& kv : a) { + bool found = false; + for (const auto& b_kv : b) { + if (PigeonInternalDeepEquals(kv.first, b_kv.first)) { + if (PigeonInternalDeepEquals(kv.second, b_kv.second)) { + found = true; + break; + } else { + return false; + } + } + } + if (!found) { + return false; + } + } + return true; +} + +bool PigeonInternalDeepEquals(const double& a, const double& b) { + // Normalize -0.0 to 0.0 and handle NaN equality. + return (a == b) || (std::isnan(a) && std::isnan(b)); +} + +template +bool PigeonInternalDeepEquals(const std::optional& a, + const std::optional& b) { + if (!a && !b) { + return true; + } + if (!a || !b) { + return false; + } + return PigeonInternalDeepEquals(*a, *b); +} + +template +bool PigeonInternalDeepEquals(const std::unique_ptr& a, + const std::unique_ptr& b) { + if (a.get() == b.get()) { + return true; + } + if (!a || !b) { + return false; + } + return PigeonInternalDeepEquals(*a, *b); +} + +bool PigeonInternalDeepEquals(const ::flutter::EncodableValue& a, + const ::flutter::EncodableValue& b) { + if (a.index() != b.index()) { + return false; + } + if (const double* da = std::get_if(&a)) { + return PigeonInternalDeepEquals(*da, std::get(b)); + } else if (const ::flutter::EncodableList* la = + std::get_if<::flutter::EncodableList>(&a)) { + return PigeonInternalDeepEquals(*la, std::get<::flutter::EncodableList>(b)); + } else if (const ::flutter::EncodableMap* ma = + std::get_if<::flutter::EncodableMap>(&a)) { + return PigeonInternalDeepEquals(*ma, std::get<::flutter::EncodableMap>(b)); + } + return a == b; +} + +template +size_t PigeonInternalDeepHash(const T& v); + +size_t PigeonInternalDeepHash(const double& v); + +template +size_t PigeonInternalDeepHash(const std::vector& v); + +template +size_t PigeonInternalDeepHash(const std::map& v); + +template +size_t PigeonInternalDeepHash(const std::optional& v); + +template +size_t PigeonInternalDeepHash(const std::unique_ptr& v); + +size_t PigeonInternalDeepHash(const ::flutter::EncodableValue& v); + +template +size_t PigeonInternalDeepHash(const T& v) { + return std::hash()(v); +} + +template +size_t PigeonInternalDeepHash(const std::vector& v) { + size_t result = 1; + for (const auto& item : v) { + result = result * 31 + PigeonInternalDeepHash(item); + } + return result; +} + +template +size_t PigeonInternalDeepHash(const std::map& v) { + size_t result = 0; + for (const auto& kv : v) { + result += ((PigeonInternalDeepHash(kv.first) * 31) ^ + PigeonInternalDeepHash(kv.second)); + } + return result; +} + +size_t PigeonInternalDeepHash(const double& v) { + if (std::isnan(v)) { + // Normalize NaN to a consistent hash. + return std::hash()(std::numeric_limits::quiet_NaN()); + } + if (v == 0.0) { + // Normalize -0.0 to 0.0 so they have the same hash code. + return std::hash()(0.0); + } + return std::hash()(v); +} + +template +size_t PigeonInternalDeepHash(const std::optional& v) { + return v ? PigeonInternalDeepHash(*v) : 0; +} + +template +size_t PigeonInternalDeepHash(const std::unique_ptr& v) { + return v ? PigeonInternalDeepHash(*v) : 0; +} + +size_t PigeonInternalDeepHash(const ::flutter::EncodableValue& v) { + size_t result = v.index(); + if (const bool* bv = std::get_if(&v)) { + result = result * 31 + PigeonInternalDeepHash(*bv); + } else if (const int32_t* iv = std::get_if(&v)) { + result = result * 31 + PigeonInternalDeepHash(*iv); + } else if (const int64_t* lv = std::get_if(&v)) { + result = result * 31 + PigeonInternalDeepHash(*lv); + } else if (const double* dv = std::get_if(&v)) { + result = result * 31 + PigeonInternalDeepHash(*dv); + } else if (const std::string* sv = std::get_if(&v)) { + result = result * 31 + PigeonInternalDeepHash(*sv); + } else if (const std::vector* bv = + std::get_if>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*bv); + } else if (const std::vector* iv = + std::get_if>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*iv); + } else if (const std::vector* lv = + std::get_if>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*lv); + } else if (const std::vector* fv = + std::get_if>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*fv); + } else if (const std::vector* dv = + std::get_if>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*dv); + } else if (const ::flutter::EncodableList* lv = + std::get_if<::flutter::EncodableList>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*lv); + } else if (const ::flutter::EncodableMap* mv = + std::get_if<::flutter::EncodableMap>(&v)) { + result = result * 31 + PigeonInternalDeepHash(*mv); + } + return result; +} + +template +std::string PigeonInternalToString(const T& v); + +std::string PigeonInternalToString(const bool& v); + +template +std::string PigeonInternalToString(const std::vector& v); + +template +std::string PigeonInternalToString(const std::map& v); + +template +std::string PigeonInternalToString(const std::optional& v); + +template +std::string PigeonInternalToString(const std::unique_ptr& v); + +std::string PigeonInternalToString(const ::flutter::EncodableValue& v); + +template +std::string PigeonInternalToString(const T& v) { + std::stringstream ss; + if constexpr (std::is_enum_v) { + ss << static_cast(v); + } else { + ss << v; + } + return ss.str(); +} + +std::string PigeonInternalToString(const bool& v) { + return v ? "true" : "false"; +} + +template +std::string PigeonInternalToString(const std::vector& v) { + std::stringstream ss; + ss << "["; + for (size_t i = 0; i < v.size(); ++i) { + if (i > 0) { + ss << ", "; + } + ss << PigeonInternalToString(v[i]); + } + ss << "]"; + return ss.str(); +} + +template +std::string PigeonInternalToString(const std::map& v) { + std::stringstream ss; + ss << "{"; + bool first = true; + for (const auto& kv : v) { + if (!first) { + ss << ", "; + } + first = false; + ss << PigeonInternalToString(kv.first) << ": " + << PigeonInternalToString(kv.second); + } + ss << "}"; + return ss.str(); +} + +template +std::string PigeonInternalToString(const std::optional& v) { + return v ? PigeonInternalToString(*v) : "null"; +} + +template +std::string PigeonInternalToString(const std::unique_ptr& v) { + return v ? PigeonInternalToString(*v) : "null"; +} + +std::string PigeonInternalToString(const ::flutter::EncodableValue& v) { + if (std::get_if(&v)) { + return "null"; + } + if (const bool* bv = std::get_if(&v)) { + return PigeonInternalToString(*bv); + } + if (const int32_t* iv = std::get_if(&v)) { + return PigeonInternalToString(*iv); + } + if (const int64_t* lv = std::get_if(&v)) { + return PigeonInternalToString(*lv); + } + if (const double* dv = std::get_if(&v)) { + return PigeonInternalToString(*dv); + } + if (const std::string* sv = std::get_if(&v)) { + return "\"" + *sv + "\""; + } + if (const std::vector* bv = std::get_if>(&v)) { + return PigeonInternalToString(*bv); + } + if (const std::vector* iv = std::get_if>(&v)) { + return PigeonInternalToString(*iv); + } + if (const std::vector* lv = std::get_if>(&v)) { + return PigeonInternalToString(*lv); + } + if (const std::vector* fv = std::get_if>(&v)) { + return PigeonInternalToString(*fv); + } + if (const std::vector* dv = std::get_if>(&v)) { + return PigeonInternalToString(*dv); + } + if (const ::flutter::EncodableList* lv = + std::get_if<::flutter::EncodableList>(&v)) { + return PigeonInternalToString(*lv); + } + if (const ::flutter::EncodableMap* mv = + std::get_if<::flutter::EncodableMap>(&v)) { + return PigeonInternalToString(*mv); + } + if (std::get_if<::flutter::CustomEncodableValue>(&v)) { + return "[custom]"; + } + return ""; +} + +} // namespace // ProductsListApiResult ProductsListApiResult::ProductsListApiResult(const std::string& cp_status, @@ -117,6 +459,54 @@ ProductsListApiResult ProductsListApiResult::FromEncodableList( return decoded; } +bool ProductsListApiResult::operator==( + const ProductsListApiResult& other) const { + return PigeonInternalDeepEquals(cp_status_, other.cp_status_) && + PigeonInternalDeepEquals(cp_result_, other.cp_result_) && + PigeonInternalDeepEquals(total_count_, other.total_count_) && + PigeonInternalDeepEquals(check_value_, other.check_value_) && + PigeonInternalDeepEquals(item_details_, other.item_details_); +} + +bool ProductsListApiResult::operator!=( + const ProductsListApiResult& other) const { + return !(*this == other); +} + +size_t ProductsListApiResult::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(cp_status_); + result = result * 31 + PigeonInternalDeepHash(cp_result_); + result = result * 31 + PigeonInternalDeepHash(total_count_); + result = result * 31 + PigeonInternalDeepHash(check_value_); + result = result * 31 + PigeonInternalDeepHash(item_details_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const ProductsListApiResult& obj) { + os << "ProductsListApiResult("; + os << "cp_status: "; + os << PigeonInternalToString(obj.cp_status_); + os << ", cp_result: "; + if (obj.cp_result_) { + os << PigeonInternalToString(*obj.cp_result_); + } else { + os << "null"; + } + os << ", total_count: "; + os << PigeonInternalToString(obj.total_count_); + os << ", check_value: "; + os << PigeonInternalToString(obj.check_value_); + os << ", item_details: "; + os << PigeonInternalToString(obj.item_details_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const ProductsListApiResult& v) { + return v.Hash(); +} + // GetUserPurchaseListAPIResult GetUserPurchaseListAPIResult::GetUserPurchaseListAPIResult( @@ -208,6 +598,55 @@ GetUserPurchaseListAPIResult GetUserPurchaseListAPIResult::FromEncodableList( return decoded; } +bool GetUserPurchaseListAPIResult::operator==( + const GetUserPurchaseListAPIResult& other) const { + return PigeonInternalDeepEquals(cp_status_, other.cp_status_) && + PigeonInternalDeepEquals(cp_result_, other.cp_result_) && + PigeonInternalDeepEquals(total_count_, other.total_count_) && + PigeonInternalDeepEquals(check_value_, other.check_value_) && + PigeonInternalDeepEquals(invoice_details_, other.invoice_details_); +} + +bool GetUserPurchaseListAPIResult::operator!=( + const GetUserPurchaseListAPIResult& other) const { + return !(*this == other); +} + +size_t GetUserPurchaseListAPIResult::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(cp_status_); + result = result * 31 + PigeonInternalDeepHash(cp_result_); + result = result * 31 + PigeonInternalDeepHash(total_count_); + result = result * 31 + PigeonInternalDeepHash(check_value_); + result = result * 31 + PigeonInternalDeepHash(invoice_details_); + return result; +} + +std::ostream& operator<<(std::ostream& os, + const GetUserPurchaseListAPIResult& obj) { + os << "GetUserPurchaseListAPIResult("; + os << "cp_status: "; + os << PigeonInternalToString(obj.cp_status_); + os << ", cp_result: "; + if (obj.cp_result_) { + os << PigeonInternalToString(*obj.cp_result_); + } else { + os << "null"; + } + os << ", total_count: "; + os << PigeonInternalToString(obj.total_count_); + os << ", check_value: "; + os << PigeonInternalToString(obj.check_value_); + os << ", invoice_details: "; + os << PigeonInternalToString(obj.invoice_details_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const GetUserPurchaseListAPIResult& v) { + return v.Hash(); +} + // BillingBuyData BillingBuyData::BillingBuyData(const std::string& pay_result, @@ -240,6 +679,34 @@ BillingBuyData BillingBuyData::FromEncodableList(const EncodableList& list) { return decoded; } +bool BillingBuyData::operator==(const BillingBuyData& other) const { + return PigeonInternalDeepEquals(pay_result_, other.pay_result_) && + PigeonInternalDeepEquals(pay_details_, other.pay_details_); +} + +bool BillingBuyData::operator!=(const BillingBuyData& other) const { + return !(*this == other); +} + +size_t BillingBuyData::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(pay_result_); + result = result * 31 + PigeonInternalDeepHash(pay_details_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const BillingBuyData& obj) { + os << "BillingBuyData("; + os << "pay_result: "; + os << PigeonInternalToString(obj.pay_result_); + os << ", pay_details: "; + os << PigeonInternalToString(obj.pay_details_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const BillingBuyData& v) { return v.Hash(); } + // VerifyInvoiceAPIResult VerifyInvoiceAPIResult::VerifyInvoiceAPIResult(const std::string& cp_status, @@ -314,6 +781,50 @@ VerifyInvoiceAPIResult VerifyInvoiceAPIResult::FromEncodableList( return decoded; } +bool VerifyInvoiceAPIResult::operator==( + const VerifyInvoiceAPIResult& other) const { + return PigeonInternalDeepEquals(cp_status_, other.cp_status_) && + PigeonInternalDeepEquals(cp_result_, other.cp_result_) && + PigeonInternalDeepEquals(app_id_, other.app_id_) && + PigeonInternalDeepEquals(invoice_id_, other.invoice_id_); +} + +bool VerifyInvoiceAPIResult::operator!=( + const VerifyInvoiceAPIResult& other) const { + return !(*this == other); +} + +size_t VerifyInvoiceAPIResult::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(cp_status_); + result = result * 31 + PigeonInternalDeepHash(cp_result_); + result = result * 31 + PigeonInternalDeepHash(app_id_); + result = result * 31 + PigeonInternalDeepHash(invoice_id_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const VerifyInvoiceAPIResult& obj) { + os << "VerifyInvoiceAPIResult("; + os << "cp_status: "; + os << PigeonInternalToString(obj.cp_status_); + os << ", cp_result: "; + if (obj.cp_result_) { + os << PigeonInternalToString(*obj.cp_result_); + } else { + os << "null"; + } + os << ", app_id: "; + os << PigeonInternalToString(obj.app_id_); + os << ", invoice_id: "; + os << PigeonInternalToString(obj.invoice_id_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const VerifyInvoiceAPIResult& v) { + return v.Hash(); +} + // ServiceAvailableAPIResult ServiceAvailableAPIResult::ServiceAvailableAPIResult( @@ -358,6 +869,43 @@ ServiceAvailableAPIResult ServiceAvailableAPIResult::FromEncodableList( return decoded; } +bool ServiceAvailableAPIResult::operator==( + const ServiceAvailableAPIResult& other) const { + return PigeonInternalDeepEquals(status_, other.status_) && + PigeonInternalDeepEquals(result_, other.result_) && + PigeonInternalDeepEquals(service_yn_, other.service_yn_); +} + +bool ServiceAvailableAPIResult::operator!=( + const ServiceAvailableAPIResult& other) const { + return !(*this == other); +} + +size_t ServiceAvailableAPIResult::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(status_); + result = result * 31 + PigeonInternalDeepHash(result_); + result = result * 31 + PigeonInternalDeepHash(service_yn_); + return result; +} + +std::ostream& operator<<(std::ostream& os, + const ServiceAvailableAPIResult& obj) { + os << "ServiceAvailableAPIResult("; + os << "status: "; + os << PigeonInternalToString(obj.status_); + os << ", result: "; + os << PigeonInternalToString(obj.result_); + os << ", service_yn: "; + os << PigeonInternalToString(obj.service_yn_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const ServiceAvailableAPIResult& v) { + return v.Hash(); +} + // ProductMessage ProductMessage::ProductMessage(const std::string& app_id, @@ -419,6 +967,46 @@ ProductMessage ProductMessage::FromEncodableList(const EncodableList& list) { return decoded; } +bool ProductMessage::operator==(const ProductMessage& other) const { + return PigeonInternalDeepEquals(app_id_, other.app_id_) && + PigeonInternalDeepEquals(country_code_, other.country_code_) && + PigeonInternalDeepEquals(page_size_, other.page_size_) && + PigeonInternalDeepEquals(page_num_, other.page_num_) && + PigeonInternalDeepEquals(check_value_, other.check_value_); +} + +bool ProductMessage::operator!=(const ProductMessage& other) const { + return !(*this == other); +} + +size_t ProductMessage::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(app_id_); + result = result * 31 + PigeonInternalDeepHash(country_code_); + result = result * 31 + PigeonInternalDeepHash(page_size_); + result = result * 31 + PigeonInternalDeepHash(page_num_); + result = result * 31 + PigeonInternalDeepHash(check_value_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const ProductMessage& obj) { + os << "ProductMessage("; + os << "app_id: "; + os << PigeonInternalToString(obj.app_id_); + os << ", country_code: "; + os << PigeonInternalToString(obj.country_code_); + os << ", page_size: "; + os << PigeonInternalToString(obj.page_size_); + os << ", page_num: "; + os << PigeonInternalToString(obj.page_num_); + os << ", check_value: "; + os << PigeonInternalToString(obj.check_value_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const ProductMessage& v) { return v.Hash(); } + // PurchaseMessage PurchaseMessage::PurchaseMessage(const std::string& app_id, @@ -481,6 +1069,46 @@ PurchaseMessage PurchaseMessage::FromEncodableList(const EncodableList& list) { return decoded; } +bool PurchaseMessage::operator==(const PurchaseMessage& other) const { + return PigeonInternalDeepEquals(app_id_, other.app_id_) && + PigeonInternalDeepEquals(custom_id_, other.custom_id_) && + PigeonInternalDeepEquals(country_code_, other.country_code_) && + PigeonInternalDeepEquals(page_num_, other.page_num_) && + PigeonInternalDeepEquals(check_value_, other.check_value_); +} + +bool PurchaseMessage::operator!=(const PurchaseMessage& other) const { + return !(*this == other); +} + +size_t PurchaseMessage::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(app_id_); + result = result * 31 + PigeonInternalDeepHash(custom_id_); + result = result * 31 + PigeonInternalDeepHash(country_code_); + result = result * 31 + PigeonInternalDeepHash(page_num_); + result = result * 31 + PigeonInternalDeepHash(check_value_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const PurchaseMessage& obj) { + os << "PurchaseMessage("; + os << "app_id: "; + os << PigeonInternalToString(obj.app_id_); + os << ", custom_id: "; + os << PigeonInternalToString(obj.custom_id_); + os << ", country_code: "; + os << PigeonInternalToString(obj.country_code_); + os << ", page_num: "; + os << PigeonInternalToString(obj.page_num_); + os << ", check_value: "; + os << PigeonInternalToString(obj.check_value_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const PurchaseMessage& v) { return v.Hash(); } + // OrderDetails OrderDetails::OrderDetails(const std::string& order_item_id, @@ -549,6 +1177,47 @@ OrderDetails OrderDetails::FromEncodableList(const EncodableList& list) { return decoded; } +bool OrderDetails::operator==(const OrderDetails& other) const { + return PigeonInternalDeepEquals(order_item_id_, other.order_item_id_) && + PigeonInternalDeepEquals(order_title_, other.order_title_) && + PigeonInternalDeepEquals(order_total_, other.order_total_) && + PigeonInternalDeepEquals(order_currency_id_, + other.order_currency_id_) && + PigeonInternalDeepEquals(order_custom_id_, other.order_custom_id_); +} + +bool OrderDetails::operator!=(const OrderDetails& other) const { + return !(*this == other); +} + +size_t OrderDetails::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(order_item_id_); + result = result * 31 + PigeonInternalDeepHash(order_title_); + result = result * 31 + PigeonInternalDeepHash(order_total_); + result = result * 31 + PigeonInternalDeepHash(order_currency_id_); + result = result * 31 + PigeonInternalDeepHash(order_custom_id_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const OrderDetails& obj) { + os << "OrderDetails("; + os << "order_item_id: "; + os << PigeonInternalToString(obj.order_item_id_); + os << ", order_title: "; + os << PigeonInternalToString(obj.order_title_); + os << ", order_total: "; + os << PigeonInternalToString(obj.order_total_); + os << ", order_currency_id: "; + os << PigeonInternalToString(obj.order_currency_id_); + os << ", order_custom_id: "; + os << PigeonInternalToString(obj.order_custom_id_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const OrderDetails& v) { return v.Hash(); } + // BuyInfoMessage BuyInfoMessage::BuyInfoMessage(const std::string& app_id, @@ -595,6 +1264,34 @@ BuyInfoMessage BuyInfoMessage::FromEncodableList(const EncodableList& list) { return decoded; } +bool BuyInfoMessage::operator==(const BuyInfoMessage& other) const { + return PigeonInternalDeepEquals(app_id_, other.app_id_) && + PigeonInternalDeepEquals(pay_detials_, other.pay_detials_); +} + +bool BuyInfoMessage::operator!=(const BuyInfoMessage& other) const { + return !(*this == other); +} + +size_t BuyInfoMessage::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(app_id_); + result = result * 31 + PigeonInternalDeepHash(pay_detials_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const BuyInfoMessage& obj) { + os << "BuyInfoMessage("; + os << "app_id: "; + os << PigeonInternalToString(obj.app_id_); + os << ", pay_detials: "; + os << *obj.pay_detials_; + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const BuyInfoMessage& v) { return v.Hash(); } + // InvoiceMessage InvoiceMessage::InvoiceMessage(const std::string& app_id, @@ -649,10 +1346,46 @@ InvoiceMessage InvoiceMessage::FromEncodableList(const EncodableList& list) { return decoded; } +bool InvoiceMessage::operator==(const InvoiceMessage& other) const { + return PigeonInternalDeepEquals(app_id_, other.app_id_) && + PigeonInternalDeepEquals(custom_id_, other.custom_id_) && + PigeonInternalDeepEquals(invoice_id_, other.invoice_id_) && + PigeonInternalDeepEquals(country_code_, other.country_code_); +} + +bool InvoiceMessage::operator!=(const InvoiceMessage& other) const { + return !(*this == other); +} + +size_t InvoiceMessage::Hash() const { + size_t result = 1; + result = result * 31 + PigeonInternalDeepHash(app_id_); + result = result * 31 + PigeonInternalDeepHash(custom_id_); + result = result * 31 + PigeonInternalDeepHash(invoice_id_); + result = result * 31 + PigeonInternalDeepHash(country_code_); + return result; +} + +std::ostream& operator<<(std::ostream& os, const InvoiceMessage& obj) { + os << "InvoiceMessage("; + os << "app_id: "; + os << PigeonInternalToString(obj.app_id_); + os << ", custom_id: "; + os << PigeonInternalToString(obj.custom_id_); + os << ", invoice_id: "; + os << PigeonInternalToString(obj.invoice_id_); + os << ", country_code: "; + os << PigeonInternalToString(obj.country_code_); + os << ")"; + return os; +} + +size_t PigeonInternalDeepHash(const InvoiceMessage& v) { return v.Hash(); } + PigeonInternalCodecSerializer::PigeonInternalCodecSerializer() {} EncodableValue PigeonInternalCodecSerializer::ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const { + uint8_t type, ::flutter::ByteStreamReader* stream) const { switch (type) { case 129: { return CustomEncodableValue(ProductsListApiResult::FromEncodableList( @@ -696,12 +1429,12 @@ EncodableValue PigeonInternalCodecSerializer::ReadValueOfType( std::get(ReadValue(stream)))); } default: - return flutter::StandardCodecSerializer::ReadValueOfType(type, stream); + return ::flutter::StandardCodecSerializer::ReadValueOfType(type, stream); } } void PigeonInternalCodecSerializer::WriteValue( - const EncodableValue& value, flutter::ByteStreamWriter* stream) const { + const EncodableValue& value, ::flutter::ByteStreamWriter* stream) const { if (const CustomEncodableValue* custom_value = std::get_if(&value)) { if (custom_value->type() == typeid(ProductsListApiResult)) { @@ -785,29 +1518,56 @@ void PigeonInternalCodecSerializer::WriteValue( return; } } - flutter::StandardCodecSerializer::WriteValue(value, stream); + ::flutter::StandardCodecSerializer::WriteValue(value, stream); } /// The codec used by InAppPurchaseApi. -const flutter::StandardMessageCodec& InAppPurchaseApi::GetCodec() { - return flutter::StandardMessageCodec::GetInstance( +const ::flutter::StandardMessageCodec& InAppPurchaseApi::GetCodec() { + return ::flutter::StandardMessageCodec::GetInstance( &PigeonInternalCodecSerializer::GetInstance()); } // Sets up an instance of `InAppPurchaseApi` to handle messages through the // `binary_messenger`. -void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, +void InAppPurchaseApi::SetUp(::flutter::BinaryMessenger* binary_messenger, InAppPurchaseApi* api) { InAppPurchaseApi::SetUp(binary_messenger, api, ""); } -void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, +void InAppPurchaseApi::SetUp(::flutter::BinaryMessenger* binary_messenger, InAppPurchaseApi* api, const std::string& message_channel_suffix) { const std::string prepended_suffix = message_channel_suffix.length() > 0 ? std::string(".") + message_channel_suffix : ""; + { + BasicMessageChannel<> channel( + binary_messenger, + "dev.flutter.pigeon.in_app_purchase_tizen.InAppPurchaseApi.initialize" + + prepended_suffix, + &GetCodec()); + if (api != nullptr) { + channel.SetMessageHandler( + [api](const EncodableValue& message, + const ::flutter::MessageReply& reply) { + try { + std::optional output = api->Initialize(); + if (output.has_value()) { + reply(WrapError(output.value())); + return; + } + EncodableList wrapped; + wrapped.push_back(EncodableValue()); + reply(EncodableValue(std::move(wrapped))); + } catch (const std::exception& exception) { + reply(WrapError(exception.what())); + } + }); + } else { + channel.SetMessageHandler(nullptr); + } + } { BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.in_app_purchase_tizen." @@ -817,7 +1577,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { const auto& args = std::get(message); const auto& encodable_product_arg = args.at(0); @@ -856,7 +1616,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { const auto& args = std::get(message); const auto& encodable_purchase_arg = args.at(0); @@ -895,7 +1655,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { const auto& args = std::get(message); const auto& encodable_buy_info_arg = args.at(0); @@ -933,7 +1693,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { const auto& args = std::get(message); const auto& encodable_invoice_arg = args.at(0); @@ -972,7 +1732,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { api->IsServiceAvailable([reply](ErrorOr&& output) { if (output.has_error()) { @@ -1001,7 +1761,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { ErrorOr output = api->GetCustomId(); if (output.has_error()) { @@ -1028,7 +1788,7 @@ void InAppPurchaseApi::SetUp(flutter::BinaryMessenger* binary_messenger, if (api != nullptr) { channel.SetMessageHandler( [api](const EncodableValue& message, - const flutter::MessageReply& reply) { + const ::flutter::MessageReply& reply) { try { ErrorOr output = api->GetCountryCode(); if (output.has_error()) { diff --git a/packages/in_app_purchase/tizen/src/messages.h b/packages/in_app_purchase/tizen/src/messages.h index 6b894f3a7..08e8f6cd1 100644 --- a/packages/in_app_purchase/tizen/src/messages.h +++ b/packages/in_app_purchase/tizen/src/messages.h @@ -1,4 +1,4 @@ -// Autogenerated from Pigeon (v22.7.4), do not edit directly. +// Autogenerated from Pigeon (v29.0.11), do not edit directly. // See also: https://pub.dev/packages/pigeon #ifndef PIGEON_MESSAGES_H_ @@ -10,6 +10,7 @@ #include #include +#include #include namespace in_app_purchase_tizen { @@ -22,17 +23,17 @@ class FlutterError { explicit FlutterError(const std::string& code, const std::string& message) : code_(code), message_(message) {} explicit FlutterError(const std::string& code, const std::string& message, - const flutter::EncodableValue& details) + const ::flutter::EncodableValue& details) : code_(code), message_(message), details_(details) {} const std::string& code() const { return code_; } const std::string& message() const { return message_; } - const flutter::EncodableValue& details() const { return details_; } + const ::flutter::EncodableValue& details() const { return details_; } private: std::string code_; std::string message_; - flutter::EncodableValue details_; + ::flutter::EncodableValue details_; }; template @@ -68,14 +69,14 @@ class ProductsListApiResult { explicit ProductsListApiResult(const std::string& cp_status, int64_t total_count, const std::string& check_value, - const flutter::EncodableList& item_details); + const ::flutter::EncodableList& item_details); // Constructs an object setting all fields. explicit ProductsListApiResult(const std::string& cp_status, const std::string* cp_result, int64_t total_count, const std::string& check_value, - const flutter::EncodableList& item_details); + const ::flutter::EncodableList& item_details); // DPI result code. // Returns "100000" on success and other codes on failure. @@ -99,20 +100,29 @@ class ProductsListApiResult { void set_check_value(std::string_view value_arg); // ItemDetails in JSON format - const flutter::EncodableList& item_details() const; - void set_item_details(const flutter::EncodableList& value_arg); + const ::flutter::EncodableList& item_details() const; + void set_item_details(const ::flutter::EncodableList& value_arg); + + bool operator==(const ProductsListApiResult& other) const; + bool operator!=(const ProductsListApiResult& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, + const ProductsListApiResult& obj); private: static ProductsListApiResult FromEncodableList( - const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string cp_status_; std::optional cp_result_; int64_t total_count_; std::string check_value_; - flutter::EncodableList item_details_; + ::flutter::EncodableList item_details_; }; // Dart wrapper around [`GetUserPurchaseListAPIResult`] in @@ -128,13 +138,13 @@ class GetUserPurchaseListAPIResult { explicit GetUserPurchaseListAPIResult( const std::string& cp_status, int64_t total_count, const std::string& check_value, - const flutter::EncodableList& invoice_details); + const ::flutter::EncodableList& invoice_details); // Constructs an object setting all fields. explicit GetUserPurchaseListAPIResult( const std::string& cp_status, const std::string* cp_result, int64_t total_count, const std::string& check_value, - const flutter::EncodableList& invoice_details); + const ::flutter::EncodableList& invoice_details); // It returns "100000" in success and other codes in failure. Refer to DPI // Error Code. @@ -158,20 +168,29 @@ class GetUserPurchaseListAPIResult { void set_check_value(std::string_view value_arg); // InvoiceDetailsin JSON format. - const flutter::EncodableList& invoice_details() const; - void set_invoice_details(const flutter::EncodableList& value_arg); + const ::flutter::EncodableList& invoice_details() const; + void set_invoice_details(const ::flutter::EncodableList& value_arg); + + bool operator==(const GetUserPurchaseListAPIResult& other) const; + bool operator!=(const GetUserPurchaseListAPIResult& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, + const GetUserPurchaseListAPIResult& obj); private: static GetUserPurchaseListAPIResult FromEncodableList( - const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string cp_status_; std::optional cp_result_; int64_t total_count_; std::string check_value_; - flutter::EncodableList invoice_details_; + ::flutter::EncodableList invoice_details_; }; // Dart wrapper around @@ -184,23 +203,31 @@ class BillingBuyData { public: // Constructs an object setting all fields. explicit BillingBuyData(const std::string& pay_result, - const flutter::EncodableMap& pay_details); + const ::flutter::EncodableMap& pay_details); // The payment result const std::string& pay_result() const; void set_pay_result(std::string_view value_arg); // The payment information. It is same with paymentDetails param of buyItem. - const flutter::EncodableMap& pay_details() const; - void set_pay_details(const flutter::EncodableMap& value_arg); + const ::flutter::EncodableMap& pay_details() const; + void set_pay_details(const ::flutter::EncodableMap& value_arg); + + bool operator==(const BillingBuyData& other) const; + bool operator!=(const BillingBuyData& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const BillingBuyData& obj); private: - static BillingBuyData FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static BillingBuyData FromEncodableList(const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string pay_result_; - flutter::EncodableMap pay_details_; + ::flutter::EncodableMap pay_details_; }; // Dart wrapper around [`VerifyInvoiceAPIResult`] in @@ -240,10 +267,19 @@ class VerifyInvoiceAPIResult { const std::string& invoice_id() const; void set_invoice_id(std::string_view value_arg); + bool operator==(const VerifyInvoiceAPIResult& other) const; + bool operator!=(const VerifyInvoiceAPIResult& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, + const VerifyInvoiceAPIResult& obj); + private: static VerifyInvoiceAPIResult FromEncodableList( - const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string cp_status_; @@ -281,10 +317,19 @@ class ServiceAvailableAPIResult { const std::string& service_yn() const; void set_service_yn(std::string_view value_arg); + bool operator==(const ServiceAvailableAPIResult& other) const; + bool operator!=(const ServiceAvailableAPIResult& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, + const ServiceAvailableAPIResult& obj); + private: static ServiceAvailableAPIResult FromEncodableList( - const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string status_; @@ -323,9 +368,17 @@ class ProductMessage { const std::string& check_value() const; void set_check_value(std::string_view value_arg); + bool operator==(const ProductMessage& other) const; + bool operator!=(const ProductMessage& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const ProductMessage& obj); + private: - static ProductMessage FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static ProductMessage FromEncodableList(const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string app_id_; @@ -367,9 +420,18 @@ class PurchaseMessage { const std::string& check_value() const; void set_check_value(std::string_view value_arg); + bool operator==(const PurchaseMessage& other) const; + bool operator!=(const PurchaseMessage& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const PurchaseMessage& obj); + private: - static PurchaseMessage FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static PurchaseMessage FromEncodableList( + const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string app_id_; @@ -404,9 +466,17 @@ class OrderDetails { const std::string& order_custom_id() const; void set_order_custom_id(std::string_view value_arg); + bool operator==(const OrderDetails& other) const; + bool operator!=(const OrderDetails& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const OrderDetails& obj); + private: - static OrderDetails FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static OrderDetails FromEncodableList(const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class BuyInfoMessage; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; @@ -437,9 +507,17 @@ class BuyInfoMessage { const OrderDetails& pay_detials() const; void set_pay_detials(const OrderDetails& value_arg); + bool operator==(const BuyInfoMessage& other) const; + bool operator!=(const BuyInfoMessage& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const BuyInfoMessage& obj); + private: - static BuyInfoMessage FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static BuyInfoMessage FromEncodableList(const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string app_id_; @@ -472,9 +550,17 @@ class InvoiceMessage { const std::string& country_code() const; void set_country_code(std::string_view value_arg); + bool operator==(const InvoiceMessage& other) const; + bool operator!=(const InvoiceMessage& other) const; + /// Returns a hash code value for the object. This method is supported for the + /// benefit of hash tables. + size_t Hash() const; + /// Stream output operator for formatted string representation. + friend std::ostream& operator<<(std::ostream& os, const InvoiceMessage& obj); + private: - static InvoiceMessage FromEncodableList(const flutter::EncodableList& list); - flutter::EncodableList ToEncodableList() const; + static InvoiceMessage FromEncodableList(const ::flutter::EncodableList& list); + ::flutter::EncodableList ToEncodableList() const; friend class InAppPurchaseApi; friend class PigeonInternalCodecSerializer; std::string app_id_; @@ -483,7 +569,8 @@ class InvoiceMessage { std::string country_code_; }; -class PigeonInternalCodecSerializer : public flutter::StandardCodecSerializer { +class PigeonInternalCodecSerializer + : public ::flutter::StandardCodecSerializer { public: PigeonInternalCodecSerializer(); inline static PigeonInternalCodecSerializer& GetInstance() { @@ -491,12 +578,12 @@ class PigeonInternalCodecSerializer : public flutter::StandardCodecSerializer { return sInstance; } - void WriteValue(const flutter::EncodableValue& value, - flutter::ByteStreamWriter* stream) const override; + void WriteValue(const ::flutter::EncodableValue& value, + ::flutter::ByteStreamWriter* stream) const override; protected: - flutter::EncodableValue ReadValueOfType( - uint8_t type, flutter::ByteStreamReader* stream) const override; + ::flutter::EncodableValue ReadValueOfType( + uint8_t type, ::flutter::ByteStreamReader* stream) const override; }; // Generated interface from Pigeon that represents a handler of messages from @@ -506,6 +593,7 @@ class InAppPurchaseApi { InAppPurchaseApi(const InAppPurchaseApi&) = delete; InAppPurchaseApi& operator=(const InAppPurchaseApi&) = delete; virtual ~InAppPurchaseApi() {} + virtual std::optional Initialize() = 0; // Retrieves the list of products registered on the Billing (DPI) server. virtual void GetProductsList( const ProductMessage& product, @@ -533,16 +621,16 @@ class InAppPurchaseApi { virtual ErrorOr GetCountryCode() = 0; // The codec used by InAppPurchaseApi. - static const flutter::StandardMessageCodec& GetCodec(); + static const ::flutter::StandardMessageCodec& GetCodec(); // Sets up an instance of `InAppPurchaseApi` to handle messages through the // `binary_messenger`. - static void SetUp(flutter::BinaryMessenger* binary_messenger, + static void SetUp(::flutter::BinaryMessenger* binary_messenger, InAppPurchaseApi* api); - static void SetUp(flutter::BinaryMessenger* binary_messenger, + static void SetUp(::flutter::BinaryMessenger* binary_messenger, InAppPurchaseApi* api, const std::string& message_channel_suffix); - static flutter::EncodableValue WrapError(std::string_view error_message); - static flutter::EncodableValue WrapError(const FlutterError& error); + static ::flutter::EncodableValue WrapError(std::string_view error_message); + static ::flutter::EncodableValue WrapError(const FlutterError& error); protected: InAppPurchaseApi() = default; diff --git a/packages/in_app_purchase/tizen/src/messages_ffi.cc b/packages/in_app_purchase/tizen/src/messages_ffi.cc new file mode 100644 index 000000000..f77425912 --- /dev/null +++ b/packages/in_app_purchase/tizen/src/messages_ffi.cc @@ -0,0 +1,663 @@ +// Autogenerated from Pigeon (v29.0.11), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +#include "messages_ffi.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace { +PigeonFfiBuffer* PigeonFfiMakeBuffer(const std::vector& message) { + auto* buffer = new PigeonFfiBuffer(); + buffer->length = message.size(); + buffer->data = nullptr; + if (!message.empty()) { + buffer->data = new uint8_t[message.size()]; + std::memcpy(buffer->data, message.data(), message.size()); + } + return buffer; +} + +PigeonFfiBuffer* PigeonFfiEncodeMessage( + const ::flutter::StandardMessageCodec& codec, + const ::flutter::EncodableValue& value) { + std::unique_ptr> message = codec.EncodeMessage(value); + return PigeonFfiMakeBuffer(*message); +} + +PigeonFfiBuffer* PigeonFfiEncodeError( + const ::flutter::StandardMessageCodec& codec, + const ::flutter::EncodableValue& error) { + return PigeonFfiEncodeMessage(codec, error); +} + +PigeonFfiBuffer* PigeonFfiEncodeErrorMessage( + const ::flutter::StandardMessageCodec& codec, const std::string& message) { + return PigeonFfiEncodeError( + codec, + ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::EncodableValue("error"), + ::flutter::EncodableValue(message), ::flutter::EncodableValue()})); +} + +void PigeonFfiSendReply(int64_t reply_id, PigeonFfiReplyCallback on_reply, + PigeonFfiBuffer* reply) { + if (on_reply == nullptr) { + pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_free_buffer( + reply); + return; + } + on_reply(reply_id, reply); +} + +} // namespace + +void pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_free_buffer( + PigeonFfiBuffer* buffer) { + if (buffer == nullptr) { + return; + } + delete[] buffer->data; + delete buffer; +} + +namespace in_app_purchase_tizen { + +namespace { +InAppPurchaseApi* g_in_app_purchase_api_api = nullptr; +PigeonFfiSyncDispatcher* g_in_app_purchase_api_dispatcher = nullptr; +} // namespace + +void SetUpInAppPurchaseApiFfi(InAppPurchaseApi* api, + PigeonFfiSyncDispatcher* dispatcher) { + if (g_in_app_purchase_api_api != nullptr) { + std::fprintf( + stderr, + "[pigeon] SetUpInAppPurchaseApiFfi() called more than once. Pigeon C++ " + "FFI registration is process-global and supports only one Flutter " + "engine per process; calls from previously registered engines will be " + "routed to the most recently registered implementation.\n"); + } + g_in_app_purchase_api_api = api; + g_in_app_purchase_api_dispatcher = dispatcher; +} + +void TearDownInAppPurchaseApiFfi() { + g_in_app_purchase_api_api = nullptr; + g_in_app_purchase_api_dispatcher = nullptr; +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiInitializeFfi(PigeonFfiBuffer* request) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + return PigeonFfiEncodeError( + codec, + InAppPurchaseApi::WrapError("InAppPurchaseApi has not been set up.")); + } + try { + std::optional output = + g_in_app_purchase_api_api->Initialize(); + if (output.has_value()) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(output.value())); + } + return PigeonFfiEncodeMessage( + codec, ::flutter::EncodableValue( + ::flutter::EncodableList{::flutter::EncodableValue()})); + } catch (const std::exception& exception) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(exception.what())); + } +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiInitializeFfiDispatch( + PigeonFfiBuffer* request) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + return g_in_app_purchase_api_dispatcher->RunSync( + [request]() { return PigeonInAppPurchaseApiInitializeFfi(request); }); + } + return PigeonInAppPurchaseApiInitializeFfi(request); +} + +void PigeonInAppPurchaseApiGetProductsListFfi(PigeonFfiBuffer* request, + int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError( + "InAppPurchaseApi has not been set up."))); + return; + } + try { + if (request == nullptr || request->data == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Request buffer is null."))); + return; + } + std::unique_ptr<::flutter::EncodableValue> message = + codec.DecodeMessage(request->data, request->length); + if (!message) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Unable to decode request."))); + return; + } + const auto* args = std::get_if<::flutter::EncodableList>(message.get()); + if (args == nullptr || args->size() != 1) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "Unexpected request arguments."))); + return; + } + const auto& encodable_product_arg = args->at(0); + if (encodable_product_arg.IsNull()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "product_arg unexpectedly null."))); + return; + } + const auto& product_arg = std::any_cast( + std::get<::flutter::CustomEncodableValue>(encodable_product_arg)); + g_in_app_purchase_api_api->GetProductsList( + product_arg, + [reply_id, on_reply](ErrorOr&& output) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (output.has_error()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError(output.error()))); + return; + } + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeMessage( + codec, + ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::CustomEncodableValue(output.value())}))); + }); + } catch (const std::exception& exception) { + PigeonFfiSendReply(reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + exception.what()))); + } +} + +void PigeonInAppPurchaseApiGetProductsListFfiDispatch( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + PigeonFfiBuffer* dispatch_error = + g_in_app_purchase_api_dispatcher->RunSync([=]() { + PigeonInAppPurchaseApiGetProductsListFfi(request, reply_id, on_reply); + return static_cast(nullptr); + }); + if (dispatch_error != nullptr) { + PigeonFfiSendReply(reply_id, on_reply, dispatch_error); + } + return; + } + PigeonInAppPurchaseApiGetProductsListFfi(request, reply_id, on_reply); +} + +void PigeonInAppPurchaseApiGetUserPurchaseListFfi( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError( + "InAppPurchaseApi has not been set up."))); + return; + } + try { + if (request == nullptr || request->data == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Request buffer is null."))); + return; + } + std::unique_ptr<::flutter::EncodableValue> message = + codec.DecodeMessage(request->data, request->length); + if (!message) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Unable to decode request."))); + return; + } + const auto* args = std::get_if<::flutter::EncodableList>(message.get()); + if (args == nullptr || args->size() != 1) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "Unexpected request arguments."))); + return; + } + const auto& encodable_purchase_arg = args->at(0); + if (encodable_purchase_arg.IsNull()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "purchase_arg unexpectedly null."))); + return; + } + const auto& purchase_arg = std::any_cast( + std::get<::flutter::CustomEncodableValue>(encodable_purchase_arg)); + g_in_app_purchase_api_api->GetUserPurchaseList( + purchase_arg, + [reply_id, on_reply](ErrorOr&& output) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (output.has_error()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError(output.error()))); + return; + } + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeMessage( + codec, + ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::CustomEncodableValue(output.value())}))); + }); + } catch (const std::exception& exception) { + PigeonFfiSendReply(reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + exception.what()))); + } +} + +void PigeonInAppPurchaseApiGetUserPurchaseListFfiDispatch( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + PigeonFfiBuffer* dispatch_error = + g_in_app_purchase_api_dispatcher->RunSync([=]() { + PigeonInAppPurchaseApiGetUserPurchaseListFfi(request, reply_id, + on_reply); + return static_cast(nullptr); + }); + if (dispatch_error != nullptr) { + PigeonFfiSendReply(reply_id, on_reply, dispatch_error); + } + return; + } + PigeonInAppPurchaseApiGetUserPurchaseListFfi(request, reply_id, on_reply); +} + +void PigeonInAppPurchaseApiBuyItemFfi(PigeonFfiBuffer* request, + int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError( + "InAppPurchaseApi has not been set up."))); + return; + } + try { + if (request == nullptr || request->data == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Request buffer is null."))); + return; + } + std::unique_ptr<::flutter::EncodableValue> message = + codec.DecodeMessage(request->data, request->length); + if (!message) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Unable to decode request."))); + return; + } + const auto* args = std::get_if<::flutter::EncodableList>(message.get()); + if (args == nullptr || args->size() != 1) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "Unexpected request arguments."))); + return; + } + const auto& encodable_buy_info_arg = args->at(0); + if (encodable_buy_info_arg.IsNull()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "buy_info_arg unexpectedly null."))); + return; + } + const auto& buy_info_arg = std::any_cast( + std::get<::flutter::CustomEncodableValue>(encodable_buy_info_arg)); + g_in_app_purchase_api_api->BuyItem( + buy_info_arg, [reply_id, on_reply](ErrorOr&& output) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (output.has_error()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError(output.error()))); + return; + } + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeMessage( + codec, + ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::CustomEncodableValue(output.value())}))); + }); + } catch (const std::exception& exception) { + PigeonFfiSendReply(reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + exception.what()))); + } +} + +void PigeonInAppPurchaseApiBuyItemFfiDispatch(PigeonFfiBuffer* request, + int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + PigeonFfiBuffer* dispatch_error = + g_in_app_purchase_api_dispatcher->RunSync([=]() { + PigeonInAppPurchaseApiBuyItemFfi(request, reply_id, on_reply); + return static_cast(nullptr); + }); + if (dispatch_error != nullptr) { + PigeonFfiSendReply(reply_id, on_reply, dispatch_error); + } + return; + } + PigeonInAppPurchaseApiBuyItemFfi(request, reply_id, on_reply); +} + +void PigeonInAppPurchaseApiVerifyInvoiceFfi(PigeonFfiBuffer* request, + int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError( + "InAppPurchaseApi has not been set up."))); + return; + } + try { + if (request == nullptr || request->data == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Request buffer is null."))); + return; + } + std::unique_ptr<::flutter::EncodableValue> message = + codec.DecodeMessage(request->data, request->length); + if (!message) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError("Unable to decode request."))); + return; + } + const auto* args = std::get_if<::flutter::EncodableList>(message.get()); + if (args == nullptr || args->size() != 1) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "Unexpected request arguments."))); + return; + } + const auto& encodable_invoice_arg = args->at(0); + if (encodable_invoice_arg.IsNull()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + "invoice_arg unexpectedly null."))); + return; + } + const auto& invoice_arg = std::any_cast( + std::get<::flutter::CustomEncodableValue>(encodable_invoice_arg)); + g_in_app_purchase_api_api->VerifyInvoice( + invoice_arg, + [reply_id, on_reply](ErrorOr&& output) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (output.has_error()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError(output.error()))); + return; + } + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeMessage( + codec, + ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::CustomEncodableValue(output.value())}))); + }); + } catch (const std::exception& exception) { + PigeonFfiSendReply(reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + exception.what()))); + } +} + +void PigeonInAppPurchaseApiVerifyInvoiceFfiDispatch( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + PigeonFfiBuffer* dispatch_error = + g_in_app_purchase_api_dispatcher->RunSync([=]() { + PigeonInAppPurchaseApiVerifyInvoiceFfi(request, reply_id, on_reply); + return static_cast(nullptr); + }); + if (dispatch_error != nullptr) { + PigeonFfiSendReply(reply_id, on_reply, dispatch_error); + } + return; + } + PigeonInAppPurchaseApiVerifyInvoiceFfi(request, reply_id, on_reply); +} + +void PigeonInAppPurchaseApiIsServiceAvailableFfi( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError( + "InAppPurchaseApi has not been set up."))); + return; + } + try { + g_in_app_purchase_api_api->IsServiceAvailable( + [reply_id, on_reply](ErrorOr&& output) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (output.has_error()) { + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeError( + codec, InAppPurchaseApi::WrapError(output.error()))); + return; + } + PigeonFfiSendReply( + reply_id, on_reply, + PigeonFfiEncodeMessage( + codec, ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::EncodableValue(output.value())}))); + }); + } catch (const std::exception& exception) { + PigeonFfiSendReply(reply_id, on_reply, + PigeonFfiEncodeError(codec, InAppPurchaseApi::WrapError( + exception.what()))); + } +} + +void PigeonInAppPurchaseApiIsServiceAvailableFfiDispatch( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + PigeonFfiBuffer* dispatch_error = + g_in_app_purchase_api_dispatcher->RunSync([=]() { + PigeonInAppPurchaseApiIsServiceAvailableFfi(request, reply_id, + on_reply); + return static_cast(nullptr); + }); + if (dispatch_error != nullptr) { + PigeonFfiSendReply(reply_id, on_reply, dispatch_error); + } + return; + } + PigeonInAppPurchaseApiIsServiceAvailableFfi(request, reply_id, on_reply); +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiGetCustomIdFfi( + PigeonFfiBuffer* request) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + return PigeonFfiEncodeError( + codec, + InAppPurchaseApi::WrapError("InAppPurchaseApi has not been set up.")); + } + try { + ErrorOr output = g_in_app_purchase_api_api->GetCustomId(); + if (output.has_error()) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(output.error())); + } + return PigeonFfiEncodeMessage( + codec, ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::EncodableValue(output.value())})); + } catch (const std::exception& exception) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(exception.what())); + } +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiGetCustomIdFfiDispatch( + PigeonFfiBuffer* request) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + return g_in_app_purchase_api_dispatcher->RunSync( + [request]() { return PigeonInAppPurchaseApiGetCustomIdFfi(request); }); + } + return PigeonInAppPurchaseApiGetCustomIdFfi(request); +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiGetCountryCodeFfi( + PigeonFfiBuffer* request) { + const auto& codec = InAppPurchaseApi::GetCodec(); + if (g_in_app_purchase_api_api == nullptr) { + return PigeonFfiEncodeError( + codec, + InAppPurchaseApi::WrapError("InAppPurchaseApi has not been set up.")); + } + try { + ErrorOr output = g_in_app_purchase_api_api->GetCountryCode(); + if (output.has_error()) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(output.error())); + } + return PigeonFfiEncodeMessage( + codec, ::flutter::EncodableValue(::flutter::EncodableList{ + ::flutter::EncodableValue(output.value())})); + } catch (const std::exception& exception) { + return PigeonFfiEncodeError(codec, + InAppPurchaseApi::WrapError(exception.what())); + } +} + +PigeonFfiBuffer* PigeonInAppPurchaseApiGetCountryCodeFfiDispatch( + PigeonFfiBuffer* request) { + if (g_in_app_purchase_api_dispatcher != nullptr) { + return g_in_app_purchase_api_dispatcher->RunSync([request]() { + return PigeonInAppPurchaseApiGetCountryCodeFfi(request); + }); + } + return PigeonInAppPurchaseApiGetCountryCodeFfi(request); +} + +} // namespace in_app_purchase_tizen + +extern "C" PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_initialize( + PigeonFfiBuffer* request) { + return in_app_purchase_tizen::PigeonInAppPurchaseApiInitializeFfiDispatch( + request); +} + +extern "C" void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_products_list( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + in_app_purchase_tizen::PigeonInAppPurchaseApiGetProductsListFfiDispatch( + request, reply_id, on_reply); +} + +extern "C" void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_user_purchase_list( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + in_app_purchase_tizen::PigeonInAppPurchaseApiGetUserPurchaseListFfiDispatch( + request, reply_id, on_reply); +} + +extern "C" void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_buy_item( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + in_app_purchase_tizen::PigeonInAppPurchaseApiBuyItemFfiDispatch( + request, reply_id, on_reply); +} + +extern "C" void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_verify_invoice( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + in_app_purchase_tizen::PigeonInAppPurchaseApiVerifyInvoiceFfiDispatch( + request, reply_id, on_reply); +} + +extern "C" void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_is_service_available( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply) { + in_app_purchase_tizen::PigeonInAppPurchaseApiIsServiceAvailableFfiDispatch( + request, reply_id, on_reply); +} + +extern "C" PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_custom_id( + PigeonFfiBuffer* request) { + return in_app_purchase_tizen::PigeonInAppPurchaseApiGetCustomIdFfiDispatch( + request); +} + +extern "C" PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_country_code( + PigeonFfiBuffer* request) { + return in_app_purchase_tizen::PigeonInAppPurchaseApiGetCountryCodeFfiDispatch( + request); +} diff --git a/packages/in_app_purchase/tizen/src/messages_ffi.h b/packages/in_app_purchase/tizen/src/messages_ffi.h new file mode 100644 index 000000000..c9ac31ef4 --- /dev/null +++ b/packages/in_app_purchase/tizen/src/messages_ffi.h @@ -0,0 +1,98 @@ +// Autogenerated from Pigeon (v29.0.11), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +#ifndef PIGEON_IN_X5F_APP_X5F_PURCHASE_X5F_TIZEN_TIZEN_X2F_SRC_X2F_MESSAGES_X5F_FFI_X2E_H_HEADER_ +#define PIGEON_IN_X5F_APP_X5F_PURCHASE_X5F_TIZEN_TIZEN_X2F_SRC_X2F_MESSAGES_X5F_FFI_X2E_H_HEADER_ + +#include +#include + +#ifdef __cplusplus +#include +#include +#include +#include +#include + +#include "messages.h" +#endif + +#if defined(_WIN32) +#define PIGEON_FFI_EXPORT __declspec(dllexport) +#else +#define PIGEON_FFI_EXPORT __attribute__((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef PIGEON_FFI_ABI_TYPES_ +#define PIGEON_FFI_ABI_TYPES_ +typedef struct PigeonFfiBuffer { + uint8_t* data; + size_t length; +} PigeonFfiBuffer; + +typedef void (*PigeonFfiReplyCallback)(int64_t reply_id, + PigeonFfiBuffer* reply); +typedef void (*PigeonFfiEventCallback)(int64_t sink_id, PigeonFfiBuffer* event); +typedef void (*PigeonFfiDoneCallback)(int64_t sink_id); +#endif // PIGEON_FFI_ABI_TYPES_ + +// Frees a buffer returned by a generated FFI function. +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_free_buffer( + PigeonFfiBuffer* buffer); +// The caller owns request; free returned buffers with +// pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_free_buffer. +PIGEON_FFI_EXPORT PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_initialize( + PigeonFfiBuffer* request); +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_products_list( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply); +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_user_purchase_list( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply); +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_buy_item( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply); +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_verify_invoice( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply); +PIGEON_FFI_EXPORT void +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_is_service_available( + PigeonFfiBuffer* request, int64_t reply_id, + PigeonFfiReplyCallback on_reply); +PIGEON_FFI_EXPORT PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_custom_id( + PigeonFfiBuffer* request); +PIGEON_FFI_EXPORT PigeonFfiBuffer* +pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_in_app_purchase_api_get_country_code( + PigeonFfiBuffer* request); + +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus +namespace in_app_purchase_tizen { +class PigeonFfiSyncDispatcher { + public: + virtual ~PigeonFfiSyncDispatcher() = default; + virtual ::PigeonFfiBuffer* RunSync( + std::function<::PigeonFfiBuffer*()> task) = 0; +}; + +void SetUpInAppPurchaseApiFfi(InAppPurchaseApi* api, + PigeonFfiSyncDispatcher* dispatcher = nullptr); +void TearDownInAppPurchaseApiFfi(); +} // namespace in_app_purchase_tizen +#endif + +#endif // PIGEON_IN_X5F_APP_X5F_PURCHASE_X5F_TIZEN_TIZEN_X2F_SRC_X2F_MESSAGES_X5F_FFI_X2E_H_HEADER_ diff --git a/packages/in_app_purchase/tool/pigeon/messages_ffigen_config.yaml b/packages/in_app_purchase/tool/pigeon/messages_ffigen_config.yaml new file mode 100644 index 000000000..721d857b8 --- /dev/null +++ b/packages/in_app_purchase/tool/pigeon/messages_ffigen_config.yaml @@ -0,0 +1,19 @@ +# Autogenerated from Pigeon (v29.0.11), do not edit directly. +# See also: https://pub.dev/packages/pigeon + +name: 'InAppPurchaseTizenFfiBindings' +description: 'Generated bindings for Pigeon C++ FFI APIs.' +output: '../../lib/src/messages.g.ffi.dart' +headers: + entry-points: + - '../../tizen/src/messages_ffi.h' + include-directives: + - '**/messages_ffi.h' +functions: + include: + - 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_.*' + rename: + 'pigeon_in_x5f_app_x5f_purchase_x5f_tizen_tizen_x2f_src_x2f_messages_x5f_ffi_x2e_h_(.*)': 'pigeon_$1' +structs: + include: + - 'PigeonFfiBuffer'