-
Notifications
You must be signed in to change notification settings - Fork 6
/
drivermanager.c
63 lines (52 loc) · 1.1 KB
/
drivermanager.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* drivermanager.c
*
* Created on: 05.04.2017
* Author: pascal
*/
#include "drivermanager.h"
#include "list.h"
#include "assert.h"
#include "stddef.h"
#include "string.h"
#include "stdbool.h"
#include "cdifs.h"
static list_t drivers;
void drivermanager_init()
{
drivers = list_create();
assert(drivers != NULL);
}
void drivermanager_registerDriver(struct cdi_driver *drv)
{
assert(drv != NULL);
list_push(drivers, drv);
if(drv->type == CDI_FILESYSTEM)
cdifs_registerFilesystemDriver((struct cdi_fs_driver*)drv);
}
struct cdi_driver *drivermanager_getDriver(const char *name)
{
struct cdi_driver *drv;
size_t i = 0;
assert(name != NULL);
while((drv = list_get(drivers, i++)) != NULL)
{
if(strcmp(name, drv->name) == 0)
return drv;
}
return drv;
}
struct cdi_driver *drivermanager_getNextDeviceDriver(cdi_device_type_t bus, struct cdi_driver *prev)
{
struct cdi_driver *drv;
size_t i = 0;
bool prev_found = prev == NULL;
while((drv = list_get(drivers, i++)) != NULL)
{
if(prev_found && drv->bus == bus)
return drv;
if(drv == prev)
prev_found = true;
}
return drv;
}