return iface.GetID();
});
stream << NLine(1);
+ GenTemplate(CB_SERVICE_DEFAULT_METHOD, stream,
+ [&]()->std::string {
+ return iface.GetID();
+ }, [&]()->std::string {
+ return iface.GetID();
+ });
+ stream << NLine(1);
}
void CppStubBodyGen::GenConstructor(std::ofstream& stream,
if (options_->IsThreadEnabled()) {
stream << CB_RUN_PENDING_JOB_BACK << NLine(1);
- GenTemplate(CB_ON_RECEIVED_CB, stream,
- [&]()->std::string {
- return iface.GetID();
- },
- [&]()->std::string {
- return iface.GetID();
- });
+ std::string code = ReplaceAll(CB_ON_RECEIVED_CB, "[NAME]",
+ iface.GetID());
+ stream << code;
} else {
stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
}
}
}
-void ##::OnConnectedCB(const char* sender, const char* instance, void *data) {
+void ##::OnConnectedCB(const char* sender, const char* instance, void* data) {
##* stub = static_cast<##*>(data);
auto s = stub->service_factory_->CreateService(sender, instance);
+
+ rpc_port_h port;
+ int ret = rpc_port_stub_get_port(stub->stub_, RPC_PORT_PORT_CALLBACK, instance.c_str(), &port);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ _E("Failed to get the port(%d)", ret);
+ return;
+ }
+
+ s->SetPort(port);
s->OnCreate();
stub->services_.emplace_back(std::move(s));
}
}
}
}
-
)__cpp_cb";
const char CB_DEFAULT_THREAD_METHODS[] =
}
if (b.get() == nullptr) {
- _E("Failed to find $$ context(%s)", instance);
+ _E("Failed to find [NAME] context(%s)", instance);
return -1;
}
}
)__cpp_cb";
+/**
+ * [NAME] The name of the interface.
+ */
const char CB_ON_RECEIVED_CB[] =
R"__cpp_cb(
-int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
+int [NAME]::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
{
- auto* cxt = static_cast<$$*>(data);
+ auto* cxt = static_cast<[NAME]*>(data);
std::shared_ptr<ServiceBase> b;
rpc_port_parcel_h parcel;
rpc_port_h callback_port;
}
if (b.get() == nullptr) {
- _E("Failed to find $$ context(%s)", instance);
+ _E("Failed to find [NAME] context(%s)", instance);
return -1;
}
const char CB_CTOR_SERVICE_BASE[] =
R"__cpp_cb($$::ServiceBase::ServiceBase(std::string sender, std::string instance)
: sender_(std::move(sender)), instance_(std::move(instance)),
- active_object_(new ActiveObject()) {})__cpp_cb";
+ active_object_(new ActiveObject()) {}
+)__cpp_cb";
+
+const char CB_SERVICE_DEFAULT_METHOD[] =
+R"__cpp_cb(void $$::ServiceBase::SetPort(rpc_port_h port) {
+ port_ = port;
+}
+
+void $$::ServiceBase::Disconnect() {
+ int ret = rpc_port_disconnect(port_);
+ if (ret == RPC_PORT_ERROR_NONE) {
+ _E("Failed to disconnect the port(%d)", ret);
+ return;
+ }
+
+ port_ = nullptr;
+}
+)__cpp_cb";
#endif // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
return instance_;
}
+ /// <summary>
+ /// Sets the client app port
+ /// </summary>
+ /// <param name="port">The port of the client</param>
+ void SetPort(rpc_port_h port);
+
+ /// <summary>
+ /// Disconnects from the client app
+ /// </summary>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ void Disconnect();
+
/// <summary>
/// This method will be called when the client is connected
/// </summary>
private:
std::string sender_;
std::string instance_;
+ rpc_port_h port_;
std::unique_ptr<ActiveObject> active_object_;
};)__cpp_cb";
)__cpp_cb";
-
const char CB_JOB[] = R"__cls_job(class Job {
public:
class IEvent {