summaryrefslogtreecommitdiffstats
path: root/src/config-load.c
blob: 19b9d3adb3484216c2926142a496ef7a2d6e00b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "config-load.h"
#include "config-process.h"
#include "device.h"
#include "util.h"

#include <libubox/avl-cmp.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

bool read_config(const char *path) {
	struct json_object *config = json_object_from_file(path);
	if (!config)
		return false;

	struct avl_tree *devices = config_process(config);
	json_object_put(config);

	if (!devices)
		return false;

	device_t *dev, *tmp;
	avl_for_each_element(devices, dev, node)
		dev->type->init(dev);

	//avl_for_each_element(devices, dev, node)
	//	dev->type->release(dev);

	avl_remove_all_elements(devices, dev, node, tmp)
		dev->type->free(dev);

	free(devices);

	return true;
}