/* * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_ #define IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_ const char CB_STRUCT_DECL[] = R"__c_cb( $$struct $$_s { rpc_port_parcelable_t parcelable;$$ }; )__c_cb"; const char CB_STRUCT_SERIALIZER[] = R"__c_cb( static void __##_to(rpc_port_parcel_h parcel, void *data) { rpc_port_##_h h = data; if (!parcel || !h) { _E("Invalid parameter"); return; } $$ } )__c_cb"; const char CB_STRUCT_DESERIALIZER[] = R"__c_cb( static void __##_from(rpc_port_parcel_h parcel, void *data) { rpc_port_##_h h = data; if (!parcel || !h) { _E("Invalid parameter"); return; } $$ } )__c_cb"; const char CB_STRUCT_CTOR[] = R"__c_cb( int rpc_port_##_create(rpc_port_##_h *h) { struct ##_s *handle; if (!h) { _E("Invalid parameter"); return -1; } handle = calloc(1, sizeof(struct ##_s)); if (!handle) { _E("Out of memory"); return -1; } handle->parcelable.to = __##_to; handle->parcelable.from = __##_from; *h = handle; return 0; } )__c_cb"; const char CB_STRUCT_DTOR[] = R"__c_cb( int rpc_port_##_destroy(rpc_port_##_h h) { if (!h) { _E("Invalid parameter"); return -1; } $$ free(h); return 0; } )__c_cb"; const char CB_STRUCT_SETTER[] = R"__c_cb( int rpc_port_$$_$$_$$(rpc_port_$$_h h, $$$$) { if ($$) { _E("Invalid parameter"); return -1; } $$ return 0; } )__c_cb"; const char CB_STRUCT_GETTER[] = R"__c_cb( int rpc_port_$$_get_$$(rpc_port_$$_h h, $$$$) { if (!h || $$) { _E("Invalid parameter"); return -1; } $$ return 0; } )__c_cb"; const char CB_STRUCT_ITERATOR[] = R"__c_cb( int rpc_port_$$_foreach_$$(rpc_port_$$_h h, bool (*callback)($$$$, void *user_data), void *user_data) { if (!h || !callback) { _E("Invalid parameter"); return -1; } $$ return 0; } )__c_cb"; const char CB_STRUCT_CLONER[] = R"__c_cb( int rpc_port_##_clone(rpc_port_##_h h, rpc_port_##_h *clone) { rpc_port_##_h handle = NULL; if (!h || !clone) { _E("Invalid parameter"); return -1; } rpc_port_##_create(&handle); if (!handle) { _E("Failed to create ## handle"); return -1; } $$ *clone = handle; return 0; } )__c_cb"; const char CB_WRITE_LIST_BLOCK[] = R"__c_cb( do { GList *iter; iter = $$; while (iter) { $$value = iter->data; iter = g_list_next(iter); if (!value) { _W("Warning: value is NULL"); continue; } $$ } } while (0); )__c_cb"; const char CB_WRITE_ARRAY_BLOCK[] = R"__c_cb( do { for (int i = 0; i < $$; i++) { $$ } } while (0); )__c_cb"; const char CB_READ_LIST_BLOCK[] = R"__c_cb(do { int len = 0; $$ for (int i = 0; i < len; i++) { $$value = NULL; $$ $$ = g_list_append($$, value); } } while (0); )__c_cb"; const char CB_READ_ARRAY_BLOCK[] = R"__c_cb( do { $$ h->## = calloc(h->##_size, sizeof(*h->##)); if (!h->##) { _E("Out of memory"); return; } for (int i = 0; i < h->##_size; i++) { $$value = $$; $$ } } while (0); )__c_cb"; const char CB_FINALIZE_LIST_BLOCK[] = R"__c_cb( do { GList *iter; iter = $$; while (iter) { $$value = iter->data; $$ iter = g_list_next(iter); } g_list_free($$); } while (0); )__c_cb"; const char CB_FINALIZE_ARRAY_BLOCK[] = R"__c_cb( do { for (int i = 0; i < $$; i++) { $$ } free($$); } while (0); )__c_cb"; const char CB_SETTER_LIST_BLOCK[] = R"__c_cb( do { $$value; value = calloc(1, sizeof(*value)); $$ $$ = g_list_append($$, value); } while (0); )__c_cb"; const char CB_SETTER_ARRAY_BLOCK[] = R"__c_cb( do { h->## = calloc(##_size, sizeof(*##)); if (!h->##) { _E("Out of memory"); return -1; } h->##_size = ##_size; for (int i = 0; i < h->##_size; i++) { $$ } } while (0); )__c_cb"; const char CB_GETTER_ARRAY_BLOCK[] = R"__c_cb( do { if (h->##_size == 0) { _W("## is empty"); break; } *## = calloc(h->##_size, sizeof(*h->##)); if (!*##) { _E("Out of memory"); return -1; } *##_size = h->##_size; for (int i = 0; i < h->##_size; i++) { $$ } } while (0); )__c_cb"; const char CB_ITERATOR_BLOCK[] = R"__c_cb( do { GList *iter; iter = $$; while (iter) { $$value = iter->data; iter = g_list_next(iter); if (!value) { _W("Warning: value is NULL"); continue; } bool ret = callback($$, user_data); if (!ret) break; } } while (0); )__c_cb"; const char CB_CLONER_LIST_BLOCK[] = R"__c_cb( do { GList *iter; iter = $$; while (iter) { $$new_value; $$value = iter->data; if (!value) { _E("Error: value is NULL"); rpc_port_$$_destroy(handle); return -1; } $$ $$ = g_list_append($$, new_value); iter = g_list_next(iter); } } while (0); )__c_cb"; const char CB_CLONER_ARRAY_BLOCK[] = R"__c_cb( do { if (h->##_size == 0) { _W("## is empty"); break; } handle->## = calloc(h->##_size, sizeof(*h->##)); if (!handle->##) { _E("Out of memory"); rpc_port_$$_destroy(handle); return -1; } handle->##_size = h->##_size; for (int i = 0; i < h->##_size; i++) { $$ } } while (0); )__c_cb"; const char CB_IF_STATEMENT_WITH_BRACES[] = R"__c_cb(if ($$) { $$ } )__c_cb"; const char CB_IF_STATEMENT[] = R"__c_cb(if ($$) $$ )__c_cb"; const char CB_DELEGATE_ENUM_FORMAT[] = "\n$$_DELEGATE_$$ = $$,"; const char CB_DELEGATE_ENUM[] = R"__c_cb( enum $$_delegate_e {$$ }; )__c_cb"; const char CB_METHOD_ENUM_FORMAT[] = "\n$$_METHOD_$$,"; const char CB_METHOD_ENUM[] = R"__c_cb( enum $$_method_e { $$_METHOD_Result, $$_METHOD_Callback,$$ }; )__c_cb"; const char CB_LOG_TAG[] = R"__c_cb( #ifdef LOG_TAG #undef LOG_TAG #endif #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, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) #define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > "fmt, basename(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__) )__c_cb"; #endif // IDLC_C_GEN_C_BODY_GEN_BASE_CB_H_