stream << CB_IMPORT << std::endl;
}
-void DartGeneratorBase::GenLogTag(std::ofstream& stream,
- const std::string& log_tag) {
- ReplaceAll(CB_LOG_TAG, "<LOG_TAG>", log_tag).Out(stream);
- stream << NLine(1);
-}
-
void DartGeneratorBase::GenVersion(std::ofstream& stream) {
ReplaceAll(CB_VERSION_DEF, "<VERSION>", FULLVER).Out(stream);
stream << NLine(1);
void GenAnnotation(std::ofstream& stream);
void GenImport(std::ofstream& stream);
- void GenLogTag(std::ofstream& stream, const std::string& log_tag);
void GenVersion(std::ofstream& stream);
void GenDelegateId(std::ofstream& stream);
void GenMethodId(std::ofstream& stream);
constexpr const char CB_IMPORT[] =
R"__dart_cb(
-import 'package:tizen_log/tizen_log.dart';
import 'package:tizen_rpc_port/tizen_rpc_port.dart';
)__dart_cb";
*/
constexpr const char CB_CALLBACK_BASE[] =
R"__dart_cb(
-/// Abstract class for creating a [CallbackBase] class for RPC.
-abstract class CallbackBase extends Parcelable {
- /// Constructor for this class.
- CallbackBase(this._id, this._once) {
- _seqId = _seqNum++;
- }
-
- /// Creating a [CallbackBase] class from the parcel.
- CallbackBase.fromParcel(Parcel parcel) {
- deserialize(parcel);
+abstract class _CallbackBase extends Parcelable {
+ _CallbackBase(this.id, this.once) {
+ sequenceId = sequenceNum++;
}
- int _id = 0;
- bool _once = false;
- int _seqId = 0;
- static int _seqNum = 0;
+ int id = 0;
+ bool once = false;
+ int sequenceId = 0;
+ static int sequenceNum = 0;
/// Gets the tag.
- String get tag => '$_id::$_seqId';
+ String get tag => '$id::$sequenceId';
<ON_RECEIVED_EVENT>
@override
void serialize(Parcel parcel) {
- parcel.writeInt32(_id);
- parcel.writeInt32(_seqId);
- parcel.writeBool(_once);
+ parcel.writeInt32(id);
+ parcel.writeInt32(sequenceId);
+ parcel.writeBool(once);
}
@override
void deserialize(Parcel parcel) {
- _id = parcel.readInt32();
- _seqId = parcel.readInt32();
- _once = parcel.readBool();
+ id = parcel.readInt32();
+ sequenceId = parcel.readInt32();
+ once = parcel.readBool();
}
}
)__dart_cb";
* <ARG> The argument.
*/
constexpr const char CB_FILE_SET_PRIVATE_SHARING[] =
-R"__dart_cb(await <PORT>.setPrivateSharing(<ARG>);)__dart_cb";
+R"__dart_cb(<PORT>.shareFile(<ARG>);)__dart_cb";
/**
* <PORT> The rpc port handle.
* <ARG> The argument.
*/
constexpr const char CB_LIST_FILE_SET_PRIVATE_SHARING[] =
-R"__dart_cb(await <PORT>.setPrivateSharingList(<ARG>);)__dart_cb";
+R"__dart_cb(<PORT>.shareFiles(<ARG>);)__dart_cb";
/**
* <SERIALIZE> The implementation to serialize the data to the parcel.
<SERIALIZE>
default:
{
- Log.error(_logTag, 'No such type');
return;
}
}
<DESERIALIZE>
default:
{
- Log.error(_logTag, 'No such type');
return;
}
}
void DartProxyGen::OnInitGen(std::ofstream& stream) {
GenAnnotation(stream);
GenImport(stream);
- GenLogTag(stream, "RPC_PORT_PROXY");
GenVersion(stream);
GenDelegateId(stream);
GenMethodId(stream);
const Declaration& decl) {
std::string code;
auto& type = decl.GetType();
+ std::string prefix = "final " + ConvertTypeToString(type) + " ret";
if (type.IsUserDefinedType()) {
code += ReplaceAll(CB_USER_DEFINED_PARCEL_READ, {
{ "<PARCEL>", "parcelReceived" },
- { "<NAME>", "final ret" }
+ { "<NAME>", prefix }
});
code += NLine(1);
} else if (type.ToString() == "list" || type.ToString() == "array") {
code += ReplaceAll(CB_LIST_PARCEL_READ, {
{ "<PARCEL>", "parcelReceived" },
- { "<NAME>", "final ret" }
+ { "<NAME>", prefix }
});
code += NLine(1);
} else {
code += ReplaceAll(CB_BASE_PARCEL_READ, {
{ "<PARCEL>", "parcelReceived" },
{ "<PARCEL_TYPE>", ConvertTypeToParcelType(type.ToString()) },
- { "<NAME>" , "final ret" }
+ { "<NAME>" , prefix }
});
code += NLine(1);
}
for (const auto& p : decl.GetParameters()) {
auto& param_type = p->GetParameterType();
auto& type = param_type.GetBaseType();
- code += ConvertTypeToString(type) + " ";
+ code += "final " + ConvertTypeToString(type) + " ";
if (type.IsUserDefinedType()) {
code += ReplaceAll(CB_USER_DEFINED_PARCEL_READ, {
{ "<NAME>", p->GetID() },
constexpr const char CB_DELEGATE_BASE[] =
R"__dart_cb(
/// The <DELEGATE_NAME> class to invoke the delegate method.
-abstract class <DELEGATE_NAME> extends CallbackBase {
+abstract class <DELEGATE_NAME> extends _CallbackBase {
/// Constructor for this class.
<DELEGATE_NAME>({bool once = false}) : super(_DelegateId.<DELEGATE_ID>.id, once);
<INTERFACE_NAME>(String appid) : super(appid, '<INTERFACE_NAME>');
bool _online = false;
- final List<CallbackBase> _delegateList = <CallbackBase>[];
+ final List<_CallbackBase> _delegateList = <_CallbackBase>[];
- /// This abstract method will be called when the connet() is succeed.
+ /// The abstract method for receiving connected event.
Future<void> onConnected();
- /// This abstract method will be called when the connection with the stub is disconnected.
+ /// The abstract method for receiving disconnected event.
Future<void> onDisconnected();
- /// This abstract method will be called when connect() is failed.
+ /// The abstract method for receiving rejected event.
Future<void> onRejected(String errorMessage);
@override
return;
}
- await _processReceivedEvent(parcel);
- }
-
- Future<void> _processReceivedEvent(Parcel parcel) async {
final int id = parcel.readInt32();
final int seqId = parcel.readInt32();
final bool once = parcel.readBool();
- for (final CallbackBase delegate in _delegateList) {
- if (delegate._id == id && delegate._seqId == seqId) {
+ for (final _CallbackBase delegate in _delegateList) {
+ if (delegate.id == id && delegate.sequenceId == seqId) {
await delegate._onReceivedEvent(parcel);
- if (delegate._once) {
+ if (delegate.once) {
_delegateList.remove(delegate);
}
break;
}
Future<Parcel> _consumeCommand(Port port) async {
- while (true) {
- try {
- final Parcel parcel = await port.receive();
- final int cmd = parcel.readInt32();
- if (cmd == _MethodId.result.id) {
- return parcel;
- }
- } catch (e) {
- Log.error(_logTag, e.toString());
- return Parcel();
+ try {
+ final Parcel parcel = Parcel.fromPort(port);
+ final int cmd = parcel.readInt32();
+
+ if (cmd != _MethodId.result.id) {
+ throw Exception('Received parcel is invalid. $cmd');
}
+
+ return parcel;
+ } catch (e) {
+ return Parcel();
}
}
/// Connects with the stub application.
@override
Future<void> connect() async {
- Log.info(_logTag, 'connect()');
await super.connect();
}
+ /// Disconnects with the stub application.
+ Future<void> disconnect() async {
+ final Port port = getPort(PortType.main);
+ port.disconnect();
+ }
+
/// Dispose registered delegate interface.
void disposeCallback(String tag) {
- Log.info(_logTag, 'disposeCallback($tag)');
- _delegateList.removeWhere((CallbackBase element) => element.tag == tag);
+ _delegateList.removeWhere((_CallbackBase element) => element.tag == tag);
}
<METHODS>
R"__dart_cb(
/// This method is used to send '<METHOD_NAME>' request to the stub app.
Future<<RETURN_TYPE>> <LOWER_METHOD_NAME>(<ARGS>) async {
- Log.info(_logTag, '<METHOD_NAME>');
<METHOD_PARCEL_WRITE>
<METHOD_PARCEL_READ>
}
<PARCEL_WRITE>
-await port.send(parcel);
+parcel.send(port);
)__dart_cb";
/**
void DartStubGen::OnInitGen(std::ofstream& stream) {
GenAnnotation(stream);
GenImport(stream);
- GenLogTag(stream, "RPC_PORT_STUB");
GenVersion(stream);
GenDelegateId(stream);
GenMethodId(stream);
/// Disconnects from the client application.
Future<void> disconnect() async {
- await _port?.disconnect();
+ _port?.disconnect();
_port = null;
}
constexpr const char CB_DELEGATE_BASE[] =
R"__dart_cb(
/// The '<DELEGATE_NAME> class to invoke the delegate method.
-class <DELEGATE_NAME> extends CallbackBase {
+class <DELEGATE_NAME> extends _CallbackBase {
/// Constructor for this class.
<DELEGATE_NAME>(this._port, this.service, {bool once = false})
: super(_DelegateId.<DELEGATE_ID>.id, once);
/// Invokes the delegate method of the client.
Future<void> invoke(<DELEGATE_PARAMS>) async {
if (_port == null) {
- Log.error(_logTag, 'port is null');
throw Exception('NotConnectedSocketException');
}
- if (_once && !_valid) {
- Log.error(_logTag, 'invalid');
+ if (once && !_valid) {
throw Exception('InvalidCallbackException');
}
<DELEGATE_PARCEL_WRITE>
- await _port?.send(parcel);
+ if (_port != null) {
+ parcel.send(_port!);
+ }
+
_valid = false;
}
}
/// Listens to the requests for connections.
@override
Future<void> listen() async {
- Log.warn(_logTag, 'listen. portName: $portName');
return await super.listen();
}
@override
Future<void> onConnectedEvent(String sender, String instance) async {
- Log.info(_logTag, 'sender: $sender, instance: $instance');
final ServiceBase service = createInstance(sender, instance);
service._port = getPort(instance, PortType.callback);
await service.onCreate();
@override
Future<void> onDisconnectedEvent(String sender, String instance) async {
- Log.info(_logTag, 'sender: $sender, instance: $instance');
for (final ServiceBase service in services) {
if (service.instance == instance) {
await service.onTerminate();
@override
Future<void> onReceivedEvent(String sender, String instance,
Parcel parcel) async {
- Log.info(_logTag, 'sender: $sender, instance: $instance');
ServiceBase? service;
for (final ServiceBase s in services) {
if (s.instance == instance) {
}
if (service == null) {
- Log.error(_logTag, 'service is null');
return;
}
final int cmd = parcel.readInt32();
if (_methodHandlers.containsKey(cmd)) {
await _methodHandlers[cmd](service, port, parcel);
- } else {
- Log.error(_logTag, 'Unknown cmd: $cmd');
}
}
}
R"__dart_cb(
Future<void> _on<METHOD_NAME>Method(ServiceBase service, Port port,
Parcel parcel) async {
- Log.info(_logTag, '<METHOD_NAME>');
<METHOD_HANDLER_PARCEL_READ>
<METHOD_HANDLER_INVOKE>
<METHOD_HANDLER_PARCEL_WRITE>
result.writeInt32(_MethodId.result.id);
<PARCEL_WRITE>
-await port.send(result);
+result.send(port);
)__dart_cb";
} // namespace tidl