Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/tizen_rpc_port/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Omit obvious local variable types.
* Reformat with a line length of 100.
* Use wrapper api.

## 0.1.8

Expand Down
140 changes: 46 additions & 94 deletions packages/tizen_rpc_port/lib/src/parcel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,14 @@ class Parcel {

/// Gets the reader position of this parcel.
int get reader {
_ensureFunctionsLoaded();
final int Function(rpc_port_parcel_h, Pointer<Uint32>)? func = _rpcPortParcelGetReader;
if (func == null) {
throw UnsupportedError(
'The reader property is not supported on this version of Tizen.',
);
}
return using((Arena arena) {
final Pointer<Uint32> pValue = arena();
final int ret = func(_handle, pValue);
final int ret = _rpcPortParcelGetReader(_handle, pValue);
if (ret == _errorNotImplemented) {
throw UnsupportedError(
'The reader property is not supported on this version of Tizen.',
);
}
if (ret != 0) {
throw PlatformException(
code: ret.toString(),
Expand All @@ -510,14 +508,12 @@ class Parcel {
/// Sets the reader position of this parcel.
set reader(int value) {
RangeError.checkNotNegative(value, 'value');
_ensureFunctionsLoaded();
final int Function(rpc_port_parcel_h, int)? func = _rpcPortParcelSetReader;
if (func == null) {
final int ret = _rpcPortParcelSetReader(_handle, value);
if (ret == _errorNotImplemented) {
throw UnsupportedError(
'The reader property is not supported on this version of Tizen.',
);
}
final int ret = func(_handle, value);
if (ret != 0) {
throw PlatformException(
code: ret.toString(),
Expand All @@ -528,16 +524,14 @@ class Parcel {

/// Gets the data size of this parcel.
int get dataSize {
_ensureFunctionsLoaded();
final int Function(rpc_port_parcel_h, Pointer<Uint32>)? func = _rpcPortParcelGetDataSize;
if (func == null) {
throw UnsupportedError(
'The dataSize property is not supported on this version of Tizen.',
);
}
return using((Arena arena) {
final Pointer<Uint32> pValue = arena();
final int ret = func(_handle, pValue);
final int ret = _rpcPortParcelGetDataSize(_handle, pValue);
if (ret == _errorNotImplemented) {
throw UnsupportedError(
'The dataSize property is not supported on this version of Tizen.',
);
}
if (ret != 0) {
throw PlatformException(
code: ret.toString(),
Expand All @@ -551,14 +545,12 @@ class Parcel {
/// Sets the data size of this parcel.
set dataSize(int value) {
RangeError.checkNotNegative(value, 'value');
_ensureFunctionsLoaded();
final int Function(rpc_port_parcel_h, int)? func = _rpcPortParcelSetDataSize;
if (func == null) {
final int ret = _rpcPortParcelSetDataSize(_handle, value);
if (ret == _errorNotImplemented) {
throw UnsupportedError(
'The dataSize property is not supported on this version of Tizen.',
);
}
final int ret = func(_handle, value);
if (ret != 0) {
throw PlatformException(
code: ret.toString(),
Expand All @@ -570,14 +562,12 @@ class Parcel {
/// Reserves the capacity of this parcel.
void reserve(int size) {
RangeError.checkNotNegative(size, 'size');
_ensureFunctionsLoaded();
final int Function(rpc_port_parcel_h, int)? func = _rpcPortParcelReserve;
if (func == null) {
final int ret = _rpcPortParcelReserve(_handle, size);
if (ret == _errorNotImplemented) {
throw UnsupportedError(
'The reserve method is not supported on this version of Tizen.',
);
}
final int ret = func(_handle, size);
if (ret != 0) {
throw PlatformException(
code: ret.toString(),
Expand All @@ -587,71 +577,33 @@ class Parcel {
}
}

DynamicLibrary? _libRpcPort;
bool _libRpcPortLoaded = false;
const int _errorNotImplemented = -38; // -ENOSYS

DynamicLibrary? _getLibRpcPort() {
if (!_libRpcPortLoaded) {
try {
_libRpcPort = DynamicLibrary.open('librpc-port.so.1');
} catch (_) {
_libRpcPort = null;
}
_libRpcPortLoaded = true;
}
return _libRpcPort;
}
final DynamicLibrary _libRpcPort = DynamicLibrary.open('libftpw_tizen_rpc_port.so');

int Function(rpc_port_parcel_h, Pointer<Uint32>)? _rpcPortParcelGetReader;
int Function(rpc_port_parcel_h, int)? _rpcPortParcelSetReader;
int Function(rpc_port_parcel_h, Pointer<Uint32>)? _rpcPortParcelGetDataSize;
int Function(rpc_port_parcel_h, int)? _rpcPortParcelSetDataSize;
int Function(rpc_port_parcel_h, int)? _rpcPortParcelReserve;

bool _functionsLoaded = false;

void _ensureFunctionsLoaded() {
if (_functionsLoaded) {
return;
}
_functionsLoaded = true;
final DynamicLibrary? lib = _getLibRpcPort();
if (lib == null) {
return;
}
try {
_rpcPortParcelGetReader = lib
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>)>>(
'rpc_port_parcel_get_reader',
)
.asFunction();
} catch (_) {}
try {
_rpcPortParcelSetReader = lib
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
'rpc_port_parcel_set_reader',
)
.asFunction();
} catch (_) {}
try {
_rpcPortParcelGetDataSize = lib
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>)>>(
'rpc_port_parcel_get_data_size',
)
.asFunction();
} catch (_) {}
try {
_rpcPortParcelSetDataSize = lib
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
'rpc_port_parcel_set_data_size',
)
.asFunction();
} catch (_) {}
try {
_rpcPortParcelReserve = lib
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
'rpc_port_parcel_reserve',
)
.asFunction();
} catch (_) {}
}
final int Function(rpc_port_parcel_h, Pointer<Uint32>) _rpcPortParcelGetReader =
_libRpcPort.lookupFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>),
int Function(rpc_port_parcel_h, Pointer<Uint32>)>(
'ftpw_tizen_rpc_port_rpc_port_parcel_get_reader',
);

final int Function(rpc_port_parcel_h, int) _rpcPortParcelSetReader = _libRpcPort.lookupFunction<
Int32 Function(rpc_port_parcel_h, Uint32), int Function(rpc_port_parcel_h, int)>(
'ftpw_tizen_rpc_port_rpc_port_parcel_set_reader',
);

final int Function(rpc_port_parcel_h, Pointer<Uint32>) _rpcPortParcelGetDataSize =
_libRpcPort.lookupFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>),
int Function(rpc_port_parcel_h, Pointer<Uint32>)>(
'ftpw_tizen_rpc_port_rpc_port_parcel_get_data_size',
);

final int Function(rpc_port_parcel_h, int) _rpcPortParcelSetDataSize = _libRpcPort.lookupFunction<
Int32 Function(rpc_port_parcel_h, Uint32), int Function(rpc_port_parcel_h, int)>(
'ftpw_tizen_rpc_port_rpc_port_parcel_set_data_size',
);

final int Function(rpc_port_parcel_h, int) _rpcPortParcelReserve = _libRpcPort.lookupFunction<
Int32 Function(rpc_port_parcel_h, Uint32), int Function(rpc_port_parcel_h, int)>(
'ftpw_tizen_rpc_port_rpc_port_parcel_reserve',
);
27 changes: 27 additions & 0 deletions packages/tizen_rpc_port/tizen/inc/ftpw_tizen_rpc_port.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2026 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_TIZEN_PLUGINS_WRAPPER_TIZEN_RPC_PORT_H_
#define FLUTTER_TIZEN_PLUGINS_WRAPPER_TIZEN_RPC_PORT_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

int ftpw_tizen_rpc_port_rpc_port_parcel_get_reader(void *parcel,
uint32_t *value);
int ftpw_tizen_rpc_port_rpc_port_parcel_set_reader(void *parcel,
uint32_t value);
int ftpw_tizen_rpc_port_rpc_port_parcel_get_data_size(void *parcel,
uint32_t *value);
int ftpw_tizen_rpc_port_rpc_port_parcel_set_data_size(void *parcel,
uint32_t value);
int ftpw_tizen_rpc_port_rpc_port_parcel_reserve(void *parcel, uint32_t value);

#ifdef __cplusplus
}
#endif

#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/tizen_rpc_port/tizen/project_def.prop
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ USER_CPP_UNDEFS =
USER_INC_DIRS = inc src
USER_INC_FILES =
USER_CPP_INC_FILES =

# User libraries
USER_LIB_DIRS += lib/${BUILD_ARCH}
USER_LIBS += ftpw_tizen_rpc_port
Loading