source: mainline/uspace/srv/devman/main.c@ 08d9c4e6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 08d9c4e6 was 08d9c4e6, checked in by Lenka Trochtova <trochtova.lenka@…>, 15 years ago

device manager - initialization of the list of available drivers

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[e2b9a993]1/*
2 * Copyright (c) 2010 Lenka Trochtova
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/**
30 * @defgroup devman Device manager.
31 * @brief HelenOS device manager.
32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <ipc/services.h>
40#include <ipc/ns.h>
41#include <async.h>
42#include <stdio.h>
43#include <errno.h>
44#include <bool.h>
45#include <fibril_synch.h>
46#include <stdlib.h>
47#include <string.h>
48#include <dirent.h>
49#include <fcntl.h>
50#include <sys/stat.h>
51#include <ctype.h>
52#include <ipc/devman.h>
53
54#include "devman.h"
55
56#define DRIVER_DEFAULT_STORE "/srv/drivers"
57
58LIST_INITIALIZE(drivers_list);
59static dev_tree_t device_tree;
60
61
62/** Function for handling connections to device manager.
63 *
64 */
65static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
66{
67 ipc_callid_t callid;
68 ipc_call_t call;
69
70 /* Accept the connection */
71 ipc_answer_0(iid, EOK);
72
73 while (1) {
74 callid = async_get_call(&call);
75
76 switch (IPC_GET_METHOD(call)) {
77 case DEVMAN_DRIVER_REGISTER:
78 // TODO register running driver instance - remember driver's phone and lookup devices to which it has been assigned
79 break;
80 case DEVMAN_ADD_CHILD_DEVICE:
81 // TODO add new device node to the device tree
82 break;
83 default:
84 ipc_answer_0(callid, EINVAL);
85 break;
86 }
87 }
88}
89
90/** Initialize device manager internal structures.
91 */
92static bool devman_init()
93{
[08d9c4e6]94 printf(NAME ": devman_init - looking for available drivers. \n");
95
[e2b9a993]96 // initialize list of available drivers
97 if (0 == lookup_available_drivers(&drivers_list, DRIVER_DEFAULT_STORE)) {
98 printf(NAME " no drivers found.");
99 return false;
100 }
[08d9c4e6]101 printf(NAME ": devman_init - list of drivers has been initialized. \n");
[e2b9a993]102
103 // create root device node
104 if (!init_device_tree(&device_tree, &drivers_list)) {
105 printf(NAME " failed to initialize device tree.");
106 return false;
107 }
108
109 return true;
110}
111
112/**
113 *
114 */
115int main(int argc, char *argv[])
116{
117 printf(NAME ": HelenOS Device Manager\n");
118
119 if (!devman_init()) {
120 printf(NAME ": Error while initializing service\n");
121 return -1;
122 }
123
124 // Set a handler of incomming connections
125 async_set_client_connection(devman_connection);
126
127 // Register device manager at naming service
128 ipcarg_t phonead;
129 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
130 return -1;
131
132 printf(NAME ": Accepting connections\n");
133 async_manager();
134
135 // Never reached
136 return 0;
137}
Note: See TracBrowser for help on using the repository browser.