project_files/frontlib/model/schemelist.c
changeset 7275 15f722e0b96f
parent 7271 5608ac657362
child 7314 6171f0bad318
equal deleted inserted replaced
7273:8eed495fd8da 7275:15f722e0b96f
    14 static void flib_schemelist_destroy(flib_schemelist *list) {
    14 static void flib_schemelist_destroy(flib_schemelist *list) {
    15 	if(list) {
    15 	if(list) {
    16 		for(int i=0; i<list->schemeCount; i++) {
    16 		for(int i=0; i<list->schemeCount; i++) {
    17 			flib_cfg_release(list->schemes[i]);
    17 			flib_cfg_release(list->schemes[i]);
    18 		}
    18 		}
       
    19 		free(list->schemes);
    19 		free(list);
    20 		free(list);
    20 	}
    21 	}
    21 }
    22 }
    22 
    23 
    23 static char *makePrefixedName(int schemeIndex, const char *settingName) {
    24 static char *makePrefixedName(int schemeIndex, const char *settingName) {
   190 		}
   191 		}
   191 	}
   192 	}
   192 	return NULL;
   193 	return NULL;
   193 }
   194 }
   194 
   195 
       
   196 GENERATE_STATIC_LIST_INSERT(insertScheme, flib_cfg*)
       
   197 GENERATE_STATIC_LIST_DELETE(deleteScheme, flib_cfg*)
       
   198 
   195 int flib_schemelist_insert(flib_schemelist *list, flib_cfg *cfg, int pos) {
   199 int flib_schemelist_insert(flib_schemelist *list, flib_cfg *cfg, int pos) {
   196 	flib_cfg **changedList = flib_list_insert(list->schemes, &list->schemeCount, sizeof(*list->schemes), &cfg, pos);
   200 	if(!list) {
   197 	if(changedList) {
   201 		flib_log_e("Invalid parameter in flib_schemelist_insert");
   198 		list->schemes = changedList;
   202 	} else if(!insertScheme(&list->schemes, &list->schemeCount, cfg, pos)) {
   199 		flib_cfg_retain(cfg);
   203 		flib_cfg_retain(cfg);
   200 		return 0;
   204 		return 0;
   201 	} else {
   205 	}
   202 		return -1;
   206 	return -1;
   203 	}
       
   204 }
   207 }
   205 
   208 
   206 int flib_schemelist_delete(flib_schemelist *list, int pos) {
   209 int flib_schemelist_delete(flib_schemelist *list, int pos) {
   207 	int result = -1;
   210 	if(!list) {
   208 	if(!list || pos<0 || pos>=list->schemeCount) {
       
   209 		flib_log_e("Invalid parameter in flib_schemelist_delete");
   211 		flib_log_e("Invalid parameter in flib_schemelist_delete");
   210 	} else {
   212 	} else {
   211 		flib_cfg *elem = list->schemes[pos];
   213 		flib_cfg *elem = list->schemes[pos];
   212 		flib_cfg **changedList = flib_list_delete(list->schemes, &list->schemeCount, sizeof(*list->schemes), pos);
   214 		if(!deleteScheme(&list->schemes, &list->schemeCount, pos)) {
   213 		if(changedList || list->schemeCount==0) {
       
   214 			list->schemes = changedList;
       
   215 			flib_cfg_release(elem);
   215 			flib_cfg_release(elem);
   216 			result = 0;
   216 			return 0;
   217 		}
   217 		}
   218 	}
   218 	}
   219 	return result;
   219 	return -1;
   220 }
   220 }