register static method
Future<void>
register({
- required SDKEnvironment environment,
- String? baseURL,
- String? accessToken,
Register model assignment callbacks with C++
Implementation
static Future<void> register({
required SDKEnvironment environment,
String? baseURL,
String? accessToken,
}) async {
if (_isRegistered) return;
_environment = environment;
_baseURL = baseURL;
_accessToken = accessToken;
try {
final lib = PlatformLoader.loadCommons();
// Allocate callbacks struct
_callbacksPtr = calloc<RacAssignmentCallbacksStruct>();
_callbacksPtr!.ref.httpGet =
Pointer.fromFunction<RacAssignmentHttpGetCallbackNative>(
_httpGetCallback, _exceptionalReturnInt32);
_callbacksPtr!.ref.getDeviceInfo =
Pointer.fromFunction<RacAssignmentGetDeviceInfoCallbackNative>(
_getDeviceInfoCallback);
_callbacksPtr!.ref.userData = nullptr;
// Register with C++
final setCallbacks = lib.lookupFunction<
Int32 Function(Pointer<RacAssignmentCallbacksStruct>),
int Function(
Pointer<RacAssignmentCallbacksStruct>)>('rac_model_assignment_set_callbacks');
final result = setCallbacks(_callbacksPtr!);
if (result != RacResultCode.success) {
_logger.warning('Failed to register assignment callbacks',
metadata: {'code': result});
calloc.free(_callbacksPtr!);
_callbacksPtr = null;
return;
}
_isRegistered = true;
_logger.debug('Model assignment callbacks registered');
} catch (e) {
_logger.debug('Model assignment registration error: $e');
_isRegistered = true; // Avoid retry loops
}
}