libcdi: +debug function; +FIFOs
[meinos.git] / apps / lib / libcdi / cdi.c
blob2bbbc1b562a66d39cca4855f2516d7067a278eba
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <string.h>
20 #include <devfs.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <cdi/misc.h>
25 #include <cdi/lists.h>
26 #include <cdi/storage.h>
27 #include <cdi/fs.h>
28 #include <rpc.h>
29 #include <cdi.h>
31 int cdi_fs_init();
33 /**
34 * Destroys CDI
36 void cdi_destroy() {
37 cdi_debug("destroy\n");
38 struct cdi_driver* driver;
39 while ((driver = cdi_list_pop(cdi_drivers))) driver->destroy(driver);
42 /**
43 * Initializes CDI
45 void cdi_init() {
46 cdi_debug("init\n");
47 atexit(cdi_destroy);
48 cdi_drivers = cdi_list_create();
49 cdi_filesystems = cdi_list_create();
50 devfs_init();
51 cdi_fs_init();
54 /**
55 * Runs all CDI drivers
57 void cdi_run_drivers() {
58 cdi_debug("run drivers\n");
59 struct cdi_driver* driver;
60 struct cdi_device* device;
61 int i, j;
63 for (i=0;(driver = cdi_list_get(cdi_drivers,i));i++) {
64 cdi_debug("init driver: %s\n",driver->name);
65 for (j = 0;(device = cdi_list_get(driver->devices,j));j++) {
66 device->driver = driver;
67 if (driver->init_device!=NULL) driver->init_device(device);
71 rpc_mainloop(-1);
74 /**
75 * Initializes a CDI driver
76 * @param driver Driver to initialize
78 void cdi_driver_init(struct cdi_driver* driver) {
79 cdi_debug("driver init\n");
80 driver->devices = cdi_list_create();
83 /**
84 * Destroys a CDI driver
85 * @param driver Driver to destroy
87 void cdi_driver_destroy(struct cdi_driver* driver) {
88 cdi_debug("driver destroy: %s\n",driver->name);
89 cdi_list_destroy(driver->devices);
92 /**
93 * Registers a CDI driver
94 * @param driver Driver to register
96 void cdi_driver_register(struct cdi_driver* driver) {
97 cdi_debug("driver register: %s\n",driver->name);
98 cdi_list_push(cdi_drivers,driver);
102 * Prints debug message
103 * @param fmt Format
104 * @param ... Parameters
106 void cdi_debug(const char *fmt,...) {
107 #ifdef CDI_DEBUG
108 va_list args;
109 va_start(args,fmt);
110 fprintf(CDI_DEBUG,"cdi (%d): ",getpid());
111 vfprintf(CDI_DEBUG,fmt,args);
112 va_end(args);
113 #endif