str += NLine(1) + "int " + i->GetID() + "_size;";
}
return str;
- }
- )
- );
+ }));
}
void CBodyGeneratorBase::GenStructureParcelSerializer(std::ofstream& stream,
str += GetParcelWriteString(i->GetID(), i->GetType());
}
return str;
- }
- )
- );
+ }));
}
void CBodyGeneratorBase::GenStructureParcelDeserializer(std::ofstream& stream,
str += GetParcelReadString(i->GetID(), i->GetType());
}
return str;
- }
- )
- );
+ }));
}
void CBodyGeneratorBase::GenStructureConstructor(std::ofstream& stream,
const Structure& st) {
- stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##", GetStructIdWithNamespace(st)));
+ stream << SmartIndent(ReplaceAll(CB_STRUCT_CTOR, "##",
+ GetStructIdWithNamespace(st)));
}
void CBodyGeneratorBase::GenStructureDestructor(std::ofstream& stream,
str += GetFinalizeString(i->GetID(), i->GetType());
}
return str;
- }
- )
- );
+ }));
}
void CBodyGeneratorBase::GenStructureSetter(std::ofstream& stream,
str += NLine(1);
str += GetSetterString(i->GetID(), i->GetType());
return str;
- }
- )
- );
+ }));
}
}
str += NLine(1);
str += GetGetterString(i->GetID(), i->GetType());
return str;
- }
- )
- );
+ }));
}
}
str += NLine(1);
str += GetIteratorString(i->GetID(), i->GetType());
return str;
- }
- )
- );
+ }));
}
}
str += GetClonerString(i->GetID(), i->GetType(), st);
}
return str;
- }
- )
- );
+ }));
}
std::string CBodyGeneratorBase::GetParcelTypeString(const BaseType& type,
if (type.ToString() == "string")
return ReplaceAll(ternary_operation, "##", "h->" + id);
return "h->" + id;
- }
- );
+ });
if (type.ToString() == "list") {
str += GenTemplateString(CB_WRITE_LIST_BLOCK,
if (type.GetMetaType()->ToString() == "string")
return ReplaceAll(ternary_operation, "##", "value");
return "*value";
- }
- );
- }
- );
+ });
+ });
} else if (type.ToString() == "array") {
str += GenTemplateString(CB_WRITE_ARRAY_BLOCK,
[&]()->std::string {
type.GetMetaType()->ToString() == "array")
return "&h->" + id + "[i]->parcelable, h->" + id +"[i]";
if (type.GetMetaType()->ToString() == "string")
- return ReplaceAll(ternary_operation, "##", "h->" + id + "[i]");
+ return ReplaceAll(ternary_operation, "##", "h->" + id
+ + "[i]");
return "h->" + id + "[i]";
- }
- );
- }
- );
+ });
+ });
}
return str;
},
[&]()->std::string {
return "&len";
- }
- );
+ });
},
[&]()->std::string {
return GetParcelParamTypeString(*type.GetMetaType());
},
[&]()->std::string {
std::string ss;
- ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to create handle\");" + NLine(1);
+ ss += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Failed to create handle\");" + NLine(1);
ss += "return;";
return ss;
- }
- );
+ });
s += NLine(1);
s += GenTemplateString(parcel,
[&]()->std::string {
},
[&]()->std::string {
return "&value->parcelable, value";
- }
- );
+ });
} else if (type.GetMetaType()->ToString() == "string" ||
type.GetMetaType()->ToString() == "bundle") {
s += GenTemplateString(parcel,
},
[&]()->std::string {
return "&value";
- }
- );
+ });
} else {
s += "value = calloc(1, sizeof(*value));" + NLine(1);
s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
},
[&]()->std::string {
std::string ss;
- ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Out of memory\");" + NLine(1);
+ ss += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Out of memory\");" + NLine(1);
ss += "return;";
return ss;
- }
- );
+ });
s += NLine(1);
s += GenTemplateString(parcel,
[&]()->std::string {
},
[&]()->std::string {
return "value";
- }
- );
+ });
}
return s;
},
[&]()->std::string {
return "h->" + id;
- }
- );
+ });
} else if (type.ToString() == "array") {
str += GenTemplateString(ReplaceAll(CB_READ_ARRAY_BLOCK, "##", id),
[&]()->std::string {
},
[&]()->std::string {
return "&h->" + id + "_size";
- }
- );
+ });
},
[&]()->std::string {
return GetReturnTypeString(*type.GetMetaType());
},
[&]()->std::string {
std::string ss;
- ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to create handle\");" + NLine(1);
+ ss += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Failed to create handle\");" + NLine(1);
ss += "return;";
return ss;
- }
- );
+ });
s += NLine(1);
s += GenTemplateString(parcel,
[&]()->std::string {
},
[&]()->std::string {
return "&value->parcelable, value";
- }
- );
+ });
} else {
s += GenTemplateString(parcel,
[&]()->std::string {
},
[&]()->std::string {
return "&value";
- }
- );
+ });
}
s += NLine(1);
s += GetSetterString("h->" + id + "[i]", "value");
return s;
- }
- );
+ });
} else {
str += GenTemplateString(parcel,
[&]()->std::string {
if (type.IsUserDefinedType())
return "&h->" + id + "h->" + id;
return "&h->" + id;
- }
- );
+ });
}
return str;
[&]()->std::string {
return GetDestructorString(*type.GetMetaType(),
"value", true) + NLine(1);
- }
- );
+ });
},
[&]()->std::string {
return "h->" + id;
- }
- );
+ });
} else if (type.ToString() == "array") {
if (!type.GetMetaType()->IsUserDefinedType() &&
type.GetMetaType()->ToString() != "list" &&
},
[&]()->std::string {
return "free(h->" + id + ");";
- }
- );
+ });
}
str += GenTemplateString(CB_FINALIZE_ARRAY_BLOCK,
[&]()->std::string {
[&]()->std::string {
return GetDestructorString(*type.GetMetaType(),
"h->" + id + "[i]", true) + NLine(1);
- }
- );
+ });
},
[&]()->std::string {
return "h->" + id;
- }
- );
+ });
} else {
str += GenTemplateString(CB_IF_STATEMENT,
[&]()->std::string {
},
[&]()->std::string {
return GetDestructorString(type, "h->" + id) + NLine(1);
- }
- );
+ });
}
return str;
s += GetDestructorString(type, "h->" + id) + NLine(1);
s += GetSetterString("h->" + id, "NULL");
return s;
- }
- );
+ });
str += NLine(1);
str += NLine(1);
},
[&]()->std::string {
std::string s;
- s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate data\");" + NLine(1);
+ s += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Failed to duplicate data\");" + NLine(1);
s += "return -1;";
return s;
- }
- );
+ });
str += NLine(1);
} else if (type.ToString() == "list") {
if (type.GetMetaType()->IsUserDefinedType() ||
if (type.GetMetaType()->ToString() == "string")
return "g_list_append(h->" + id + ", strdup(" + id + "))";
return "g_list_append(h->" + id + ", " + id + ")";
- }
- );
+ });
} else {
str += GenTemplateString(CB_SETTER_LIST_BLOCK,
[&]()->std::string {
},
[&]()->std::string {
std::string s;
- s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Out of memory\");" + NLine(1);
+ s += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Out of memory\");" + NLine(1);
s += "return -1;";
return s;
- }
- );
+ });
s += NLine(1);
s += GetSetterString("*value", id);
return s;
},
[&]()->std::string {
return "h->" + id;
- }
- );
+ });
}
} else if (type.ToString() == "array") {
str += GetFinalizeString(id, type) + NLine(1);
[&]()->std::string {
return GetSetterString(*type.GetMetaType(),
"h->" + id + "[i]", id + "[i]");
- }
- );
+ });
} else {
str += GetSetterString(type, "h->" + id, id);
}
[&]()->std::string {
return GetSetterString(*type.GetMetaType(),
"(*" + id + ")[i]", "h->" + id + "[i]");
- }
- );
+ });
} else {
if (type.IsUserDefinedType() ||
type.ToString() == "string" ||
},
[&]()->std::string {
std::string s;
- s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Invalid parameter: h->" + id +
- " is NULL\");" + NLine(1);
+ s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Invalid parameter: h->"
+ + id + " is NULL\");" + NLine(1);
s += "return -1;";
return s;
- }
- );
+ });
str += NLine(1);
str += NLine(1);
}
},
[&]()->std::string {
std::string s;
- s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate " + id + "\");" + NLine(1);
+ s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate "
+ + id + "\");" + NLine(1);
s += "return -1;";
return s;
- }
- );
+ });
str += NLine(1);
}
}
return "value";
return "*value";
- }
- );
+ });
return str;
}
},
[&]()->std::string {
std::string ss;
- ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate h->" + id + "\");" +
- NLine(1);
- ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
- NLine(1);
+ ss += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Failed to duplicate h->" + id + "\");" + NLine(1);
+ ss += "rpc_port_" + GetStructIdWithNamespace(st)
+ + "_destroy(handle);" + NLine(1);
ss += "return -1;";
return ss;
- }
- );
+ });
return s;
- }
- );
+ });
str += NLine(1);
} else if (type.ToString() == "list") {
str += GenTemplateString(CB_CLONER_LIST_BLOCK,
},
[&]()->std::string {
std::string ss;
- ss += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate value\");" +
- NLine(1);
- ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
- NLine(1);
+ ss += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Failed to duplicate value\");" + NLine(1);
+ ss += "rpc_port_" + GetStructIdWithNamespace(st)
+ + "_destroy(handle);" + NLine(1);
ss += "return -1;";
return ss;
- }
- );
+ });
} else {
s += "new_value = calloc(1, sizeof(*new_value));" + NLine(1);
s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
},
[&]()->std::string {
std::string tmp;
- tmp += "dlog_print(DLOG_ERROR, LOG_TAG, \"Out of memory\");" + NLine(1);
- tmp += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" +
- NLine(1);
+ tmp += "dlog_print(DLOG_ERROR, LOG_TAG," \
+ " \"Out of memory\");" + NLine(1);
+ tmp += "rpc_port_" + GetStructIdWithNamespace(st)
+ + "_destroy(handle);" + NLine(1);
tmp += "return -1;";
return tmp;
- }
- );
+ });
s += NLine(1);
s += GetSetterString(*type.GetMetaType(),
"*new_value", "*value");
},
[&]()->std::string {
return "handle->" + id;
- }
- );
+ });
} else if (type.ToString() == "array") {
str += GenTemplateString(ReplaceAll(CB_CLONER_ARRAY_BLOCK, "##", id),
[&]()->std::string {
[&]()->std::string {
return GetSetterString(*type.GetMetaType(),
"handle->" + id + "[i]", "h->" + id + "[i]");
- }
- );
+ });
} else {
str += GetSetterString(type, "handle->" + id, "h->" + id);
}
GenTemplate(CB_LOG_TAG, stream,
[&]()->std::string {
return log_tag;
- }
- );
+ });
}
void CBodyGeneratorBase::GenInterfaceEnumerations(std::ofstream& stream,
},
[&]()->std::string {
return std::to_string(count++);
- }
- );
+ });
}
return str;
- }
- )
- );
+ }));
}
void CBodyGeneratorBase::GenInterfaceMethodEnumeration(
},
[&]()->std::string {
return i->GetID();
- }
- );
+ });
}
return str;
- }
- )
- );
+ }));
}
} // namespace tidl
void GenStructure(std::ofstream& stream, const Structure& st);
void GenStructureDeclaration(std::ofstream& stream, const Structure& st);
void GenStructureParcelSerializer(std::ofstream& stream, const Structure& st);
- void GenStructureParcelDeserializer(std::ofstream& stream, const Structure& st);
+ void GenStructureParcelDeserializer(std::ofstream& stream,
+ const Structure& st);
void GenStructureConstructor(std::ofstream& stream, const Structure& st);
void GenStructureDestructor(std::ofstream& stream, const Structure& st);
void GenStructureSetter(std::ofstream& stream, const Structure& st);
const std::string& rvalue);
std::string GetSetterString(const std::string& lvalue,
const std::string& rvalue);
+
private:
std::map<std::string, std::string> parcel_type_map_;
};
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
+
const char CB_STRUCT_DECL[] =
R"__c_cb(
$$struct $$_s {
#define LOG_TAG "$$"
)__c_cb";
+
+#endif // IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_
type_map_ = {
{"char", "char "}, {"int", "int "}, {"short", "short "},
{"long", "long long "}, {"bool", "bool "}, {"string", "char *"},
- {"list", "GList *"}, {"float","float "}, {"double", "double "},
+ {"list", "GList *"}, {"float", "float "}, {"double", "double "},
{"bundle", "bundle *"}, {"void", "void "}
};
}
}
if (type.ToString() == "array") {
- if (direction == ParameterType::Direction::IN) {
- return GetReturnTypeString(*type.GetMetaType()) + "*";
- } else {
- return GetReturnTypeString(*type.GetMetaType()) + "**";
- }
+ if (direction == ParameterType::Direction::IN) {
+ return GetReturnTypeString(*type.GetMetaType()) + "*";
+ } else {
+ return GetReturnTypeString(*type.GetMetaType()) + "**";
+ }
}
if (type.ToString() == "string") {
return result;
}
-std::string CGeneratorBase::Trim(const std::string& str)
-{
+std::string CGeneratorBase::Trim(const std::string& str) {
std::size_t first = str.find_first_not_of(" \t\r\n");
if (first == std::string::npos)
return str;
std::time_t t = std::time(NULL);
std::tm* local_time = std::localtime(&t);
return std::to_string(local_time->tm_year + 1900);
- }
- );
+ });
}
void CGeneratorBase::GenIncludeDefaultHeaders(std::ofstream& stream,
return type_map_[type.ToString()] + "*";
}
-std::string CGeneratorBase::GetErrorValue(const BaseType& type)
-{
+std::string CGeneratorBase::GetErrorValue(const BaseType& type) {
if (type.IsUserDefinedType() ||
type.ToString() == "list" ||
type.ToString() == "array" ||
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_GEN_BASE_CB_H_
+
const char CB_COPYRIGHT[] =
R"__c_cb(/*
* Generated by tidlc $$.
#include <rpc-port.h>
#include <rpc-port-parcel.h>
)__c_cb";
+
+#endif // IDLC_C_GEN_C_GEN_BASE_CB_H_
},
[&]()->std::string {
return GetStructIdWithNamespace(st);
- }
- );
+ });
}
void CHeaderGeneratorBase::GenStructureConstructor(std::ofstream& stream,
},
[&]()->std::string {
return GetStructIdWithNamespace(st);
- }
- );
+ });
}
void CHeaderGeneratorBase::GenStructureDestructor(std::ofstream& stream,
},
[&]()->std::string {
return GetStructIdWithNamespace(st);
- }
- );
+ });
}
void CHeaderGeneratorBase::GenStructureSetter(std::ofstream& stream,
return str;
}
return i->GetID();
- }
- );
+ });
}
}
return str;
}
return i->GetID();
- }
- );
+ });
}
}
},
[&]()->std::string {
return i->GetID();
- }
- );
+ });
}
}
},
[&]()->std::string {
return GetStructIdWithNamespace(st);
- }
- );
+ });
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
+#define IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
+
const char CB_EXPLICIT_LINKAGE_OPEN[] =
R"__c_cb(
#ifdef __cplusplus
R"__c_cb(
int rpc_port_$$_clone(rpc_port_$$_h h, rpc_port_$$_h *clone);
)__c_cb";
+
+#endif // IDLC_C_GEN_C_HEADER_GEN_BASE_CB_H_
void CProxyBodyGen::GenTypedefProxyDelegate(std::ofstream& stream) {
const char format[] =
- "typedef void (*proxy_delegate)(GList **list, rpc_port_parcel_h parcel, int seq_id, int id);\n";
+ "typedef void (*proxy_delegate)(GList **list, rpc_port_parcel_h parcel," \
+ " int seq_id, int id);\n";
stream << NLine(1);
stream << std::string(format);
}
void CProxyBodyGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_STRUCT, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDelegators(std::ofstream& stream,
},
[&]()->std::string {
return decl.GetID();
- }
- )
- );
+ }));
}
void CProxyBodyGen::GenInterfaceDelegatorDisposer(
}
if (cnt > 0)
str += NLine(1);
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
i->GetParameterType().GetBaseType().ToString() == "list" ||
i->GetParameterType().GetBaseType().ToString() == "array") {
},
[&]()->std::string {
if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
- i->GetParameterType().GetBaseType().ToString() == "list" ||
+ i->GetParameterType().GetBaseType()
+ .ToString() == "list" ||
i->GetParameterType().GetBaseType().ToString() == "array")
return "&" + i->GetID() + "->parcelable, " + i->GetID();
return "&" + i->GetID();
- }
- );
+ });
}
return str;
},
[&]()->std::string {
std::string str;
str += "handle->callback(handle->user_data";
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
str += ", ";
str += i->GetID();
}
},
[&]()->std::string {
std::string str;
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
str += GetDestructorString(i->GetParameterType().GetBaseType(),
i->GetID());
}
return str;
- }
- )
- );
+ }));
}
void CProxyBodyGen::GenInterfaceDelegatorTable(std::ofstream& stream,
return GetInterfaceIdWithNamespace(inf) + "_DELEGATE_" + i->GetID();
},
[&]()->std::string {
- return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_" + i->GetID();
- }
- );
+ return "__" + GetInterfaceIdWithNamespace(inf) + "_delegate_"
+ + i->GetID();
+ });
cnt++;
}
},
[&]()->std::string {
return str;
- }
- )
- );
+ }));
}
void CProxyBodyGen::GenInterfaceDelegatorHandler(std::ofstream& stream,
}
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##", GetInterfaceIdWithNamespace(inf)),
- [&]()->std::string {
- if (cnt == 0)
- return str;
- return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##", GetInterfaceIdWithNamespace(inf));
- }
- )
- );
+ ReplaceAll(CB_PROCESS_RECEIVED_EVENT, "##",
+ GetInterfaceIdWithNamespace(inf)),
+ [&]()->std::string {
+ if (cnt == 0)
+ return str;
+ return ReplaceAll(CB_PROCESS_RECEIVED_EVENT_IMPL, "##",
+ GetInterfaceIdWithNamespace(inf));
+ }));
}
void CProxyBodyGen::GenInterfaceConsumeCommand(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_CONSUME_COMMAND, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_ON_CONNECTED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_ON_DISCONNECTED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnRejectedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_ON_REJECTED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_ON_RECEIVED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceMethods(std::ofstream& stream,
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
stream << SmartIndent(GenTemplateString(
- ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
+ ReplaceAll(CB_INTERFACE_METHODS, "##",
+ GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
return GetReturnTypeString(i->GetType());
},
[&]()->std::string {
std::string str;
for (auto& p : i->GetParameters().GetParams()) {
- if (p->GetParameterType().GetDirection() == ParameterType::Direction::OUT ||
+ if (p->GetParameterType().GetDirection() ==
+ ParameterType::Direction::OUT ||
p->GetParameterType().GetBaseType().IsUserDefinedType() ||
p->GetParameterType().GetBaseType().ToString() == "list" ||
p->GetParameterType().GetBaseType().ToString() == "array" ||
},
[&]()->std::string {
return GetMethodReadString(inf, *i);
- }
- )
- );
+ }));
}
}
void CProxyBodyGen::GenInterfaceConstructor(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_CTOR, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDestructor(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DTOR, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceConnect(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_CONNECT, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyBodyGen::GenInterfaceDisconnect(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DISCONNECT, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
std::string CProxyBodyGen::GetMethodWriteString(const Interface& inf,
continue;
if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
str += GenTemplateString(ReplaceAll(CB_DELEGATE_BLOCK, "##",
- GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType().GetBaseType().ToString()),
+ GetInterfaceIdWithNamespace(inf) + "_" + p->GetParameterType()
+ .GetBaseType().ToString()),
[&]()->std::string {
return p->GetID();
- }
- );
+ });
} else {
str += GenTemplateString(setter,
[&]()->std::string {
p->GetParameterType().GetBaseType().ToString() == "array") {
if (p->GetParameterType().GetDirection()
== ParameterType::Direction::REF)
- return "&(*" + p->GetID() + ")->parcelable, " + "*" + p->GetID();
+ return "&(*" + p->GetID() + ")->parcelable, " + "*"
+ + p->GetID();
else
return "&" + p->GetID() + "->parcelable, " + p->GetID();
} else if (p->GetParameterType().GetDirection()
if (p->GetParameterType().GetBaseType().ToString() == "string")
return ReplaceAll(ternary_operation, "##", "*" + p->GetID());
return "*" + p->GetID();
- } else if (p->GetParameterType().GetBaseType().ToString() == "string") {
+ } else if (p->GetParameterType().GetBaseType().ToString() ==
+ "string") {
return ReplaceAll(ternary_operation, "##", p->GetID());
}
return p->GetID();
- }
- );
+ });
}
}
return str;
[&]()->std::string {
std::string s;
for (auto& p : decl.GetParameters().GetParams()) {
- if (p->GetParameterType().GetDirection() != ParameterType::Direction::OUT)
+ if (p->GetParameterType().GetDirection() !=
+ ParameterType::Direction::OUT)
continue;
s += GetReturnTypeString(p->GetParameterType().GetBaseType()) +
"out_" + p->GetID() + ";" + NLine(1);
[&]()->std::string {
std::string s;
for (auto& p : decl.GetParameters().GetParams()) {
- if (p->GetParameterType().GetDirection() != ParameterType::Direction::OUT)
+ if (p->GetParameterType().GetDirection() !=
+ ParameterType::Direction::OUT)
continue;
if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
p->GetParameterType().GetBaseType().ToString() == "list" ||
return "parcel_received";
},
[&]()->std::string {
- if (p->GetParameterType().GetBaseType().IsUserDefinedType() ||
- p->GetParameterType().GetBaseType().ToString() == "list" ||
- p->GetParameterType().GetBaseType().ToString() == "array")
- return "&out_" + p->GetID() + "->parcelable, out_" + p->GetID();
+ auto& t = p->GetParameterType().GetBaseType();
+ if (t.IsUserDefinedType() || t.ToString() == "list" ||
+ t.ToString() == "array") {
+ return "&out_" + p->GetID() + "->parcelable, out_"
+ + p->GetID();
+ }
+
return "&out_" + p->GetID();
- }
- );
+ });
s += "*" + p->GetID() + " = out_" + p->GetID() + ";" + NLine(1);
}
if (GetReturnTypeString(decl.GetType()) != "void ") {
decl.GetType().ToString() == "array")
return "&ret->parcelable, ret";
return "&ret";
- }
- );
+ });
}
return s;
- }
- );
+ });
if (GetReturnTypeString(decl.GetType()) != "void ") {
str += NLine(1);
str += "return ret;";
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
+#define IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
+
const char CB_INTERFACE_STRUCT[] =
R"__c_cb(
struct ##_s {
} while (0);
g_rec_mutex_unlock(&h->mutex);
)__c_cb";
+
+#endif // IDLC_C_GEN_C_PROXY_BODY_GEN_CB_H_
p->GetParameterType().GetBaseType()) + p->GetID();
}
return str;
- }
- );
+ });
stream << ReplaceAll(CB_DELEGATE_CTOR, "##", id + "_" + decl.GetID());
stream << GenTemplateString(
void CProxyHeaderGen::GenInterfaceDeclaration(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_DECL, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CProxyHeaderGen::GenInterfaceMethods(std::ofstream& stream,
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
stream << GenTemplateString(
- ReplaceAll(CB_INTERFACE_METHODS, "##", GetInterfaceIdWithNamespace(inf)),
+ ReplaceAll(CB_INTERFACE_METHODS, "##",
+ GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
return GetReturnTypeString(i->GetType());
},
}
}
return str;
- }
- );
+ });
}
}
void CProxyHeaderGen::GenInterfaceConnect(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONNECT, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_CONNECT, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CProxyHeaderGen::GenInterfaceDisconnect(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_DISCONNECT, "##",
+ GetInterfaceIdWithNamespace(inf));
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
+#define IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
+
const char CB_INTERFACE_DECL[] =
R"__c_cb(
typedef struct ##_s *rpc_port_proxy_##_h;
R"__c_cb(
int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate);
)__c_cb";
+
+#endif // IDLC_C_GEN_C_PROXY_HEADER_GEN_CB_H_
},
[&]()->std::string {
return GetMethodString(inf, *i);
- }
- )
- );
+ }));
}
}
return GetInterfaceIdWithNamespace(inf) + "_METHOD_" + i->GetID();
},
[&]()->std::string {
- return "__" + GetInterfaceIdWithNamespace(inf) + "_method_" + i->GetID();
- }
- );
+ return "__" + GetInterfaceIdWithNamespace(inf) + "_method_"
+ + i->GetID();
+ });
cnt++;
}
},
[&]()->std::string {
return str;
- }
- )
- );
+ }));
}
void CStubBodyGen::GenInterfaceOnConnectedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
+ ReplaceAll(CB_INTERFACE_ON_CONNECTED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceOnDisconnectedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##", GetInterfaceIdWithNamespace(inf)));
+ ReplaceAll(CB_INTERFACE_ON_DISCONNECTED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceOnReceivedEventCB(std::ofstream& stream,
const Interface& inf) {
stream << SmartIndent(
- ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##", GetInterfaceIdWithNamespace(inf)));
+ ReplaceAll(CB_INTERFACE_ON_RECEIVED, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceRegister(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_REGISTER, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceUnregister(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
void CStubBodyGen::GenInterfaceGlobalVariables(std::ofstream& stream,
const Interface& inf) {
- stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##", GetInterfaceIdWithNamespace(inf)));
+ stream << SmartIndent(ReplaceAll(CB_GLOBALS, "##",
+ GetInterfaceIdWithNamespace(inf)));
}
std::string CStubBodyGen::GetMethodString(const Interface& inf,
}
str += NLine(1);
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
continue;
},
[&]()->std::string {
return i->GetID();
- }
- );
+ });
} else {
str += GetConstructorString(i->GetParameterType().GetBaseType(),
i->GetID());
i->GetParameterType().GetBaseType().ToString() == "array")
return "&" + i->GetID() + "->parcelable, " + i->GetID();
return "&" + i->GetID();
- }
- );
+ });
}
if (cnt > 0)
}
str += "context->callback." + decl.GetID() + "(context";
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
str += ", ";
if (i->GetParameterType().GetDirection() != ParameterType::Direction::IN)
str += "&" + i->GetID();
},
[&]()->std::string {
std::string s;
- for (auto& i: decl.GetParameters().GetParams()) {
- if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN)
+ for (auto& i : decl.GetParameters().GetParams()) {
+ if (i->GetParameterType().GetDirection() ==
+ ParameterType::Direction::IN)
continue;
s += GenTemplateString(setter,
[&]()->std::string {
return "result";
},
[&]()->std::string {
- if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
- i->GetParameterType().GetBaseType().ToString() == "list" ||
- i->GetParameterType().GetBaseType().ToString() == "array")
+ auto& t = i->GetParameterType().GetBaseType();
+ if (t.IsUserDefinedType() || t.ToString() == "list" ||
+ t.ToString() == "array")
return "&" + i->GetID() + "->parcelable, " + i->GetID();
- else if (i->GetParameterType().GetBaseType().ToString() == "string")
+ else if (t.ToString() == "string")
return ReplaceAll(ternary_operation, "##", i->GetID());
return i->GetID();
- }
- );
+ });
}
if (decl.GetType().ToString() != "void") {
s += GenTemplateString(setter,
else if (decl.GetType().ToString() == "string")
return ReplaceAll(ternary_operation, "##", "ret");
return "ret";
- }
- );
+ });
}
return s;
- }
- );
+ });
}
- for (auto& i: decl.GetParameters().GetParams()) {
+ for (auto& i : decl.GetParameters().GetParams()) {
str += NLine(1);
if (IsDelegateType(inf, i->GetParameterType().GetBaseType())) {
str += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
},
[&]()->std::string {
return attr.GetValue();
- }
- );
+ });
return str;
}
},
[&]()->std::string {
return attr.GetValue();
- }
- );
+ });
return str;
}
stream << SmartIndent(GenTemplateString(CB_INTERFACE_DELEGATOR_DECL,
[&]()->std::string {
return id + "_" + decl.GetID();
- }
- )
- );
+ }));
}
void CStubBodyGen::GenInterfaceDelegatorConstructor(std::ofstream& stream,
},
[&]()->std::string {
return decl.GetID();
- }
- )
- );
+ }));
}
void CStubBodyGen::GenInterfaceDelegatorDestructor(std::ofstream& stream,
i->GetParameterType().GetBaseType(), true);
},
[&]()->std::string {
- if (i->GetParameterType().GetBaseType().IsUserDefinedType() ||
- i->GetParameterType().GetBaseType().ToString() == "list" ||
- i->GetParameterType().GetBaseType().ToString() == "array")
+ auto& t = i->GetParameterType().GetBaseType();
+ if (t.IsUserDefinedType() || t.ToString() == "list" ||
+ t.ToString() == "array")
return "&" + i->GetID() + "->parcelable, " + i->GetID();
- else if (i->GetParameterType().GetBaseType().ToString() == "string")
+ else if (t.ToString() == "string")
return ReplaceAll(ternary_operation, "##", i->GetID());
return i->GetID();
- }
- );
+ });
}
return str;
- }
- )
- );
+ }));
}
void CStubBodyGen::GenInterfaceDelegatorPortSetter(std::ofstream& stream,
std::string str;
for (auto& a : inf.GetAttributes().GetAttrs()) {
if (a->GetKey() == "privilege") {
- str += GetAddPrivilegeString(GetInterfaceIdWithNamespace(inf), *a);
+ str += GetAddPrivilegeString(
+ GetInterfaceIdWithNamespace(inf), *a);
str += NLine(1);
} else if (a->GetKey() == "trusted" && a->GetValue() == "true") {
str += GetTrustedModeString(GetInterfaceIdWithNamespace(inf), *a);
if (!str.empty())
str = SmartIndent("int r;\n\n") + str;
return str;
- }
- )
- );
+ }));
}
} // namespace tidl
* limitations under the License.
*/
-#ifndef IDLC_C_GEN_STUB_BODY_GEN_H_
-#define IDLC_C_GEN_STUB_BODY_GEN_H_
+#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_H_
+#define IDLC_C_GEN_C_STUB_BODY_GEN_H_
#include <memory>
#include <string>
} // namespace tidl
-#endif // IDLC_C_GEN_STUB_BODY_GEN_H_
+#endif // IDLC_C_GEN_C_STUB_BODY_GEN_H_
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
+#define IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
+
const char CB_INTERFACE_METHOD[] =
R"__c_cb(
static int __$$_method_$$(rpc_port_h port, rpc_port_parcel_h parcel, void *data)
return r;
}
)__c_cb";
+
+#endif // IDLC_C_GEN_C_STUB_BODY_GEN_CB_H_
CB_INTERFACE_DECL, "##", GetInterfaceIdWithNamespace(inf)),
[&]()->std::string {
std::string str;
- for (auto& i: inf.GetDeclarations().GetDecls()) {
+ for (auto& i : inf.GetDeclarations().GetDecls()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
str += NLine(1);
[&]()->std::string {
std::string s;
for (auto& p : i->GetParameters().GetParams()) {
- if (IsDelegateType(inf, p->GetParameterType().GetBaseType())) {
- s += "rpc_port_" + GetInterfaceIdWithNamespace(inf) + "_" +
- p->GetParameterType().GetBaseType().ToString() + "_h " +
- p->GetID();
+ if (IsDelegateType(inf, p->GetParameterType()
+ .GetBaseType())) {
+ s += "rpc_port_" + GetInterfaceIdWithNamespace(inf)
+ + "_" + p->GetParameterType().GetBaseType().ToString()
+ + "_h " + p->GetID();
} else {
- s += GetParamTypeString(p->GetParameterType().GetDirection(),
- p->GetParameterType().GetBaseType()) + p->GetID();
+ s += GetParamTypeString(p->GetParameterType()
+ .GetDirection(), p->GetParameterType().GetBaseType())
+ + p->GetID();
}
s += ", ";
}
return s;
- }
- );
+ });
}
return str;
- }
- )
- );
+ }));
}
void CStubHeaderGen::GenInterfaceContext(std::ofstream& stream,
void CStubHeaderGen::GenInterfaceContextDeclaration(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_DECL, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextTagSetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_SET_TAG, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextTagGetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_TAG, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceContextSenderGetter(
std::ofstream& stream, const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_CONTEXT_GET_SENDER, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceDelegators(std::ofstream& stream,
i->GetParameterType().GetBaseType()) + i->GetID();
}
return str;
- }
- );
+ });
}
void CStubHeaderGen::GenInterfaceRegister(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_REGISTER, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_REGISTER, "##",
+ GetInterfaceIdWithNamespace(inf));
}
void CStubHeaderGen::GenInterfaceUnregister(std::ofstream& stream,
const Interface& inf) {
- stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##", GetInterfaceIdWithNamespace(inf));
+ stream << ReplaceAll(CB_INTERFACE_UNREGISTER, "##",
+ GetInterfaceIdWithNamespace(inf));
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
+#define IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
+
const char CB_INTERFACE_DECL[] =
R"__c_cb(
typedef struct {
R"__c_cb(
int rpc_port_stub_##_unregister(void);
)__c_cb";
+
+#endif // IDLC_C_GEN_C_STUB_HEADER_GEN_CB_H_
#include "idlc/cpp_gen/cpp_gen_base.h"
namespace {
-#include "cpp_gen_base_cb.h"
+#include "idlc/cpp_gen/cpp_gen_base_cb.h"
}
namespace tidl {
type_map_ = {
{"char", "char"}, {"int", "int"}, {"short", "short"},
{"long", "long long"}, {"string", "std::string"}, {"bool", "bool"},
- {"list", "std::list"}, {"float","float"}, {"double", "double"},
+ {"list", "std::list"}, {"float", "float"}, {"double", "double"},
{"bundle", "Bundle"}, {"void", "void"}, {"array", "std::vector"}
};
n++;
}
return str;
- }
- );
+ });
stream << NLine(1);
for (auto& i : st.GetElements().GetElms()) {
}
str += NLine(1);
return str;
- }
- );
+ });
}, false, false);
stream << ";" << NLine(1);
}
return ele.GetID();
},
[&]()->std::string {
- if(ele.GetType().IsUserDefinedType() ||
+ if (ele.GetType().IsUserDefinedType() ||
ele.GetType().GetMetaType() != nullptr ||
ele.GetType().ToString() == "string" ||
ele.GetType().ToString() == "bundle") {
}
return ele.GetID();
- }
- );
+ });
stream << NLine(1);
}
GenTemplate(AddIndent(TAB_SIZE, getter, true), stream,
[&]()->std::string {
- if(ele.GetType().IsUserDefinedType() ||
+ if (ele.GetType().IsUserDefinedType() ||
ele.GetType().GetMetaType() != nullptr ||
ele.GetType().ToString() == "string" ||
ele.GetType().ToString() == "bundle") {
},
[&]()->std::string {
return ele.GetID();
- }
- );
+ });
}
void CppGeneratorBase::GenStructuresForBody(std::ofstream& stream) {
}
}
-void CppGeneratorBase::GenStructureForBody(std::ofstream& stream, const Structure& st) {
+void CppGeneratorBase::GenStructureForBody(std::ofstream& stream,
+ const Structure& st) {
std::vector<std::pair<std::string, std::string>> v;
const char ctor[] = "##::##() {}\n\n" \
"##::##($$)\n" \
[&]()->std::string {
std::string str;
for (auto& i : v) {
- str += i.first + " " + i.second ;
+ str += i.first + " " + i.second;
if (i != v.back())
str += ", ";
str += ", ";
}
return str;
- }
- );
+ });
stream << NLine(2);
}
for (auto& i : st.GetElements().GetElms()) {
stream << AddIndent(TAB_SIZE,
ConvertTypeToDeserializer(i->GetType(), i->GetID(), "h"));
- stream << Tab(1) << "param.Set" << i->GetID() << "(std::move(" << i->GetID() << "));"
- << NLine(2);
+ stream << Tab(1) << "param.Set" << i->GetID() << "(std::move("
+ << i->GetID() << "));" << NLine(2);
}
stream << Tab(1) << "return h;" << NLine(1);
}, false);
if (make_new_type) {
ret += n + " ";
if (IsDelegateType(type)) {
- ret += id + "(new " + type.ToString() + "(port, std::weak_ptr<ServiceBase>(b)));\n";
+ ret += id + "(new " + type.ToString()
+ + "(port, std::weak_ptr<ServiceBase>(b)));\n";
} else {
ret += id + ";\n";
}
ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p"));
}
return m;
- }
- );
+ });
} else {
GenTemplate(CB_CALLBACK_ON_RECEIVED_EVENT_METHOD, stream,
[&]()->std::string {
ret += ");";
return ret;
- }
- );
+ });
}
}
bool is_proxy) {
stream << CB_CALLBACK_BASE_HEADER_FRONT;
if (is_proxy) {
- stream << Tab(1) << " virtual void OnReceivedEvent(rpc_port_parcel_h port) = 0;"
+ stream << Tab(1)
+ << " virtual void OnReceivedEvent(rpc_port_parcel_h port) = 0;"
<< NLine(1);
}
stream << CB_CALLBACK_BASE_HEADER_BACK;
std::time_t t = std::time(NULL);
std::tm* local_time = std::localtime(&t);
return std::to_string(local_time->tm_year + 1900);
- }
- );
+ });
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
+#define IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
+
const char CB_BUNDLE[] = R"__cls_bundle(class Bundle final {
public:
Bundle() {
$$
}
)__cpp_cb";
+
+#endif // IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_
#include "idlc/cpp_gen/cpp_proxy_body_gen.h"
namespace {
-#include "cpp_proxy_body_gen_cb.h"
+#include "idlc/cpp_gen/cpp_proxy_body_gen_cb.h"
}
namespace tidl {
},
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
}
void CppProxyBodyGen::GenDestructor(std::ofstream& stream,
},
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
}
void CppProxyBodyGen::GenHelperMethods(std::ofstream& stream,
}
}
-void CppProxyBodyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
+void CppProxyBodyGen::GenInvocation(std::ofstream& stream,
+ const Declaration& decl) {
stream << CB_INVOCATION_PRE;
// Serialize
* limitations under the License.
*/
+#ifndef IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
+
const char CB_DTOR[] =
R"__cpp_cb(
$$::~$$() {
rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
}
)__cpp_cb";
+
+#endif // IDLC_CPP_GEN_CPP_PROXY_BODY_GEN_CB_H_
#include "idlc/cpp_gen/cpp_proxy_header_gen.h"
namespace {
-#include "cpp_proxy_header_gen_cb.h"
+#include "idlc/cpp_gen/cpp_proxy_header_gen_cb.h"
}
namespace tidl {
},
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
GenMethods(stream, iface);
stream << NLine(1) << " private:" << NLine(1);
GenMethodId(stream, iface);
* limitations under the License.
*/
+#ifndef IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
+
const char CB_EXCEPTIONS[] =
R"__cpp_cb(
class Exception {};
#include <list>
)__cpp_cb";
+
+#endif // IDLC_CPP_GEN_CPP_PROXY_HEADER_GEN_CB_H_
#include "idlc/cpp_gen/cpp_stub_body_gen.h"
namespace {
-#include "cpp_stub_body_gen_cb.h"
+#include "idlc/cpp_gen/cpp_stub_body_gen_cb.h"
}
namespace tidl {
GenTemplate(CB_CTOR_SERVICE_BASE, stream,
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
stream << NLine(1);
}
},
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
for (auto& i : iface.GetDeclarations().GetDecls()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
continue;
- stream << Tab(2) << "case static_cast<int>(MethodId::" << i->GetID() << "): ";
+ stream << Tab(2) << "case static_cast<int>(MethodId::"
+ << i->GetID() << "): ";
GenBrace(stream, TAB_SIZE * 2, [&]() {
GenInvocation(stream, *i);
stream << Tab(3) << "break;" << NLine(1);
stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
}
-void CppStubBodyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
+void CppStubBodyGen::GenInvocation(std::ofstream& stream,
+ const Declaration& decl) {
int cnt = 1;
// Deserialize
return;
cnt = 0;
- m = "rpc_port_parcel_write_int32(result, static_cast<int>(MethodId::__Result));\n";
+ m = "rpc_port_parcel_write_int32(" \
+ "result, static_cast<int>(MethodId::__Result));\n";
for (auto& i : decl.GetParameters().GetParams()) {
auto& pt = i->GetParameterType();
cnt++;
* limitations under the License.
*/
+#ifndef IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
+
const char CB_CTOR_FRONT[] =
R"__cpp_cb(
##::##() {
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)) {})__cpp_cb";
+
+#endif // IDLC_CPP_GEN_CPP_STUB_BODY_GEN_CB_H_
#include "idlc/cpp_gen/cpp_stub_header_gen.h"
namespace {
-#include "cpp_stub_header_gen_cb.h"
+#include "idlc/cpp_gen/cpp_stub_header_gen_cb.h"
}
namespace tidl {
* limitations under the License.
*/
+#ifndef IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
+#define IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
+
const char CB_EXCEPTIONS[] =
R"__cpp_cb(
class Exception {};
#include <list>
)__cpp_cb";
+
+#endif // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_CB_COPYRIGHT_H_
+#define IDLC_CS_GEN_CS_CB_COPYRIGHT_H_
+
const char cs_cb_copyright[] =
R"__cs_cb(/*
* Generated by tidlc $$.
* limitations under the License.
*/
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_CB_COPYRIGHT_H_
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_CB_INTEROP_H_
+#define IDLC_CS_GEN_CS_CB_INTEROP_H_
+
const char cs_cb_interop[] =
R"__cs_cb(
internal static partial class Interop
}
)__cs_cb";
+#endif // IDLC_CS_GEN_CS_CB_INTEROP_H_
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_CB_PROXY_INTEROP_H_
+#define IDLC_CS_GEN_CS_CB_PROXY_INTEROP_H_
+
const char cs_cb_proxy_interop[] =
R"__cs_cb(
internal static partial class Proxy
internal static extern ErrorCode AddReceivedEventCb(IntPtr handle, ReceivedEventCallback cb, IntPtr data);
}
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_CB_PROXY_INTEROP_H_
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_CB_STUB_INTEROP_H_
+#define IDLC_CS_GEN_CS_CB_STUB_INTEROP_H_
+
const char cs_cb_stub_interop[] =
R"__cs_cb(
internal static partial class Stub
internal static extern ErrorCode SetTrusted(IntPtr handle, bool trusted);
}
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_CB_STUB_INTEROP_H_
type_map_ = {
{"char", "byte"}, {"int", "int"}, {"short", "short"},
{"long", "long"}, {"string", "string"}, {"bool", "bool"},
- {"list", "LinkedList"}, {"array", "List"}, {"float","float"},
+ {"list", "LinkedList"}, {"array", "List"}, {"float", "float"},
{"double", "double"}, {"bundle", "Bundle"}, {"void", "void"}
};
},
[&]()->std::string {
return i->GetID();
- }
- );
+ });
if (i->GetType().ToString() == "bundle") {
v.push_back(i->GetID() + " = " + "new Bundle()");
}
str += " " + i + ";\n";
}
return str;
- }
- );
+ });
});
}
-void CsGeneratorBase::GenSerializer(std::ofstream& stream, const Structure& st) {
+void CsGeneratorBase::GenSerializer(std::ofstream& stream,
+ const Structure& st) {
stream << NLine(1) << Tab(3) << "private static void Serialize(IntPtr h, "
<< st.GetID() << " param)" << NLine(1);
GenBrace(stream, TAB_SIZE * 3, [&]() {
stream << Tab(4) << "Deserialize(h, param." << i->GetID()
<< ");" << NLine(1);
}
-
}
});
}
}
}
-void CsGeneratorBase::GenListSerializer(std::ofstream& stream, const BaseType& type) {
+void CsGeneratorBase::GenListSerializer(std::ofstream& stream,
+ const BaseType& type) {
stream << NLine(1) << Tab(3) << "private static void Serialize(IntPtr h, "
<< ConvertTypeToString(type) << " param)" << NLine(1);
GenBrace(stream, TAB_SIZE * 3, [&]() {
return t;
}
-void CsGeneratorBase::GenWriteBundle(std::ofstream& stream, const std::string& id) {
+void CsGeneratorBase::GenWriteBundle(std::ofstream& stream,
+ const std::string& id) {
GenTemplate(CB_WRITE_BUNDLE, stream,
[&]()->std::string {
return id;
},
[&]()->std::string {
return id;
- }
- );
+ });
}
-void CsGeneratorBase::GenMethodId(std::ofstream& stream, const Interface& iface) {
+void CsGeneratorBase::GenMethodId(std::ofstream& stream,
+ const Interface& iface) {
stream << Tab(3) << "private enum MethodId : int" << NLine(1);
GenBrace(stream, TAB_SIZE * 3, [&]() {
int cnt = 2;
});
}
-void CsGeneratorBase::GenDelegateId(std::ofstream& stream, const Interface& iface) {
+void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
+ const Interface& iface) {
stream << Tab(3) << "private enum DelegateId : int" << NLine(1);
GenBrace(stream, TAB_SIZE * 3, [&]() {
int cnt = 1;
stream << ")";
}
-void CsGeneratorBase::GenParameters(std::ofstream& stream, const Parameters& ps) {
+void CsGeneratorBase::GenParameters(std::ofstream& stream,
+ const Parameters& ps) {
stream << GetParameters(ps);
}
},
[&]()->std::string {
return decl.GetID();
- }
- );
+ });
stream << NLine(1);
if (is_proxy) {
m += ConvertTypeToSerializer(pt.GetBaseType(), i->GetID(), "p", id);
}
return AddIndent(TAB_SIZE * 5, m);
- }
- );
+ });
}
void CsGeneratorBase::GenCopyright(std::ofstream& stream) {
std::time_t t = std::time(NULL);
std::tm* local_time = std::localtime(&t);
return std::to_string(local_time->tm_year + 1900);
- }
- );
+ });
stream << NLine(1);
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_GEN_BASE_CB_H_
+#define IDLC_CS_GEN_CS_GEN_BASE_CB_H_
+
const char CB_EXCEPTIONS[] =
R"__cs_cb( public class InvalidIOException : InvalidOperationException {}
public class InvalidIDException : InvalidOperationException {}
Interop.LibRPCPort.Parcel.WriteBundle(h, new Bundle().SafeBundleHandle.DangerousGetHandle());
}
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_GEN_BASE_CB_H_
GenTemplate(AddIndent(TAB_SIZE, ::cs_cb_interop), stream,
[&]()->std::string {
return AddIndent(TAB_SIZE, ::cs_cb_proxy_interop);
- }
- );
+ });
});
});
stream << NLine(1);
}
void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
-
stream << Tab(2) << "public class " << iface.GetID()
<< " : IDisposable" << NLine(1);
GenBrace(stream, TAB_SIZE * 2, [&]() {
GenTemplate(AddIndent(TAB_SIZE * 3, m), stream,
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
}
-void CsProxyGen::GenConnectMethod(std::ofstream& stream, const Interface& iface) {
+void CsProxyGen::GenConnectMethod(std::ofstream& stream,
+ const Interface& iface) {
GenTemplate(CB_CONNECT_METHOD, stream,
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
stream << NLine(1);
}
GenTemplate(CB_DISPOSABLE, stream,
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
}
} // namespace tidl
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
+#define IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
+
const char CB_DATA_MEMBERS[] =
R"__cs_cb( public event EventHandler Connected;
public event EventHandler Disconnected;
R"__cs_cb( // Send
Interop.LibRPCPort.Parcel.Send(p, _port);
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_PROXY_GEN_CB_H_
GenTemplate(AddIndent(TAB_SIZE, ::cs_cb_interop), stream,
[&]()->std::string {
return AddIndent(TAB_SIZE, ::cs_cb_stub_interop);
- }
- );
+ });
});
});
stream << NLine(1);
}
}
-void CsStubGen::GenReceivedEvent(std::ofstream& stream, const Interface& iface) {
+void CsStubGen::GenReceivedEvent(std::ofstream& stream,
+ const Interface& iface) {
stream << CB_ON_RECEIVED_EVENT_FRONT;
for (auto& i : iface.GetDeclarations().GetDecls()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
},
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
for (auto& i : iface.GetAttributes().GetAttrs()) {
if (i->GetKey() == "privilege") {
GenTemplate(CB_DISPOSABLE, stream,
[&]()->std::string {
return iface.GetID();
- }
- );
+ });
}
} // namespace tidl
* limitations under the License.
*/
-#ifndef IDLC_CS_GEN_STUB_GEN_H_
-#define IDLC_CS_GEN_STUB_GEN_H_
+#ifndef IDLC_CS_GEN_CS_STUB_GEN_H_
+#define IDLC_CS_GEN_CS_STUB_GEN_H_
#include <memory>
#include <string>
} // namespace tidl
-#endif // IDLC_CS_GEN_STUB_GEN_H_
+#endif // IDLC_CS_GEN_CS_STUB_GEN_H_
* limitations under the License.
*/
+#ifndef IDLC_CS_GEN_CS_STUB_GEN_CB_H_
+#define IDLC_CS_GEN_CS_STUB_GEN_CB_H_
+
const char CB_DATA_MEMBERS[] =
R"__cs_cb( private IntPtr _stub;
private List<ServiceBase> _services = new List<ServiceBase>();
}
#endregion
)__cs_cb";
+
+#endif // IDLC_CS_GEN_CS_STUB_GEN_CB_H_
Declaration(std::string id, BaseType* ret_type, Parameters* params,
std::string comments, unsigned line,
- MethodType mtype = MethodType::SYNC);
+ MethodType mtype = MethodType::SYNC);
const std::string& GetID() const;
const BaseType& GetType() const;
#include <fstream>
#include <iostream>
#include <memory>
+#include <utility>
#include "idlc/document.h"
#include "idlc/parameter.h"
}
template<typename T, typename ...ARGS>
- void GenTemplate(std::string templ, std::ofstream& stream, T cb, ARGS... args) {
+ void GenTemplate(std::string templ, std::ofstream& stream,
+ T cb, ARGS... args) {
size_t f = templ.find("$$");
templ.replace(f, std::string("$$").length(), cb());
GenTemplate(std::move(templ), stream, args...);
void GenBrace(std::ofstream& stream, int indent, T cb,
bool start_indent = true, bool ended_new_line = true) {
if (start_indent) {
- for(int i = 0; i < indent; i++)
+ for (int i = 0; i < indent; i++)
stream << " ";
}
stream << "{" << std::endl;
cb();
- for(int i = 0; i < indent; i++)
+ for (int i = 0; i < indent; i++)
stream << " ";
stream << "}";
if (ended_new_line)
{ "output", 'o', 0, G_OPTION_ARG_STRING, &opt[OPT_OUTPUT],
"The generated interface file.", "OUTPUT" },
{ "namespace", 'n', 0, G_OPTION_ARG_NONE, &opt[OPT_NAMESPACE],
- "Add the prefix in the funtion name as output file name (C language only).",
+ "Add the prefix in the funtion name as output file name " \
+ "(C language only).",
NULL },
{ NULL }
};
gen.Run("test.cs");
ASSERT_TRUE(FindStringFromFile("test.cs", "namespace RPCPort"));
- ASSERT_TRUE(FindStringFromFile("test.cs", " internal static partial class Proxy"));
- ASSERT_TRUE(FindStringFromFile("test.cs", " public sealed class Student"));
- ASSERT_TRUE(FindStringFromFile("test.cs", " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " internal static partial class Proxy"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public string name { get; set; }"));
ASSERT_TRUE(FindStringFromFile("test.cs", " public sealed class Class"));
- ASSERT_TRUE(FindStringFromFile("test.cs", " public LinkedList<Student> students { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test.cs",
+ " public LinkedList<Student> students { get; set; }"));
}
gen.Run("test_stub.cs");
ASSERT_TRUE(FindStringFromFile("test_stub.cs", "namespace RPCPort"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", " internal static partial class Stub"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public sealed class Student"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public string name { get; set; }"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public sealed class Class"));
- ASSERT_TRUE(FindStringFromFile("test_stub.cs", " public LinkedList<Student> students { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " internal static partial class Stub"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public sealed class Student"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public string name { get; set; }"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public sealed class Class"));
+ ASSERT_TRUE(FindStringFromFile("test_stub.cs",
+ " public LinkedList<Student> students { get; set; }"));
}
TEST_F(GeneratorTest, Generator_Run) {
EXPECT_NE(gen, nullptr);
gen->Run("test.out");
- EXPECT_TRUE(gen->GetCount() == 2);
+ EXPECT_EQ(gen->GetCount(), 2);
}