source: mainline/uspace/srv/devman/main.c@ e2b9a993

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

device manager - parts of code

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