This patch adds a new method for inhouse developers.
- <PREFIX>_<NAME>_context_get_peer_info()
- ServiceBase::GetPid()
- ServiceBase::GetUid()
Change-Id: I1ad077c2feece1004056fbd3549525b3aa6fe118
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
GenInterfaceMethodTable(stream, iface);
GenInterfaceContextBase(stream, iface);
+ if (options_->UseExtension()) GenInterfaceContextExtensionBase(stream, iface);
if (has_delegate)
GenInterfaceCallbackPortCheck(stream, iface);
stream << SmartIndent(code);
}
+void CStubBodyGen::GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ ReplaceAll(CB_INTERFACE_CONTEXT_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string str) { return SmartIndent(str); })
+ .Out(stream);
+}
+
} // namespace tidl
const Interface& iface);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface);
std::string GenMethodEnums(const Interface& iface);
std::string GenDelegateEnums(const Interface& iface);
}
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_CONTEXT_EXTENSION_BASE[] =
+R"__c_cb(
+int <PREFIX>_<NAME>_context_get_peer_info(<PREFIX>_<NAME>_context_h context, pid_t *pid, uid_t *uid)
+{
+ return rpc_port_get_peer_info(context->port, pid, uid);
+}
+)__c_cb";
+
/**
* <PREFIX> The prefix of the interface.
* <NAME> The name of the interface.
void CStubHeaderGen::GenInterface(std::ofstream& stream,
const Interface& iface) {
GenInterfaceContextBase(stream, iface);
+ if (options_->UseExtension()) GenInterfaceContextExtensionBase(stream, iface);
for (const auto& d : iface.GetDeclarations()) {
if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
stream << SmartIndent(code);
}
+void CStubHeaderGen::GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface) {
+ ReplaceAll(CB_INTERFACE_CONTEXT_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string str) { return SmartIndent(str); })
+ .Out(stream);
+}
+
} // namespace tidl
const Declaration& decl);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface);
std::string GenDelegateParams(const Interface& iface,
const Declaration& decl);
int <PREFIX>_<NAME>_context_disconnect(<PREFIX>_<NAME>_context_h context);
)__c_cb";
+constexpr const char CB_INTERFACE_CONTEXT_EXTENSION_BASE[] =
+R"__c_cb(
+/**
+ * @brief Gets the peer info from the context handle.
+ *
+ * @param[in] context The context handle
+ * @param[out] pid The process ID
+ * @param[out] uid The user ID
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
+ */
+int <PREFIX>_<NAME>_context_get_peer_info(<PREFIX>_<NAME>_context_h context, pid_t *pid, uid_t *uid);
+)__c_cb";
+
/**
* <PREFIX> The prefix of the interface.
* <NAME> The name of the interface.
void CppStubBodyGen::GenServiceBase(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_CTOR_SERVICE_BASE, stream,
- [&]()->std::string {
- return iface.GetID();
- });
+ ReplaceAll(CB_CTOR_SERVICE_BASE).Replace("$$", iface.GetID()).Out(stream);
stream << NLine(1);
- GenTemplate(CB_SERVICE_DEFAULT_METHOD, stream,
- [&]()->std::string {
- return iface.GetID();
- }, [&]()->std::string {
- return iface.GetID();
- });
+
+ std::string extension_impl =
+ options_->UseExtension() ? "rpc_port_get_peerinfo(port, &pid_, &uid_);"
+ : "// Set Port";
+ auto code =
+ ReplaceAll(CB_SERVICE_DEFAULT_METHOD).Replace("$$", iface.GetID());
+ ReplaceAll(code).Change("<EXTENSION_IMPL>", extension_impl).Out(stream);
stream << NLine(1);
}
const char CB_SERVICE_DEFAULT_METHOD[] =
R"__cpp_cb(void $$::ServiceBase::SetPort(rpc_port_h port) {
+ <EXTENSION_IMPL>
port_ = port;
}
stream << ") = 0;" << NLine(1);
}
+ if (options_->UseExtension()) stream << CB_SERVICE_EXTENSION_BASE;
+
stream << CB_SERVICE_BASE_BACK << NLine(2);
}
bool HasPendingRequest() const;
)__cpp_cb";
+const char CB_SERVICE_EXTENSION_BASE[] =
+R"__cpp_cb(
+ /// <summary>
+ /// Gets the process ID of the client.
+ /// </summary>
+ pid_t GetPid() const { return pid_; }
+
+ /// <summary>
+ /// Gets the user ID of the client.
+ /// </summary>
+ uid_t GetUid() const { return uid_; }
+
+ private:
+ pid_t pid_ = -1;
+ uid_t uid_ = 0;
+)__cpp_cb";
+
#endif // IDLC_CPP_GEN_CPP_STUB_HEADER_GEN_CB_H_
GenInterfaceMethodPrivilegeCheckerTable(stream, iface);
GenInterfaceMethodTable(stream, iface);
GenInterfaceContextBase(stream, iface);
+ GenInterfaceContextExtensionBase(stream, iface);
if (has_delegate)
GenInterfaceCallbackPortCheck(stream, iface);
}
}
+// @see #CB_INTERFACE_CONTEXT_EXTENSION_BASE
+void CStubBodyGenerator::GenInterfaceContextExtensionBase(
+ std::ofstream& stream, const Interface& iface) {
+ if (options_->UseExtension()) {
+ ReplaceAll(CB_INTERFACE_CONTEXT_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+ }
+}
+
} // namespace version2
} // namespace tidl
const Interface& iface);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface);
std::string GenMethodEnums(const Interface& iface);
std::string GenDelegateEnums(const Interface& iface);
}
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_CONTEXT_EXTENSION_BASE[] =
+R"__c_cb(
+EXPORT_API int <PREFIX>_<NAME>_context_get_peer_info(<PREFIX>_<NAME>_context_h context, pid_t *pid, uid_t *uid)
+{
+ return rpc_port_get_peer_info(context->port, pid, uid);
+}
+)__c_cb";
+
} // namespace version2
} // namespace tidl
}
}
+// @see #CB_INTERFACE_CONTEXT_EXTENSION_BASE
+void CStubHeaderGenerator::GenInterfaceContextExtensionBase(
+ std::ofstream& stream, const Interface& iface) {
+ if (options_->UseExtension()) {
+ ReplaceAll(CB_INTERFACE_CONTEXT_EXTENSION_BASE)
+ .Change("<PREFIX>", GetHandlePrefix())
+ .Change("<NAME>", iface.GetID())
+ .Transform([&](std::string code) { return SmartIndent(code); })
+ .Out(stream);
+ }
+}
+
} // namespace version2
} // namespace tidl
const Declaration& decl);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
void GenInterfaceExtensionBase(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceContextExtensionBase(std::ofstream& stream,
+ const Interface& iface);
std::string GenDelegateParams(const Interface& iface,
const Declaration& decl);
*/
constexpr const char CB_INTERFACE_EXTENSION_BASE[] =
R"__c_cb(
+/**
+ * @brief Checks whether the pending request exists or not.
+ *
+ * @return @c true if the pending request exists,
+ * otherwise @c false
+ */
bool <PREFIX>_<NAME>_has_pending_request(void);
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_CONTEXT_EXTENSION_BASE[] =
+R"__c_cb(
+/**
+ * @brief Gets the peer information from the context handle.
+ *
+ * @param[in] context The context handle
+ * @param[out] pid The process ID of the client
+ * @param[out] uid The user ID of the client
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #RPC_PORT_ERROR_NONE Successful
+ * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #RPC_PORT_ERROR_IO_ERROR I/O error
+ */
+int <PREFIX>_<NAME>_context_get_peer_info(<PREFIX>_<NAME>_context_h context, pid_t *pid, uid_t *uid);
+)__c_cb";
+
} // namespace version2
} // namespace tidl
.Change("<CLS_NAME>", iface.GetID())
.Change("<CALLBACKS>", GenInterfaceCallbacks(iface))
.Change("<IMPL_SERVICE_BASE_THREAD_MEMBER_INIT>",
- GenInterfaceImplServiceBaseThreadMemberInit())
+ GenInterfaceImplServiceBaseThreadMemberInit())
.Change("<IMPL_SERVICE_BASE_DISPATCH_FUNC_INIT>",
- GenInterfaceImplServiceBaseDispatchFuncInit(iface))
+ GenInterfaceImplServiceBaseDispatchFuncInit(iface))
.Change("<IMPL_SERVICE_BASE_DISPATCH>",
- GenInterfaceImplServiceBaseDispatch())
+ GenInterfaceImplServiceBaseDispatch())
.Change("<IMPL_SERVICE_BASE_DISPATCH_FUNCS>",
- GenInterfaceImplServiceBaseDispatchFuncs(iface))
+ GenInterfaceImplServiceBaseDispatchFuncs(iface))
.Change("<IMPL_SERVICE_BASE_SET_PRIVILEGE_MAP>",
- GenInterfaceImplServiceBaseSetPrivilegeMap(iface))
+ GenInterfaceImplServiceBaseSetPrivilegeMap(iface))
.Repeat("IMPL_ADD_PRIVILEGE", iface.GetAttributes(),
- [&](ReplaceAll* ra, const std::unique_ptr<tidl::Attribute>& attr) {
- if (attr->GetKey() != "privilege")
- return false;
-
- ra->Replace("PRIVILEGE", attr->GetValue());
- return true;
- })
- .Remove("IMPL_SET_TRUSTED", std::find_if(
- iface.GetAttributes().begin(),
- iface.GetAttributes().end(),
- [](const auto& attr) {
- return attr->GetKey() == "trusted" && attr->GetValue() == "true";
- }) == iface.GetAttributes().end()));
+ [&](ReplaceAll* ra,
+ const std::unique_ptr<tidl::Attribute>& attr) {
+ if (attr->GetKey() != "privilege") return false;
+
+ ra->Replace("PRIVILEGE", attr->GetValue());
+ return true;
+ })
+ .Remove("IMPL_SET_TRUSTED",
+ std::find_if(iface.GetAttributes().begin(),
+ iface.GetAttributes().end(),
+ [](const auto& attr) {
+ return attr->GetKey() == "trusted" &&
+ attr->GetValue() == "true";
+ }) == iface.GetAttributes().end())
+ .Change("<IMPL_SERVICE_BASE_EXTENSION>", [&]() {
+ if (options_->UseExtension())
+ return "rpc_port_get_peer_info(port_, &pid_, &uid_);";
+
+ return "";
+ }));
}
std::string CppStubBodyGenerator::GenInterfaceCallbacks(
* <IMPL_SERVICE_BASE_DISPATCH> The implementation of the dispatch method of the service base.
* <IMPL_SERVICE_BASE_DISPATCH_FUNCS> The implementation of the dispatch functions of the service base.
* <IMPL_SERVICE_BASE_SET_PRIVILEGE_MAP> The implementation of setting privilege map of the service base.
+ * <IMPL_SERVICE_BASE_EXTENSION> The implementation of the extension codes of the service base.
*/
constexpr const char CB_INTERFACE_BASE[] =
R"__cpp_cb(
}
void <CLS_NAME>::ServiceBase::SetPort(rpc_port_h port) {
+ <IMPL_SERVICE_BASE_EXTENSION>
port_ = port;
}
GenInterfaceServiceBaseImplThreadMember())
.Change("<EXTENSION_BASE>", GenInterfaceExtensionBase())
.Change("<METHOD_IDS>", GenMethodIds(iface))
- .Change("<DELEGATE_IDS>", GenDelegateIds(iface)));
+ .Change("<DELEGATE_IDS>", GenDelegateIds(iface))
+ .Change("<SERVICE_BASE_EXTENSION>",
+ GenInterfaceServiceBaseExtension()));
}
std::string CppStubHeaderGenerator::GenInterfaceCallbacks(
return "";
}
+std::string CppStubHeaderGenerator::GenInterfaceServiceBaseExtension() {
+ if (options_->UseExtension())
+ return std::string(CB_INTERFACE_SERVICE_BASE_EXTENSION);
+
+ return "";
+}
+
} // namespace version2
} // namespace tidl
std::string GenInterfaceServiceBaseDispatchFuncs(const Interface& iface);
std::string GenInterfaceServiceBaseImplThreadMember();
std::string GenInterfaceExtensionBase();
+ std::string GenInterfaceServiceBaseExtension();
private:
std::shared_ptr<Options> options_;
* <SERVICE_BASE_IMPL_THREAD_MEMBER> The member variable of the thread of service base.
* <METHOD_IDS> The enumeration of methods of the interface.
* <DELEGATE_IDS> The enumeration of delegates(callbacks) of the interface.
+ * <SERVICE_BASE_EXTENSION> The extension methods of the service base of the interface.
*/
constexpr const char CB_INTERFACE_BASE[] =
R"__cpp_cb(
void Dispatch(rpc_port_h port, rpc_port_h callback_port, rpc_port_parcel_h parcel);
<SERVICE_BASE_METHODS>
+ <SERVICE_BASE_EXTENSION>
protected:
ServiceBase(std::string sender, std::string instance);
std::unique_ptr<ActiveObject> active_object_;
)__cpp_cb";
+constexpr const char CB_INTERFACE_SERVICE_BASE_EXTENSION[] =
+R"__cpp_cb(
+ /// <summary>
+ /// Gets the process ID of the client.
+ /// </summary>
+ pid_t GetPid() const { return pid_; }
+
+ /// <summary>
+ /// Gets the user ID of the client.
+ /// </summary>
+ uid_t GetUid() const { return uid_; }
+
+private:
+ pid_t pid_ = -1;
+ uid_t uid_ = 0;
+)__cpp_cb";
+
constexpr const char CB_LEM_BASE[] =
R"__cpp_cb(
class LocalExecution {