_E("Failed to create security handle. error(%d)", ret);
throw InvalidIOException();
}
+ auto security_auto = std::unique_ptr<
+ std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
+ security, cion_security_destroy);
- ret = cion_server_create(&cion_server_, service_name.c_str(),
+ cion_server_h server;
+ ret = cion_server_create(&server, service_name.c_str(),
display_name.c_str(), security);
if (ret != CION_ERROR_NONE) {
_E("Failed to create handle. error(%d)", ret);
throw InvalidIOException();
}
+ auto server_auto = std::unique_ptr<
+ std::remove_pointer<cion_server_h>::type, decltype(cion_server_destroy)*>(
+ server, cion_server_destroy);
- ret = cion_server_add_connection_result_cb(cion_server_, OnConnectionResultCB,
+ ret = cion_server_add_connection_result_cb(server, OnConnectionResultCB,
this);
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_server_add_connection_result_cb. error(%d)", ret);
throw InvalidIOException();
}
- ret = cion_server_add_payload_received_cb(cion_server_, OnPayloadReceivedCB,
+ ret = cion_server_add_payload_received_cb(server, OnPayloadReceivedCB,
this);
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_server_add_payload_received_cb. error(%d)", ret);
throw InvalidIOException();
}
- ret = cion_server_set_data_received_cb(cion_server_, OnDataReceivedCB, this);
+ ret = cion_server_set_data_received_cb(server, OnDataReceivedCB, this);
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_server_set_data_received_cb. error(%d)", ret);
throw InvalidIOException();
}
- ret = cion_server_add_disconnected_cb(cion_server_, OnDisconnectedCB, this);
+ ret = cion_server_add_disconnected_cb(server, OnDisconnectedCB, this);
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_server_add_disconnected_cb. error(%d)", ret);
throw InvalidIOException();
}
+
+ cion_security_ = security_auto.release();
+ cion_server_ = server_auto.release();
}
)__cpp_cb";
for (auto& i : services_) {
i->OnTerminate();
}
+
+ if (cion_server_ != nullptr)
+ cion_server_destroy(cion_server_);
+
+ if (cion_security_ != nullptr)
+ cion_security_destroy(cion_security_);
}
void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) {