The implemenation that the callback port check is separated.
If the interface doesn't have the delegate, the callback port check
is not needed.
Change-Id: I04aaf8c0d5a00347901afbbebda75f85744bf442
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
void CStubBodyGen::GenInterfaceDef(std::ofstream& stream,
const Interface& iface) {
+ bool has_delegate = false;
for (auto& d : iface.GetDeclarations().GetDecls()) {
if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
GenInterfaceDelegateDef(stream, iface, *d);
+ has_delegate = true;
}
+ if (has_delegate)
+ GenInterfaceCallbackPortCheckDef(stream, iface);
+
GenInterfaceContextDef(stream, iface);
GenInterfaceBaseDef(stream, iface);
}
stream << SmartIndent(code);
}
+// @see #CB_INTERFACE_CALLBACK_PORT_CHECK_DEF
+void CStubBodyGen::GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
+ const Interface& iface) {
+ std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK_DEF,
+ "<PREFIX>", GetHandlePrefix());
+ code = ReplaceAll(code, "<NAME>", iface.GetID());
+
+ stream << SmartIndent(code);
+}
+
// @see #CB_INTERFACE_CONTEXT_DEF
void CStubBodyGen::GenInterfaceContextDef(std::ofstream& stream,
const Interface& iface) {
}
void CStubBodyGen::GenInterface(std::ofstream& stream, const Interface& iface) {
+ bool has_delegate = false;
for (auto& d : iface.GetDeclarations().GetDecls()) {
if (d->GetMethodType() != Declaration::MethodType::DELEGATE)
continue;
GenInterfaceDelegateBase(stream, iface, *d);
+ has_delegate = true;
}
for (auto& d : iface.GetDeclarations().GetDecls()) {
GenInterfaceMethodTable(stream, iface);
GenInterfaceContextBase(stream, iface);
+
+ if (has_delegate)
+ GenInterfaceCallbackPortCheck(stream, iface);
+
GenInterfaceBase(stream, iface);
}
stream << SmartIndent(code);
}
+// @see #CB_INTERFACE_CALLBACK_PORT_CHECK
+void CStubBodyGen::GenInterfaceCallbackPortCheck(std::ofstream& stream,
+ const Interface& iface) {
+ std::string code = ReplaceAll(CB_INTERFACE_CALLBACK_PORT_CHECK, "<PREFIX>",
+ GetHandlePrefix());
+ code = ReplaceAll(code, "<NAME>", iface.GetID());
+
+ stream << SmartIndent(code);
+}
+
// @see #CB_INTERFACE_PRIVILEGE_ADD
// @see #CB_INTERFACE_TRUSTED_SET
std::string CStubBodyGen::GenAccessControlSet(const Interface& iface) {
void GenInterfaceContextDef(std::ofstream& stream, const Interface& iface);
void GenInterfaceDelegateDef(std::ofstream& stream, const Interface& iface,
const Declaration& decl);
+ void GenInterfaceCallbackPortCheckDef(std::ofstream& stream,
+ const Interface& iface);
void GenInterfaceBaseDef(std::ofstream& stream, const Interface& iface);
void GenInterfaces(std::ofstream& stream);
void GenInterfaceMethodHandlerBase(std::ofstream& stream,
const Interface& iface, const Declaration& decl);
void GenInterfaceMethodTable(std::ofstream& stream, const Interface& iface);
+ void GenInterfaceCallbackPortCheck(std::ofstream& stream,
+ const Interface& iface);
void GenInterfaceBase(std::ofstream& stream, const Interface& iface);
std::string GenMethodEnums(const Interface& iface);
bool done;
#endif /* TIDL_THREAD_ENABLE */
} <PREFIX>_<NAME>_context_t;
+)__c_cb";
+/**
+ *
+ */
+constexpr const char CB_INTERFACE_CALLBACK_PORT_CHECK_DEF[] =
+R"__c_cb(
static bool __<PREFIX>_<NAME>_exist_callback_port(rpc_port_h callback_port);
)__c_cb";
__<NAME>.contexts = g_list_remove(__<NAME>.contexts, context);
g_rec_mutex_unlock(&__<NAME>.mutex);
}
-
-static bool __<PREFIX>_<NAME>_exist_callback_port(rpc_port_h callback_port)
-{
- rpc_port_h port;
- GList *iter;
-
- g_rec_mutex_lock(&__<NAME>.mutex);
- iter = __<NAME>.callback_ports;
- while (iter) {
- port = iter->data;
- if (port == callback_port) {
- g_rec_mutex_unlock(&__<NAME>.mutex);
- return true;
- }
-
- iter = g_list_next(iter);
- }
- g_rec_mutex_unlock(&__<NAME>.mutex);
-
- return false;
-}
-
-static void __<PREFIX>_<NAME>_add_callback_port(rpc_port_h callback_port)
-{
- g_rec_mutex_lock(&__<NAME>.mutex);
- __<NAME>.callback_ports = g_list_append(__<NAME>.callback_ports, callback_port);
- g_rec_mutex_unlock(&__<NAME>.mutex);
-}
-
-static void __<PREFIX>_<NAME>_remove_callback_port(rpc_port_h callback_port)
-{
- g_rec_mutex_lock(&__<NAME>.mutex);
- __<NAME>.callback_ports = g_list_remove(__<NAME>.callback_ports, callback_port);
- g_rec_mutex_unlock(&__<NAME>.mutex);
-}
)__c_cb";
/**
*/
constexpr const char CB_INTERFACE_BASE[] =
R"__c_cb(
+static void __<PREFIX>_<NAME>_add_callback_port(rpc_port_h callback_port)
+{
+ g_rec_mutex_lock(&__<NAME>.mutex);
+ __<NAME>.callback_ports = g_list_append(__<NAME>.callback_ports, callback_port);
+ g_rec_mutex_unlock(&__<NAME>.mutex);
+}
+
+static void __<PREFIX>_<NAME>_remove_callback_port(rpc_port_h callback_port)
+{
+ g_rec_mutex_lock(&__<NAME>.mutex);
+ __<NAME>.callback_ports = g_list_remove(__<NAME>.callback_ports, callback_port);
+ g_rec_mutex_unlock(&__<NAME>.mutex);
+}
+
static void __<PREFIX>_<NAME>_connected_event_cb(const char *sender, const char *instance, void *user_data)
{
<PREFIX>_<NAME>_context_h context;
}
)__c_cb";
+/**
+ * <PREFIX> The prefix of the interface.
+ * <NAME> The name of the interface.
+ */
+constexpr const char CB_INTERFACE_CALLBACK_PORT_CHECK[] =
+R"__c_cb(
+static bool __<PREFIX>_<NAME>_exist_callback_port(rpc_port_h callback_port)
+{
+ rpc_port_h port;
+ GList *iter;
+
+ g_rec_mutex_lock(&__<NAME>.mutex);
+ iter = __<NAME>.callback_ports;
+ while (iter) {
+ port = iter->data;
+ if (port == callback_port) {
+ g_rec_mutex_unlock(&__<NAME>.mutex);
+ return true;
+ }
+
+ iter = g_list_next(iter);
+ }
+ g_rec_mutex_unlock(&__<NAME>.mutex);
+
+ return false;
+}
+)__c_cb";
+
/**
* <NAME> The name of the interface.
* <PRIVILEGE> The privilege name.