diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2018-06-14 17:55:19 +0900 |
---|---|---|
committer | HwanKyu Jhun <h.jhun@samsung.com> | 2018-06-14 10:30:05 +0000 |
commit | 05cfe7156f1da4892f8683a1e4b2dc01b67e0478 (patch) | |
tree | 843b65547404371d2900f63b3b727a2808077f6d | |
parent | 27385233c23471ad5d46801f493faad51601acb5 (diff) | |
download | tidl-05cfe7156f1da4892f8683a1e4b2dc01b67e0478.tar.gz tidl-05cfe7156f1da4892f8683a1e4b2dc01b67e0478.tar.bz2 tidl-05cfe7156f1da4892f8683a1e4b2dc01b67e0478.zip |
Change dlog messages
After this patch is applied, the generated code prints
file name, function name and line numbers.
Change-Id: I07ea6c638ebfde97714fe3e2ea16da6318250c04
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | idlc/c_gen/c_body_gen_base.cc | 34 | ||||
-rw-r--r-- | idlc/c_gen/c_body_gen_base.h | 1 | ||||
-rw-r--r-- | idlc/c_gen/c_body_gen_base_cb.h | 62 | ||||
-rw-r--r-- | idlc/c_gen/c_proxy_body_gen.cc | 1 | ||||
-rw-r--r-- | idlc/c_gen/c_proxy_body_gen_cb.h | 48 | ||||
-rw-r--r-- | idlc/c_gen/c_stub_body_gen.cc | 1 | ||||
-rw-r--r-- | idlc/c_gen/c_stub_body_gen_cb.h | 72 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_gen_base.cc | 4 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_gen_base.h | 1 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_gen_base_cb.h | 24 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_proxy_body_gen.cc | 1 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_proxy_body_gen_cb.h | 12 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_stub_body_gen.cc | 1 | ||||
-rw-r--r-- | idlc/cpp_gen/cpp_stub_body_gen_cb.h | 10 |
14 files changed, 162 insertions, 110 deletions
diff --git a/idlc/c_gen/c_body_gen_base.cc b/idlc/c_gen/c_body_gen_base.cc index dcff508..bc8eaea 100644 --- a/idlc/c_gen/c_body_gen_base.cc +++ b/idlc/c_gen/c_body_gen_base.cc @@ -469,8 +469,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, }, [&]()->std::string { std::string ss; - ss += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Failed to create handle\");" + NLine(1); + ss += "_E(\"Failed to create handle\");" + NLine(1); ss += "return;"; return ss; }); @@ -499,8 +498,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, }, [&]()->std::string { std::string ss; - ss += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Out of memory\");" + NLine(1); + ss += "_E(\"Out of memory\");" + NLine(1); ss += "return;"; return ss; }); @@ -551,8 +549,7 @@ std::string CBodyGeneratorBase::GetParcelReadString(const std::string& id, }, [&]()->std::string { std::string ss; - ss += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Failed to create handle\");" + NLine(1); + ss += "_E(\"Failed to create handle\");" + NLine(1); ss += "return;"; return ss; }); @@ -696,8 +693,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, }, [&]()->std::string { std::string s; - s += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Failed to duplicate data\");" + NLine(1); + s += "_E(\"Failed to duplicate data\");" + NLine(1); s += "return -1;"; return s; }); @@ -730,8 +726,7 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id, }, [&]()->std::string { std::string s; - s += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Out of memory\");" + NLine(1); + s += "_E(\"Out of memory\");" + NLine(1); s += "return -1;"; return s; }); @@ -782,8 +777,7 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, }, [&]()->std::string { std::string s; - s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Invalid parameter: h->" - + id + " is NULL\");" + NLine(1); + s += "_E(\"Invalid parameter: h->" + id + " is NULL\");" + NLine(1); s += "return -1;"; return s; }); @@ -806,8 +800,7 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id, }, [&]()->std::string { std::string s; - s += "dlog_print(DLOG_ERROR, LOG_TAG, \"Failed to duplicate " - + id + "\");" + NLine(1); + s += "_E(\"Failed to duplicate " + id + "\");" + NLine(1); s += "return -1;"; return s; }); @@ -863,8 +856,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, }, [&]()->std::string { std::string ss; - ss += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Failed to duplicate h->" + id + "\");" + NLine(1); + ss += "_E(\"Failed to duplicate h->" + id + "\");" + NLine(1); ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" + NLine(1); ss += "return -1;"; @@ -902,8 +894,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, }, [&]()->std::string { std::string ss; - ss += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Failed to duplicate value\");" + NLine(1); + ss += "_E(\"Failed to duplicate value\");" + NLine(1); ss += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" + NLine(1); ss += "return -1;"; @@ -917,8 +908,7 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id, }, [&]()->std::string { std::string tmp; - tmp += "dlog_print(DLOG_ERROR, LOG_TAG," \ - " \"Out of memory\");" + NLine(1); + tmp += "_E(\"Out of memory\");" + NLine(1); tmp += "rpc_port_" + GetStructIdWithNamespace(st) + "_destroy(handle);" + NLine(1); tmp += "return -1;"; @@ -1103,4 +1093,8 @@ void CBodyGeneratorBase::GenInterfaceMethodEnumeration( })); } +void CBodyGeneratorBase::GenLogDefinition(std::ofstream& stream) { + stream << SmartIndent(CB_LOG_DEF); +} + } // namespace tidl diff --git a/idlc/c_gen/c_body_gen_base.h b/idlc/c_gen/c_body_gen_base.h index 3b8e77d..1126d5d 100644 --- a/idlc/c_gen/c_body_gen_base.h +++ b/idlc/c_gen/c_body_gen_base.h @@ -44,6 +44,7 @@ class CBodyGeneratorBase : public CGeneratorBase { std::string GetConstructorString(const BaseType& type, const std::string& value); bool HasDelegate(const Interface& inf) const; + void GenLogDefinition(std::ofstream& stream); private: void GenInterfaceMethodEnumeration(std::ofstream& stream, diff --git a/idlc/c_gen/c_body_gen_base_cb.h b/idlc/c_gen/c_body_gen_base_cb.h index d03cec1..7fe8c84 100644 --- a/idlc/c_gen/c_body_gen_base_cb.h +++ b/idlc/c_gen/c_body_gen_base_cb.h @@ -31,7 +31,7 @@ static void __##_to(rpc_port_parcel_h parcel, void *data) rpc_port_##_h h = data; if (!parcel || !h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } $$ @@ -45,7 +45,7 @@ static void __##_from(rpc_port_parcel_h parcel, void *data) rpc_port_##_h h = data; if (!parcel || !h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } $$ @@ -59,13 +59,13 @@ int rpc_port_##_create(rpc_port_##_h *h) struct ##_s *handle; if (!h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } handle = calloc(1, sizeof(struct ##_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } @@ -83,7 +83,7 @@ R"__c_cb( int rpc_port_##_destroy(rpc_port_##_h h) { if (!h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -99,7 +99,7 @@ R"__c_cb( int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$) { if ($$) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } $$ @@ -112,7 +112,7 @@ R"__c_cb( int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$) { if (!h || $$) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } $$ @@ -126,7 +126,7 @@ int rpc_port_$$_foreach_$$(rpc_port_$$_h h, bool (*callback)($$$$, void *user_data), void *user_data) { if (!h || !callback) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } $$ @@ -141,13 +141,13 @@ int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone) rpc_port_##_h handle = NULL; if (!h || !clone) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } rpc_port_##_create(&handle); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create ## handle"); + _E("Failed to create ## handle"); return -1; } $$ @@ -168,7 +168,7 @@ do { iter = g_list_next(iter); if (!value) { - dlog_print(DLOG_WARN, LOG_TAG, "Warning: value is NULL"); + _W("Warning: value is NULL"); continue; } $$ @@ -206,7 +206,7 @@ do { h->## = calloc(h->##_size, sizeof(*h->##)); if (!h->##) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return; } @@ -259,7 +259,7 @@ R"__c_cb( do { h->## = calloc(##_size, sizeof(*##)); if (!h->##) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } h->##_size = ##_size; @@ -274,13 +274,13 @@ const char CB_GETTER_ARRAY_BLOCK[] = R"__c_cb( do { if (h->##_size == 0) { - dlog_print(DLOG_WARN, LOG_TAG, "## is empty"); + _W("## is empty"); break; } *## = calloc(h->##_size, sizeof(*h->##)); if (!*##) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } *##_size = h->##_size; @@ -302,7 +302,7 @@ do { iter = g_list_next(iter); if (!value) { - dlog_print(DLOG_WARN, LOG_TAG, "Warning: value is NULL"); + _W("Warning: value is NULL"); continue; } @@ -324,7 +324,7 @@ do { $$value = iter->data; if (!value) { - dlog_print(DLOG_ERROR, LOG_TAG, "Error: value is NULL"); + _E("Error: value is NULL"); rpc_port_$$_destroy(handle); return -1; } @@ -340,13 +340,13 @@ const char CB_CLONER_ARRAY_BLOCK[] = R"__c_cb( do { if (h->##_size == 0) { - dlog_print(DLOG_WARN, LOG_TAG, "## is empty"); + _W("## is empty"); break; } handle->## = calloc(h->##_size, sizeof(*h->##)); if (!handle->##) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); rpc_port_$$_destroy(handle); return -1; } @@ -396,4 +396,28 @@ R"__c_cb( #define LOG_TAG "$$" )__c_cb"; +const char CB_LOG_DEF[] = +R"__c_cb( +#ifdef _E +#undef _E +#endif + +#ifdef _W +#undef _W +#endif + +#ifdef _I +#undef _I +#endif + +#ifdef _D +#undef _D +#endif + +#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +)__c_cb"; + #endif // IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_ diff --git a/idlc/c_gen/c_proxy_body_gen.cc b/idlc/c_gen/c_proxy_body_gen.cc index 9a42a33..4b78826 100644 --- a/idlc/c_gen/c_proxy_body_gen.cc +++ b/idlc/c_gen/c_proxy_body_gen.cc @@ -31,6 +31,7 @@ void CProxyBodyGen::OnInitGen(std::ofstream& stream) { GenIncludeDefaultHeaders(stream); GenIncludeHeader(stream); GenLogTag(stream, std::string("RPC_PORT_PROXY")); + GenLogDefinition(stream); GenTypedefProxyDelegate(stream); GenStructures(stream); GenInterfaces(stream); diff --git a/idlc/c_gen/c_proxy_body_gen_cb.h b/idlc/c_gen/c_proxy_body_gen_cb.h index e03e737..7ff8448 100644 --- a/idlc/c_gen/c_proxy_body_gen_cb.h +++ b/idlc/c_gen/c_proxy_body_gen_cb.h @@ -49,7 +49,7 @@ static void __##_to(rpc_port_parcel_h parcel, void *data) struct ##_s *handle = data; if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } @@ -66,7 +66,7 @@ static void __##_from(rpc_port_parcel_h parcel, void *data) struct ##_s *handle = data; if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } @@ -85,7 +85,7 @@ rpc_port_##_h rpc_port_##_create(## callback, bool once, void *user_data) handle = calloc(1, sizeof(struct ##_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return NULL; } @@ -109,7 +109,7 @@ int rpc_port_proxy_##_dispose(rpc_port_proxy_$$_h proxy, rpc_port_##_h delegate) GList *iter; if (!proxy || !delegate) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid handle %p %p", proxy, delegate); + _E("Invalid handle %p %p", proxy, delegate); return -1; } @@ -178,7 +178,7 @@ if (id > 0 && id < (sizeof(__##_delegate_table) / sizeof(__##_delegate_table[0]) if (__##_delegate_table[id]) __##_delegate_table[id](list, parcel, seq_id, id); } else { - dlog_print(DLOG_WARN, LOG_TAG, "Unknown id(%d)", id); + _W("Unknown id(%d)", id); })__c_cb"; const char CB_CONSUME_COMMAND[] = @@ -215,7 +215,7 @@ static void __##_on_connected(const char *endpoint, const char *port_name, rpc_p handle->port = port; if (handle->callback.connected) handle->callback.connected(handle, handle->user_data); - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); + _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); } )__c_cb"; @@ -228,7 +228,7 @@ static void __##_on_disconnected(const char *endpoint, const char *port_name, vo handle->port = NULL; if (handle->callback.disconnected) handle->callback.disconnected(handle, handle->user_data); - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); + _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); } )__c_cb"; @@ -241,7 +241,7 @@ static void __##_on_rejected(const char *endpoint, const char *port_name, void * handle->port = NULL; if (handle->callback.rejected) handle->callback.rejected(handle, handle->user_data); - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); + _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); } )__c_cb"; @@ -254,14 +254,14 @@ static void __##_on_received(const char *endpoint, const char *port_name, void * int cmd = -1; if (g_rec_mutex_trylock(&handle->mutex) == FALSE) { - dlog_print(DLOG_WARN, LOG_TAG, "Failed to try to lock the mutex"); + _W("Failed to try to lock the mutex"); return; } rpc_port_parcel_create_from_port(&parcel_received, handle->port); rpc_port_parcel_read_int32(parcel_received, &cmd); if (cmd != ##_METHOD_Callback) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid protocol"); + _E("Invalid protocol"); rpc_port_parcel_destroy(parcel_received); g_rec_mutex_unlock(&handle->mutex); return; @@ -269,7 +269,7 @@ static void __##_on_received(const char *endpoint, const char *port_name, void * __##_process_received_event(&handle->delegates, parcel_received); rpc_port_parcel_destroy(parcel_received); - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); + _I("[__RPC_PORT__] endpoint(%s), port_name(%s)", endpoint, port_name); g_rec_mutex_unlock(&handle->mutex); } )__c_cb"; @@ -282,12 +282,12 @@ $$rpc_port_proxy_##_invoke_$$(rpc_port_proxy_##_h h$$) $$ if (!h$$) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return$$; } if (!h->port) { - dlog_print(DLOG_ERROR, LOG_TAG, "Not connected"); + _E("Not connected"); return$$; } @@ -308,20 +308,20 @@ static struct ##_s *__create_##(const char *stub_appid, rpc_port_proxy_##_callba handle = calloc(1, sizeof(struct ##_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return NULL; } handle->stub_appid = strdup(stub_appid); if (!handle->stub_appid) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); free(handle); return NULL; } rpc_port_proxy_create(&handle->proxy); if (!handle->proxy) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create proxy"); + _E("Failed to create proxy"); free(handle->stub_appid); free(handle); return NULL; @@ -366,7 +366,7 @@ int rpc_port_proxy_##_connect(const char *stub_appid, rpc_port_proxy_##_callback int r; if (!stub_appid || !callback || !h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -376,35 +376,35 @@ int rpc_port_proxy_##_connect(const char *stub_appid, rpc_port_proxy_##_callback r = rpc_port_proxy_add_connected_event_cb(handle->proxy, __##_on_connected, handle); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add connected event cb. err = %d", r); + _E("Failed to add connected event cb. err = %d", r); __destroy_##(handle); return r; } r = rpc_port_proxy_add_disconnected_event_cb(handle->proxy, __##_on_disconnected, handle); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add disconnected event cb. err = %d", r); + _E("Failed to add disconnected event cb. err = %d", r); __destroy_##(handle); return r; } r = rpc_port_proxy_add_rejected_event_cb(handle->proxy, __##_on_rejected, handle); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add rejected event cb. err = %d", r); + _E("Failed to add rejected event cb. err = %d", r); __destroy_##(handle); return r; } r = rpc_port_proxy_add_received_event_cb(handle->proxy, __##_on_received, handle); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add received event cb. err = %d", r); + _E("Failed to add received event cb. err = %d", r); __destroy_##(handle); return r; } r = rpc_port_proxy_connect(handle->proxy, stub_appid, "##"); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to connect ##(%s)", stub_appid); + _E("Failed to connect ##(%s)", stub_appid); __destroy_##(handle); return r; } @@ -420,7 +420,7 @@ R"__c_cb( int rpc_port_proxy_##_disconnect(rpc_port_proxy_##_h h) { if (!h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -447,7 +447,7 @@ do { $$ parcel_received = __$$_consume_command(h); if (!parcel_received) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid protocol"); + _E("Invalid protocol"); break; } diff --git a/idlc/c_gen/c_stub_body_gen.cc b/idlc/c_gen/c_stub_body_gen.cc index d18b4db..a11c157 100644 --- a/idlc/c_gen/c_stub_body_gen.cc +++ b/idlc/c_gen/c_stub_body_gen.cc @@ -31,6 +31,7 @@ void CStubBodyGen::OnInitGen(std::ofstream& stream) { GenIncludeDefaultHeaders(stream); GenIncludeHeader(stream); GenLogTag(stream, std::string("RPC_PORT_STUB")); + GenLogDefinition(stream); GenTypedefStubMethod(stream); GenStructures(stream); GenInterfaces(stream); diff --git a/idlc/c_gen/c_stub_body_gen_cb.h b/idlc/c_gen/c_stub_body_gen_cb.h index 66c96c4..51455f8 100644 --- a/idlc/c_gen/c_stub_body_gen_cb.h +++ b/idlc/c_gen/c_stub_body_gen_cb.h @@ -42,7 +42,7 @@ static void __##_on_connected(const char *sender, const char *instance, void *da { rpc_port_stub_##_context_h context; - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); + _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); context = __create_##_context(sender, instance); if (!context) return; @@ -59,7 +59,7 @@ static void __##_on_disconnected(const char *sender, const char *instance, void { rpc_port_stub_##_context_h context; - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); + _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); context = __find_##_context(instance); if (!context) return; @@ -80,17 +80,17 @@ static int __##_on_received(const char *sender, const char *instance, rpc_port_h int cmd = -1; int r; - dlog_print(DLOG_INFO, LOG_TAG, "[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); + _I("[__RPC_PORT__] sender(%s), instance(%s)", sender, instance); context = __find_##_context(instance); if (!context) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find ## context(%s)", instance); + _E("Failed to find ## context(%s)", instance); return -1; } context->port = port; r = rpc_port_parcel_create_from_port(&parcel, port); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create parcel from port"); + _E("Failed to create parcel from port"); return r; } @@ -99,7 +99,7 @@ static int __##_on_received(const char *sender, const char *instance, rpc_port_h if (__##_method_table[cmd]) r = __##_method_table[cmd](port, parcel, context); } else { - dlog_print(DLOG_ERROR, LOG_TAG, "Unknown Command(%d)", cmd); + _E("Unknown Command(%d)", cmd); r = -1; } @@ -116,12 +116,12 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ int r; if (__##_stub) { - dlog_print(DLOG_WARN, LOG_TAG, "Already exists"); + _W("Already exists"); return -1; } if (!callback) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -129,13 +129,13 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ __##_user_data = user_data; r = rpc_port_stub_create(&__##_stub, "##"); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create stub handle"); + _E("Failed to create stub handle"); return r; } r = rpc_port_stub_add_received_event_cb(__##_stub, __##_on_received, NULL); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add received event callback"); + _E("Failed to add received event callback"); rpc_port_stub_destroy(__##_stub); __##_stub = NULL; return r; @@ -143,7 +143,7 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ r = rpc_port_stub_add_connected_event_cb(__##_stub, __##_on_connected, NULL); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add connected event callback"); + _E("Failed to add connected event callback"); rpc_port_stub_destroy(__##_stub); __##_stub = NULL; return r; @@ -151,7 +151,7 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ r = rpc_port_stub_add_disconnected_event_cb(__##_stub, __##_on_disconnected, NULL); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add disconnected event callback"); + _E("Failed to add disconnected event callback"); rpc_port_stub_destroy(__##_stub); __##_stub = NULL; return r; @@ -159,7 +159,7 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ r = __##_add_privileges(); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add privileges"); + _E("Failed to add privileges"); rpc_port_stub_destroy(__##_stub); __##_stub = NULL; return r; @@ -167,7 +167,7 @@ int rpc_port_stub_##_register(rpc_port_stub_##_callback_s *callback, void *user_ r = rpc_port_stub_listen(__##_stub); if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to listen stub"); + _E("Failed to listen stub"); rpc_port_stub_destroy(__##_stub); __##_stub = NULL; return r; @@ -226,13 +226,13 @@ int rpc_port_##_create(rpc_port_##_h *h) static int seq_num; if (!h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } handle = calloc(1, sizeof(struct ##_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } @@ -254,7 +254,7 @@ R"__c_cb( int rpc_port_##_destroy(rpc_port_##_h h) { if (!h) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -271,7 +271,7 @@ static void __##_to(rpc_port_parcel_h parcel, void *data) rpc_port_##_h handle = data; if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } @@ -288,7 +288,7 @@ static void __##_from(rpc_port_parcel_h parcel, void *data) rpc_port_##_h handle = data; if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return; } @@ -305,13 +305,13 @@ int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone) rpc_port_##_h handle; if (!h || !clone) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } handle = calloc(1, sizeof(struct ##_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } @@ -335,23 +335,23 @@ int rpc_port_$$_invoke($$) rpc_port_parcel_h parcel = NULL; if (!h || !h->port) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } if (!__$$_context_port_exist(h->port)) { - dlog_print(DLOG_ERROR, LOG_TAG, "Port doesn't exist"); + _E("Port doesn't exist"); return -1; } if (h->once && !h->valid) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid callback"); + _E("Invalid callback"); return -1; } rpc_port_parcel_create(&parcel); if (!parcel) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create parcel"); + _E("Failed to create parcel"); return -1; } @@ -371,7 +371,7 @@ R"__c_cb( int rpc_port_##_set_port(rpc_port_##_h h, rpc_port_h port) { if (!h || !port) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -401,20 +401,20 @@ static struct ##_context_s *__create_##_context(const char *sender, const char * handle = calloc(1, sizeof(struct ##_context_s)); if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return NULL; } handle->sender = strdup(sender); if (!handle->sender) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); free(handle); return NULL; } handle->instance = strdup(instance); if (!handle->instance) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); free(handle->sender); free(handle); return NULL; @@ -434,7 +434,7 @@ static void __destroy_##_context(gpointer data) struct ##_context_s *handle = data; if (!handle) { - dlog_print(DLOG_ERROR, LOG_TAG, "Critical error!"); + _E("Critical error!"); return; } @@ -468,7 +468,7 @@ R"__c_cb( int rpc_port_stub_##_context_set_tag(rpc_port_stub_##_context_h ctx, void *tag) { if (!ctx) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -483,7 +483,7 @@ R"__c_cb( int rpc_port_stub_##_context_get_tag(rpc_port_stub_##_context_h ctx, void **tag) { if (!ctx || !tag) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } @@ -498,13 +498,13 @@ R"__c_cb( int rpc_port_stub_##_context_get_sender(rpc_port_stub_##_context_h ctx, char **sender) { if (!ctx || !sender) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid parameter"); + _E("Invalid parameter"); return -1; } *sender = strdup(ctx->sender); if (*sender == NULL) { - dlog_print(DLOG_ERROR, LOG_TAG, "Out of memory"); + _E("Out of memory"); return -1; } @@ -548,7 +548,7 @@ $$ const char CB_INTERFACE_PRIVILEGE_BLOCK[] = R"__c_cb(r = $$; if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add privilege($$)"); + _E("Failed to add privilege($$)"); return r; } )__c_cb"; @@ -556,7 +556,7 @@ if (r != 0) { const char CB_INTERFACE_TRUSTED_MODE_BLOCK[] = R"__c_cb(r = $$; if (r != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to set trusted mode($$)"); + _E("Failed to set trusted mode($$)"); return r; } )__c_cb"; diff --git a/idlc/cpp_gen/cpp_gen_base.cc b/idlc/cpp_gen/cpp_gen_base.cc index c8c9bdf..92a4c68 100644 --- a/idlc/cpp_gen/cpp_gen_base.cc +++ b/idlc/cpp_gen/cpp_gen_base.cc @@ -701,4 +701,8 @@ void CppGeneratorBase::GenLogTag(std::ofstream& stream, std::string id) { }); } +void CppGeneratorBase::GenLogDefinition(std::ofstream& stream) { + stream << CB_LOG_DEF; +} + } // namespace tidl diff --git a/idlc/cpp_gen/cpp_gen_base.h b/idlc/cpp_gen/cpp_gen_base.h index 865a52b..4224b0f 100644 --- a/idlc/cpp_gen/cpp_gen_base.h +++ b/idlc/cpp_gen/cpp_gen_base.h @@ -58,6 +58,7 @@ class CppGeneratorBase : public Generator { std::string id, std::string parcel); std::string GetParameters(const Parameters& ps); void GenLogTag(std::ofstream& stream, std::string id); + void GenLogDefinition(std::ofstream& stream); private: void GenSetter(std::ofstream& stream, const Element& ele); diff --git a/idlc/cpp_gen/cpp_gen_base_cb.h b/idlc/cpp_gen/cpp_gen_base_cb.h index 4dc00d6..de349f9 100644 --- a/idlc/cpp_gen/cpp_gen_base_cb.h +++ b/idlc/cpp_gen/cpp_gen_base_cb.h @@ -222,4 +222,28 @@ R"__cpp_cb( #define LOG_TAG "$$" )__cpp_cb"; +const char CB_LOG_DEF[] = +R"__cpp_cb( +#ifdef _E +#undef _E +#endif + +#ifdef _W +#undef _W +#endif + +#ifdef _I +#undef _I +#endif + +#ifdef _D +#undef _D +#endif + +#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +)__cpp_cb"; + #endif // IDLC_CPP_GEN_CPP_GEN_BASE_CB_H_ diff --git a/idlc/cpp_gen/cpp_proxy_body_gen.cc b/idlc/cpp_gen/cpp_proxy_body_gen.cc index cc4c641..9338d0f 100644 --- a/idlc/cpp_gen/cpp_proxy_body_gen.cc +++ b/idlc/cpp_gen/cpp_proxy_body_gen.cc @@ -41,6 +41,7 @@ void CppProxyBodyGen::OnInitGen(std::ofstream& stream) { << NLine(1) << "#include \"" << header_file << "\"" << NLine(2); GenLogTag(stream, "RPC_PORT_PROXY"); + GenLogDefinition(stream); stream << NLine(1); GenNamespace(stream); } diff --git a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h index 45d150e..cc97a44 100644 --- a/idlc/cpp_gen/cpp_proxy_body_gen_cb.h +++ b/idlc/cpp_gen/cpp_proxy_body_gen_cb.h @@ -27,7 +27,7 @@ $$::~$$() { const char CB_INVOCATION_PRE[] = R"__cpp_cb( if (port_ == nullptr) { - dlog_print(DLOG_ERROR, LOG_TAG, "Not connected"); + _E("Not connected"); throw NotConnectedSocketException(); } @@ -44,7 +44,7 @@ R"__cpp_cb( const char CB_INVOCATION_RECEIVE[] = R"__cpp_cb( if (parcel_received == nullptr) { - dlog_print(DLOG_ERROR, LOG_TAG, "Invalid protocol"); + _E("Invalid protocol"); throw InvalidProtocolException(); } )__cpp_cb"; @@ -62,7 +62,7 @@ R"__cpp_cb( void ##::Connect() { int ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "##"); if (ret != RPC_PORT_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to connect ##"); + _E("Failed to connect ##"); switch (ret) { case RPC_PORT_ERROR_INVALID_PARAMETER: throw InvalidIDException(); @@ -147,12 +147,12 @@ void ##::OnReceivedCB(const char *ep, const char *port_name, void *data) { rpc_port_parcel_h parcel_received; if (!l->mutex_.try_lock()) { - dlog_print(DLOG_WARN, LOG_TAG, "Failed to try to lock the mutex"); + _W("Failed to try to lock the mutex"); return; } if (rpc_port_parcel_create_from_port(&parcel_received, l->port_) != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create parcel from port"); + _E("Failed to create parcel from port"); l->mutex_.unlock(); return; } @@ -177,7 +177,7 @@ $$::$$(IEventListener* listener, const std::string& target_appid) int r = rpc_port_proxy_create(&proxy_); if (r != RPC_PORT_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create proxy"); + _E("Failed to create proxy"); throw InvalidIOException(); } diff --git a/idlc/cpp_gen/cpp_stub_body_gen.cc b/idlc/cpp_gen/cpp_stub_body_gen.cc index a4e3dc9..1d48b7d 100644 --- a/idlc/cpp_gen/cpp_stub_body_gen.cc +++ b/idlc/cpp_gen/cpp_stub_body_gen.cc @@ -41,6 +41,7 @@ void CppStubBodyGen::OnInitGen(std::ofstream& stream) { << NLine(1) << "#include \"" << header_file << "\"" << NLine(2); GenLogTag(stream, "RPC_PORT_STUB"); + GenLogDefinition(stream); stream << NLine(1); GenNamespace(stream); } diff --git a/idlc/cpp_gen/cpp_stub_body_gen_cb.h b/idlc/cpp_gen/cpp_stub_body_gen_cb.h index b718dcd..86d3498 100644 --- a/idlc/cpp_gen/cpp_stub_body_gen_cb.h +++ b/idlc/cpp_gen/cpp_stub_body_gen_cb.h @@ -22,7 +22,7 @@ R"__cpp_cb( ##::##() { int r = rpc_port_stub_create(&stub_, "##"); if (r != RPC_PORT_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create stub handle"); + _E("Failed to create stub handle"); throw InvalidIOException(); } rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this); @@ -46,7 +46,7 @@ void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) { service_factory_ = std::move(service_factory); int r = rpc_port_stub_listen(stub_); if (r != RPC_PORT_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to listen stub"); + _E("Failed to listen stub"); switch (r) { case RPC_PORT_ERROR_INVALID_PARAMETER: case RPC_PORT_ERROR_IO_ERROR: @@ -94,13 +94,13 @@ int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, } if (b.get() == nullptr) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to find $$ context(%s)", instance); + _E("Failed to find $$ context(%s)", instance); return -1; } ret = rpc_port_parcel_create_from_port(&p, port); if (ret != 0) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to create parcel from port"); + _E("Failed to create parcel from port"); return ret; } @@ -112,7 +112,7 @@ int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, const char CB_ON_RECEIVED_CB_BACK[] = R"__cpp_cb( default: - dlog_print(DLOG_ERROR, LOG_TAG, "Unknown command(%d)", cmd); + _E("Unknown command(%d)", cmd); rpc_port_parcel_destroy(p); rpc_port_parcel_destroy(result); return -1; |