if (unit_map == nullptr || name == nullptr || value == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- ret = <PARAM_TYPE_CTOR>(&h);
- if (ret != RPC_PORT_ERROR_NONE)
- return ret;
-
- *value = h;
unit = g_hash_table_lookup(unit_map->table, name);
if (unit == nullptr) {
_E("g_hash_table_lookup() is failed. name: %s", name);
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
+ ret = <PARAM_TYPE_CTOR>(&h);
+ if (ret != RPC_PORT_ERROR_NONE)
+ return ret;
+
+ *value = h;
rpc_port_parcel_read(unit->parcel, &h->parcelable, h);
return get_last_result();
if (unit_map == nullptr || name == nullptr || value == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- delegate = rpc_port_delegate_create();
- if (delegate == NULL)
- return RPC_PORT_ERROR_OUT_OF_MEMORY;
-
- *value = delegate;
unit = g_hash_table_lookup(unit_map->table, name);
if (unit == nullptr) {
_E("g_hash_table_lookup() is failed. name: %s", name);
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
+ delegate = rpc_port_delegate_create();
+ if (delegate == NULL)
+ return RPC_PORT_ERROR_OUT_OF_MEMORY;
+
+ *value = delegate;
rpc_port_parcel_read(unit->parcel, &delegate->parcelable, delegate);
return get_last_result();
}
}
-void CStubBodyGenerator::GenInterface(std::ofstream& stream, const Interface& iface) {
+void CStubBodyGenerator::GenInterface(std::ofstream& stream,
+ const Interface& iface) {
bool has_delegate = false;
for (const auto& d : iface.GetDeclarations()) {
if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
} else if (type.GetUserDefinedType() == BaseType::UserType::STRUCTURE ||
type.GetMetaType() != nullptr ||
type.GetKeyType() != nullptr) {
- parcel_read_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_READ)
- .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
- .Change("<ARG_NAME>", p->GetID())
- .Change("<ARG>", p->GetID());
+ parcel_read_code =
+ ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_READ)
+ .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
+ .Change("<ARG_NAME>", p->GetID())
+ .Change("<ARG>", p->GetID());
} else if (type.ToString() == "bundle") {
parcel_read_code = ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_UNIT_MAP_READ)
.Change("<ARG_NAME>", p->GetID())
if (type.GetUserDefinedType() == BaseType::UserType::DELEGATE) {
parcel_write_code = ReplaceAll(CB_INTERFACE_METHOD_DELEGATE_UNIT_MAP_WRITE)
- .Change("<ARG_NAME>", std::string("delegate"))
- .Change("<ARG>", arg);
+ .Change("<ARG_NAME>", std::string("delegate"))
+ .Change("<ARG>", arg);
} else if (type.GetUserDefinedType() == BaseType::UserType::ENUM) {
parcel_write_code = ReplaceAll(CB_INTERFACE_METHOD_ENUM_UNIT_MAP_WRITE)
- .Change("<ARG_NAME>", arg_name)
- .Change("<ARG>", arg);
+ .Change("<ARG_NAME>", arg_name)
+ .Change("<ARG>", arg);
} else if (type.IsUserDefinedType() ||
type.GetMetaType() != nullptr ||
type.GetKeyType() != nullptr) {
- parcel_write_code = ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_WRITE)
- .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
- .Change("<ARG_NAME>", arg_name)
- .Change("<ARG>", arg);
+ parcel_write_code =
+ ReplaceAll(CB_INTERFACE_METHOD_USER_DEFINED_UNIT_MAP_WRITE)
+ .Change("<TYPE_NAME>", GetFullNameFromType(type, iface))
+ .Change("<ARG_NAME>", arg_name)
+ .Change("<ARG>", arg);
parcel_write_code += GetPrivateSharingString(type, iface, "port", arg);
} else if (type.ToString() == "bundle") {
parcel_write_code = ReplaceAll(CB_INTERFACE_METHOD_BUNDLE_UNIT_MAP_WRITE)
.Change("<ARG>", arg);
}
- return parcel_write_code;
+ return parcel_write_code;
}
// @see #CB_INTERFACE_METHOD_PARCEL_WRITE_PRE
// @see #CB_INTERFACE_METHOD_PARCEL_WRITE_POST
return code;
}
+// @see #CB_INTERFACE_METHOD_PRIVILEGE_CHECKER
+std::string CStubBodyGenerator::GenMethodPrivilegeChecker(
+ const Declaration& decl) {
+ auto privileges = GenPrivileges(decl);
+ if (privileges.empty())
+ return "return RPC_PORT_ERROR_NONE;" + NLine(1);
+
+ std::string sync =
+ (decl.GetMethodType() == Declaration::MethodType::SYNC) ?
+ "true" : "false";
+ std::string code(ReplaceAll(CB_INTERFACE_METHOD_PRIVILEGE_CHECKER)
+ .Change("<PRIVILEGES>", privileges)
+ .Change("<SYNC_TRUE_OR_FALSE>", sync));
+ return RemoveLine(code);
+}
+
// @see #CB_INTERFACE_METHOD_PRIVILEGE_CHECKER_BASE
void CStubBodyGenerator::GenInterfaceMethodPrivilegeCheckerBase(
std::ofstream& stream, const Interface& iface, const Declaration& decl) {
- std::string sync =
- (decl.GetMethodType() == Declaration::MethodType::SYNC) ? "true" : "false";
ReplaceAll(CB_INTERFACE_METHOD_PRIVILEGE_CHECKER_BASE)
.Change("<PREFIX>", GetHandlePrefix())
.Change("<NAME>", iface.GetID())
.Change("<METHOD_NAME>", decl.GetID())
- .Change("<PRIVILEGES>", GenPrivileges(decl))
- .Change("<SYNC_TRUE_OR_FALSE>", sync)
+ .Change("<METHOD_PRIVILEGE_CHECKER>", GenMethodPrivilegeChecker(decl))
.Transform([&](std::string code) { return SmartIndent(code); })
.Out(stream);
}
* <PREFIX> The prefix of the interace.
* <NAME> The name of the interface.
* <METHOD_NAME> The name of the method of the interface.
- * <PRIVILEGES> The privileges of the method
- * <SYNC_TRUE_OR_FALSE> The flag if it's true, the stub should throw the remote exception.
+ * <METHOD_PRIVILEGE_CHECKER> The implementation of the method privilege checker.
*/
constexpr const char CB_INTERFACE_METHOD_PRIVILEGE_CHECKER_BASE[] =
R"__c_cb(
static int __<PREFIX>_<NAME>_method_<METHOD_NAME>_privilege_checker(<PREFIX>_<NAME>_context_h h, bool *sync)
{
- static const char *privileges[] = {
- <PRIVILEGES>
- };
-
- *sync = <SYNC_TRUE_OR_FALSE>;
- for (int i = 0; i < ARRAY_SIZE(privileges); ++i) {
- if (!g_hash_table_contains(h->privileges, privileges[i])) {
- _E("Permission denied. %s : %s", h->sender, privileges[i]);
- return RPC_PORT_ERROR_PERMISSION_DENIED;
- }
- }
+ <METHOD_PRIVILEGE_CHECKER>
+}
+)__c_cb";
- return RPC_PORT_ERROR_NONE;
+/**
+ * <PRIVILEGES> The privileges of the method
+ * <SYNC_TRUE_OR_FALSE> The flag if it's true, the stub should throw the remote exception.
+ */
+constexpr const char CB_INTERFACE_METHOD_PRIVILEGE_CHECKER[] =
+R"__c_cb(
+static const char *privileges[] = {
+ <PRIVILEGES>
+};
+
+*sync = <SYNC_TRUE_OR_FALSE>;
+for (size_t i = 0; i < ARRAY_SIZE(privileges); ++i) {
+ if (!g_hash_table_contains(h->privileges, privileges[i])) {
+ _E("Permission denied. %s : %s", h->sender, privileges[i]);
+ return RPC_PORT_ERROR_PERMISSION_DENIED;
+ }
}
+
+return RPC_PORT_ERROR_NONE;
)__c_cb";
/**