.Out(stream);
}
+std::string CppCionGeneratorBase::GenSecurity(const Interface& iface) {
+ std::string security_path;
+
+ for (const auto& attr : iface.GetAttributes()) {
+ if (attr->GetKey() == "ca_path")
+ security_path += ReplaceAll(CB_INTERFACE_SECURITY_CA, "<ARG>",
+ attr->GetValue());
+ else if (attr->GetKey() == "cert_path")
+ security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "<ARG>",
+ attr->GetValue());
+ else if (attr->GetKey() == "private_key")
+ security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "<ARG>",
+ attr->GetValue());
+ }
+
+ return security_path;
+}
+
void CppCionGeneratorBase::GenVersion(std::ofstream& stream) {
GenTemplate(CB_VERSION, stream,
[&]()->std::string {
bool is_proxy);
void GenHeaderCallbacks(std::ofstream& stream, const Interface& iface,
bool is_proxy);
+ std::string GenSecurity(const Interface& iface);
std::string ConvertTypeToString(const BaseType& type);
std::string Tab(int cnt);
std::string NLine(int cnt);
}
)__cpp_cb";
+const char CB_INTERFACE_SECURITY_CA[] =
+R"__cpp_cb(
+ if (cion_security_set_ca_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set ca path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_CERT[] =
+R"__cpp_cb(
+ if (cion_security_set_cert_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set cert path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] =
+R"__cpp_cb(
+ if (cion_security_set_private_key_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set private key path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
const char CB_LOG_TAG[] =
R"__cpp_cb(
#ifdef LOG_TAG
void CppCionGroupBodyGen::GenConstructor(std::ofstream& stream,
const Interface& iface) {
- stream << ReplaceAll(CB_GROUP_INTERFACE_CTOR, "<CLS_NAME>", iface.GetID())
- << NLine(1);
+ ReplaceAll(CB_GROUP_INTERFACE_CTOR)
+ .Change("<CLS_NAME>", iface.GetID())
+ .Change("<SET_SECURITY>", GenSecurity(iface))
+ .Out(stream);
}
void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream,
_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);
-
+<SET_SECURITY>
cion_group_h group = nullptr;
ret = cion_group_create(&group, topic_name_.c_str(), security);
if (ret != CION_ERROR_NONE) {
void CppCionProxyBodyGen::GenConstructor(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_PROXY_INTERFACE_CTOR, stream,
- [&]()->std::string {
- return iface.GetID();
- },
- [&]()->std::string {
- return iface.GetID();
- });
+ ReplaceAll(CB_PROXY_INTERFACE_CTOR)
+ .Change("$$", iface.GetID())
+ .Change("<SET_SECURITY>", GenSecurity(iface))
+ .Out(stream);
}
void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream,
_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);
-
+<SET_SECURITY>
cion_client_h client = nullptr;
ret = cion_client_create(&client, service_name.c_str(), security);
if (ret != CION_ERROR_NONE) {
void CppCionStubBodyGen::GenConstructor(std::ofstream& stream,
const Interface& iface) {
- stream << ReplaceAll(CB_CTOR_FRONT, "##", iface.GetID());
+ ReplaceAll(CB_CTOR_FRONT)
+ .Change("##", iface.GetID())
+ .Change("<SET_SECURITY>", GenSecurity(iface))
+ .Out(stream);
}
void CppCionStubBodyGen::GenDefaultMethods(std::ofstream& stream,
_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);
-
+<SET_SECURITY>
cion_server_h server;
ret = cion_server_create(&server, service_name.c_str(),
display_name.c_str(), security);