return RemoveLine(code);
}
+std::string CBodyGeneratorBase::GenMapCompareKeyVarsImpl(const BaseType& type) {
+ std::string code;
+ if (type.ToString() == "string")
+ code = CB_MAP_STRING_COMPARISION_IMPL;
+ else if (type.ToString() == "bool")
+ code = CB_MAP_BOOL_COMPARISION_IMPL;
+ else
+ code = CB_MAP_BASE_COMPARISION_IMPL;
+
+ return RemoveLine(code);
+}
+
std::string CBodyGeneratorBase::GenMapUnitMapValueRead(
const BaseType& type) {
std::string code;
.Change("<MAP_UNIT_MAP_VALUE_READ>", GenMapUnitMapValueRead(value_type))
.Change("<MAP_COMPARE_KEY_VARS_DEF>",
GenMapCompareKeyVarsDefinition(key_type))
+ .Change("<MAP_COMPARE_KEY_VARS_IMPL>",
+ GenMapCompareKeyVarsImpl(key_type))
.Change("<MAP_KEY_FREE_FUNC>", GenMapFreeFunc(key_type))
.Change("<MAP_VALUE_FREE_FUNC>", GenMapFreeFunc(value_type))
.Change("<MAP_INSERT_ARGS_NULL_CHECK>",
return RemoveLine(code);
}
+std::string CBodyGeneratorBase::GenSetCompareKeyVarsImpl(const BaseType& type) {
+ std::string code;
+ if (type.ToString() == "string")
+ code = CB_SET_STRING_COMPARISION_IMPL;
+ else if (type.ToString() == "bool")
+ code = CB_SET_BOOL_COMPARISION_IMPL;
+ else
+ code = CB_SET_BASE_COMPARISION_IMPL;
+
+ return RemoveLine(code);
+}
+
std::string CBodyGeneratorBase::GenSetUnitMapKeyRead(const BaseType& type) {
std::string code;
.Change("<SET_UNIT_MAP_KEY_READ>", GenSetUnitMapKeyRead(key_type))
.Change("<SET_COMPARE_KEY_VARS_DEF>",
GenSetCompareKeyVarsDefinition(key_type))
+ .Change("<SET_COMPARE_KEY_VARS_IMPL>",
+ GenSetCompareKeyVarsImpl(key_type))
.Change("<SET_KEY_FREE_FUNC>", GenSetKeyFreeFunc(key_type))
.Change("<SET_INSERT_ARGS_NULL_CHECK>", GenSetKeyNullCheck(key_type))
.Change("<SET_INSERT>", GenSetInsert(key_type))
std::string code;
for (const auto& elm : elms) {
auto& type = elm->GetType();
- auto param_type_in = GetParamTypeString(ParameterType::Direction::IN, type, name);
- auto param_type_out = GetParamTypeString(ParameterType::Direction::OUT, type, name);
+ auto param_type_in =
+ GetParamTypeString(ParameterType::Direction::IN, type, name);
+ auto param_type_out =
+ GetParamTypeString(ParameterType::Direction::OUT, type, name);
code += ReplaceAll(CB_STRUCTURE_BASE_SET_GET)
.Change("<PREFIX>", GetHandlePrefix())
const BaseType& value_type);
std::string GenMapFreeFunc(const BaseType& type);
std::string GenMapCompareKeyVarsDefinition(const BaseType& type);
+ std::string GenMapCompareKeyVarsImpl(const BaseType& type);
std::string GenMapUnitMapValueRead(const BaseType& type);
std::string GenMapUnitMapKeyRead(const BaseType& type);
std::string GenMapUnitMapValueWrite(const BaseType& type);
std::string GenSetKeyNullCheck(const BaseType& type);
std::string GenSetKeyFreeFunc(const BaseType& type);
std::string GenSetCompareKeyVarsDefinition(const BaseType& type);
+ std::string GenSetCompareKeyVarsImpl(const BaseType& type);
std::string GenSetUnitMapKeyRead(const BaseType& type);
std::string GenSetUnitMapKeyWrite(const BaseType& type);
void GenStructureSetBase(std::ofstream& stream, const Structure& st);
typedef struct <PREFIX>_<NAME>_s {
rpc_port_parcelable_t parcelable;
GTree *node;
- <PREFIX>_<NAME>_compare_cb compare_cb;
void *user_data;
} <PREFIX>_<NAME>_t;
-static <PREFIX>_<NAME>_compare_cb __<PREFIX>_<NAME>_compare_cb;
-static void *__<PREFIX>_<NAME>_user_data;
-
typedef struct <PREFIX>_<NAME>_traverse_info_s {
rpc_port_unit_map_h map;
int number;
* <MAP_UNIT_MAP_KEY_READ> The implementation to read the key from the unit map.
* <MAP_UNIT_MAP_VALUE_READ> The implementation to read the value from the unit map.
* <MAP_COMPARE_KEY_VARS_DEF> The definition of the key variables of the compare callback function.
+ * <MAP_COMPARE_KEY_VARS_IMPL> The implemenation to compare key variables.
* <MAP_KEY_FREE_FUNC> The implementation to free the key.
* <MAP_VALUE_FREE_FUNC> The implementation to free the value.
* <MAP_INSERT_ARGS_NULL_CHECK> The implementation to check whether the arg is nullptr or not.
{
<MAP_COMPARE_KEY_VARS_DEF>
- if (__<PREFIX>_<NAME>_compare_cb == nullptr) {
- _E("<PREFIX>_<NAME>_set_compare_cb() MUST be called");
- return -1;
- }
-
- return __<PREFIX>_<NAME>_compare_cb(key_a, key_b, __<PREFIX>_<NAME>_user_data);
+ <MAP_COMPARE_KEY_VARS_IMPL>
}
int <PREFIX>_<NAME>_create(<PREFIX>_<NAME>_h *h)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
- if (__<PREFIX>_<NAME>_compare_cb == nullptr) {
- _E("<PREFIX>_<NAME>_set_compare_cb() MUST be called");
- return RPC_PORT_ERROR_IO_ERROR;
- }
-
handle = calloc(1, sizeof(<PREFIX>_<NAME>_t));
if (handle == nullptr) {
_E("Out of memory");
return ret;
}
-int <PREFIX>_<NAME>_set_compare_cb(<PREFIX>_<NAME>_compare_cb callback, void *user_data)
-{
- if (callback == nullptr) {
- _E("Invalid parameter");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
- }
-
- __<PREFIX>_<NAME>_compare_cb = callback;
- __<PREFIX>_<NAME>_user_data = user_data;
-
- return RPC_PORT_ERROR_NONE;
-}
-
int <PREFIX>_<NAME>_insert(<PREFIX>_<NAME>_h h, <KEY_PARAM_TYPE>key, <VALUE_PARAM_TYPE>value)
{
<PREFIX>_<NAME>_t *handle = h;
}
)__c_cb";
+constexpr const char CB_MAP_STRING_COMPARISION_IMPL[] =
+R"__c_cb(
+return strcmp(key_a, key_b);
+)__c_cb";
+
+constexpr const char CB_MAP_BASE_COMPARISION_IMPL[] =
+R"__c_cb(
+if (key_a == key_b)
+ return 0;
+
+if (key_a > key_b)
+ return 1;
+
+return -1;
+)__c_cb";
+
+constexpr const char CB_MAP_BOOL_COMPARISION_IMPL[] =
+R"__c_cb(
+if (key_a == key_b)
+ return 0;
+
+return -1;
+)__c_cb";
+
/**
* <KEY> The name of the key.
* <KEY_TYPE> The type of the key.
GTree *node;
} <PREFIX>_<NAME>_t;
-static <PREFIX>_<NAME>_compare_cb __<PREFIX>_<NAME>_compare_cb;
-static void *__<PREFIX>_<NAME>_user_data;
-
typedef struct <PREFIX>_<NAME>_traverse_info_s {
rpc_port_unit_map_h map;
int number;
* <SET_UNIT_MAP_KEY_WRITE> The implementation to write the key to the unit map.
* <SET_UNIT_MAP_KEY_READ> The implementation to read the key from the unit map.
* <SET_COMPARE_KEY_VARS_DEF> The definition of the key variables of the compare callback function.
+ * <SET_COMPARE_KEY_VARS_IMPL> The implementation to compare key variables.
* <SET_KEY_FREE_FUNC> The implementation to free the key.
* <SET_INSERT_ARGS_NULL_CHECK> The implementation to check whether the arg is nullptr or not.
* <SET_INSERT> The implementation to insert the key and the value to the set.
{
<SET_COMPARE_KEY_VARS_DEF>
- if (__<PREFIX>_<NAME>_compare_cb == nullptr) {
- _E("<PREFIX>_<NAME>_set_compare_cb() MUST be called");
- return -1;
- }
-
- return __<PREFIX>_<NAME>_compare_cb(key_a, key_b, __<PREFIX>_<NAME>_user_data);
-}
-
-int <PREFIX>_<NAME>_set_compare_cb(<PREFIX>_<NAME>_compare_cb callback, void *user_data)
-{
- if (callback == nullptr) {
- _E("Invalid parameter");
- return RPC_PORT_ERROR_INVALID_PARAMETER;
- }
-
- __<PREFIX>_<NAME>_compare_cb = callback;
- __<PREFIX>_<NAME>_user_data = user_data;
-
- return RPC_PORT_ERROR_NONE;
+ <SET_COMPARE_KEY_VARS_IMPL>
}
int <PREFIX>_<NAME>_create(<PREFIX>_<NAME>_h *h)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
- if (__<PREFIX>_<NAME>_compare_cb == nullptr) {
- _E("<PREFIX>_<NAME>_set_compare_cb() MUST be called");
- return RPC_PORT_ERROR_IO_ERROR;
- }
-
handle = calloc(1, sizeof(<PREFIX>_<NAME>_t));
if (handle == nullptr) {
_E("Out of memory");
}
)__c_cb";
+constexpr const char CB_SET_STRING_COMPARISION_IMPL[] =
+R"__c_cb(
+return strcmp(key_a, key_b);
+)__c_cb";
+
+constexpr const char CB_SET_BASE_COMPARISION_IMPL[] =
+R"__c_cb(
+if (key_a == key_b)
+ return 0;
+
+if (key_a > key_b)
+ return 1;
+
+return -1;
+)__c_cb";
+
+constexpr const char CB_SET_BOOL_COMPARISION_IMPL[] =
+R"__c_cb(
+if (key_a == key_b)
+ return 0;
+
+return -1;
+)__c_cb";
+
/**
* <KEY> The name of the key.
* <KEY_TYPE> The type of the key.
constexpr const char CB_STRUCTURE_MAP_BASE[] =
R"__c_cb(
-/**
- * @brief Called to compare the keys in the <PREFIX>_<NAME> handle.
- *
- * @param[in] a A key
- * @param[in] b B key
- * @param[in] user_data The user data passed from the registration function
- * @return Nagative value if a < b,
- * zero if a = b,
- * positive value if a > b.
- * @see <PREFIX>_<NAME>_set_compare_cb()
- */
-typedef int (*<PREFIX>_<NAME>_compare_cb)(<KEY_PARAM_TYPE>a, <KEY_PARAM_TYPE>b, void *user_data);
-
/**
* @brief Called to retrieve the key/value contained in the <PREFIX>_<NAME> handle.
*
*/
typedef bool (*<PREFIX>_<NAME>_foreach_cb)(<KEY_PARAM_TYPE>key, <VALUE_PARAM_TYPE>value, void *user_data);
-/**
- * @brief Sets the comparision callback function for the <PREFIX>_<NAME> handle.
- * @details The <PREFIX>_<NAME> uses the registered callback function.
- * If it's not set, calling the <PREFIX>_<NAME>_create() returns a negative error value.
- *
- * @param[in] callback The comparison callback function
- * @param[in] user_data The user data to be passed to the comparision callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @see <PREFIX>_<NAME>_create()
- */
-int <PREFIX>_<NAME>_set_compare_cb(<PREFIX>_<NAME>_compare_cb callback, void *user_data);
-
/**
* @brief Creates a <PREFIX>_<NAME> handle.
*
constexpr const char CB_STRUCTURE_SET_BASE[] =
R"__c_cb(
-/**
- * @brief Called to compare the keys in the <PREFIX>_<NAME> handle.
- *
- * @param[in] a A key
- * @param[in] b B key
- * @param[in] user_data The user data passed from the registration function
- * @return Nagative value if a < b,
- * zero if a = b,
- * positive value if a > b.
- * @see <PREFIX>_<NAME>_set_compare_cb()
- */
-typedef int (*<PREFIX>_<NAME>_compare_cb)(<KEY_PARAM_TYPE>a, <KEY_PARAM_TYPE>b, void *user_data);
-
/**
* @brief Called to retrieve the key contained in the <PREFIX>_<NAME> handle.
*
*/
typedef bool (*<PREFIX>_<NAME>_foreach_cb)(<KEY_PARAM_TYPE>key, void *user_data);
-/**
- * @brief Sets the comparision callback function for the <PREFIX>_<NAME> handle.
- * @details The <PREFIX>_<NAME> uses the registered callback function.
- * If it's not set, calling the <PREFIX>_<NAME>_create() returns a negative error value.
- *
- * @param[in] callback The comparison callback function
- * @param[in] user_data The user data to be passed to the comparison callback function
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #RPC_PORT_ERROR_NONE Successful
- * @retval #RPC_PORT_ERROR_INVALID_PARAMETER Invalid parameter
- * @see <PREFIX>_<NAME>_create()
- */
-int <PREFIX>_<NAME>_set_compare_cb(<PREFIX>_<NAME>_compare_cb callback, void *user_data);
-
/**
* @brief Creates a <PREFIX>_<NAME> handle.
*