GenStructureSetter(stream, st);
GenStructureGetter(stream, st);
GenStructureIterator(stream, st);
+ GenStructureRemover(stream, st);
+ GenStructureLengthGetter(stream, st);
}
void CBodyGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
[&]()->std::string {
std::string str;
for (auto& i : st.GetElements().GetElms()) {
- str += GetFinalizeString(i->GetID(), i->GetType());
+ str += GetFinalizeString(i->GetID(), i->GetType(), "h->");
}
return str;
}));
}
}
+void CBodyGeneratorBase::GenStructureRemover(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ stream << SmartIndent(GenTemplateString(CB_STRUCT_REMOVER,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+ i->GetType().GetMetaType()->ToString() == "list" ||
+ i->GetType().GetMetaType()->ToString() == "array")
+ return GetParcelParamTypeString(*i->GetType().GetMetaType());
+
+ return ConvertTypeToString(ParameterType::Direction::IN,
+ *i->GetType().GetMetaType(), false);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ std::string str;
+
+ if (i->GetType().GetMetaType()->IsUserDefinedType() ||
+ i->GetType().GetMetaType()->ToString() == "list" ||
+ i->GetType().GetMetaType()->ToString() == "array") {
+ str = GetHandlePrefix()
+ + GetFullNameFromType(*i->GetType().GetMetaType())
+ + "_destroy(value);";
+ } else {
+ str = GetFinalizeString("value", *i->GetType().GetMetaType(), "");
+ }
+
+ if (str == "")
+ return "free(value);\n";
+ return str;
+ }));
+ }
+}
+
+void CBodyGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ stream << SmartIndent(GenTemplateString(CB_STRUCT_LENGTH_GETTER,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ }));
+ }
+}
+
void CBodyGeneratorBase::GenStructureCloner(std::ofstream& stream,
const Structure& st) {
stream << SmartIndent(GenTemplateString(
}
std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id,
- const BaseType& type) {
+ const BaseType& type, const std::string& handle) {
std::string str;
if (!type.IsUserDefinedType() &&
if (type.ToString() == "list") {
str += GenTemplateString(CB_FINALIZE_LIST_BLOCK,
[&]()->std::string {
- return "h->" + id;
+ return handle + id;
},
[&]()->std::string {
return GetParcelParamTypeString(*type.GetMetaType());
});
},
[&]()->std::string {
- return "h->" + id;
+ return handle + id;
});
} else if (type.ToString() == "array") {
if (!type.GetMetaType()->IsUserDefinedType() &&
type.GetMetaType()->ToString() != "bundle") {
return GenTemplateString(CB_IF_STATEMENT,
[&]()->std::string {
- return "h->" + id;
+ return handle + id;
},
[&]()->std::string {
- return "free(h->" + id + ");";
+ return "free(" + handle + id + ");";
});
}
str += GenTemplateString(CB_FINALIZE_ARRAY_BLOCK,
[&]()->std::string {
- return "h->" + id + "_size";
+ return handle + id + "_size";
},
[&]()->std::string {
return GenTemplateString(CB_IF_STATEMENT,
[&]()->std::string {
- return "h->" + id + "[i]";
+ return handle + id + "[i]";
},
[&]()->std::string {
return GetDestructorString(*type.GetMetaType(),
- "h->" + id + "[i]", true) + NLine(1);
+ handle + id + "[i]", true) + NLine(1);
});
},
[&]()->std::string {
- return "h->" + id;
+ return handle + id;
});
} else {
str += GenTemplateString(CB_IF_STATEMENT,
[&]()->std::string {
- return "h->" + id;
+ return handle + id;
},
[&]()->std::string {
- return GetDestructorString(type, "h->" + id) + NLine(1);
+ return GetDestructorString(type, handle + id) + NLine(1);
});
}
});
}
} else if (type.ToString() == "array") {
- str += GetFinalizeString(id, type) + NLine(1);
+ str += GetFinalizeString(id, type, "h->") + NLine(1);
str += GetSetterString("h->" + id, "NULL");
str += NLine(1);
str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id),
void GenStructureGetter(std::ofstream& stream, const Structure& st);
void GenStructureIterator(std::ofstream& stream, const Structure& st);
void GenStructureCloner(std::ofstream& stream, const Structure& st);
+ void GenStructureRemover(std::ofstream& stream, const Structure& st);
+ void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
private:
std::string GetParcelTypeString(const BaseType& type, bool meta_type);
std::string GetParcelWriteString(const std::string& id, const BaseType& type);
std::string GetParcelReadString(const std::string& id, const BaseType& type);
- std::string GetFinalizeString(const std::string& id, const BaseType& type);
+ std::string GetFinalizeString(const std::string& id, const BaseType& type,
+ const std::string& handle);
std::string GetSetterString(const std::string& id, const BaseType& type);
std::string GetGetterString(const std::string& id, const BaseType& type);
std::string GetIteratorString(const std::string& id, const BaseType& type);
}
)__c_cb";
+const char CB_STRUCT_REMOVER[] =
+R"__c_cb(
+int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth)
+{
+ GList *iter;
+
+ if (!h) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ iter = g_list_nth(h->$$, nth);
+ if (iter == NULL)
+ return -1;
+
+ $$value = iter->data;
+ h->$$ = g_list_remove_link(h->$$, iter);
+$$
+ g_list_free(iter);
+
+ return 0;
+}
+)__c_cb";
+
+const char CB_STRUCT_LENGTH_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length)
+{
+ if (!h || !length) {
+ _E("Invalid parameter");
+ return -1;
+ }
+
+ *length = g_list_length(h->$$);
+
+ return 0;
+}
+)__c_cb";
+
const char CB_STRUCT_CLONER[] =
R"__c_cb(
int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone)
}
std::string CGeneratorBase::ConvertTypeToString(
- ParameterType::Direction direction, const BaseType& type) {
+ ParameterType::Direction direction, const BaseType& type, bool bconst) {
if (type.IsUserDefinedType()) {
if (direction == ParameterType::Direction::IN)
return GetHandlePrefix() + type.ToString() + "_h ";
}
if (type.ToString() == "string") {
- if (direction == ParameterType::Direction::IN)
+ if (direction == ParameterType::Direction::IN) {
+ if (!bconst)
+ return "char *";
return "const char *";
- else
+ } else
return "char **";
}
- if (direction == ParameterType::Direction::IN)
+ if (direction == ParameterType::Direction::IN && bconst)
return type_map_[type.ToString()];
return type_map_[type.ToString()] + "*";
std::string Tab(int cnt);
std::string NLine(int cnt);
std::string ConvertTypeToString(ParameterType::Direction direction,
- const BaseType& type);
+ const BaseType& type, bool bconst = true);
std::string GetFullNameFromType(const BaseType& type);
std::string GetParcelParamTypeString(const BaseType& type,
bool is_pointer = true);
GenStructureSetter(stream, st);
GenStructureGetter(stream, st);
GenStructureIterator(stream, st);
+ GenStructureRemover(stream, st);
+ GenStructureLengthGetter(stream, st);
}
void CHeaderGeneratorBase::GenStructureDeclaration(std::ofstream& stream,
}
}
+void CHeaderGeneratorBase::GenStructureRemover(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ GenTemplate(CB_STRUCT_REMOVER, stream,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ });
+ }
+}
+
+void CHeaderGeneratorBase::GenStructureLengthGetter(std::ofstream& stream,
+ const Structure& st) {
+ for (auto& i : st.GetElements().GetElms()) {
+ if (i->GetType().ToString() != "list")
+ continue;
+
+ GenTemplate(CB_STRUCT_LENGTH_GETTER, stream,
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ },
+ [&]()->std::string {
+ return i->GetID();
+ },
+ [&]()->std::string {
+ return GetStructIdWithNamespace(st);
+ });
+ }
+}
+
void CHeaderGeneratorBase::GenStructureCloner(std::ofstream& stream,
const Structure& st) {
GenTemplate(CB_STRUCT_CLONER, stream,
void GenStructureSetter(std::ofstream& stream, const Structure& st);
void GenStructureGetter(std::ofstream& stream, const Structure& st);
void GenStructureIterator(std::ofstream& stream, const Structure& st);
+ void GenStructureRemover(std::ofstream& stream, const Structure& st);
+ void GenStructureLengthGetter(std::ofstream& stream, const Structure& st);
void GenStructureCloner(std::ofstream& stream, const Structure& st);
};
bool (*callback)($$$$, void *user_data), void *user_data);
)__c_cb";
+const char CB_STRUCT_REMOVER[] =
+R"__c_cb(
+int rpc_port_$$_remove_$$(rpc_port_$$_h h, unsigned int nth);
+)__c_cb";
+
+const char CB_STRUCT_LENGTH_GETTER[] =
+R"__c_cb(
+int rpc_port_$$_get_$$_length(rpc_port_$$_h h, unsigned int *length);
+)__c_cb";
+
const char CB_STRUCT_CLONER[] =
R"__c_cb(
int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);