source: mainline/uspace/srv/devman/main.c@ 0c3666d

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

parts of device manager (unstable)

  • Property mode set to 100644
File size: 3.7 KB
Line 
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
58static driver_list_t 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{
94 printf(NAME ": devman_init - looking for available drivers. \n");
95
96 // initialize list of available drivers
97 init_driver_list(&drivers_list);
98 if (0 == lookup_available_drivers(&drivers_list, DRIVER_DEFAULT_STORE)) {
99 printf(NAME " no drivers found.");
100 return false;
101 }
102 printf(NAME ": devman_init - list of drivers has been initialized. \n");
103
104 // create root device node
105 if (!init_device_tree(&device_tree, &drivers_list)) {
106 printf(NAME " failed to initialize device tree.");
107 return false;
108 }
109
110 return true;
111}
112
113int main(int argc, char *argv[])
114{
115 printf(NAME ": HelenOS Device Manager\n");
116
117 if (!devman_init()) {
118 printf(NAME ": Error while initializing service\n");
119 return -1;
120 }
121
122 // Set a handler of incomming connections
123 async_set_client_connection(devman_connection);
124
125 // Register device manager at naming service
126 ipcarg_t phonead;
127 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
128 return -1;
129
130 printf(NAME ": Accepting connections\n");
131 async_manager();
132
133 // Never reached
134 return 0;
135}
Note: See TracBrowser for help on using the repository browser.