return pascal_case;
}
+std::string operator ""_hash(const char* str, std::size_t) {
+ return std::to_string(Generator::GetHashCode(str));
+}
+
} // namespace tidl
bool IsDelegateType(const BaseType& type);
std::string GetInterfaceNameFromDelegate(const BaseType& type);
- int32_t GetHashCode(std::string_view str) const {
+ static int32_t GetHashCode(std::string_view str) {
int32_t hash = 0;
for (auto& a : str) {
return hash;
}
+ static std::string GetHashCodeStr(std::string_view str) {
+ return std::to_string(GetHashCode(str));
+ }
+
void EnableNamespace(bool enable) {
hasNamespace_ = enable;
}
ChannelType type_ = TYPE_UNKNOWN;
};
+std::string operator ""_hash(const char* str, std::size_t);
+
} // namespace tidl
#endif // IDLC_GENERATOR_H_
ReplaceAll& AddIndent(int indent, bool space = true);
void Out(std::ofstream& stream);
+ std::string ToString() {
+ return str_;
+ }
private:
int GetTagStartPos(int pos);
#include <map>
#include <memory>
#include <mutex>
+#include <set>
#include <string>
#include <vector>
#include <unordered_map>
{"bundle", "Bundle"}, {"file", "String"}};
}
-void CsGeneratorBase::GenStructures(std::ofstream& stream) {
- for (auto& i : GetDocument().GetBlocks()) {
- if (i->GetType() != Block::TYPE_STRUCTURE) continue;
- Structure& st = static_cast<Structure&>(*i);
- GenStructure(stream, st);
- stream << std::endl;
- }
-}
-
-void CsGeneratorBase::GenRemoteException(std::ofstream& stream) {
- stream << CB_REMOTE_EXCEPTION_BASE;
-}
-
-void CsGeneratorBase::GenUsingNamespace(std::ofstream& stream) {
- stream << CB_USING_NAMESPACE;
-}
-
-std::string CsGeneratorBase::GenEnum(const Block& block, int tab_size) {
- std::string str;
- for (const auto& e : block.GetEnums()) {
- str += Tab(tab_size) + "public enum " + e->GetID() + " {" + NLine(1);
- for (auto& f : e->GetFields()) {
- if (f->GetValue().empty()) {
- str += Tab(tab_size + 1) + f->GetID() + "," + NLine(1);
- } else {
- str += Tab(tab_size + 1) + f->GetID() + " = " + f->GetValue() + "," +
- NLine(1);
- }
- }
- str += Tab(tab_size) + "}" + NLine(1);
- }
- return str;
-}
-
-void CsGeneratorBase::GenEnum(std::ofstream& stream, const Block& block,
- int tab_size) {
- stream << GenEnum(block, tab_size);
-}
-
-void CsGeneratorBase::GenStructure(std::ofstream& stream, const Structure& st) {
- std::vector<std::string> v;
-
- stream << Tab(1) << "public class " << st.GetID();
-
- if (st.GetBase() == nullptr) {
- stream << NLine(1);
- } else {
- stream << " : " << st.GetBase()->GetID() << NLine(1);
- }
-
- GenBrace(stream, TAB_SIZE, [&]() {
- GenEnum(stream, st, 2);
- for (const auto& i : st.GetElements()) {
- GenTemplate(
- CB_PROPERTY, stream,
- [&]() -> std::string { return ConvertTypeToString(i->GetType()); },
- [&]() -> std::string { return i->GetID(); });
- if (i->GetType().ToString() == "bundle" ||
- i->GetType().ToString() == "map" ||
- i->GetType().ToString() == "set") {
- v.push_back(i->GetID() + " = " + "new " +
- ConvertTypeToString(i->GetType()) + "()");
- }
- }
-
- GenTemplate(
- CB_CTOR, stream, [&]() -> std::string { return st.GetID(); },
- [&]() -> std::string {
- std::string str;
- for (auto& i : v) {
- str += " " + i + ";\n";
- }
- return str;
- });
- });
-}
-
-void CsGeneratorBase::GenSerializer(std::ofstream& stream,
- const Structure& st) {
- stream << GetSerializer(st);
-}
-
-std::string CsGeneratorBase::GetStructureSerialize(const Structure& st) {
- std::string code;
- std::string type_str;
-
- for (const auto& i : st.GetElements()) {
- code += Tab(4) + "map.Write(\"" + i->GetID() + "\", param." +
- i->GetID() + ");" + NLine(1);
- }
-
- if (st.GetBase() != nullptr)
- code += GetStructureSerialize(*st.GetBase());
-
- return code;
-}
-
-std::string CsGeneratorBase::GetStructureDeserialize(const Structure& st) {
- std::string code;
- std::string type_str;
-
- for (const auto& i : st.GetElements()) {
- auto& t = i->GetType();
- if (t.IsEnumType())
- type_str = "int";
- else
- type_str = GetTypeString(t);
-
- code += Tab(4) + "map.Read(\"" + i->GetID() + "\", out param." +
- i->GetID() + ");" + NLine(1);
- }
-
- if (st.GetBase() != nullptr)
- code += GetStructureDeserialize(*st.GetBase());
-
- return code;
+std::string CsGeneratorBase::GetStructures() {
+ auto structures = [&](auto& r, const auto& i) {
+ if (i->GetType() != Block::Type::TYPE_STRUCTURE) return false;
+
+ auto& st = static_cast<const Structure&>(*i);
+
+ r.Remove("CLASS_BASE", st.GetBase() == nullptr)
+ .Replace("CLASS_ID", st.GetID())
+ .Replace("BASE_CLASS_ID", st.GetBase()->GetID())
+ .Repeat("PROPERTIES", st.GetElements(),
+ [&](auto& r, const auto& i) {
+ r.Replace("S_TYPE", ConvertTypeToString(i->GetType()))
+ .Replace("S_VAR", i->GetID());
+ return true;
+ })
+ .Repeat("PROPERTY_INITS", st.GetElements(),
+ [&](auto& r, const auto& i) {
+ if (i->GetType().ToString() != "bundle" &&
+ i->GetType().ToString() != "map" &&
+ i->GetType().ToString() != "set")
+ return false;
+
+ r.Replace("S_TYPE", ConvertTypeToString(i->GetType()))
+ .Replace("S_VAR", i->GetID());
+ return true;
+ })
+ .Replace("ENUMS", GetEnum(st, 1));
+
+ return true;
+ };
+
+ return ReplaceAll(CB_STRUCTES)
+ .Repeat("STRUCTES", GetDocument().GetBlocks(), structures)
+ .ToString();
+}
+
+std::string CsGeneratorBase::GetRemoteException() {
+ return CB_REMOTE_EXCEPTION_BASE;
+}
+
+std::string CsGeneratorBase::GetEnum(const Block& block, int tab_size) {
+ auto enums = [&](auto& r, const auto& i) {
+ r.Repeat("FIELDS", i->GetFields(), [&](auto& r, const auto& i) {
+ r.Remove("VALUE", i->GetValue().empty())
+ .Remove("NO_VALUE", !i->GetValue().empty())
+ .Replace("FIELD_ID", i->GetID())
+ .Replace("VAL", i->GetValue());
+ return true;
+ }).Replace("ID", i->GetID());
+
+ return true;
+ };
+
+ return AddIndent(
+ TAB_SIZE * tab_size,
+ ReplaceAll(CB_ENUMS).Repeat("ENUMS", block.GetEnums(), enums).ToString());
}
std::string CsGeneratorBase::GetSerializer(const Structure& st) {
- std::string str(ReplaceAll(CB_SERIALIZER)
- .Change("<TYPE>", st.GetID())
- .Change("<BODY>", GetStructureSerialize(st)));
-
- str += ReplaceAll(CB_DESERIALIZER)
- .Change("<TYPE>", st.GetID())
- .Change("<BODY>", GetStructureDeserialize(st));
- return str;
-}
-
-void CsGeneratorBase::GenSerializer(std::ofstream& stream) {
- stream << GetSerializer();
-
- if (GetChannelType() != ChannelType::TYPE_GROUP)
- stream << CB_REMOTE_EXCEPTION_SERIALIZE;
+ auto elements = [&](auto& r, const auto& i) {
+ auto& t = i->GetType();
+ bool default_type = IsDefaultType(&t);
+ bool is_enum = t.IsEnumType();
+
+ r.Remove("USER_TYPE", default_type)
+ .Remove("DEFAULT_TYPE", !default_type)
+ .Replace("FROM_CAST",
+ is_enum ? std::string("(<PARAM_TYPE>)") : std::string())
+ .Replace("ID", i->GetID())
+ .Replace("PARAM_TYPE", ConvertTypeToString(t))
+ .Replace("CAST", is_enum ? std::string("(int)") : std::string())
+ .Replace("PARCEL_TYPE", ConvertTypeToParcelType(&t));
+ return true;
+ };
+
+ return ReplaceAll(CB_STRUCT_SERIALIZER)
+ .RemoveAll("HAS_BASE", !st.GetBase())
+ .Replace("BASE_TYPE",
+ [&]() {
+ if (!st.GetBase()) return std::string();
+
+ return st.GetBase()->GetID();
+ })
+ .Repeat("ELEMENTS_SER", st.GetElements(), elements)
+ .Repeat("ELEMENTS_DER", st.GetElements(), elements)
+ .Replace("TYPE", st.GetID())
+ .ToString();
}
std::string CsGeneratorBase::GetSerializer() {
}
}
-std::string CsGeneratorBase::GenListWrite(const BaseType& type,
- const std::string& type_str) {
- std::string ret;
-
- if (type.ToString() == "map") {
- ret = CB_LIST_MAP_WRITE;
- } else if (type.ToString() == "set") {
- ret = CB_LIST_SET_WRITE;
- } else {
- ret = CB_LIST_WRITE;
- }
-
- return ret;
-}
-
-std::string CsGeneratorBase::GenListRead(const BaseType& type,
- const std::string& type_str) {
- std::string ret;
-
- if (type.ToString() == "map") {
- if (type.GetValueType()->IsEnumType()) {
- ret = ReplaceAll(CB_LIST_MAP_READ)
- .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
- .Change("<VALUE_TYPE>", type.GetValueType()->ToString());
- } else {
- ret =
- ReplaceAll(CB_LIST_MAP_READ)
- .Change("<KEY_TYPE>", ConvertTypeToString(*type.GetKeyType()))
- .Change("<VALUE_TYPE>",
- ConvertTypeToString(*type.GetValueType()));
- }
- } else if (type.ToString() == "set") {
- ret = ReplaceAll(CB_LIST_SET_READ)
- .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetMetaType()));
- } else if (type.GetMetaType()->IsEnumType()) {
- std::string list_method;
- if (type.ToString() == "list")
- list_method = "Last";
-
- ret = ReplaceAll(CB_LIST_READ)
- .Change("<LIST_METHOD>", list_method)
- .Change("<VALUE_TYPE>", type.GetMetaType()->ToString());
- } else {
- std::string list_method;
- if (type.ToString() == "list")
- list_method = "Last";
+bool CsGeneratorBase::IsDefaultType(const BaseType* type) const {
+ if (!type) return true;
- ret = ReplaceAll(CB_LIST_READ)
- .Change("<LIST_METHOD>", list_method)
- .Change("<VALUE_TYPE>", ConvertTypeToString(*type.GetMetaType()));
- }
+ if (type->GetUserDefinedType() == BaseType::UserType::ENUM) return true;
- return ret;
+ return !type->IsUserDefinedType() && type->GetMetaType() == nullptr &&
+ type->GetKeyType() == nullptr;
}
-std::string CsGeneratorBase::GetLengthName(const BaseType& type) {
- if (type.ToString() == "list") {
- return "length";
- } else {
- return "size";
- }
-}
std::string CsGeneratorBase::GetListSerializer(const BaseType& type,
const std::string& type_str) {
- std::string code;
- code = ReplaceAll(CB_LIST_SERIALIZER)
- .Change("<TYPE>", type_str)
- .Change("<LENGTH_NAME>", GetLengthName(type))
- .Change("<WRITE_LIST>", GenListWrite(type, type_str));
-
- code += ReplaceAll(CB_LIST_DESERIALIZER)
- .Change("<TYPE>", type_str)
- .Change("<LENGTH_NAME>", GetLengthName(type))
- .Change("<READ_LIST>", GenListRead(type, type_str));
-
- return code;
-}
-
-void CsGeneratorBase::GenListSerializer(std::ofstream& stream) {
- stream << GetListSerializer();
+ auto* key_type = type.GetKeyType();
+ auto* value_type = type.GetValueType();
+ auto* meta_type = type.GetMetaType();
+
+ return ReplaceAll(CB_LIST_SERIALIZER)
+ .RemoveAll("MAP", type.ToString() != "map")
+ .RemoveAll("SET", type.ToString() != "set")
+ .RemoveAll("LIST", type.ToString() != "list")
+ .RemoveAll("ARRAY", type.ToString() != "array")
+ .RemoveAll("DEFAULT_KEY_TYPE", !IsDefaultType(key_type))
+ .RemoveAll("USER_KEY_TYPE", IsDefaultType(key_type))
+ .RemoveAll("DEFAULT_VALUE_TYPE", !IsDefaultType(value_type))
+ .RemoveAll("USER_VALUE_TYPE", IsDefaultType(value_type))
+ .RemoveAll("DEFAULT_META_TYPE", !IsDefaultType(meta_type))
+ .RemoveAll("USER_META_TYPE", IsDefaultType(meta_type))
+ .Replace("TYPE", type_str)
+ .Replace("CAST", ((value_type && value_type->IsEnumType()) ||
+ (meta_type && meta_type->IsEnumType()))
+ ? std::string("(int)")
+ : std::string())
+ .Replace("MAP_FROM_CAST", (value_type && value_type->IsEnumType())
+ ? std::string("(<VALUE_TYPE>)")
+ : std::string())
+ .Replace("LIST_FROM_CAST", (meta_type && meta_type->IsEnumType())
+ ? std::string("(<META_TYPE>)")
+ : std::string())
+ .Replace("KEY_TYPE", key_type ? ConvertTypeToString(*key_type) : "")
+ .Replace("VALUE_TYPE", value_type ? ConvertTypeToString(*value_type) : "")
+ .Replace("META_TYPE", meta_type ? ConvertTypeToString(*meta_type) : "")
+ .Replace("PARCEL_TYPE_KEY", ConvertTypeToParcelType(key_type))
+ .Replace("PARCEL_TYPE_VALUE", ConvertTypeToParcelType(value_type))
+ .Replace("PARCEL_TYPE_META", ConvertTypeToParcelType(meta_type))
+ .ToString();
}
std::string CsGeneratorBase::GetListSerializer() {
return st_id + "." + type.ToString();
}
- if (type.IsUserDefinedType())
- return type.ToString();
+ if (type.IsUserDefinedType()) return type.ToString();
if (type.GetMetaType() != nullptr)
return type_map_[type.ToString()] + "<" +
return parcel_type_map_[key];
}
-std::string CsGeneratorBase::ConvertTypeToDeserializer(
- const BaseType& type, std::string gen_id, std::string param_id,
- std::string map, bool make_new_type, std::string iface_id) {
- std::string ret;
- std::string new_type = "";
-
- if (make_new_type) {
- if (type.IsUserDefinedType() || type.GetMetaType() != nullptr) {
- if (type.GetMetaType() != nullptr)
- new_type = ConvertTypeToString(type);
- else
- new_type = type.ToString();
- } else {
- new_type = ConvertTypeToString(type);
- }
- }
-
- ret += map + ".Read(" + "\"" + param_id + "\", out ";
- if (IsDelegateType(type)) {
- ret += "CallbackBase del_" + gen_id + ");\n";
- ret += ReplaceAll(CB_DLELGATGE_CREATE)
- .Change("<TYPE>", new_type)
- .Change("<GEN_ID>", gen_id);
- } else {
- if (make_new_type) {
- ret += new_type + " " + gen_id + ");\n";
- } else {
- ret += gen_id + ");\n";
- }
- }
-
- return ret;
-}
+std::string CsGeneratorBase::ConvertTypeToParcelType(const BaseType* type) {
+ if (!type) return "";
-std::string CsGeneratorBase::ConvertTypeToSerializer(std::string gen_id,
- std::string param_id,
- std::string map) {
+ if (type->GetUserDefinedType() == BaseType::UserType::ENUM) return "Int";
- return map + ".Write(\"" + param_id + "\", " + gen_id + ");\n";
+ return ConvertTypeToParcelType(type->ToString());
}
std::string CsGeneratorBase::Tab(int cnt) {
return t;
}
-void CsGeneratorBase::GenWriteBundle(std::ofstream& stream,
- const std::string& id) {
- GenTemplate(
- CB_WRITE_BUNDLE, stream, [&]() -> std::string { return id; },
- [&]() -> std::string { return id; });
-}
-
std::string CsGeneratorBase::GetMethodId(const Interface& iface) {
- return std::string(ReplaceAll(CB_METHOD_IDS).Change("<METHOD_IDS>", [&]() {
- int cnt = 2;
- std::string str;
- for (const auto& i : iface.GetDeclarations()) {
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue;
- str +=
- Tab(4) + i->GetID() + " = " + std::to_string(cnt++) + "," + NLine(1);
- }
- return str;
- }));
-}
+ int cnt = 2;
+ return ReplaceAll(CB_METHOD_IDS)
+ .Repeat(
+ "METHOD_IDS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) {
+ if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+ return false;
-void CsGeneratorBase::GenMethodId(std::ofstream& stream,
- const Interface& iface) {
- stream << GetMethodId(iface);
+ r.Replace("ID", i->GetID()).Replace("VAL", std::to_string(cnt++));
+ return true;
+ })
+ .ToString();
}
-void CsGeneratorBase::GenDelegateId(std::ofstream& stream,
- const Interface& iface) {
- if (HasDelegate(iface) == false)
- return;
+std::string CsGeneratorBase::GetDelegateId(const Interface& iface) {
+ if (HasDelegate(iface) == false) return "";
- stream << Tab(3) << "private enum DelegateId : int" << NLine(1);
- GenBrace(stream, TAB_SIZE * 3, [&]() {
- int cnt = 1;
- for (const auto& i : iface.GetDeclarations()) {
- if (i->GetMethodType() != Declaration::MethodType::DELEGATE) continue;
- stream << Tab(4) << i->GetID() << " = " << cnt++ << "," << NLine(1);
- }
- });
- stream << NLine(1);
-}
+ int cnt = 1;
+ return ReplaceAll(CB_DELEGATE_IDS)
+ .Repeat(
+ "DELEGATE_IDS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) {
+ if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
+ return false;
-void CsGeneratorBase::GenDeclaration(std::ofstream& stream,
- const Declaration& decl, bool semicol) {
- stream << GetDeclaration(decl, semicol);
+ r.Replace("ID", i->GetID()).Replace("VAL", std::to_string(cnt++));
+ return true;
+ })
+ .ToString();
}
std::string CsGeneratorBase::GetDeclaration(const Declaration& decl,
return ret;
}
-void CsGeneratorBase::GenParameters(std::ofstream& stream,
- const Parameters& ps) {
- stream << GetParameters(ps);
-}
-
bool CsGeneratorBase::HasDelegate(const Interface& iface) {
bool found = false;
for (const auto& i : iface.GetDeclarations()) {
return ret;
}
-std::string CsGeneratorBase::GenUnitMapParamType(const BaseType& base_type,
- const std::string& type_str) {
- std::string ret;
- if (base_type.GetUserDefinedType() == BaseType::UserType::DELEGATE)
- ret = "CallbackBase";
- else if (base_type.GetFullName() == "[REMOTE_EXCEPTION]")
- ret = "RemoteException";
- else
- ret = type_str;
-
- return ret;
-}
-
std::string CsGeneratorBase::GenUnitMapParamInit(const Interface& iface,
const BaseType& base_type,
const std::string& type_str) {
std::string ret;
- if (base_type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
+ if (type_str == "CallbackBase") {
ret = "value = new CallbackBase(1, false);";
} else if (type_str == "string") {
ret = "value = new string(\"\");";
- } else if (type_str == "[REMOTE_EXCEPTION]") {
+ } else if (type_str == "RemoteException") {
ret = "value = new RemoteException();";
} else {
ret = "value = new " + type_str + "();";
std::string CsGeneratorBase::GetEnumTypeString(const BaseType& base_type) {
std::string ret = base_type.GetFullName(true);
auto pos = ret.find('.');
- if (pos == std::string::npos)
- return ret;
+ if (pos == std::string::npos) return ret;
std::string block_id = ret.substr(0, pos);
std::string type_id = ret.substr(pos + 1, ret.size() - (pos + 1));
std::string CsGeneratorBase::GetTypeString(const BaseType& base_type) {
std::string ret;
- if (!base_type.IsUserDefinedType() && base_type.GetMetaType() == nullptr &&
- base_type.GetKeyType() == nullptr) {
- if (base_type.ToString() == "file")
+ if (IsDefaultType(&base_type)) {
+ if (base_type.ToString() == "file" || base_type.ToString() == "bundle")
ret = base_type.ToString();
else
ret = ConvertTypeToString(base_type);
const BaseType& base_type) {
std::string ret;
- if (!base_type.IsUserDefinedType() && base_type.GetMetaType() == nullptr &&
- base_type.GetKeyType() == nullptr) {
- ret = "unit.parcel.Write" + ConvertTypeToParcelType(base_type.ToString()) +
- "(value);";
- } else if (base_type.GetUserDefinedType() == BaseType::UserType::ENUM) {
- ret = "unit.parcel.WriteInt((int)value);";
+ if (base_type.GetUserDefinedType() == BaseType::UserType::ENUM) {
+ ret = "parcel.WriteInt((int)value);";
} else if (base_type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
- ret = "CallbackBase.Serialize(unit.parcel, value);";
+ ret = "CallbackBase.Serialize(parcel, value);";
+ } else if (IsDefaultType(&base_type)) {
+ ret = "parcel.Write" + ConvertTypeToParcelType(&base_type) + "(value);";
} else {
- ret = iface.GetID() + ".Serialize(unit.parcel, value);";
+ ret = iface.GetID() + ".Serialize(parcel, value);";
}
return ret;
const std::string& type_str) {
std::string ret;
- if (!base_type.IsUserDefinedType() && base_type.GetMetaType() == nullptr &&
- base_type.GetKeyType() == nullptr) {
- ret = "value = unit.parcel.Read" +
- ConvertTypeToParcelType(base_type.ToString()) + "();";
- } else if (base_type.GetUserDefinedType() == BaseType::UserType::ENUM) {
+ if (base_type.GetUserDefinedType() == BaseType::UserType::ENUM) {
ret = "int enum_int = unit.parcel.ReadInt();" + NLine(1) + Tab(1) +
"value = (" + type_str + ")enum_int;";
} else if (base_type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
ret = "CallbackBase.Deserialize(unit.parcel, value);";
+ } else if (IsDefaultType(&base_type)) {
+ ret = "value = unit.parcel.Read" + ConvertTypeToParcelType(&base_type) +
+ "();";
} else {
ret = iface.GetID() + ".Deserialize(unit.parcel, value);";
}
std::unordered_map<std::string, BaseType>& types, const BaseType& base_type,
const std::string& st_id) {
types[ConvertTypeToString(base_type, st_id)] = base_type;
-
- if (base_type.GetMetaType() != nullptr) {
- AddTypeMap(types, *base_type.GetMetaType(), st_id);
- }
-
- if (base_type.GetKeyType() != nullptr) {
- AddTypeMap(types, *base_type.GetKeyType(), st_id);
-
- if (base_type.GetValueType() != nullptr) {
- AddTypeMap(types, *base_type.GetValueType(), st_id);
- }
- }
}
std::string CsGeneratorBase::GenUnitMapReadWrite(const Interface& iface) {
BaseType bB("bool", "bool");
if (GetChannelType() != ChannelType::TYPE_GROUP) {
- BaseType bE("[REMOTE_EXCEPTION]", "", BaseType::UserType::STRUCTURE);
+ BaseType bCB("CallbackBase", "", BaseType::UserType::DELEGATE);
+ BaseType bE("RemoteException", "", BaseType::UserType::STRUCTURE);
types[bE.GetFullName()] = bE;
+ types[bCB.GetFullName()] = bCB;
}
types[bI.GetFullName()] = bI;
for (const auto& i : iface.GetDeclarations()) {
types[ConvertTypeToString(i->GetType())] = i->GetType();
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE) {
- BaseType del(i->GetID(), "", BaseType::UserType::DELEGATE);
- AddTypeMap(types, del);
- }
for (const auto& j : i->GetParameters()) {
auto& type = j->GetParameterType().GetBaseType();
+ if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE) continue;
AddTypeMap(types, type);
}
}
- for (auto& i : GetDocument().GetBlocks()) {
- if (i->GetType() == Block::TYPE_STRUCTURE) {
- const Structure& st = static_cast<const Structure&>(*i);
- for (const auto& i : st.GetElements()) {
- auto& type = i->GetType();
-
- std::string name = type.GetFullName();
- std::size_t pos = name.find('.');
-
- if (pos == std::string::npos) {
- AddTypeMap(types, type, st.GetID());
- } else {
- std::string st_id = name.substr(0, pos);
- std::string enum_id = name.substr(pos + 1, name.size() - (pos + 1));
- BaseType enum_type(enum_id, "", BaseType::UserType::ENUM);
- AddTypeMap(types, enum_type, st_id);
- }
- }
- }
- }
-
types.erase("void");
std::string code = "";
else
unit_type = GetTypeString(base_type);
- code +=
- ReplaceAll(CB_UNITMAP_READ_READ_BASE)
- .Change("<PARAM_TYPE>", GenUnitMapParamType(base_type, type_str))
- .Change("<PARAM_INIT>",
- GenUnitMapParamInit(iface, base_type, type_str))
- .Change("<UNIT_TYPE>", unit_type)
- .Change("<UINT_READ>",
- GenUnitMaUintRead(iface, base_type, type_str));
+ if (base_type.ToString() == "RemoteException")
+ unit_type = "remote_exception";
+
code +=
ReplaceAll(CB_UNITMAP_READ_WRITE_BASE)
- .Change("<PARAM_TYPE>", GenUnitMapParamType(base_type, type_str))
- .Change("<UNIT_TYPE>", unit_type)
- .Change("<UINT_WRITE>", GenUnitMaUintWrite(iface, base_type));
+ .Replace("PARAM_TYPE", type_str)
+ .Replace("PARAM_INIT",
+ GenUnitMapParamInit(iface, base_type, type_str))
+ .Replace("UNIT_TYPE", unit_type)
+ .Replace("HASH_UNIT_TYPE", GetHashCodeStr(unit_type))
+ .Replace("UINT_READ", GenUnitMaUintRead(iface, base_type, type_str))
+ .Replace("UINT_WRITE", GenUnitMaUintWrite(iface, base_type));
}
return AddIndent(TAB_SIZE, code);
}
-void CsGeneratorBase::GenUnitMap(std::ofstream& stream, const Interface& iface,
- int tabSize) {
- stream << GetUnitMap(iface, tabSize);
-}
-
std::string CsGeneratorBase::GetUnitMap(const Interface& iface, int tabSize) {
- std::string ret_string(CB_UNIT_BASE);
- ret_string += ReplaceAll(CB_UNITMAP_BASE)
- .Change("<PARAM_READ_WRITE>", GenUnitMapReadWrite(iface));
- return AddIndent(TAB_SIZE * tabSize, ret_string);
-}
-
-void CsGeneratorBase::GenCallbacks(std::ofstream& stream,
- const Interface& iface, bool is_proxy) {
- if (HasDelegate(iface) == false)
- return;
- stream << CB_CALLBACK_BASE;
-
- for (const auto& i : iface.GetDeclarations()) {
- if (i->GetMethodType() != Declaration::MethodType::DELEGATE)
- continue;
- GenCallback(stream, *i, iface.GetID(), is_proxy);
- }
+ std::string ret = ReplaceAll(CB_UNITMAP_BASE)
+ .Replace("PARAM_READ_WRITE", GenUnitMapReadWrite(iface))
+ .ToString();
+ return AddIndent(TAB_SIZE * tabSize, ret);
}
-void CsGeneratorBase::GenCallback(std::ofstream& stream,
- const Declaration& decl,
- const std::string& id, bool is_proxy) {
- stream << Tab(3) << "public sealed class " << decl.GetID()
- << " : CallbackBase" << NLine(1);
- GenBrace(stream, TAB_SIZE * 3, [&]() {
- if (is_proxy) {
- GenTemplate(
- CB_CALLBACK_CTOR_PROXY, stream,
- [&]() -> std::string { return decl.GetID(); },
- [&]() -> std::string { return decl.GetID(); });
- } else {
- GenTemplate(
- CB_CALLBACK_CTOR_STUB, stream,
- [&]() -> std::string { return decl.GetID(); },
- [&]() -> std::string { return decl.GetID(); },
- [&]() -> std::string { return decl.GetID(); });
- }
- stream << NLine(1);
-
- if (is_proxy) {
- stream << Tab(4) << "public delegate void Callback(";
- GenParameters(stream, decl.GetParameters());
- stream << ");" << NLine(1);
- stream << Tab(4) << "public event Callback Received;" << NLine(2);
- GenReceivedEvent(stream, decl, id);
- } else {
- stream << CB_CALLBACK_STUB_MEMBERS;
- GenInvokeMethod(stream, decl, id);
- }
- });
- stream << NLine(1);
-}
+std::string CsGeneratorBase::GetCallbacks(const Interface& iface,
+ bool is_proxy) {
+ auto callbacks = [&](auto& r, const auto& i) {
+ if (i->GetMethodType() != Declaration::MethodType::DELEGATE) return false;
-void CsGeneratorBase::GenReceivedEvent(std::ofstream& stream,
- const Declaration& decl,
- const std::string& id) {
- stream << Tab(4) << "internal override void OnReceivedEvent(UnitMap map)"
- << NLine(1);
- GenBrace(stream, TAB_SIZE * 4, [&]() {
int cnt = 1;
- for (const auto& i : decl.GetParameters()) {
- std::string v = "param" + std::to_string(cnt);
- std::string c = ConvertTypeToDeserializer(
- i->GetParameterType().GetBaseType(), v, i->GetID(), "map", true, id);
- stream << AddIndent(TAB_SIZE * 5, c);
- cnt++;
- }
+ auto serializer = [&](auto& r, const auto& i) {
+ r.Replace("HASH_ID", GetHashCodeStr(i->GetID()))
+ .Replace("ID", i->GetID());
+ return true;
+ };
+
+ auto params = [&]() {
+ std::string m;
+ int cnt = 1;
+ for (const auto& j : i->GetParameters()) {
+ (void)j;
+ if (cnt != 1) {
+ m += ", ";
+ }
- cnt = 1;
- stream << NLine(1) << Tab(5) << "Received?.Invoke(";
- for (auto i = decl.GetParameters().begin(); i != decl.GetParameters().end();
- ++i) {
- if (cnt != 1) {
- stream << ", ";
+ m += "param" + std::to_string(cnt);
+ cnt++;
}
- std::string v = "param" + std::to_string(cnt);
- stream << v;
- cnt++;
- }
- stream << ");" << NLine(1);
- });
- stream << NLine(1);
-}
-
-void CsGeneratorBase::GenInvokeMethod(std::ofstream& stream,
- const Declaration& decl,
- const std::string& id) {
- GenTemplate(
- CB_CALLBACK_INVOKE_METHOD, stream,
- [&]() -> std::string { return GetParameters(decl.GetParameters()); },
- [&]() -> std::string {
- std::string m;
- for (const auto& i : decl.GetParameters()) {
- m += ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
- }
- return AddIndent(TAB_SIZE * 5, m);
- });
-}
-void CsGeneratorBase::GenVersion(std::ofstream& stream) {
- GenTemplate(::cs_cb_version, stream,
- [&]() -> std::string { return FULLVER; });
- stream << NLine(1);
+ return m;
+ };
+
+ auto param_decl = [&](auto& r, const auto& i) {
+ std::string v = "param" + std::to_string(cnt++);
+ r.Replace("HASH_PARAM", GetHashCodeStr(i->GetID()))
+ .Replace("PARAM", i->GetID())
+ .Replace("PARAM_TYPE",
+ ConvertTypeToString(i->GetParameterType().GetBaseType()))
+ .Replace("VAL", v);
+
+ return true;
+ };
+
+ r.Remove("PROXY", !is_proxy)
+ .Remove("STUB", is_proxy)
+ .Repeat("PARAMS_WRITE", i->GetParameters(), serializer)
+ .Repeat("PARAMS_DECL", i->GetParameters(), param_decl)
+ .Replace("CLASS_ID", i->GetID())
+ .Replace("CALLBACK_PARMS", GetParameters(i->GetParameters()))
+ .Replace("PARAMS", params)
+ .Replace("HASH_METHOD", "[METHOD]"_hash)
+ .Replace("HASH_DELEGATE", "delegate"_hash);
+ return true;
+ };
+
+ return ReplaceAll(CB_CALLBACK_BASE)
+ .Repeat("CALLBACKS", iface.GetDeclarations(), callbacks)
+ .ToString();
+}
+
+std::string CsGeneratorBase::GetRemoteExceptionSerializer() {
+ return CB_REMOTE_EXCEPTION_SERIALIZE;
}
} // namespace version2
explicit CsGeneratorBase(std::shared_ptr<Document> doc);
virtual ~CsGeneratorBase() = default;
- void GenVersion(std::ofstream& stream);
- void GenStructures(std::ofstream& stream);
- void GenStructure(std::ofstream& stream, const Structure& st);
- void GenSerializer(std::ofstream& stream);
+ std::string GetStructures();
std::string GetSerializer();
- void GenSerializer(std::ofstream& stream, const Structure& st);
- std::string GetSerializer(const Structure& st);
- void GenListSerializer(std::ofstream& stream);
std::string GetListSerializer();
- std::string GetListSerializer(const BaseType& type,
- const std::string& st_id = "");
- void GenMethodId(std::ofstream& stream, const Interface& iface);
+ std::string GetRemoteExceptionSerializer();
std::string GetMethodId(const Interface& iface);
- void GenDelegateId(std::ofstream& stream, const Interface& iface);
- void GenDeclaration(std::ofstream& stream, const Declaration& decl,
- bool semicol = true);
+ std::string GetDelegateId(const Interface& iface);
std::string GetDeclaration(const Declaration& decl, bool semicol = true);
- void GenParameters(std::ofstream& stream, const Parameters& ps);
- void GenCallbacks(std::ofstream& stream, const Interface& iface,
- bool is_proxy);
+ std::string GetCallbacks(const Interface& iface, bool is_proxy);
std::string ConvertTypeToString(const BaseType& type,
const std::string& st_id = "");
- std::string ConvertTypeToDeserializer(const BaseType& type,
- std::string gen_id,
- std::string parma_id, std::string map,
- bool make_new_type = true,
- const std::string iface_id = "");
- std::string ConvertTypeToSerializer(std::string gen_id, std::string param_id,
- std::string map);
std::string ConvertTypeToParcelType(const std::string& key);
+ std::string ConvertTypeToParcelType(const BaseType* type);
std::string GetParameters(const Parameters& ps);
std::string Tab(int cnt);
std::string NLine(int cnt);
- void GenUnitMap(std::ofstream& stream, const Interface& iface, int tabSize);
std::string GetUnitMap(const Interface& iface, int tabSize);
std::string GetTypeString(const BaseType& base_type);
- void GenUsingNamespace(std::ofstream& stream);
- void GenEnum(std::ofstream& stream, const Block& block, int tab);
- std::string GenEnum(const Block& block, int tab_size);
+ std::string GetEnum(const Block& block, int tab_size);
bool HasDelegate(const Interface& iface);
- void GenRemoteException(std::ofstream& stream);
+ std::string GetRemoteException();
protected:
const int TAB_SIZE = 4;
private:
+ std::string GetSerializer(const Structure& st);
+ std::string GetListSerializer(const BaseType& type,
+ const std::string& st_id = "");
std::string GetEnumTypeString(const BaseType& base_type);
void AddTypeMap(std::unordered_map<std::string, BaseType>& types,
const BaseType& base_type, const std::string& st_id = "");
void GenWriteBundle(std::ofstream& stream, const std::string& id);
void AddSerializerList(const BaseType& type, const std::string& st_id = "");
- void GenCallback(std::ofstream& stream, const Declaration& decl,
- const std::string& id, bool is_proxy);
void GenReceivedEvent(std::ofstream& stream, const Declaration& decl,
const std::string& id);
- void GenInvokeMethod(std::ofstream& stream, const Declaration& decl,
- const std::string& id);
std::string GenUnitMapReadWrite(const Interface& iface);
- std::string GenUnitMapParamType(const BaseType& base_type,
- const std::string& type_str);
std::string GenUnitMaUintRead(const Interface& iface,
const BaseType& base_type,
const std::string& type_str);
std::string GenUnitMaUintWrite(const Interface& iface,
const BaseType& base_type);
- std::string GenListWrite(const BaseType& type, const std::string& type_str);
- std::string GenListRead(const BaseType& type, const std::string& type_str);
- std::string GetLengthName(const BaseType& type);
std::string GenUnitMapParamInit(const Interface& iface,
const BaseType& base_type,
const std::string& type_str);
- std::string GetStructureSerialize(const Structure& st);
- std::string GetStructureDeserialize(const Structure& st);
std::string GetStructTypeString(const BaseType& base_type);
std::string GetStructTypeString(const Structure& st);
+ bool IsDefaultType(const BaseType* type) const;
private:
std::map<std::string, std::string> type_map_;
#ifndef IDLC_CS_GEN_VERSION2_CS_GENRATOR_BASE_CB_H_
#define IDLC_CS_GEN_VERSION2_CS_GENRATOR_BASE_CB_H_
-const char CB_USING_NAMESPACE[] =
+const char CB_STRUCTES[] =
R"__cs_cb(
-using System;
-using System.Collections.Generic;
-using System.Collections.Concurrent;
-using System.Threading;
-using System.Reflection;
-using Tizen.Applications;
-using Tizen.Applications.RPCPort;
+<STRUCTES*>
+public class <CLASS_ID><CLASS_BASE?> : <BASE_CLASS_ID></CLASS_BASE?>
-)__cs_cb";
-
-const char CB_REMOTE_EXCEPTION_BASE[] =
-R"__cs_cb(
- public class RemoteException : Exception
- {
- public RemoteException()
- {
- }
-
- public RemoteException(string message)
- {
- this.Message = message;
- }
+{
+ <ENUMS>
- public RemoteException(string message, int cause)
- {
- this.Message = message;
- this.Cause = cause;
- }
+ <PROPERTIES*>
+ public <S_TYPE> <S_VAR>;
+ </PROPERTIES*>
- public new string Message { get; set; }
- public int Cause { get; set; }
+ public <CLASS_ID>()
+ {
+ <PROPERTY_INITS*>
+ <S_VAR> = new <S_TYPE>();
+ </PROPERTY_INITS*>
}
+}
-)__cs_cb";
+</STRUCTES*>
-const char CB_REMOTE_EXCEPTION_SERIALIZE[] =
-R"__cs_cb(
- private static void Serialize(Parcel h, RemoteException param)
- {
- UnitMap map = new UnitMap();
- map.Write("cause", param.Cause);
- map.Write("message", param.Message);
-
- map.Serialize(h);
- }
-
- private static void Deserialize(Parcel h, RemoteException param)
- {
- UnitMap map = new UnitMap();
- map.Deserialize(h);
- map.Read("cause", out int cause);
- param.Cause = cause;
- map.Read("message", out string message);
- param.Message = message;
- }
)__cs_cb";
-const char CB_UNIT_BASE[] =
+const char CB_REMOTE_EXCEPTION_BASE[] =
R"__cs_cb(
-internal class Unit
+public class RemoteException : Exception
{
- internal string name;
- internal string type;
- internal Parcel parcel;
- internal Unit()
+ public RemoteException()
{
- parcel = new Parcel(false);
}
- internal void Serialize(Parcel h)
+ public RemoteException(string message)
{
- h.WriteString(name);
- h.WriteString(type);
-
- byte[] raw = parcel.ToBytes();
- h.WriteArrayCount(raw.Length & int.MaxValue);
- h.Write(raw);
+ this.Message = message;
}
- internal void Deserialize(Parcel h)
+ public RemoteException(string message, int cause)
{
- name = h.ReadString();
- type = h.ReadString();
-
- int size = h.ReadArrayCount();
- byte[] raw = h.Read(size);
- parcel.Write(raw);
+ this.Message = message;
+ this.Cause = cause;
}
+
+ public new string Message { get; set; }
+ public int Cause { get; set; }
}
+
)__cs_cb";
+const char CB_REMOTE_EXCEPTION_SERIALIZE[] =
+R"__cs_cb(
+private static void Serialize(Parcel h, RemoteException param)
+{
+ h.WriteInt(param.Cause);
+ h.WriteString(param.Message);
+}
+
+private static void Deserialize(Parcel h, RemoteException param)
+{
+ param.Cause = h.ReadInt();
+ param.Message = h.ReadString();
+}
+)__cs_cb";
-const char CB_UNITMAP_READ_READ_BASE[] =
+const char CB_UNITMAP_READ_WRITE_BASE[] =
R"__cs_cb(
-internal void Read(string name, out <PARAM_TYPE> value)
+internal void Read(int name, out <PARAM_TYPE> value)
{
<PARAM_INIT>
if (map.ContainsKey(name) == false)
}
Unit unit = map[name];
- if (unit.type != "<UNIT_TYPE>")
+ if (unit.type != <HASH_UNIT_TYPE> /*<UNIT_TYPE>*/)
{
Tizen.Log.Error("RPC_PORT", "type is not <UNIT_TYPE> : " + unit.type);
return;
}
<UINT_READ>
}
-)__cs_cb";
-const char CB_UNITMAP_READ_WRITE_BASE[] =
-R"__cs_cb(
-internal void Write(string name, <PARAM_TYPE> value)
+internal void Write(int name, <PARAM_TYPE> value)
{
Unit unit = new Unit();
unit.name = name;
- unit.type = "<UNIT_TYPE>";
- <UINT_WRITE>
+ unit.type = <HASH_UNIT_TYPE>; /*<UNIT_TYPE>*/
+ unit.cmds.Add((parcel) =>
+ {
+ <UINT_WRITE>
+ });
+
map[name] = unit;
}
)__cs_cb";
const char CB_UNITMAP_BASE[] =
R"__cs_cb(
+internal class Unit
+{
+ internal int name;
+ internal int type;
+ internal Parcel parcel;
+ internal List<Action<Parcel>> cmds = new List<Action<Parcel>>();
+ internal Unit()
+ {
+ }
+
+ internal void Serialize(Parcel h)
+ {
+ h.WriteInt(name);
+ h.WriteInt(type);
+
+ var sizePos = h.GetDataSize();
+ h.Reserve(4);
+
+ foreach(var cb in cmds)
+ {
+ cb(h);
+ }
+
+ var curPos = h.GetDataSize();
+ var size = curPos - sizePos - 4;
+ h.SetDataSize(sizePos);
+ h.WriteInt((int)size);
+ h.SetDataSize(curPos);
+ }
+
+ internal void Deserialize(Parcel h)
+ {
+ name = h.ReadInt();
+ type = h.ReadInt();
+ var size = h.ReadArrayCount();
+ if (size == 0)
+ return;
+
+ var startPos = h.GetReader();
+ parcel = new Parcel(h, startPos, (uint)size);
+ parcel.Reserve((uint)size);
+ h.SetReader(startPos + (uint)size);
+ }
+}
+
internal class UnitMap
{
- internal Dictionary<string, Unit> map;
+ internal Dictionary<int, Unit> map;
internal UnitMap()
{
- map = new Dictionary<string, Unit>();
+ map = new Dictionary<int, Unit>();
}
internal void Serialize(Parcel parcel)
{
parcel.WriteArrayCount(map.Count & int.MaxValue);
- foreach (Unit unit in map.Values) {
+ foreach (Unit unit in map.Values)
+ {
unit.Serialize(parcel);
}
}
internal void Deserialize(Parcel parcel)
{
int size = parcel.ReadArrayCount();
+ parcel.Pin();
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++)
+ {
Unit unit = new Unit();
unit.Deserialize(parcel);
}
}
- internal bool ContainsName(string name)
+ internal bool ContainsName(int name)
{
return map.ContainsKey(name);
}
+
<PARAM_READ_WRITE>
}
)__cs_cb";
const char CB_CALLBACK_BASE[] =
R"__cs_cb(
- public class CallbackBase
- {
- internal int Id;
- internal int SeqId;
- internal bool Once;
- private static volatile int _seqNum = 0;
-
- public string Tag
- {
- get
- {
- return Id.ToString() + "::" + SeqId.ToString();
- }
- }
-
- public CallbackBase(int delegateId, bool once)
- {
- Id = delegateId;
- SeqId = _seqNum++;
- Once = once;
- }
-
- internal virtual void OnReceivedEvent(UnitMap map) {}
-
- internal static void Serialize(Parcel h, CallbackBase param)
- {
- UnitMap map = new UnitMap();
- map.Write("id", param.Id);
- map.Write("seq_id", param.SeqId);
- map.Write("once", param.Once);
- map.Serialize(h);
- }
-
- internal static void Deserialize(Parcel h, CallbackBase param)
- {
- UnitMap map = new UnitMap();
- map.Deserialize(h);
- map.Read("id", out param.Id);
- map.Read("seq_id", out param.SeqId);
- map.Read("once", out param.Once);
- }
- }
+public class CallbackBase
+{
+ internal int Id;
+ internal int SeqId;
+ internal bool Once;
+ private static volatile int _seqNum = 0;
-)__cs_cb";
+ public string Tag
+ {
+ get
+ {
+ return Id.ToString() + "::" + SeqId.ToString();
+ }
+ }
-const char CB_CALLBACK_CTOR_PROXY[] =
-R"__cs_cb( public $$(bool once = false) : base((int)DelegateId.$$, once)
- {
- }
-)__cs_cb";
+ public CallbackBase(int delegateId, bool once)
+ {
+ Id = delegateId;
+ SeqId = _seqNum++;
+ Once = once;
+ }
-const char CB_CALLBACK_CTOR_STUB[] =
-R"__cs_cb( internal $$(Port port, WeakReference service) : base((int)DelegateId.$$, false)
- {
- _port = port;
- _service = service;
- }
-
- internal $$(Port port, WeakReference service, CallbackBase cb) : base(cb.Id, cb.Once)
- {
- _port = port;
- _service = service;
- SeqId = cb.SeqId;
- }
-)__cs_cb";
+ internal virtual void OnReceivedEvent(UnitMap map) {}
-const char CB_CALLBACK_STUB_MEMBERS[] =
-R"__cs_cb( private Port _port;
- private WeakReference _service;
- private bool _valid = true;
- internal LocalExecution _lem;
-)__cs_cb";
+ internal static void Serialize(Parcel h, CallbackBase param)
+ {
+ h.WriteInt(param.Id);
+ h.WriteInt(param.SeqId);
+ h.WriteBool(param.Once);
+ }
-const char CB_CALLBACK_INVOKE_METHOD[] =
-R"__cs_cb(
- public void Invoke($$)
- {
- if (_port == null && _lem == null)
- throw new NotConnectedSocketException();
- if (!_service.IsAlive)
- throw new InvalidProtocolException();
- if (Once && !_valid)
- throw new InvalidCallbackException();
- if (_lem != null && _lem._online == false)
- throw new NotConnectedSocketException();
-
- var p = new Parcel();
- UnitMap map = new UnitMap();
-
- map.Write("[METHOD]", (int)MethodId.__Callback);
- map.Write("delegate", this);
-
-$$
- map.Serialize(p);
-
- if (_lem != null)
- {
- _lem.SendRequest(p);
- } else
- {
- // Send
- p.Send(_port);
- }
- _valid = false;
- }
-)__cs_cb";
+ internal static void Deserialize(Parcel h, CallbackBase param)
+ {
+ param.Id = h.ReadInt();
+ param.SeqId = h.ReadInt();
+ param.Once = h.ReadBool();
+ }
+}
-const char CB_PROPERTY[] = R"__cs_cb( public $$ $$;
-)__cs_cb";
+<CALLBACKS*>
+public sealed class <CLASS_ID> : CallbackBase
+{
+ <PROXY?>
+ public <CLASS_ID>(bool once = false) : base((int)DelegateId.<CLASS_ID>, once)
+ {
+ }
-const char CB_CTOR[] = R"__cs_cb(
- public $$()
+ public delegate void Callback(<CALLBACK_PARMS>);
+ public event Callback Received;
+
+ internal override void OnReceivedEvent(UnitMap map)
+ {
+ <PARAMS_DECL*>
+ map.Read(<HASH_PARAM> /*<PARAM>*/, out <PARAM_TYPE> <VAL>);
+ </PARAMS_DECL*>
+
+ Received?.Invoke(<PARAMS>);
+ }
+ </PROXY?>
+
+ <STUB?>
+ internal <CLASS_ID>(Port port, WeakReference service) : base((int)DelegateId.<CLASS_ID>, false)
+ {
+ _port = port;
+ _service = service;
+ }
+
+ internal <CLASS_ID>(Port port, WeakReference service, CallbackBase cb) : base(cb.Id, cb.Once)
+ {
+ _port = port;
+ _service = service;
+ SeqId = cb.SeqId;
+ }
+
+ private Port _port;
+ private WeakReference _service;
+ private bool _valid = true;
+ internal LocalExecution _lem;
+
+ public void Invoke(<CALLBACK_PARMS>)
+ {
+ if (_port == null && _lem == null)
+ throw new NotConnectedSocketException();
+ if (!_service.IsAlive)
+ throw new InvalidProtocolException();
+ if (Once && !_valid)
+ throw new InvalidCallbackException();
+ if (_lem != null && _lem._online == false)
+ throw new NotConnectedSocketException();
+
+ var p = new Parcel();
+ UnitMap map = new UnitMap();
+ int methodId = (int)MethodId.__Callback;
+
+ map.Write(<HASH_METHOD> /*[METHOD]*/, methodId);
+ map.Write(<HASH_DELEGATE> /*delegate*/, this);
+ <PARAMS_WRITE*>
+ map.Write(<HASH_ID> /*<ID>*/, <ID>);
+ </PARAMS_WRITE*>
+ map.Serialize(p);
+
+ if (_lem != null)
+ {
+ _lem.SendRequest(p);
+ } else
{
-$$
+ // Send
+ p.Send(_port);
}
-)__cs_cb";
-
-const char CB_DLELGATGE_CREATE[] =
-R"__cs_cb(
-Port cb_port;
-if (b._lem != null)
- cb_port = null;
-else
- cb_port = GetPort(Port.Type.Callback, instance);
+ _valid = false;
+ }
+ </STUB?>
+}
-<TYPE> <GEN_ID> = new <TYPE>(cb_port, new WeakReference(b), del_<GEN_ID>);
+</CALLBACKS*>
-if (b._lem != null)
- param3._lem = b._lem;
)__cs_cb";
-
-const char CB_WRITE_BUNDLE[] =
+const char CB_ENUMS[] =
R"__cs_cb(
- if (param.$$ != null)
- {
- h.WriteBundle(param.$$);
- }
- else
- {
- h.WriteBundle(new Bundle());
- }
+<ENUMS*>
+public enum <ID>
+{
+ <FIELDS*>
+ <VALUE?>
+ <FIELD_ID> = <VAL>,
+ </VALUE?>
+ <NO_VALUE?>
+ <FIELD_ID>,
+ </NO_VALUE?>
+
+ </FIELDS*>
+}
+
+</ENUMS*>
)__cs_cb";
const char CB_METHOD_IDS[] =
R"__cs_cb(
- private enum MethodId : int
- {
- __Result = 0,
- __Callback = 1,
-<METHOD_IDS>
- }
+private enum MethodId : int
+{
+ __Result = 0,
+ __Callback = 1,
+ <METHOD_IDS*>
+ <ID> = <VAL>,
+ </METHOD_IDS*>
+}
)__cs_cb";
-const char CB_SERIALIZER[] =
+const char CB_DELEGATE_IDS[] =
R"__cs_cb(
- private static void Serialize(Parcel h, <TYPE> param)
- {
- UnitMap map = new UnitMap();
-<BODY>
- map.Serialize(h);
- }
+private enum DelegateId : int
+{
+ <DELEGATE_IDS*>
+ <ID> = <VAL>,
+ </DELEGATE_IDS*>
+}
)__cs_cb";
-const char CB_DESERIALIZER[] =
+const char CB_STRUCT_SERIALIZER[] =
R"__cs_cb(
- private static void Deserialize(Parcel h, <TYPE> param)
- {
- UnitMap map = new UnitMap();
- map.Deserialize(h);
-<BODY>
- }
-)__cs_cb";
-
-constexpr const char CB_LIST_MAP_WRITE[] =
-R"__cs_cb( map.Write("key-" + index.ToString(), i.Key);
- map.Write("value-" + index.ToString(), i.Value);)__cs_cb";
-
-constexpr const char CB_LIST_SET_WRITE[] =
-R"__cs_cb( map.Write("key-" + index.ToString(), i);)__cs_cb";
-
-constexpr const char CB_LIST_WRITE[] =
-R"__cs_cb( map.Write(index.ToString(), i);)__cs_cb";
-
-constexpr const char CB_LIST_MAP_READ[] =
-R"__cs_cb( map.Read("key-" + index.ToString(), out <KEY_TYPE> key);
- map.Read("value-" + index.ToString(), out <VALUE_TYPE> value);
- param[key] = value;)__cs_cb";
-
-constexpr const char CB_LIST_SET_READ[] =
-R"__cs_cb( map.Read("key-" + index.ToString(), out <VALUE_TYPE> value);
- param.Add(value);)__cs_cb";
+private static void Serialize(Parcel h, <TYPE> param)
+{
+ <HAS_BASE?>
+ Serialize(h, (<BASE_TYPE>)param);
+ </HAS_BASE?>
+ <ELEMENTS_SER*>
+ <USER_TYPE?>
+ Serialize(h, param.<ID>);
+ </USER_TYPE?>
+ <DEFAULT_TYPE?>
+ h.Write<PARCEL_TYPE>(<CAST>param.<ID>);
+ </DEFAULT_TYPE?>
+ </ELEMENTS_SER*>
+}
-constexpr const char CB_LIST_READ[] =
-R"__cs_cb( map.Read("key-" + index.ToString(), out <VALUE_TYPE> value);
- param.Add<LIST_METHOD>(value);)__cs_cb";
+private static void Deserialize(Parcel h, <TYPE> param)
+{
+ <HAS_BASE?>
+ Deserialize(h, (<BASE_TYPE>)param);
+ </HAS_BASE?>
+ <ELEMENTS_DER*>
+ <USER_TYPE?>
+ param.<ID> = new <PARAM_TYPE>();
+ Deserialize(h, param.<ID>);
+ </USER_TYPE?>
+ <DEFAULT_TYPE?>
+ var <ID> = h.Read<PARCEL_TYPE>();
+ param.<ID> = <FROM_CAST><ID>;
+ </DEFAULT_TYPE?>
+ </ELEMENTS_DER*>
+}
+)__cs_cb";
const char CB_LIST_SERIALIZER[] =
R"__cs_cb(
- private static void Serialize(Parcel h, <TYPE> param)
- {
- UnitMap map = new UnitMap();
- map.Write("<LENGTH_NAME>", param.Count & int.MaxValue);
- int index = 0;
- foreach (var i in param)
- {
-<WRITE_LIST>
- index++;
- }
- map.Serialize(h);
- }
-)__cs_cb";
+private static void Serialize(Parcel h, <TYPE> param)
+{
+ h.WriteArrayCount(param.Count);
+ foreach (var i in param)
+ {
+ <MAP?>
+ <DEFAULT_KEY_TYPE?>
+ h.Write<PARCEL_TYPE_KEY>(i.Key);
+ </DEFAULT_KEY_TYPE?>
+ <USER_KEY_TYPE?>
+ Serialize(h, i.Key);
+ </USER_KEY_TYPE?>
+ <DEFAULT_VALUE_TYPE?>
+ h.Write<PARCEL_TYPE_VALUE>(<CAST>i.Value);
+ </DEFAULT_VALUE_TYPE?>
+ <USER_VALUE_TYPE?>
+ Serialize(h, i.Value);
+ </USER_VALUE_TYPE?>
+ </MAP?>
+ <SET?>
+ <DEFAULT_META_TYPE?>
+ h.Write<PARCEL_TYPE_META>(i);
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ Serialize(h, i);
+ </USER_META_TYPE?>
+ </SET?>
+ <LIST?>
+ <DEFAULT_META_TYPE?>
+ h.Write<PARCEL_TYPE_META>(<CAST>i);
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ Serialize(h, i);
+ </USER_META_TYPE?>
+ </LIST?>
+ <ARRAY?>
+ <DEFAULT_META_TYPE?>
+ h.Write<PARCEL_TYPE_META>(<CAST>i);
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ Serialize(h, i);
+ </USER_META_TYPE?>
+ </ARRAY?>
+ }
+}
-const char CB_LIST_DESERIALIZER[] =
-R"__cs_cb(
- private static void Deserialize(Parcel h, <TYPE> param)
- {
- UnitMap map = new UnitMap();
- map.Deserialize(h);
- map.Read("<LENGTH_NAME>", out int length);
- for (int index = 0; index < length; index++)
- {
-<READ_LIST>
- }
- }
+private static void Deserialize(Parcel h, <TYPE> param)
+{
+ int l = h.ReadArrayCount();
+ for (int i = 0; i < l; i++)
+ {
+ <MAP?>
+ <DEFAULT_KEY_TYPE?>
+ var k = h.Read<PARCEL_TYPE_KEY>();
+ </DEFAULT_KEY_TYPE?>
+ <USER_KEY_TYPE?>
+ var k = new <KEY_TYPE>();
+ Deserialize(h, k);
+ </USER_KEY_TYPE?>
+ <DEFAULT_VALUE_TYPE?>
+ var v = <MAP_FROM_CAST>h.Read<PARCEL_TYPE_VALUE>();
+ </DEFAULT_VALUE_TYPE?>
+ <USER_VALUE_TYPE?>
+ var v = new <VALUE_TYPE>();
+ Deserialize(h, v);
+ </USER_VALUE_TYPE?>
+ param.Add(k, v);
+ </MAP?>
+ <SET?>
+ <DEFAULT_META_TYPE?>
+ var k = h.Read<PARCEL_TYPE_META>();
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ var k = new <META_TYPE>();
+ Deserialize(h, k);
+ </USER_META_TYPE?>
+ param.Add(k);
+ </SET?>
+ <LIST?>
+ <DEFAULT_META_TYPE?>
+ var k = <LIST_FROM_CAST>h.Read<PARCEL_TYPE_META>();
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ var k = new <META_TYPE>();
+ Deserialize(h, k);
+ </USER_META_TYPE?>
+ param.AddLast(k);
+ </LIST?>
+ <ARRAY?>
+ <DEFAULT_META_TYPE?>
+ var k = <LIST_FROM_CAST>h.Read<PARCEL_TYPE_META>();
+ </DEFAULT_META_TYPE?>
+ <USER_META_TYPE?>
+ var k = new <META_TYPE>();
+ Deserialize(h, k);
+ </USER_META_TYPE?>
+ param.Add(k);
+ </ARRAY?>
+ }
+}
)__cs_cb";
void CsGroupGen::OnInitGen(std::ofstream& stream) {
SetChannelType(Generator::ChannelType::TYPE_GROUP);
- GenVersion(stream);
- GenUsingNamespace(stream);
- stream << CB_USING_NAMESPACE_GROUP;
-
- GenNamespace(stream);
+ auto interfaces = [&](auto& r, const auto& i) {
+ if (i->GetType() != Block::TYPE_INTERFACE) return false;
+ auto& iface = static_cast<const Interface&>(*i);
+
+ r.Replace("ENUMS", GetEnum(iface, 4))
+ .Replace("UNITMAP", GetUnitMap(iface, 4))
+ .Replace("METHOD_IDS", AddIndent(TAB_SIZE * 4, GetMethodId(iface)))
+ .Replace("SERIALIZER", AddIndent(TAB_SIZE * 4, GetSerializer()))
+ .Replace("LIST_SERIALIZER",
+ AddIndent(TAB_SIZE * 4, GetListSerializer()))
+ .Repeat("METHODS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) { return RepeatMethods(r, i); })
+ .Repeat("DISPATCHERS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) { return RepeatDispatchers(r, i); })
+ .Replace("CLS_NAME", iface.GetID());
+
+ return true;
+ };
+
+ ReplaceAll(CB_MAIN_GROUP)
+ .Replace("FULLVER", std::string(FULLVER))
+ .Replace("FILE_NAMESPACE", GetFileNamespace())
+ .Replace("STRUCTRES", AddIndent(TAB_SIZE * 2, GetStructures()))
+ .Repeat("INTERFACES", GetDocument().GetBlocks(), interfaces)
+ .Replace("HASH_METHOD", "[METHOD]"_hash)
+ .Replace("HASH_INT", "int"_hash)
+ .Out(stream);
}
void CsGroupGen::OnFiniGen(std::ofstream& stream) {}
-void CsGroupGen::GenNamespace(std::ofstream& stream) {
- stream << NLine(1);
- stream << "namespace RPCPort" << NLine(1);
- GenBrace(stream, 0, [&]() {
- stream << "namespace " << GetFileNamespace() << NLine(1);
- GenBrace(stream, 0, [&]() {
- GenStructures(stream);
- stream << Tab(1) << "namespace Group" << NLine(1);
- GenBrace(stream, TAB_SIZE, [&]() {
- GenInterfaces(stream);
+bool CsGroupGen::RepeatMethods(ReplaceAll& r,
+ const std::unique_ptr<Declaration>& i) {
+ r.Replace("PARAMS", GetParameters(i->GetParameters()))
+ .Replace("COMMENTS", i->GetComments().empty()
+ ? ""
+ : AddIndent(TAB_SIZE * 3, i->GetComments()))
+ .Replace("DECL", GetDeclaration(*i, false))
+ .Replace("METHOD_ID", i->GetID())
+ .Repeat("PARAMS", i->GetParameters(), [&](auto& r, const auto& i) {
+ auto& pt = i->GetParameterType();
+ if (pt.GetDirection() == ParameterType::Direction::OUT) return false;
+ r.Replace("ID", i->GetID())
+ .Replace("HASH_ID", GetHashCodeStr(i->GetID()));
+
+ return true;
});
- });
- });
-}
-
-void CsGroupGen::GenInterfaces(std::ofstream& stream) {
- for (auto& i : GetDocument().GetBlocks()) {
- if (i->GetType() != Block::TYPE_INTERFACE) continue;
- Interface& iface = static_cast<Interface&>(*i);
- GenInterface(stream, iface);
- stream << NLine(1);
- }
-}
-
-void CsGroupGen::GenInterface(std::ofstream& stream, const Interface& iface) {
- ReplaceAll(CB_INTERFACE_FULL)
- .Change("<CLS_NAME>", iface.GetID())
- .Change("<ENUMS>", GenEnum(iface, 3))
- .Change("<UNITMAP>", GetUnitMap(iface, 3))
- .Change("<METHOD_IDS>", GetMethodId(iface))
- .Change("<SERIALIZER>", GetSerializer())
- .Change("<LIST_SERIALIZER>", GetListSerializer())
- .Change("<METHODS>", GetMethods(iface))
- .Change("<DISPATCHERS>", GetDispatchers(iface))
- .Out(stream);
-}
-
-std::string CsGroupGen::GetDispatchers(const Interface& iface) {
- std::string ret;
- for (const auto& i : iface.GetDeclarations()) {
- ret += ReplaceAll(CB_DISPATCHER)
- .Change("<METHOD_ID>", i->GetID())
- .Change("<PARAM_DESERIALIZER>", GetParamDeserializer(*i))
- .Change("<CALL_PARAMS>", GetCallParams(*i));
- }
-
- return ret;
-}
-
-std::string CsGroupGen::GetMethods(const Interface& iface) {
- std::string ret;
- auto& decls = iface.GetDeclarations();
- for (const auto& i : decls) {
- ret += ReplaceAll(CB_METHOD)
- .Change("<PARAMS>", GetParameters(i->GetParameters()))
- .Change("<COMMENTS>",
- i->GetComments().empty()
- ? ""
- : AddIndent(TAB_SIZE * 3, i->GetComments()))
- .Change("<DECL>", GetDeclaration(*i, false))
- .Change("<METHOD_ID>", i->GetID())
- .Change("<PARAM_SERIALIZER>", GetParamSerializer(*i))
- .Change("<CLS_NAME>", iface.GetID());
- }
-
- return ret;
-}
-
-std::string CsGroupGen::GetParamSerializer(const Declaration& decl) {
- std::string m;
- for (const auto& i : decl.GetParameters()) {
- auto& pt = i->GetParameterType();
- if (pt.GetDirection() == ParameterType::Direction::OUT)
- continue;
- m += Tab(5) + ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
- }
- return m;
+ return true;
}
-std::string CsGroupGen::GetParamDeserializer(const Declaration& decl) {
+bool CsGroupGen::RepeatDispatchers(ReplaceAll& r,
+ const std::unique_ptr<Declaration>& i) {
int cnt = 1;
- std::string m;
- for (const auto& i : decl.GetParameters()) {
+ auto params = [&](auto& r, const auto& i) {
if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
cnt++;
- continue;
+ return false;
}
- std::string v = "param" + std::to_string(cnt);
- std::string c = ConvertTypeToDeserializer(
- i->GetParameterType().GetBaseType(), v, i->GetID(), "map");
- m += AddIndent(TAB_SIZE * 6, c);
-
- cnt++;
- }
-
- return m;
+ auto& pt = i->GetParameterType();
+ r.Replace("ID", i->GetID())
+ .Replace("HASH_ID", GetHashCodeStr(i->GetID()))
+ .Replace("ID_TMP", "param" + std::to_string(cnt++))
+ .Replace("TYPE", ConvertTypeToString(pt.GetBaseType()));
+
+ return true;
+ };
+
+ r.Replace("METHOD_ID", i->GetID())
+ .Repeat("PARAMS", i->GetParameters(), params)
+ .Replace("CALL_PARAMS", GetCallParams(*i));
+ return true;
}
std::string CsGroupGen::GetCallParams(const Declaration& decl) {
void OnFiniGen(std::ofstream& stream) override;
private:
- void GenNamespace(std::ofstream& stream);
- void GenInterfaces(std::ofstream& stream);
- void GenInterface(std::ofstream& stream, const Interface& iface);
- std::string GetMethods(const Interface& iface);
- std::string GetParamSerializer(const Declaration& decl);
- std::string GetParamDeserializer(const Declaration& decl);
- std::string GetDispatchers(const Interface& iface);
+ bool RepeatMethods(ReplaceAll& r, const std::unique_ptr<Declaration>& i);
+ bool RepeatDispatchers(ReplaceAll& r, const std::unique_ptr<Declaration>& i);
std::string GetCallParams(const Declaration& decl);
};
#ifndef IDLC_GEN_VERSION2_CS_GROUP_GENRATOR_CB_H_
#define IDLC_GEN_VERSION2_CS_GROUP_GENRATOR_CB_H_
-const char CB_USING_NAMESPACE_GROUP[] =
-R"__cs_cb(using Tizen.Applications.EventManager;
-
-)__cs_cb";
-
-const char CB_INTERFACE_FULL[] =
+const char CB_MAIN_GROUP[] =
R"__cs_cb(
- public class <CLS_NAME> : IDisposable
- {
-<ENUMS>
- private EventReceiver _eventReceiver;
- private Object _lock = new Object();
- private bool _disposedValue = false;
- private string _senderAppid;
-<UNITMAP>
- private Bundle GetBundleFromParcel(Parcel p)
- {
- byte[] bytes = p.ToBytes();
- Bundle b = new Bundle();
- b.AddItem("TIDL_RAW", bytes);
- return b;
- }
+/*
+ * Generated by tidlc <FULLVER>.
+ */
- private Parcel GetParcelFromBundle(Bundle b)
+using System;
+using System.Collections.Generic;
+using Tizen.Applications;
+using Tizen.Applications.EventManager;
+using Tizen.Applications.RPCPort;
+
+namespace RPCPort
+{
+ namespace <FILE_NAMESPACE>
+ {
+<STRUCTRES>
+ namespace Group
+ {
+ <INTERFACES*>
+ public class <CLS_NAME> : IDisposable
{
- byte[] bytes = (byte[])b.GetItem("TIDL_RAW");
+ <ENUMS>
+ private EventReceiver _eventReceiver;
+ private Object _lock = new Object();
+ private bool _disposedValue = false;
+ private string _senderAppid;
- return new Parcel(bytes);
- }
+ <UNITMAP>
- private string GetEventName(string appid, string iface_name)
- {
- return "event." + appid + ".tidl_iface_" + iface_name;
- }
+ private Bundle GetBundleFromParcel(Parcel p)
+ {
+ byte[] bytes = p.ToBytes();
+ Bundle b = new Bundle();
+ b.AddItem("TIDL_RAW", bytes);
+ return b;
+ }
- private void OnReceive(Parcel p)
- {
- UnitMap map = new UnitMap();
- map.Deserialize(p);
+ private Parcel GetParcelFromBundle(Bundle b)
+ {
+ byte[] bytes = (byte[])b.GetItem("TIDL_RAW");
- map.Read("[METHOD]", "int", out int cmd);
+ return new Parcel(bytes);
+ }
- switch ((MethodId)cmd)
+ private string GetEventName(string appid, string iface_name)
{
-<DISPATCHERS>
+ return "event." + appid + ".tidl_iface_" + iface_name;
}
- }
-
-<METHOD_IDS>
-<SERIALIZER>
-<LIST_SERIALIZER>
- public <CLS_NAME>(string senderAppid)
- {
- string eventName = GetEventName(senderAppid, "<CLS_NAME>");
- _senderAppid = senderAppid;
- _eventReceiver = new EventReceiver(eventName);
- _eventReceiver.Received += (obj, args) =>
+ private void OnReceive(Parcel p)
{
- Bundle b = args.Data;
- using (var parcel = GetParcelFromBundle(b))
+ UnitMap map = new UnitMap();
+ map.Deserialize(p);
+
+ map.Read(<HASH_METHOD> /*[METHOD]*/, out int cmd);
+
+ switch ((MethodId)cmd)
{
- OnReceive(parcel);
+ <DISPATCHERS*>
+ case MethodId.<METHOD_ID>:
+ {
+ <PARAMS*>
+ map.Read(<HASH_ID> /*<ID>*/, out <TYPE> <ID_TMP>);
+ </PARAMS*>
+ <METHOD_ID>Event?.Invoke(<CALL_PARAMS>);
+ break;
+ }
+ </DISPATCHERS*>
}
- };
- }
+ }
- ~<CLS_NAME>()
- {
- Dispose(false);
- }
+ <METHOD_IDS>
+ <SERIALIZER>
+ <LIST_SERIALIZER>
- protected void Dispose(bool disposing)
- {
- if (!_disposedValue)
+ public <CLS_NAME>(string senderAppid)
{
- if (disposing)
+ string eventName = GetEventName(senderAppid, "<CLS_NAME>");
+ _senderAppid = senderAppid;
+ _eventReceiver = new EventReceiver(eventName);
+ _eventReceiver.Received += (obj, args) =>
{
- if (_eventReceiver != null)
+ Bundle b = args.Data;
+ using (var parcel = GetParcelFromBundle(b))
{
- _eventReceiver.Dispose();
- _eventReceiver = null;
+ OnReceive(parcel);
}
- }
-
- _disposedValue = true;
+ };
}
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
+ ~<CLS_NAME>()
+ {
+ Dispose(false);
+ }
-<METHODS>
+ protected void Dispose(bool disposing)
+ {
+ if (!_disposedValue)
+ {
+ if (disposing)
+ {
+ if (_eventReceiver != null)
+ {
+ _eventReceiver.Dispose();
+ _eventReceiver = null;
+ }
+ }
- }
-)__cs_cb";
+ _disposedValue = true;
+ }
+ }
-const char CB_METHOD[] =
-R"__cs_cb(
- public delegate void <METHOD_ID>EventHandler(<PARAMS>);
- public event <METHOD_ID>EventHandler <METHOD_ID>Event;
-<COMMENTS>
- public <DECL>
- {
- using (Parcel p = new Parcel())
+ public void Dispose()
{
- UnitMap map = new UnitMap();
- map.Write("[METHOD]", "int", (int)MethodId.<METHOD_ID>);
-<PARAM_SERIALIZER>
- map.Serialize(p);
-
- var bundle = GetBundleFromParcel(p);
- string eventName = GetEventName(_senderAppid, "<CLS_NAME>");
- ApplicationEventManager.Publish(eventName, bundle);
+ Dispose(true);
+ GC.SuppressFinalize(this);
}
- }
-)__cs_cb";
-const char CB_DISPATCHER[] =
-R"__cs_cb(
- case MethodId.<METHOD_ID>:
+ <METHODS*>
+ public delegate void <METHOD_ID>EventHandler(<PARAMS>);
+ public event <METHOD_ID>EventHandler <METHOD_ID>Event;
+
+ <COMMENTS>
+ public <DECL>
+ {
+ using (Parcel p = new Parcel())
{
-<PARAM_DESERIALIZER>
- <METHOD_ID>Event?.Invoke(<CALL_PARAMS>);
- break;
+ UnitMap map = new UnitMap();
+ var __methodId = (int)MethodId.<METHOD_ID>;
+ map.Write(<HASH_METHOD> /*[METHOD]*/, __methodId);
+
+ <PARAMS*>
+ map.Write(<HASH_ID> /*<ID>*/, <ID>);
+ </PARAMS*>
+ map.Serialize(p);
+
+ var bundle = GetBundleFromParcel(p);
+ string eventName = GetEventName(_senderAppid, "<CLS_NAME>");
+ ApplicationEventManager.Publish(eventName, bundle);
}
-)__cs_cb";
-
+ }
+ </METHODS*>
+ }
+ </INTERFACES*>
+ }
+ }
+}
+)__cs_cb";
#endif // IDLC_GEN_VERSION2_CS_GROUP_GENRATOR_CB_H_
\ No newline at end of file
void CsProxyGen::OnInitGen(std::ofstream& stream) {
SetChannelType(Generator::ChannelType::TYPE_PROXY);
- GenVersion(stream);
- GenUsingNamespace(stream);
- GenNamespace(stream);
-}
-
-void CsProxyGen::OnFiniGen(std::ofstream& stream) {}
-
-void CsProxyGen::GenNamespace(std::ofstream& stream) {
- stream << "namespace RPCPort" << NLine(1);
- GenBrace(stream, 0, [&]() {
- stream << "namespace " << GetFileNamespace() << NLine(1);
- GenBrace(stream, 0, [&]() {
- GenLemBase(stream);
- GenRemoteException(stream);
- GenStructures(stream);
- stream << Tab(1) << "namespace Proxy" << NLine(1);
- GenBrace(stream, TAB_SIZE, [&]() {
- GenInterfaces(stream);
- });
- });
- });
-}
-
-void CsProxyGen::GenLemBase(std::ofstream& stream) {
- stream << CB_LEM_BASE;
-}
-
-void CsProxyGen::GenInterfaces(std::ofstream& stream) {
- for (auto& i : GetDocument().GetBlocks()) {
- if (i->GetType() != Block::TYPE_INTERFACE) continue;
- Interface& iface = static_cast<Interface&>(*i);
- GenInterface(stream, iface);
- stream << NLine(1);
- }
-}
-
-void CsProxyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
- stream << Tab(2) << "public class " << iface.GetID() << " : ProxyBase"
- << NLine(1);
- GenBrace(stream, TAB_SIZE * 2, [&]() {
- GenEnum(stream, iface, 3);
- GenMemberData(stream, iface);
- GenUnitMap(stream, iface, 3);
- GenCallbacks(stream, iface, true);
- GenDelegateId(stream, iface);
- GenMethodId(stream, iface);
- GenEventMethod(stream, iface);
- GenSerializer(stream);
- GenListSerializer(stream);
- GenCtor(stream, iface);
- GenConnectMethod(stream, iface);
- GenMethods(stream, iface);
- });
-}
-
-void CsProxyGen::GenMemberData(std::ofstream& stream, const Interface& iface) {
- ReplaceAll(CB_DATA_MEMBERS)
- .Change("<VERSION>", std::string(FULLVER))
- .Change("<CALLBACK_LIST>",
- HasDelegate(iface) ? CB_DATA_CALLBACK_LIST : std::string(""))
- .Out(stream);
-}
-
-void CsProxyGen::GenEventMethod(std::ofstream& stream, const Interface& iface) {
- bool found = HasDelegate(iface);
-
- ReplaceAll(CB_EVENT_METHODS)
- .Change("<PROCESS_EVENT_BASE>",
- found ? CB_EVENT_PROCESS_EVENT_BASE : std::string(""))
- .Change("<RECEIVE_EVENT_BASE>",
- found ? CB_EVENT_RECEIVE_EVENT_BASE : std::string(""))
+ auto interfaces = [&](auto& r, const auto& i) {
+ if (i->GetType() != Block::TYPE_INTERFACE) return false;
+ auto& iface = static_cast<const Interface&>(*i);
+
+ r.Replace("CLASS_ID", iface.GetID())
+ .Replace("ENUMS", GetEnum(iface, 4))
+ .Replace("UNITMAP", GetUnitMap(iface, 4))
+ .Replace("CALLBACKS",
+ AddIndent(TAB_SIZE * 4, GetCallbacks(iface, true)))
+ .Replace("METHOD_IDS", AddIndent(TAB_SIZE * 4, GetMethodId(iface)))
+ .Replace("DELEGATE_IDS", AddIndent(TAB_SIZE * 4, GetDelegateId(iface)))
+ .Replace("SERIALIZER", AddIndent(TAB_SIZE * 4, GetSerializer()))
+ .Replace("LIST_SERIALIZER",
+ AddIndent(TAB_SIZE * 4, GetListSerializer()))
+ .Replace("REMOTE_EXCEPTION_SERIALIZER",
+ AddIndent(TAB_SIZE * 4, GetRemoteExceptionSerializer()))
+ .Repeat("METHODS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) { return RepeatMethods(r, i); });
+ return true;
+ };
+
+ ReplaceAll(CB_MAIN_PROXY)
+ .Replace("FILE_NAMESPACE", GetFileNamespace())
+ .Replace("REMOTE_EXCEPTION",
+ AddIndent(TAB_SIZE * 2, GetRemoteException()))
+ .Replace("STRUCTURES", AddIndent(TAB_SIZE * 2, GetStructures()))
+ .Repeat("INTERFACES", GetDocument().GetBlocks(), interfaces)
+ .Replace("FULLVER", std::string(FULLVER))
+ .Replace("HASH_METHOD", "[METHOD]"_hash)
+ .Replace("HASH_INT", "int"_hash)
+ .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+ .Replace("HASH_DELEGATE", "delegate"_hash)
+ .Replace("HASH_RESULT", "[RESULT]"_hash)
.Out(stream);
}
-void CsProxyGen::GenCtor(std::ofstream& stream, const Interface& iface) {
- ReplaceAll(CB_CONSTRUCTOR_METHOD)
- .Change("<NAME>", iface.GetID())
- .Out(stream);
-}
-
-void CsProxyGen::GenConnectMethod(std::ofstream& stream,
- const Interface& iface) {
- GenTemplate(
- CB_CONNECT_METHOD, stream,
- [&]() -> std::string { return iface.GetID(); },
- [&]() -> std::string { return iface.GetID(); });
-
- if (HasDelegate(iface)) {
- stream << CB_DISPOSE_CALLBACK_METHOD;
- }
-
- stream << NLine(1);
-}
-
-void CsProxyGen::GenMethods(std::ofstream& stream, const Interface& iface) {
- auto& decls = iface.GetDeclarations();
-
- for (const auto& i : decls) {
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue;
-
- if (!i->GetComments().empty())
- stream << AddIndent(TAB_SIZE * 3, i->GetComments());
-
- stream << Tab(3) << "public ";
- GenDeclaration(stream, *i, false);
- stream << NLine(1);
- GenBrace(stream, TAB_SIZE * 3, [&]() { GenInvocation(stream, *i); });
- stream << NLine(1);
- }
-}
-
-void CsProxyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
- GenTemplate(CB_INVOCATION_PRE, stream, [&]() -> std::string {
- std::string st;
- for (const auto& i : decl.GetParameters()) {
- auto& pt = i->GetParameterType();
- if (pt.GetDirection() == ParameterType::Direction::OUT) continue;
-
- if (pt.GetBaseType().ToString() == "file" ||
- (pt.GetBaseType().GetMetaType() != nullptr &&
- pt.GetBaseType().GetMetaType()->ToString() == "file")) {
- st += GenTemplateString(CB_SHARE_FILE, [&]() -> std::string {
- std::string str = "";
- str += Tab(6) + "Port.ShareFile(" + i->GetID() + ");";
- return str;
- });
- }
- }
-
- std::string m;
- std::string l;
-
- m += Tab(5) + NLine(1) + "UnitMap map = new UnitMap();" + NLine(1);
- m += ConvertTypeToSerializer("(int)MethodId." + decl.GetID(), "[METHOD]",
- "map");
-
- for (const auto& i : decl.GetParameters()) {
- auto& pt = i->GetParameterType();
- if (pt.GetDirection() == ParameterType::Direction::OUT)
- continue;
-
- m += ConvertTypeToSerializer(i->GetID(), i->GetID(), "map");
-
- if (IsDelegateType(pt.GetBaseType())) {
- l += "_delegateList.Add(" + i->GetID() + ");\n";
- }
- }
- m += NLine(1) + "map.Serialize(p);" + NLine(1);
-
- st += AddIndent(TAB_SIZE * 5, m) + NLine(1);
-
- st += Tab(5) + "lock (_lock)" + NLine(1);
- st += Tab(5) + "{" + NLine(1);
- if (!l.empty()) st += AddIndent(TAB_SIZE * 6, l) + NLine(1);
-
-
-
- // Deserialize
- if (decl.GetMethodType() == Declaration::MethodType::ASYNC) {
- st += CB_INVOCATION_ASYNC_MID + NLine(1);
- st += Tab(5) + "}";
- return st;
- } else {
- st += CB_INVOCATION_SYNC_MID + NLine(1);
- }
-
- st += NLine(1) + AddIndent(TAB_SIZE * 5, CB_INVOCATION_RECEIVE);
- st += NLine(1);
-
- for (const auto& i : decl.GetParameters()) {
- if (i->GetParameterType().GetDirection() ==
- ParameterType::Direction::IN) {
- continue;
- }
-
- std::string c = ConvertTypeToDeserializer(
- i->GetParameterType().GetBaseType(), i->GetID(), i->GetID(),
- "mapReceived", false);
- if (c != "") st += AddIndent(TAB_SIZE * 5, c);
- }
-
- if (decl.GetType().ToString() != "void") {
- st += AddIndent(TAB_SIZE * 5, CB_INVOCATION_REMOTE_EXCEPTION);
- st += AddIndent(TAB_SIZE * 6, NLine(1) + ConvertTypeToDeserializer(
- decl.GetType(), "ret",
- "[RESULT]", "mapReceived"));
- st += AddIndent(TAB_SIZE * 6, NLine(1) + "return ret;");
- }
- st += AddIndent(TAB_SIZE * 5, NLine(1) + "}");
+void CsProxyGen::OnFiniGen(std::ofstream& stream) {}
- return st;
- });
+bool CsProxyGen::RepeatMethods(ReplaceAll& r,
+ const std::unique_ptr<Declaration>& i) {
+ if (i->GetMethodType() == Declaration::MethodType::DELEGATE) return false;
+
+ r.Replace("DECLARATION", GetDeclaration(*i, false))
+ .Repeat("FILES", i->GetParameters(),
+ [&](auto& r, const auto& i) {
+ auto& pt = i->GetParameterType();
+ if (pt.GetDirection() == ParameterType::Direction::OUT)
+ return false;
+ if (pt.GetBaseType().ToString() == "file" ||
+ (pt.GetBaseType().GetMetaType() != nullptr &&
+ pt.GetBaseType().GetMetaType()->ToString() == "file")) {
+ r.Replace("PARAM_ID", i->GetID());
+ return true;
+ }
+ return false;
+ })
+ .Remove("ASYNC", i->GetMethodType() != Declaration::MethodType::ASYNC)
+ .Remove("SYNC", i->GetMethodType() == Declaration::MethodType::ASYNC)
+ .Remove("RETURN", i->GetType().ToString() == "void")
+ .Replace("ID", i->GetID())
+ .Repeat("PARAMS", i->GetParameters(),
+ [&](auto& r, const auto& i) {
+ if (i->GetParameterType().GetDirection() ==
+ ParameterType::Direction::OUT)
+ return false;
+ r.Remove("DELEGATE",
+ !i->GetParameterType().GetBaseType().IsDelegateType())
+ .Replace("PARAM", i->GetID())
+ .Replace("HASH_PARAM", GetHashCodeStr(i->GetID()));
+ return true;
+ })
+ .Repeat("OUTS", i->GetParameters(),
+ [&](auto& r, const auto& i) {
+ auto& pt = i->GetParameterType();
+ if (pt.GetDirection() != ParameterType::Direction::OUT &&
+ pt.GetDirection() != ParameterType::Direction::REF)
+ return false;
+ r.Replace("HASH_OUT", GetHashCodeStr(i->GetID()))
+ .Replace("OUT", i->GetID());
+ return true;
+ })
+ .Replace("RET_TYPE", ConvertTypeToString(i->GetType()));
+ return true;
}
} // namespace version2
void OnFiniGen(std::ofstream& stream) override;
private:
- void GenNamespace(std::ofstream& stream);
- void GenInterfaces(std::ofstream& stream);
- void GenInterface(std::ofstream& stream, const Interface& iface);
- void GenCtor(std::ofstream& stream, const Interface& iface);
- void GenConnectMethod(std::ofstream& stream, const Interface& iface);
- void GenMethods(std::ofstream& stream, const Interface& iface);
- void GenInvocation(std::ofstream& stream, const Declaration& decl);
- void GenEventMethod(std::ofstream& stream, const Interface& iface);
- void GenMemberData(std::ofstream& stream, const Interface& iface);
- void GenLemBase(std::ofstream& stream);
+ bool RepeatMethods(ReplaceAll& r, const std::unique_ptr<Declaration>& i);
};
} // namespace version2
#ifndef IDLC_CS_GEN_VERSION2_CS_PROXY_GENRATOR_CB_H_
#define IDLC_CS_GEN_VERSION2_CS_PROXY_GENRATOR_CB_H_
-/**
- * <VERSION> Version of TIDL Compiler.
+const char CB_MAIN_PROXY[] =
+R"__cs_cb(
+/*
+ * Generated by tidlc <FULLVER>.
*/
-const char CB_DATA_MEMBERS[] =
-R"__cs_cb( public event EventHandler Connected;
- public event EventHandler Disconnected;
- public event EventHandler Rejected;
-
- private static readonly string _tidlVersion = "<VERSION>";
- private bool _online = false;
- private string _appId;
- private Object _lock = new Object();
- private bool _connecting = false;
- private LocalExecution _lem;
- private SynchronizationContext _async_context = TizenSynchronizationContext.Current;
-<CALLBACK_LIST>
-)__cs_cb";
-
-const char CB_LEM_BASE[] =
-R"__cs_cb( internal class LocalExecution
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Threading;
+using Tizen.Applications;
+using Tizen.Applications.RPCPort;
+
+namespace RPCPort
+{
+ namespace <FILE_NAMESPACE>
{
- internal bool IsListen = false;
- object _instance = null;
- string _instance_id = null;
- string _appId = null;
- static int _seq = 0;
- MethodInfo _send = null;
- MethodInfo _connect = null;
- MethodInfo _disconnect = null;
- ConcurrentQueue<Parcel> _result = new ConcurrentQueue<Parcel>();
-
- internal LocalExecution(string appId, string interfaceName)
+ internal class LocalExecution
{
- string current_appid = Application.Current.ApplicationInfo.ApplicationId;
+ internal bool IsListen = false;
+ object _instance = null;
+ string _instance_id = null;
+ string _appId = null;
+ static int _seq = 0;
+ MethodInfo _send = null;
+ MethodInfo _connect = null;
+ MethodInfo _disconnect = null;
+ ConcurrentQueue<Parcel> _result = new ConcurrentQueue<Parcel>();
+
+ internal LocalExecution(string appId, string interfaceName)
+ {
+ string current_appid = Application.Current.ApplicationInfo.ApplicationId;
- if (current_appid != appId)
- return;
+ if (current_appid != appId)
+ return;
- _seq++;
- _instance_id = appId + "::" + _seq.ToString();
- _appId = appId;
+ _seq++;
+ _instance_id = appId + "::" + _seq.ToString();
+ _appId = appId;
- Assembly assembly = Assembly.GetExecutingAssembly();
- Type type = null;
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ Type type = null;
- foreach (Type t in assembly.GetTypes())
- {
- if (t.Name != interfaceName)
- continue;
+ foreach (Type t in assembly.GetTypes())
+ {
+ if (t.Name != interfaceName)
+ continue;
- string[] name = t.FullName?.Split('.');
+ string[] name = t.FullName?.Split('.');
- if (name == null || name.Length != 4)
- continue;
+ if (name == null || name.Length != 4)
+ continue;
- if (name[0] == "RPCPort" && name[2] == "Stub")
- {
- if (type == null)
- {
- type = t;
- }
- else
+ if (name[0] == "RPCPort" && name[2] == "Stub")
{
- type = null;
- break;
+ if (type == null)
+ {
+ type = t;
+ }
+ else
+ {
+ type = null;
+ break;
+ }
}
}
- }
- if (type == null)
- return;
+ if (type == null)
+ return;
- MethodInfo getInstance = type.GetMethod("GetInstance", BindingFlags.Static | BindingFlags.NonPublic);
- if (getInstance == null) { return; }
+ MethodInfo getInstance = type.GetMethod("GetInstance", BindingFlags.Static | BindingFlags.NonPublic);
+ if (getInstance == null) { return; }
- _instance = getInstance.Invoke(null, null);
- if (_instance == null) { return; }
+ _instance = getInstance.Invoke(null, null);
+ if (_instance == null) { return; }
- _send = type.GetMethod("OnLemReceivedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_send == null) { return; }
+ _send = type.GetMethod("OnLemReceivedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (_send == null) { return; }
- _connect = type.GetMethod("OnLemConnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_connect == null) { return; }
+ _connect = type.GetMethod("OnLemConnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (_connect == null) { return; }
- _disconnect = type.GetMethod("OnLemDisconnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_disconnect == null) { return; }
+ _disconnect = type.GetMethod("OnLemDisconnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (_disconnect == null) { return; }
- MethodInfo getListen = type.GetMethod("GetListenStatus", BindingFlags.NonPublic | BindingFlags.Instance);
- if (getListen == null) { return; }
+ MethodInfo getListen = type.GetMethod("GetListenStatus", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (getListen == null) { return; }
- object ret = getListen.Invoke(_instance, null);
- if (ret == null) { return; }
- IsListen = (bool)ret;
- }
+ object ret = getListen.Invoke(_instance, null);
+ if (ret == null) { return; }
+ IsListen = (bool)ret;
+ }
- internal void Connect(object proxy_instance)
- {
- _connect.Invoke(_instance, new object[] { proxy_instance, _appId, _instance_id });
- }
+ internal void Connect(object proxy_instance)
+ {
+ _connect.Invoke(_instance, new object[] { proxy_instance, _appId, _instance_id });
+ }
- internal void Disconnect()
- {
- _disconnect.Invoke(_instance, new object[] { _appId, _instance_id });
- }
+ internal void Disconnect()
+ {
+ _disconnect.Invoke(_instance, new object[] { _appId, _instance_id });
+ }
- internal void Send(Parcel p)
- {
- _send.Invoke(_instance, new object[] { _instance_id, p});
- }
+ internal void Send(Parcel p)
+ {
+ _send.Invoke(_instance, new object[] { _instance_id, p});
+ }
- internal void Send(Parcel p, ref Parcel resutl)
- {
- Send(p);
+ internal void Send(Parcel p, ref Parcel resutl)
+ {
+ Send(p);
- int count = 0;
- while (_result.IsEmpty && count++ < 100)
- Thread.Sleep(100);
+ int count = 0;
+ while (_result.IsEmpty && count++ < 100)
+ Thread.Sleep(100);
- if (ResultQueuePop(out resutl))
+ if (ResultQueuePop(out resutl))
+ {
+ Tizen.Log.Error("RPC_PORT", "ResultQueuePop");
+ return;
+ }
+
+ Tizen.Log.Error("RPC_PORT_PROXY", "Failed to get result from server");
+ throw new InvalidIOException();
+ }
+
+ internal void ResultQueuePush(Parcel p)
{
- Tizen.Log.Error("RPC_PORT", "ResultQueuePop");
- return;
+ _result.Enqueue(p);
}
- Tizen.Log.Error("RPC_PORT_PROXY", "Failed to get result from server");
- throw new InvalidIOException();
+ internal bool ResultQueuePop(out Parcel p)
+ {
+ return _result.TryDequeue(out p);
+ }
}
- internal void ResultQueuePush(Parcel p)
- {
- _result.Enqueue(p);
- }
+ <REMOTE_EXCEPTION>
+ <STRUCTURES>
- internal bool ResultQueuePop(out Parcel p)
+ namespace Proxy
{
- return _result.TryDequeue(out p);
- }
- }
-)__cs_cb";
-
-const char CB_DATA_CALLBACK_LIST[] =
-R"__cs_cb(
- private List<CallbackBase> _delegateList = new List<CallbackBase>();
-)__cs_cb";
-const char CB_EVENT_PROCESS_EVENT_BASE[] =
-R"__cs_cb(
- private void ProcessReceivedEvent(Parcel parcelReceived)
+ <INTERFACES*>
+ public class <CLASS_ID> : ProxyBase
{
- UnitMap map = new UnitMap();
- map.Deserialize(parcelReceived);
-
- int cmd;
- map.Read("[METHOD]", out cmd);
-
- if (cmd != (int)MethodId.__Callback)
+ <ENUMS>
+
+ public event EventHandler Connected;
+ public event EventHandler Disconnected;
+ public event EventHandler Rejected;
+
+ private static readonly string _tidlVersion = "<FULLVER>";
+ private bool _online = false;
+ private string _appId;
+ private Object _lock = new Object();
+ private bool _connecting = false;
+ private LocalExecution _lem;
+ private SynchronizationContext _async_context = TizenSynchronizationContext.Current;
+ private List<CallbackBase> _delegateList = new List<CallbackBase>();
+
+ <UNITMAP>
+ <DELEGATE_IDS>
+ <CALLBACKS>
+ <METHOD_IDS>
+
+ protected override void OnConnectedEvent(string endPoint, string portName, Port port)
{
- return;
+ _online = true;
+ _connecting = false;
+ Connected?.Invoke(this, null);
}
- CallbackBase cb;
- map.Read("delegate", out cb);
-
- foreach (var i in _delegateList)
+ protected override void OnDisconnectedEvent(string endPoint, string portName)
{
- if ((int)i.Id == cb.Id && i.SeqId == cb.SeqId)
- {
- i.OnReceivedEvent(map);
- if (i.Once)
- _delegateList.Remove(i);
- break;
- }
+ _online = false;
+ Disconnected?.Invoke(this, null);
}
- }
- internal void OnLemReceivedEvent(Parcel parcelReceived)
- {
- _async_context.Post((data) =>
+ internal void OnLemDisconnectedEvent()
{
- ProcessReceivedEvent(parcelReceived);
-
- }, null);
- }
-
-)__cs_cb";
+ _async_context.Post((data) =>
+ {
+ OnDisconnectedEvent(null, null);
-const char CB_EVENT_RECEIVE_EVENT_BASE[] =
-R"__cs_cb( Parcel parcelReceived;
+ }, null);
- try
- {
- parcelReceived = new Parcel(CallbackPort);
}
- catch (InvalidIOException)
+
+ internal void OnLemResultEvent(Parcel result)
{
- return;
+ _lem.ResultQueuePush(result);
}
- using (parcelReceived)
+ protected override void OnRejectedEvent(string endPoint, string portName)
{
- ProcessReceivedEvent(parcelReceived);
+ _connecting = false;
+ Rejected?.Invoke(this, null);
}
-)__cs_cb";
-const char CB_EVENT_METHODS[] =
-R"__cs_cb(
- protected override void OnConnectedEvent(string endPoint, string portName, Port port)
- {
- _online = true;
- _connecting = false;
- Connected?.Invoke(this, null);
- }
+ private void ProcessReceivedEvent(Parcel parcelReceived)
+ {
+ UnitMap map = new UnitMap();
+ map.Deserialize(parcelReceived);
- protected override void OnDisconnectedEvent(string endPoint, string portName)
- {
- _online = false;
- Disconnected?.Invoke(this, null);
- }
+ int cmd;
+ map.Read(<HASH_METHOD> /*[METHOD]*/, out cmd);
- internal void OnLemDisconnectedEvent()
- {
- _async_context.Post((data) =>
- {
- OnDisconnectedEvent(null, null);
+ if (cmd != (int)MethodId.__Callback)
+ {
+ return;
+ }
- }, null);
+ CallbackBase cb;
+ map.Read(<HASH_DELEGATE> /*delegate*/, out cb);
- }
+ foreach (var i in _delegateList)
+ {
+ if ((int)i.Id == cb.Id && i.SeqId == cb.SeqId)
+ {
+ i.OnReceivedEvent(map);
+ if (i.Once)
+ _delegateList.Remove(i);
+ break;
+ }
+ }
+ }
- internal void OnLemResultEvent(Parcel result)
- {
- _lem.ResultQueuePush(result);
- }
+ internal void OnLemReceivedEvent(Parcel parcelReceived)
+ {
+ _async_context.Post((data) =>
+ {
+ ProcessReceivedEvent(parcelReceived);
- protected override void OnRejectedEvent(string endPoint, string portName)
- {
- _connecting = false;
- Rejected?.Invoke(this, null);
- }
-<PROCESS_EVENT_BASE>
- protected override void OnReceivedEvent(string endPoint, string portName)
- {
-<RECEIVE_EVENT_BASE>
- }
+ }, null);
+ }
- private void ConsumeCommand(out UnitMap unitMap, Port port, ParcelHeader header)
- {
- do
+ protected override void OnReceivedEvent(string endPoint, string portName)
{
- Parcel p;
+ Parcel parcelReceived;
try
{
- p = new Parcel(port);
+ parcelReceived = new Parcel(CallbackPort);
}
catch (InvalidIOException)
{
- unitMap = null;
return;
}
- ParcelHeader headerReceived = p.GetHeader();
- if (!string.IsNullOrEmpty(headerReceived.GetTag()))
+ using (parcelReceived)
{
- if (headerReceived.GetSequenceNumber() != header.GetSequenceNumber())
+ ProcessReceivedEvent(parcelReceived);
+ }
+ }
+
+ private void ConsumeCommand(out UnitMap unitMap, Port port, ParcelHeader header)
+ {
+ do
+ {
+ Parcel p;
+
+ try
{
- Tizen.Log.Error("RPC_PORT_PROXY", headerReceived.GetSequenceNumber().ToString() + " - " + headerReceived.GetTag() + " : " + header.GetSequenceNumber().ToString() + " - " + header.GetTag());
- continue;
+ p = new Parcel(port);
+ }
+ catch (InvalidIOException)
+ {
+ unitMap = null;
+ return;
}
- }
- UnitMap map = new UnitMap();
- map.Deserialize(p);
+ ParcelHeader headerReceived = p.GetHeader();
+ if (!string.IsNullOrEmpty(headerReceived.GetTag()))
+ {
+ if (headerReceived.GetSequenceNumber() != header.GetSequenceNumber())
+ {
+ Tizen.Log.Error("RPC_PORT_PROXY", headerReceived.GetSequenceNumber().ToString() + " - " + headerReceived.GetTag() + " : " + header.GetSequenceNumber().ToString() + " - " + header.GetTag());
+ continue;
+ }
+ }
- unitMap = map;
- return;
- } while (true);
- }
-)__cs_cb";
+ UnitMap map = new UnitMap();
+ map.Deserialize(p);
-const char CB_DISPOSE_CALLBACK_METHOD[] =
-R"__cs_cb(
- /// <summary>
- /// Disposes delegate objects in this interface
- /// </summary>
- /// <param name="tag">The tag string from delegate object</param>
- void DisposeCallback(string tag)
- {
- foreach (var i in _delegateList)
- {
- if (i.Tag.Equals(tag))
- {
- _delegateList.Remove(i);
+ unitMap = map;
return;
- }
+ } while (true);
}
- }
-)__cs_cb";
-const char CB_CONSTRUCTOR_METHOD[] =
-R"__cs_cb(
- public <NAME>(string appId)
- {
- _appId = appId;
- _lem = new LocalExecution(appId, "<NAME>");
- }
-)__cs_cb";
+ <SERIALIZER>
+ <LIST_SERIALIZER>
+ <REMOTE_EXCEPTION_SERIALIZER>
+ public <CLASS_ID>(string appId)
+ {
+ _appId = appId;
+ _lem = new LocalExecution(appId, "<CLASS_ID>");
+ }
-const char CB_CONNECT_METHOD[] =
-R"__cs_cb(
- /// <summary>
- /// Connects to the stub app.
- /// </summary>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- /// <privilege>http://tizen.org/privilege/datasharing</privilege>
- /// <exception cref="InvalidIDException">
- /// Thrown when the appid to connect is invalid.
- /// </exception>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- /// <exception cref="PermissionDeniedException">
- /// Thrown when the permission is denied.
- /// </exception>
- /// <remark> If you want to use this method, you must add privileges.</remark>
- public void Connect()
- {
- if (_lem.IsListen)
+ /// <summary>
+ /// Connects to the stub app.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+ /// <exception cref="InvalidIDException">
+ /// Thrown when the appid to connect is invalid.
+ /// </exception>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="PermissionDeniedException">
+ /// Thrown when the permission is denied.
+ /// </exception>
+ /// <remark> If you want to use this method, you must add privileges.</remark>
+ public void Connect()
{
- if (_online || _connecting)
- throw new InvalidIDException();
+ if (_lem.IsListen)
+ {
+ if (_online || _connecting)
+ throw new InvalidIDException();
- _connecting = true;
- _lem.Connect(this);
+ _connecting = true;
+ _lem.Connect(this);
- _async_context.Post((data) =>
+ _async_context.Post((data) =>
+ {
+ OnConnectedEvent(null, null, null);
+ }, null);
+ }
+ else
{
- OnConnectedEvent(null, null, null);
- }, null);
- }
- else
- {
- Connect(_appId, "$$");
+ Connect(_appId, "<CLASS_ID>");
+ }
}
- }
- /// <summary>
- /// Disconnects from the stub app.
- /// </summary>
- /// <exception cref="System.InvalidOperationException">
- /// Thrown when an internal IO error occurrs.
- /// </exception>
- public void Disconnect()
- {
- if (_lem.IsListen)
- {
- if (_online)
- _lem.Disconnect();
- }
- else
+ /// <summary>
+ /// Disconnects from the stub app.
+ /// </summary>
+ /// <exception cref="System.InvalidOperationException">
+ /// Thrown when an internal IO error occurrs.
+ /// </exception>
+ public void Disconnect()
{
- Port?.Disconnect();
+ if (_lem.IsListen)
+ {
+ if (_online)
+ _lem.Disconnect();
+ }
+ else
+ {
+ Port?.Disconnect();
+ }
+ _online = false;
}
- _online = false;
- }
- /// <summary>
- /// Connects to the stub app synchronously.
- /// </summary>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- /// <privilege>http://tizen.org/privilege/datasharing</privilege>
- /// <exception cref="InvalidIDException">
- /// Thrown when the appid to connect is invalid.
- /// </exception>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- /// <exception cref="PermissionDeniedException">
- /// Thrown when the permission is denied.
- /// </exception>
- /// <remark> If you want to use this method, you must add privileges.</remark>
- public void ConnectSync()
- {
- if (_lem.IsListen)
+ /// <summary>
+ /// Connects to the stub app synchronously.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+ /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+ /// <exception cref="InvalidIDException">
+ /// Thrown when the appid to connect is invalid.
+ /// </exception>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="PermissionDeniedException">
+ /// Thrown when the permission is denied.
+ /// </exception>
+ /// <remark> If you want to use this method, you must add privileges.</remark>
+ public void ConnectSync()
{
- if (_online || _connecting)
- throw new InvalidIDException();
+ if (_lem.IsListen)
+ {
+ if (_online || _connecting)
+ throw new InvalidIDException();
- _connecting = true;
- _lem.Connect(this);
- OnConnectedEvent(null, null, null);
- }
- else
- {
- ConnectSync(_appId, "$$");
+ _connecting = true;
+ _lem.Connect(this);
+ OnConnectedEvent(null, null, null);
+ }
+ else
+ {
+ ConnectSync(_appId, "<CLASS_ID>");
+ }
}
- }
-)__cs_cb";
-
-const char CB_INVOCATION_PRE[] =
-R"__cs_cb( if (!_online)
- throw new NotConnectedSocketException();
- using (Parcel p = new Parcel())
+ /// <summary>
+ /// Disposes delegate objects in this interface
+ /// </summary>
+ /// <param name="tag">The tag string from delegate object</param>
+ void DisposeCallback(string tag)
{
- ParcelHeader header = p.GetHeader();
- header.SetTag(_tidlVersion);
-$$
+ foreach (var i in _delegateList)
+ {
+ if (i.Tag.Equals(tag))
+ {
+ _delegateList.Remove(i);
+ return;
+ }
+ }
}
-)__cs_cb";
+ <METHODS*>
+ public <DECLARATION>
+ {
+ if (!_online)
+ throw new NotConnectedSocketException();
-const char CB_SHARE_FILE[] =
-R"__cs_cb(
- try
+ using (Parcel p = new Parcel())
{
-$$
- }
- catch (InvalidIOException)
- {
- throw new InvalidIOException();
- }
-)__cs_cb";
-
-const char CB_INVOCATION_ASYNC_MID[] =
-R"__cs_cb( // Send
- if (_lem.IsListen)
+ ParcelHeader header = p.GetHeader();
+ header.SetTag(_tidlVersion);
+ try
{
- _lem.Send(p);
+ <FILES*>
+ Port.ShareFile(<PARAM_ID>);
+ </FILES*>
}
- else
+ catch (InvalidIOException)
{
- p.Send(Port);
+ throw new InvalidIOException();
}
-)__cs_cb";
-const char CB_INVOCATION_SYNC_MID[] =
-R"__cs_cb( // Send
- Parcel ret_parcel = new Parcel();
- // Send
- if (_lem.IsListen)
- {
- _lem.Send(p, ref ret_parcel);
- }
- else
+ var methodId = (int)MethodId.<ID>;
+ UnitMap map = new UnitMap();
+ map.Write(<HASH_METHOD> /*[METHOD]*/, methodId);
+ <PARAMS*>
+ map.Write(<HASH_PARAM> /*<PARAM>*/, <PARAM>);
+ <DELEGATE?>
+ _delegateList.Add(<PARAM>);
+ </DELEGATE?>
+ </PARAMS*>
+ map.Serialize(p);
+
+ lock (_lock)
{
- p.Send(Port);
+ <ASYNC?>
+ // Send
+ if (_lem.IsListen)
+ {
+ _lem.Send(p);
+ }
+ else
+ {
+ p.Send(Port);
+ }
+ </ASYNC?>
+ <SYNC?>
+ // Send
+ Parcel ret_parcel = new Parcel();
+ // Send
+ if (_lem.IsListen)
+ {
+ _lem.Send(p, ref ret_parcel);
+ }
+ else
+ {
+ p.Send(Port);
+ }
+
+ UnitMap mapReceived;
+ if (_lem.IsListen)
+ {
+ mapReceived = new UnitMap();
+ mapReceived.Deserialize(ret_parcel);
+ }
+ else
+ {
+ // Receive
+ ConsumeCommand(out mapReceived, Port, header);
+ }
+
+ if (mapReceived == null)
+ {
+ throw new InvalidProtocolException();
+ }
+
+ <RETURN?>
+ if (mapReceived.ContainsName(<HASH_REMOTE_EXCEPTION> /*[REMOTE_EXCEPTION]*/))
+ {
+ mapReceived.Read(<HASH_REMOTE_EXCEPTION> /*[REMOTE_EXCEPTION]*/, out RemoteException exception);
+ throw exception;
+ }
+
+ <OUTS*>
+ mapReceived.Read(<HASH_OUT> /*<OUT>*/, out <OUT>);
+ </OUTS*>
+ mapReceived.Read(<HASH_RESULT> /*[RESULT]*/, out <RET_TYPE> ret);
+
+ return ret;
+ </RETURN?>
+ </SYNC?>
}
-)__cs_cb";
+ }
+ }
-const char CB_INVOCATION_RECEIVE[] =
-R"__cs_cb( UnitMap mapReceived;
- if (_lem.IsListen)
- {
- mapReceived = new UnitMap();
- mapReceived.Deserialize(ret_parcel);
- }
- else
- {
- // Receive
- ConsumeCommand(out mapReceived, Port, header);
- }
+ </METHODS*>
+ }
- if (mapReceived == null)
- {
- throw new InvalidProtocolException();
+ </INTERFACES*>
+ }
}
-)__cs_cb";
+}
-const char CB_INVOCATION_REMOTE_EXCEPTION[] =
-R"__cs_cb( if (mapReceived.ContainsName("[REMOTE_EXCEPTION]"))
- {
- mapReceived.Read("[REMOTE_EXCEPTION]", out RemoteException exception);
- throw exception;
- }
)__cs_cb";
#endif // IDLC_CS_GEN_VERSION2_CS_PROXY_GENRATOR_CB_H_
\ No newline at end of file
void CsStubGen::OnInitGen(std::ofstream& stream) {
SetChannelType(Generator::ChannelType::TYPE_STUB);
- GenVersion(stream);
- GenUsingNamespace(stream);
- GenNamespace(stream);
+ auto interfaces = [&](auto& r, const auto& i) {
+ if (i->GetType() != Block::TYPE_INTERFACE) return false;
+ auto& iface = static_cast<const Interface&>(*i);
+
+ r.Replace("CLASS_ID", iface.GetID())
+ .Replace("ENUMS", GetEnum(iface, 4))
+ .Replace("UNITMAP", GetUnitMap(iface, 4))
+ .Replace("CALLBACKS",
+ AddIndent(TAB_SIZE * 4, GetCallbacks(iface, false)))
+ .Replace("METHOD_IDS", AddIndent(TAB_SIZE * 4, GetMethodId(iface)))
+ .Replace("SERIALIZER", AddIndent(TAB_SIZE * 4, GetSerializer()))
+ .Replace("LIST_SERIALIZER",
+ AddIndent(TAB_SIZE * 4, GetListSerializer()))
+ .Replace("REMOTE_EXCEPTION_SERIALIZER",
+ AddIndent(TAB_SIZE * 4, GetRemoteExceptionSerializer()))
+ .Replace("DELEGATE_IDS", AddIndent(TAB_SIZE * 4, GetDelegateId(iface)))
+ .Repeat("ATTRIBUTES", iface.GetAttributes(),
+ [&](auto& r, const auto& i) {
+ r.Remove("PRIVILEGE", i->GetKey() != "privilege")
+ .Remove("TRUSTED", !(i->GetKey() == "trusted" &&
+ i->GetValue() == "true"))
+ .Replace("VAL", i->GetValue());
+ return true;
+ })
+ .Repeat("PRIVILEGE_MAP", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) {
+ if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
+ return false;
+
+ std::string code = GetPrivileges(*i, i->GetID());
+ if (code.empty()) return false;
+
+ r.Replace("METHOD_ID", i->GetID())
+ .Replace("PRIVILEGE_LIST", code);
+ return true;
+ })
+ .Repeat("METHODS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) { return RepeatMethods(r, i); })
+ .Repeat(
+ "INVOCATIONS", iface.GetDeclarations(),
+ [&](auto& r, const auto& i) { return RepeatInvocations(r, i); });
+ return true;
+ };
+
+ ReplaceAll(CB_MAIN_STUB)
+ .Replace("FILE_NAMESPACE", GetFileNamespace())
+ .Replace("REMOTE_EXCEPTION",
+ AddIndent(TAB_SIZE * 2, GetRemoteException()))
+ .Replace("STRUCTURES", AddIndent(TAB_SIZE * 2, GetStructures()))
+ .Repeat("INTERFACES", GetDocument().GetBlocks(), interfaces)
+ .Replace("FULLVER", std::string(FULLVER))
+ .Replace("HASH_METHOD", "[METHOD]"_hash)
+ .Replace("HASH_INT", "int"_hash)
+ .Replace("HASH_REMOTE_EXCEPTION", "[REMOTE_EXCEPTION]"_hash)
+ .Replace("HASH_RESULT", "[RESULT]"_hash)
+ .Out(stream);
}
void CsStubGen::OnFiniGen(std::ofstream& stream) {}
-void CsStubGen::GenNamespace(std::ofstream& stream) {
- stream << "namespace RPCPort" << NLine(1);
- GenBrace(stream, 0, [&]() {
- stream << "namespace " << GetFileNamespace() << NLine(1);
- GenBrace(stream, 0, [&]() {
- GenLemBase(stream);
- GenRemoteException(stream);
- GenStructures(stream);
- stream << Tab(1) << "namespace Stub" << NLine(1);
- GenBrace(stream, TAB_SIZE, [&]() { GenInterfaces(stream); });
- });
- });
-}
-
-void CsStubGen::GenLemBase(std::ofstream& stream) {
- stream << CB_LEM_BASE;
-}
-
-void CsStubGen::GenInterfaces(std::ofstream& stream) {
- for (auto& i : GetDocument().GetBlocks()) {
- if (i->GetType() != Block::TYPE_INTERFACE) continue;
- Interface& iface = static_cast<Interface&>(*i);
- GenInterface(stream, iface);
- stream << std::endl;
- }
-}
-
-void CsStubGen::GenInterface(std::ofstream& stream, const Interface& iface) {
- stream << Tab(2) << "public sealed class " << iface.GetID() << " : StubBase"
- << NLine(1);
- GenBrace(stream, TAB_SIZE * 2, [&]() {
- GenEnum(stream, iface, 3);
- stream << ReplaceAll(CB_DATA_MEMBERS, "<VERSION>", FULLVER);
- GenServiceBase(stream, iface);
- GenUnitMap(stream, iface, 3);
- GenCallbacks(stream, iface, false);
- GenDelegateId(stream, iface);
- GenMethodId(stream, iface);
- GenSerializer(stream);
- GenListSerializer(stream);
- GenCheckPrivilege(stream);
- GenReceivedEvent(stream, iface);
- GenConnectedEvent(stream);
- GenDisconnectedEvent(stream);
- GenCtor(stream, iface);
- GenCommonMethods(stream);
- GenDisposable(stream, iface);
- });
-}
-
-void CsStubGen::GenServiceBase(std::ofstream& stream, const Interface& iface) {
- stream << CB_SERVICE_BASE_FRONT;
- GenDeclarations(stream, iface.GetDeclarations());
- stream << NLine(1);
- stream << AddIndent(TAB_SIZE * 3, "}\n");
-}
+bool CsStubGen::RepeatMethods(ReplaceAll& r,
+ const std::unique_ptr<Declaration>& i) {
+ if (i->GetMethodType() == Declaration::MethodType::DELEGATE) return false;
+ r.Replace("DECLARATION", GetDeclaration(*i));
-void CsStubGen::GenDeclarations(std::ofstream& stream,
- const Declarations& decls) {
- for (const auto& i : decls) {
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue;
- if (!i->GetComments().empty())
- stream << NLine(1) << AddIndent(TAB_SIZE * 4, i->GetComments());
- stream << Tab(4) << "public abstract ";
- GenDeclaration(stream, *i);
- stream << NLine(1);
- }
+ return true;
}
-void CsStubGen::GenCheckPrivilege(std::ofstream& stream) {
- stream << CB_CHECK_PRIVILEGE_METHOD;
-}
-
-void CsStubGen::GenReceivedEvent(std::ofstream& stream,
- const Interface& iface) {
- stream << CB_ON_RECEIVED_EVENT_FRONT;
- for (const auto& i : iface.GetDeclarations()) {
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE) continue;
- stream << Tab(6) << "case MethodId." << i->GetID() << ":" << NLine(1);
- GenBrace(stream, TAB_SIZE * 7, [&]() {
- GenInvocation(stream, *i);
- stream << Tab(8) << "break;" << NLine(1);
- });
- }
- stream << CB_ON_RECEIVED_EVENT_BACK;
-}
-
-
-std::string CsStubGen::GetWriteOutParam(const Declaration& decl) {
- int cnt = 0;
- std::string code;
+bool CsStubGen::RepeatInvocations(ReplaceAll& r,
+ const std::unique_ptr<Declaration>& i) {
+ if (i->GetMethodType() == Declaration::MethodType::DELEGATE) return false;
- for (const auto& i : decl.GetParameters()) {
- auto& pt = i->GetParameterType();
- cnt++;
- if (pt.GetDirection() == ParameterType::Direction::IN)
- continue;
+ int cnt = 1;
+ int param_cnt = 1;
+ auto params = [&](auto& r, const auto& i) {
+ if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
+ cnt++;
+ return false;
+ }
- code += ConvertTypeToSerializer("param" + std::to_string(cnt),
- i->GetID(), "result_map");
- }
+ bool is_del = i->GetParameterType().GetBaseType().GetUserDefinedType() ==
+ BaseType::UserType::DELEGATE;
+
+ r.Remove("DELEGATE", !is_del)
+ .Remove("NO_DELEGATE", is_del)
+ .Replace("HASH_ID", GetHashCodeStr(i->GetID()))
+ .Replace("PARAM_ID", i->GetID())
+ .Replace("TYPE",
+ ConvertTypeToString(i->GetParameterType().GetBaseType()))
+ .Replace("CNT", std::to_string(cnt++));
+ return true;
+ };
+
+ auto out_params = [&](auto& r, const auto& i) {
+ if (i->GetParameterType().GetDirection() == ParameterType::Direction::IN) {
+ param_cnt++;
+ return false;
+ }
+ r.Replace("HASH_ID", GetHashCodeStr(i->GetID()))
+ .Replace("PARAM_ID", i->GetID())
+ .Replace("CNT", std::to_string(param_cnt++));
- return code;
-}
+ return true;
+ };
-std::string CsStubGen::GetInvocationMethod(const Declaration& decl) {
- std::string code;
- if (decl.GetType().ToString() != "void") {
- code =
- ReplaceAll(CB_INVOCATION_REMOTE_EXCEPTION)
- .Change("<SYNC_INVOCATION>", GetInvocationMethodParam(decl, true))
- .Change("<WRITE_RESULT>", ConvertTypeToSerializer(
- "retVal", "[RESULT]", "result_map"))
- .Change("<WRITE_OUT_PARAM>", GetWriteOutParam(decl));
- } else {
- code = NLine(1) + GetInvocationMethodParam(decl, false);
- }
+ r.RemoveAll("SYNC", i->GetMethodType() == Declaration::MethodType::ASYNC)
+ .RemoveAll("ASYNC", i->GetMethodType() != Declaration::MethodType::ASYNC)
+ .Repeat("PARAMS", i->GetParameters(), params)
+ .Repeat("OUT_PARAMS", i->GetParameters(), out_params)
+ .Replace("ID", i->GetID())
+ .Replace("INVOKE_PARAMS", GetInvocationMethodParam(*i));
- return code;
+ return true;
}
-std::string CsStubGen::GetInvocationMethodParam(const Declaration& decl,
- bool hasRet) {
+std::string CsStubGen::GetInvocationMethodParam(const Declaration& decl) {
int cnt = 1;
std::string code;
- if (hasRet)
- code = "var retVal = ";
-
- code += "b." + decl.GetID() + "(";
for (const auto& i : decl.GetParameters()) {
if (cnt != 1) {
code += ", ";
cnt++;
}
- code += ");\n";
-
return code;
}
-void CsStubGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
- int cnt = 1;
- // Deserialize
- for (const auto& i : decl.GetParameters()) {
- if (i->GetParameterType().GetDirection() == ParameterType::Direction::OUT) {
- cnt++;
- continue;
- }
-
- std::string v = "param" + std::to_string(cnt);
- std::string c = ConvertTypeToDeserializer(
- i->GetParameterType().GetBaseType(), v, i->GetID(), "map");
- stream << AddIndent(TAB_SIZE * 8, c);
- cnt++;
- }
-
- // Invoke
- std::string m;
-
- m += NLine(1) + "UnitMap result_map = new UnitMap();";
-
- m += ReplaceAll(CB_INVOCATION_CHECK_PRIVILEGE)
- .Change("<INVOCATION>",
- AddIndent(TAB_SIZE, GetInvocationMethod(decl)));
-
- stream << AddIndent(TAB_SIZE * 8, m);
-
- // Serialize
- if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
- return;
-
- cnt = 0;
- m = CB_INVOCATION_RESULT;
- stream << AddIndent(TAB_SIZE * 8, m);
-}
-
-void CsStubGen::GenConnectedEvent(std::ofstream& stream) {
- stream << CB_ON_CONNECTED_EVENT;
-}
-
-void CsStubGen::GenDisconnectedEvent(std::ofstream& stream) {
- stream << CB_ON_DISCONNECTED_EVENT;
-}
-
-std::string CsStubGen::GenPrivileges(const Declaration& decl,
+std::string CsStubGen::GetPrivileges(const Declaration& decl,
const std::string& id) {
std::string code;
for (const auto& attr : decl.GetAttributes()) {
- if (attr->GetKey() != "privilege")
- continue;
+ if (attr->GetKey() != "privilege") continue;
code +=
Tab(4) + "list" + id + ".Add(\"" + attr->GetValue() + "\");" + NLine(1);
return code;
}
-void CsStubGen::GenCtor(std::ofstream& stream, const Interface& iface) {
- GenTemplate(
- CB_CTOR_FRONT, stream,
- [&]() -> std::string { return iface.GetID(); },
- [&]() -> std::string { return iface.GetID(); });
-
- for (const auto& i : iface.GetAttributes()) {
- if (i->GetKey() == "privilege") {
- stream << Tab(4) << "AddPrivilege(\"" << i->GetValue() << "\");"
- << NLine(1);
- } else if (i->GetKey() == "trusted" && i->GetValue() == "true") {
- stream << Tab(4) << "SetTrusted(" << i->GetValue() << ");" << NLine(1);
- }
- }
-
- for (const auto& i : iface.GetDeclarations()) {
- if (i->GetMethodType() == Declaration::MethodType::DELEGATE)
- continue;
-
- std::string code = GenPrivileges(*i, i->GetID());
- if (code.empty())
- continue;
-
- ReplaceAll(CB_PRIVILEGE_MAP_BASE)
- .Change("<METHOD_ID>", i->GetID())
- .Change("<PRIVILEGE_LIST>", code)
- .Out(stream);
- }
-
- stream << Tab(3) << "}" << NLine(1);
-}
-
-void CsStubGen::GenCommonMethods(std::ofstream& stream) {
- stream << CB_COMMON_METHODS;
-}
-
-void CsStubGen::GenDisposable(std::ofstream& stream, const Interface& iface) {
- stream << CB_DISPOSABLE;
-}
-
} // namespace version2
} // namespace tidl
void OnFiniGen(std::ofstream& stream) override;
private:
- void GenNamespace(std::ofstream& stream);
- void GenInterfaces(std::ofstream& stream);
- void GenInterface(std::ofstream& stream, const Interface& iface);
- void GenServiceBase(std::ofstream& stream, const Interface& iface);
- void GenReceivedEvent(std::ofstream& stream, const Interface& iface);
- void GenConnectedEvent(std::ofstream& stream);
- void GenCheckPrivilege(std::ofstream& stream);
- std::string GenPrivileges(const Declaration& decl, const std::string& id);
- void GenDisconnectedEvent(std::ofstream& stream);
- void GenCtor(std::ofstream& stream, const Interface& iface);
- void GenCommonMethods(std::ofstream& stream);
- void GenDeclarations(std::ofstream& stream, const Declarations& decls);
- void GenInvocation(std::ofstream& stream, const Declaration& decl);
- void GenDisposable(std::ofstream& stream, const Interface& iface);
- std::string GetInvocationMethodParam(const Declaration& decl, bool hasRet);
- std::string GetInvocationMethod(const Declaration& decl);
- std::string GetWriteOutParam(const Declaration& decl);
- void GenLemBase(std::ofstream& stream);
+ bool RepeatMethods(ReplaceAll& r, const std::unique_ptr<Declaration>& i);
+ bool RepeatInvocations(ReplaceAll& r, const std::unique_ptr<Declaration>& i);
+ std::string GetInvocationMethodParam(const Declaration& decl);
+ std::string GetPrivileges(const Declaration& decl, const std::string& id);
};
} // namespace version2
#ifndef IDLC_CS_GEN_VERSION2_CS_STUB_GENRATOR_CB_H_
#define IDLC_CS_GEN_VERSION2_CS_STUB_GENRATOR_CB_H_
-/**
- * <VERSION> Version of TIDL Compiler.
+const char CB_MAIN_STUB[] =
+R"__cs_cb(
+/*
+ * Generated by tidlc <FULLVER>.
*/
-const char CB_DATA_MEMBERS[] =
-R"__cs_cb( private List<ServiceBase> _services = new List<ServiceBase>();
- private Type _serviceType;
- private static readonly string _tidlVersion = "<VERSION>";
- private Dictionary<MethodId, List<string>> _privilege_map = new Dictionary<MethodId, List<string>>();
- private static Message _instance;
- private bool _isListen = false;
- private SynchronizationContext _async_context = TizenSynchronizationContext.Current;
-)__cs_cb";
-const char CB_LEM_BASE[] =
-R"__cs_cb( internal class LocalExecution
+using System;
+using System.Collections.Generic;
+using System.Collections.Concurrent;
+using System.Threading;
+using System.Reflection;
+using Tizen.Applications;
+using Tizen.Applications.RPCPort;
+
+namespace RPCPort
+{
+ namespace <FILE_NAMESPACE>
{
- object _instance = null;
- MethodInfo _send_result = null;
- MethodInfo _send_request = null;
- MethodInfo _disconnect = null;
+ internal class LocalExecution
+ {
+ object _instance = null;
+ MethodInfo _send_result = null;
+ MethodInfo _send_request = null;
+ MethodInfo _disconnect = null;
- internal bool _online = false;
+ internal bool _online = false;
- internal LocalExecution (object instance)
- {
- Type type = instance.GetType();
+ internal LocalExecution (object instance)
+ {
+ Type type = instance.GetType();
- if (type == null)
- return;
+ if (type == null)
+ return;
- _send_result = type.GetMethod("OnLemResultEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_send_result == null) { return; }
+ _send_result = type.GetMethod("OnLemResultEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (_send_result == null) { return; }
- _send_request = type.GetMethod("OnLemReceivedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ _send_request = type.GetMethod("OnLemReceivedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- _disconnect = type.GetMethod("OnLemDisconnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_disconnect == null) { return; }
+ _disconnect = type.GetMethod("OnLemDisconnectedEvent", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (_disconnect == null) { return; }
- _instance = instance;
- _online = true;
+ _instance = instance;
+ _online = true;
}
internal void Disconnect()
{
if (_online)
- _disconnect.Invoke(_instance, null);
+ _disconnect.Invoke(_instance, null);
_online = false;
}
}
-)__cs_cb";
-const char CB_SERVICE_BASE_FRONT[] =
-R"__cs_cb(
- public abstract class ServiceBase
+ <REMOTE_EXCEPTION>
+ <STRUCTURES>
+ namespace Stub
+ {
+ <INTERFACES*>
+ public class <CLASS_ID> : StubBase
{
- internal bool _is_app = true;
- internal List<string> _privileges;
- internal LocalExecution _lem;
-
- /// <summary>
- /// The client app ID
- /// </summary>
- public string Sender
+ <ENUMS>
+ private List<ServiceBase> _services = new List<ServiceBase>();
+ private Type _serviceType;
+ private static readonly string _tidlVersion = "<FULLVER>";
+ private Dictionary<MethodId, List<string>> _privilege_map = new Dictionary<MethodId, List<string>>();
+ private static <CLASS_ID> _instance;
+ private bool _isListen = false;
+ private SynchronizationContext _async_context = TizenSynchronizationContext.Current;
+
+ public abstract class ServiceBase
{
- get; internal set;
- }
+ internal bool _is_app = true;
+ internal List<string> _privileges;
+ internal LocalExecution _lem;
+
+ /// <summary>
+ /// The client app ID
+ /// </summary>
+ public string Sender
+ {
+ get; internal set;
+ }
- /// <summary>
- /// The client instance ID
- /// </summary>
- public string Instance
- {
- get; internal set;
- }
+ /// <summary>
+ /// The client instance ID
+ /// </summary>
+ public string Instance
+ {
+ get; internal set;
+ }
- public Port Port
- {
- get;
- internal set;
+ public Port Port
+ {
+ get;
+ internal set;
+ }
+
+ protected ServiceBase()
+ {
+ }
+
+ internal void LoadPrivilege()
+ {
+ ApplicationInfo info = new ApplicationInfo(Sender);
+ if (info.PackageId == string.Empty)
+ {
+ _is_app = false;
+ return;
+ }
+
+ Package pkg = PackageManager.GetPackage(info.PackageId);
+ _privileges = new List<string>(pkg.Privileges);
+ }
+
+ /// <summary>
+ /// Disconnects from the proxy app
+ /// </summary>
+ /// <exception cref="System.InvalidOperationException">
+ /// Thrown when an internal IO error occurrs.
+ /// </exception>
+ public void Disconnect()
+ {
+ if(_lem != null)
+ {
+ _lem.Disconnect();
+ }
+ else
+ {
+ Port?.Disconnect();
+ Port = null;
+ }
+ }
+
+ /// <summary>
+ /// This method will be called when the client is connected
+ /// </summary>
+ public abstract void OnCreate();
+
+ /// <summary>
+ /// This method will be called when the client is disconnected
+ /// </summary>
+ public abstract void OnTerminate();
+
+ <METHODS*>
+ public abstract <DECLARATION>
+
+ </METHODS*>
}
- protected ServiceBase()
+ <UNITMAP>
+ <CALLBACKS>
+ <DELEGATE_IDS>
+ <METHOD_IDS>
+ <SERIALIZER>
+ <LIST_SERIALIZER>
+ <REMOTE_EXCEPTION_SERIALIZER>
+
+ private bool CheckPrivilege(MethodId id, ServiceBase b)
{
+ if (_privilege_map.ContainsKey(id) == false)
+ return true;
+
+ foreach (var item in _privilege_map[id])
+ {
+ if (b._privileges.Contains(item) == false) {
+ Tizen.Log.Error("RPC_PORT", "Permission denied. " + b.Sender + " : " + item);
+ return false;
+ }
+ }
+
+ return true;
}
- internal void LoadPrivilege()
+ protected override bool OnReceivedEvent(string sender, string instance, Port port)
{
- ApplicationInfo info = new ApplicationInfo(Sender);
- if (info.PackageId == string.Empty)
+ Parcel p;
+
+ try
{
- _is_app = false;
- return;
+ p = new Parcel(port);
+ }
+ catch (InvalidIOException)
+ {
+ return false;
}
- Package pkg = PackageManager.GetPackage(info.PackageId);
- _privileges = new List<string>(pkg.Privileges);
+ return OnReceivedEvent(instance, port, p);
}
- /// <summary>
- /// Disconnects from the proxy app
- /// </summary>
- /// <exception cref="System.InvalidOperationException">
- /// Thrown when an internal IO error occurrs.
- /// </exception>
- public void Disconnect()
+ internal void OnLemReceivedEvent(string instance, Parcel p)
{
- if(_lem != null)
+ if (Thread.CurrentThread.ManagedThreadId != 1)
{
- _lem.Disconnect();
+ _async_context.Post((data) =>
+ {
+ ((<CLASS_ID>)data).OnReceivedEvent(instance, null, p);
+ }, this);
}
else
{
- Port?.Disconnect();
- Port = null;
+ OnReceivedEvent(instance, null, p);
}
}
- /// <summary>
- /// This method will be called when the client is connected
- /// </summary>
- public abstract void OnCreate();
-
- /// <summary>
- /// This method will be called when the client is disconnected
- /// </summary>
- public abstract void OnTerminate();
-)__cs_cb";
+ internal bool OnReceivedEvent(string instance, Port port, Parcel p)
+ {
+ try
+ {
+ ServiceBase b = null;
+ foreach (var i in _services)
+ {
+ if (i.Instance.Equals(instance))
+ {
+ b = i;
+ break;
+ }
+ }
-const char CB_CHECK_PRIVILEGE_METHOD[] =
-R"__cs_cb(
- private bool CheckPrivilege(MethodId id, ServiceBase b)
- {
- if (_privilege_map.ContainsKey(id) == false)
- return true;
+ if (b == null)
+ {
+ return false;
+ }
- foreach (var item in _privilege_map[id])
- {
- if (b._privileges.Contains(item) == false) {
- Tizen.Log.Error("RPC_PORT", "Permission denied. " + b.Sender + " : " + item);
- return false;
- }
- }
+ Port cb_port;
+ if (b._lem != null)
+ cb_port = null;
+ else
+ cb_port = GetPort(Port.Type.Callback, instance);
- return true;
- }
-)__cs_cb";
+ var result = new Parcel();
-const char CB_PRIVILEGE_MAP_BASE[] =
-R"__cs_cb(
- List<string> list<METHOD_ID> = new List<string>();
-<PRIVILEGE_LIST>
- _privilege_map[MethodId.<METHOD_ID>] = list<METHOD_ID>;
-)__cs_cb";
+ int cmd;
+ UnitMap map = new UnitMap();
+ map.Deserialize(p);
+ map.Read(<HASH_METHOD> /*[METHOD]*/, out cmd);
-const char CB_ON_RECEIVED_EVENT_FRONT[] =
-R"__cs_cb(
- protected override bool OnReceivedEvent(string sender, string instance, Port port)
- {
- Parcel p;
+ switch ((MethodId)cmd)
+ {
+ <INVOCATIONS*>
+ case MethodId.<ID>:
+ {
+ <PARAMS*>
+ <DELEGATE?>
+ map.Read(<HASH_ID> /*<PARAM_ID>*/, out CallbackBase del_param<CNT>);
+ var param<CNT> = new <TYPE>(cb_port, new WeakReference(b), del_param<CNT>);
+ </DELEGATE?>
+ <NO_DELEGATE?>
+ map.Read(<HASH_ID> /*<PARAM_ID>*/, out <TYPE> param<CNT>);
+ </NO_DELEGATE?>
+ </PARAMS*>
+ UnitMap result_map = new UnitMap();
+ if (b._is_app && CheckPrivilege((MethodId)cmd, b) == false)
+ {
+ RemoteException ex = new RemoteException("Permission denied", (int)Tizen.Internals.Errors.ErrorCode.PermissionDenied);
+ result_map.Write(<HASH_REMOTE_EXCEPTION> /*[REMOTE_EXCEPTION]*/, ex);
+ } else {
+ <SYNC?>
+ try
+ {
+ var retVal = b.<ID>(<INVOKE_PARAMS>);
+ result_map.Write(<HASH_RESULT> /*[RESULT]*/, retVal);
+ <OUT_PARAMS*>
+ result_map.Write(<HASH_ID> /*<PARAM_ID>*/, param<CNT>);
+ </OUT_PARAMS*>
+ } catch (RemoteException ex)
+ {
+ result_map.Write(<HASH_REMOTE_EXCEPTION> /*[REMOTE_EXCEPTION]*/, ex);
+ }
+ </SYNC?>
+ <ASYNC?>
+ b.<ID>(<INVOKE_PARAMS>);
+ </ASYNC?>
+ }
+
+ <SYNC?>
+ ParcelHeader header = p.GetHeader();
+ ParcelHeader resultHeader = result.GetHeader();
+ resultHeader.SetTag(_tidlVersion);
+ resultHeader.SetSequenceNumber(header.GetSequenceNumber());
+ int ret_cmd = (int)MethodId.__Result;
+ result_map.Write(<HASH_METHOD> /*[METHOD]*/, ret_cmd);
+ result_map.Serialize(result);
+
+ if (b._lem != null)
+ b._lem.SendResult(result);
+ else
+ result.Send(port);
+ </SYNC?>
+ break;
+ }
+ </INVOCATIONS*>
+
+ default:
+ return false;
+ }
- try
- {
- p = new Parcel(port);
+ return true;
+ }
+ catch (InvalidIOException)
+ {
+ return false;
+ }
+ finally
+ {
+ p.Dispose();
+ }
}
- catch (InvalidIOException)
+
+ protected override void OnConnectedEvent(string sender, string instance)
{
- return false;
+ ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
+ s.Sender = sender;
+ s.LoadPrivilege();
+ s.Instance = instance;
+ s.Port = GetPort(Port.Type.Callback, instance);
+ _services.Add(s);
+ s.OnCreate();
}
- return OnReceivedEvent(instance, port, p);
- }
-
- internal void OnLemReceivedEvent(string instance, Parcel p)
- {
- if (Thread.CurrentThread.ManagedThreadId != 1)
+ internal void OnLemConnectedEvent(object proxy_instance, string sender, string instance)
{
- _async_context.Post((data) =>
+ ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
+ s.Sender = sender;
+ s.LoadPrivilege();
+ s.Instance = instance;
+ s._lem = new LocalExecution(proxy_instance);
+ _services.Add(s);
+ if (Thread.CurrentThread.ManagedThreadId != 1)
{
- ((Message)data).OnReceivedEvent(instance, null, p);
- }, this);
- }
- else
- {
- OnReceivedEvent(instance, null, p);
+ _async_context.Post((data) =>
+ {
+ ((ServiceBase)data).OnCreate();
+ }, s);
+ }
+ else
+ {
+ s.OnCreate();
+ }
}
- }
- internal bool OnReceivedEvent(string instance, Port port, Parcel p)
- {
- try
+ protected override void OnDisconnectedEvent(string sender, string instance)
{
- ServiceBase b = null;
-
- foreach (var i in _services)
+ foreach (var i in _services)
{
if (i.Instance.Equals(instance))
{
- b = i;
+ if (i._lem != null)
+ i._lem._online = false;
+
+ i.OnTerminate();
+ _services.Remove(i);
break;
}
}
+ }
- if (b == null)
+ internal void OnLemDisconnectedEvent(string sender, string instance)
+ {
+ if (Thread.CurrentThread.ManagedThreadId != 1)
{
- return false;
+ _async_context.Post((data) =>
+ {
+ ((<CLASS_ID>)data).OnDisconnectedEvent(sender, instance);
+ }, this);
}
-
- var result = new Parcel();
-
- int cmd;
- UnitMap map = new UnitMap();
- map.Deserialize(p);
-
- map.Read("[METHOD]", out cmd);
-
- switch ((MethodId)cmd)
+ else
{
-)__cs_cb";
-
-const char CB_ON_RECEIVED_EVENT_BACK[] =
-R"__cs_cb(
- default:
- return false;
+ OnDisconnectedEvent(sender, instance);
}
-
- return true;
}
- catch (InvalidIOException)
+
+ internal static <CLASS_ID> GetInstance()
{
- return false;
+ return _instance;
}
- finally
+
+ internal bool GetListenStatus()
{
- p.Dispose();
+ return _isListen;
}
- }
-)__cs_cb";
-const char CB_ON_CONNECTED_EVENT[] =
-R"__cs_cb(
- protected override void OnConnectedEvent(string sender, string instance)
- {
- ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
- s.Sender = sender;
- s.LoadPrivilege();
- s.Instance = instance;
- s.Port = GetPort(Port.Type.Callback, instance);
- _services.Add(s);
- s.OnCreate();
- }
+ public <CLASS_ID>() : base("<CLASS_ID>")
+ {
+ _instance = this;
+ <ATTRIBUTES*>
+ <PRIVILEGE?>
+ AddPrivilege("<VAL>");
+ </PRIVILEGE?>
+ <TRUSTED?>
+ SetTrusted(<VAL>);
+ </TRUSTED?>
+ </ATTRIBUTES*>
+
+ <PRIVILEGE_MAP*>
+ List<string> list<METHOD_ID> = new List<string>();
+ <PRIVILEGE_LIST>
+ _privilege_map[MethodId.<METHOD_ID>] = list<METHOD_ID>;
+ </PRIVILEGE_MAP*>
+ }
- internal void OnLemConnectedEvent(object proxy_instance, string sender, string instance)
- {
- ServiceBase s = Activator.CreateInstance(_serviceType) as ServiceBase;
- s.Sender = sender;
- s.LoadPrivilege();
- s.Instance = instance;
- s._lem = new LocalExecution(proxy_instance);
- _services.Add(s);
- if (Thread.CurrentThread.ManagedThreadId != 1)
+ /// <summary>
+ /// Listens to client apps
+ /// </summary>
+ /// <param name="serviceType">The type object for making service instances</param>
+ /// <exception cref="InvalidIOException">
+ /// Thrown when internal I/O error happen.
+ /// </exception>
+ /// <exception cref="ArgumentException">
+ /// Thrown when serviceType is invalid.
+ /// </exception>
+ public void Listen(Type serviceType)
{
- _async_context.Post((data) =>
- {
- ((ServiceBase)data).OnCreate();
- }, s);
+ if (!typeof(ServiceBase).IsAssignableFrom(serviceType))
+ throw new ArgumentException("Invalid type");
+ _serviceType = serviceType;
+ Listen();
+ _isListen = true;
}
- else
+
+ /// <summary>
+ /// Gets service objects which are connected
+ /// </summary>
+ /// <returns>The enumerable service objects which are connected</returns>
+ public IEnumerable<ServiceBase> GetServices()
{
- s.OnCreate();
+ return _services;
}
- }
-)__cs_cb";
-const char CB_ON_DISCONNECTED_EVENT[] =
-R"__cs_cb(
- protected override void OnDisconnectedEvent(string sender, string instance)
- {
- foreach (var i in _services)
+ protected override void OnTerminatedEvent()
{
- if (i.Instance.Equals(instance))
+ foreach (var i in _services)
{
if (i._lem != null)
- i._lem._online = false;
-
+ i._lem._online = false;
i.OnTerminate();
- _services.Remove(i);
- break;
}
}
- }
- internal void OnLemDisconnectedEvent(string sender, string instance)
- {
- if (Thread.CurrentThread.ManagedThreadId != 1)
- {
- _async_context.Post((data) =>
- {
- ((Message)data).OnDisconnectedEvent(sender, instance);
- }, this);
- }
- else
- {
- OnDisconnectedEvent(sender, instance);
- }
+ </INTERFACES*>
}
-)__cs_cb";
-
-const char CB_CTOR_FRONT[] =
-R"__cs_cb(
- internal static Message GetInstance()
- {
- return _instance;
- }
-
- internal bool GetListenStatus()
- {
- return _isListen;
- }
-
- public $$() : base("$$")
- {
- _instance = this;
-)__cs_cb";
-
-const char CB_COMMON_METHODS[] =
-R"__cs_cb(
- /// <summary>
- /// Listens to client apps
- /// </summary>
- /// <param name="serviceType">The type object for making service instances</param>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- /// <exception cref="ArgumentException">
- /// Thrown when serviceType is invalid.
- /// </exception>
- public void Listen(Type serviceType)
- {
- if (!typeof(ServiceBase).IsAssignableFrom(serviceType))
- throw new ArgumentException("Invalid type");
- _serviceType = serviceType;
- Listen();
- _isListen = true;
- }
-
- /// <summary>
- /// Gets service objects which are connected
- /// </summary>
- /// <returns>The enumerable service objects which are connected</returns>
- public IEnumerable<ServiceBase> GetServices()
- {
- return _services;
- }
-)__cs_cb";
-
-const char CB_DISPOSABLE[] =
-R"__cs_cb(
- protected override void OnTerminatedEvent()
- {
- foreach (var i in _services)
- {
- if (i._lem != null)
- i._lem._online = false;
- i.OnTerminate();
- }
- }
-)__cs_cb";
-
-constexpr const char CB_INVOCATION_CHECK_PRIVILEGE[] =
-R"__cs_cb(
-if (b._is_app && CheckPrivilege((MethodId)cmd, b) == false)
-{
- RemoteException ex = new RemoteException("Permission denied", (int)Tizen.Internals.Errors.ErrorCode.PermissionDenied);
- result_map.Write("[REMOTE_EXCEPTION]", ex);
-} else {
- <INVOCATION>
+ }
+ }
}
-)__cs_cb";
-
-constexpr const char CB_INVOCATION_REMOTE_EXCEPTION[] =
-R"__cs_cb(try
-{
- <SYNC_INVOCATION>
- <WRITE_RESULT>
- <WRITE_OUT_PARAM>
-} catch (RemoteException ex)
-{
- result_map.Write("[REMOTE_EXCEPTION]", ex);
-})__cs_cb";
-
-constexpr const char CB_INVOCATION_RESULT[] =
-R"__cs_cb(
-ParcelHeader header = p.GetHeader();
-ParcelHeader resultHeader = result.GetHeader();
-resultHeader.SetTag(_tidlVersion);
-resultHeader.SetSequenceNumber(header.GetSequenceNumber());
-result_map.Write("[METHOD]", (int)MethodId.__Result);
-result_map.Serialize(result);
-
-if (b._lem != null)
- b._lem.SendResult(result);
-else
- result.Send(port);
)__cs_cb";