/** * Computes the checksum of the registered functions. * The function name is used to compute the checksum. */ uint32_t compute_functions_checksum() { uint32_t checksum = 0; for (int i = funcs.size(); i-->0; ) { checksum += string_crc(funcs[i].userFuncKey); } return checksum; }
/** * Computes the checksum of the registered variables. * The checksum is derived from the variable name and type. */ uint32_t compute_variables_checksum() { uint32_t checksum = 0; for (int i = vars.size(); i-->0; ) { checksum += string_crc(vars[i].userVarKey); checksum += crc(vars[i].userVarType); } return checksum; }
User_Var_Lookup_Table_t* find_var_by_key(const char* varKey) { for (int i = vars.size(); i-->0; ) { if (0 == strncmp(vars[i].userVarKey, varKey, USER_VAR_KEY_LENGTH)) { return &vars[i]; } } return NULL; }
User_Func_Lookup_Table_t* find_func_by_key(const char* funcKey) { for (int i = funcs.size(); i-->0; ) { if (0 == strncmp(funcs[i].userFuncKey, funcKey, USER_FUNC_KEY_LENGTH)) { return &funcs[i]; } } return NULL; }
/** * Register a function. * @param desc * @param reserved * @return */ bool spark_function_internal(const cloud_function_descriptor* desc, void* reserved) { User_Func_Lookup_Table_t* item = NULL; if (NULL != desc->fn && NULL != desc->funcKey && strlen(desc->funcKey)<=USER_FUNC_KEY_LENGTH) { if ((item=find_func_by_key(desc->funcKey)) || (item = funcs.add())) { item->pUserFunc = desc->fn; item->pUserFuncData = desc->data; memset(item->userFuncKey, 0, USER_FUNC_KEY_LENGTH); memcpy(item->userFuncKey, desc->funcKey, USER_FUNC_KEY_LENGTH); } } return item!=NULL; }
User_Func_Lookup_Table_t* find_func_by_key_or_add(const char* funcKey) { User_Func_Lookup_Table_t* result = find_func_by_key(funcKey); return result ? result : funcs.add(); }
User_Var_Lookup_Table_t* find_var_by_key_or_add(const char* varKey) { User_Var_Lookup_Table_t* result = find_var_by_key(varKey); return result ? result : vars.add(); }