if (trimmed_line.find('{') != std::string::npos) {
control_flow_statement_with_single_line = false;
+ bool else_statement = false;
+ if (trimmed_line.find("} else {") != std::string::npos) {
+ else_statement = true;
+ indentation = indentation.substr(0, indentation.length() - 2);
+ }
+
code += indentation + trimmed_line + NLine(1);
+ if (else_statement)
+ indentation += Tab(1);
+
if (trimmed_line.find("namespace ") == std::string::npos &&
trimmed_line.find('}') == std::string::npos)
indentation += Tab(1);
.Change("<INTERFACES>", GenInterfaces())
.Transform([&](std::string str) { return SmartIndent(str); })
.Out(stream);
+ stream << NLine(1);
}
void CppProxyBodyGenerator::GenLemAnonymousNamespace(std::ofstream& stream) {
stream << SmartIndent(CB_LEM_ANONYMOUS_NAMESPACE);
+ stream << NLine(1);
}
void CppProxyBodyGenerator::GenLemAPI(std::ofstream& stream) {
}
void <CLS_NAME>::Connect(bool sync) {
+ int ret;
if (local_execution_.get() != nullptr && local_execution_->LoadSymbols()) {
- if (local_execution_->Connect(sync))
- return;
+ ret = local_execution_->Connect(sync);
+ } else {
+ if (sync)
+ ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "<CLS_NAME>");
+ else
+ ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "<CLS_NAME>");
}
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "<CLS_NAME>");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "<CLS_NAME>");
-
if (ret != RPC_PORT_ERROR_NONE) {
_E("Failed to connect to <CLS_NAME>. error(%d)", ret);
switch (ret) {
}
}
-bool LocalExecution::Connect(bool sync) {
+int LocalExecution::Connect(bool sync) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (connecting_) {
+ _E("Already connecting");
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+ }
+
+ if (connected_) {
+ _E("Already connected");
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+ }
+
if (connect_func_) {
- if (connect_func_(this, GetAppId().c_str(), instance_.c_str(), sync) != RPC_PORT_ERROR_NONE)
- return false;
+ int ret = connect_func_(this, GetAppId().c_str(), instance_.c_str(), sync);
+ if (ret != RPC_PORT_ERROR_NONE)
+ return ret;
}
- return true;
+ connecting_ = true;
+ return RPC_PORT_ERROR_NONE;
}
void LocalExecution::Disconnect() {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ connecting_ = false;
if (disconnect_func_)
disconnect_func_(this, GetAppId().c_str(), instance_.c_str());
}
void LocalExecution::OnConnected() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
+ connecting_ = false;
connected_ = true;
if (listener_ != nullptr)
listener_->OnLocalConnected();
void LocalExecution::OnDisconnected() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
+ connecting_ = false;
connected_ = false;
if (listener_ != nullptr)
listener_->OnLocalDisconnected();
LocalExecution(std::string port_name, IEvent* listener);
virtual ~LocalExecution();
- bool Connect(bool sync);
+ int Connect(bool sync);
void Disconnect();
int Send(rpc_port_parcel_h request, rpc_port_parcel_h* result);
IEvent* listener_;
std::string instance_;
bool connected_ = false;
+ bool connecting_ = false;
bool loaded_ = false;
StubConnectFunc connect_func_ = nullptr;
StubDisconnectFunc disconnect_func_ = nullptr;
.Change("<INTERFACES>", GenInterfaces())
.Transform([&](std::string str) { return SmartIndent(str); })
.Out(stream);
+ stream << NLine(1);
}
void CppStubBodyGenerator::GenLemAnonymousNamespace(std::ofstream& stream) {
.Change("<LEM_CONTEXT>", GenLemContext())
.Transform([&](std::string code) { return SmartIndent(code); })
.Out(stream);
+ stream << NLine(1);
}
std::string CppStubBodyGenerator::GenLemContext() {
return;
}
- rpc_port_parcel_h p = Clone(parcel);
- service->Dispatch(nullptr, nullptr, p, service);
+ service->Dispatch(nullptr, nullptr, parcel, service);
}
)__cpp_cb";
return handle;
}
+void IdleAddOnce(std::function<void()>* func) {
+ g_idle_add([](gpointer user_data) {
+ auto* cb = static_cast<std::function<void()>*>(user_data);
+ (*cb)();
+ delete cb;
+ return G_SOURCE_REMOVE;
+ }, func);
+}
+
<LEM_CONTEXT>
} // namespace
return RPC_PORT_ERROR_IO_ERROR;
}
- <CLS_NAME>_context_->OnConnected(context, sender, instance, sync);
+ if (gettid() != getpid()) {
+ std::string sender_str(sender);
+ std::string instance_str(instance);
+ auto* func = new std::function<void()>([context, sender_str, instance_str, sync] {
+ <CLS_NAME>_context_->OnConnected(context, sender_str, instance_str, sync);
+ });
+ IdleAddOnce(func);
+ } else {
+ <CLS_NAME>_context_->OnConnected(context, sender, instance, sync);
+ }
+
return RPC_PORT_ERROR_NONE;
}
return RPC_PORT_ERROR_IO_ERROR;
}
- <CLS_NAME>_context_->OnDisconnected(context, sender, instance);
+ if (gettid() != getpid()) {
+ std::string sender_str(sender);
+ std::string instance_str(instance);
+ auto* func = new std::function<void()>([context, sender_str, instance_str] {
+ <CLS_NAME>_context_->OnDisconnected(context, sender_str, instance_str);
+ });
+ IdleAddOnce(func);
+ } else {
+ <CLS_NAME>_context_->OnDisconnected(context, sender, instance);
+ }
+
return RPC_PORT_ERROR_NONE;
}
return RPC_PORT_ERROR_IO_ERROR;
}
- <CLS_NAME>_context_->OnReceived(context, parcel);
+ rpc_port_parcel_h cloned_parcel = Clone(parcel);
+ if (getpid() != getpid()) {
+ auto* func = new std::function<void()>([context, cloned_parcel] {
+ <CLS_NAME>_context_->OnReceived(context, cloned_parcel);
+ });
+ IdleAddOnce(func);
+ } else {
+ <CLS_NAME>_context_->OnReceived(context, cloned_parcel);
+ }
+
return RPC_PORT_ERROR_NONE;
}
)__cpp_cb";