devman.h

00001 /*
00002  * Copyright (c) 2010 Lenka Trochtova
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00033 #ifndef LIBC_IPC_DEVMAN_H_
00034 #define LIBC_IPC_DEVMAN_H_
00035 
00036 #include <ipc/common.h>
00037 #include <adt/list.h>
00038 #include <malloc.h>
00039 #include <mem.h>
00040 
00041 #define DEVMAN_NAME_MAXLEN  256
00042 
00043 typedef sysarg_t devman_handle_t;
00044 
00045 typedef enum {
00047         fun_invalid = 0,
00049         fun_inner,
00051         fun_exposed
00052 } fun_type_t;
00053 
00056 typedef struct match_id {
00059         link_t link;
00062         const char *id;
00067         unsigned int score;
00068 } match_id_t;
00069 
00073 typedef struct match_id_list {
00074         link_t ids;
00075 } match_id_list_t;
00076 
00077 static inline match_id_t *create_match_id(void)
00078 {
00079         match_id_t *id = malloc(sizeof(match_id_t));
00080         memset(id, 0, sizeof(match_id_t));
00081         return id;
00082 }
00083 
00084 static inline void delete_match_id(match_id_t *id)
00085 {
00086         if (id) {
00087                 if (NULL != id->id) {
00088                         free(id->id);
00089                 }
00090                 free(id);
00091         }
00092 }
00093 
00094 static inline void add_match_id(match_id_list_t *ids, match_id_t *id)
00095 {
00096         match_id_t *mid = NULL;
00097         link_t *link = ids->ids.next;
00098         
00099         while (link != &ids->ids) {
00100                 mid = list_get_instance(link, match_id_t,link);
00101                 if (mid->score < id->score) {
00102                         break;
00103                 }       
00104                 link = link->next;
00105         }
00106         
00107         list_insert_before(&id->link, link);
00108 }
00109 
00110 static inline void init_match_ids(match_id_list_t *id_list)
00111 {
00112         list_initialize(&id_list->ids);
00113 }
00114 
00115 static inline void clean_match_ids(match_id_list_t *ids)
00116 {
00117         link_t *link = NULL;
00118         match_id_t *id;
00119         
00120         while(!list_empty(&ids->ids)) {
00121                 link = ids->ids.next;
00122                 list_remove(link);              
00123                 id = list_get_instance(link, match_id_t, link);
00124                 delete_match_id(id);            
00125         }       
00126 }
00127 
00128 typedef enum {
00129         DEVMAN_DRIVER = 1,
00130         DEVMAN_CLIENT,
00131         DEVMAN_CONNECT_TO_DEVICE,
00132         DEVMAN_CONNECT_FROM_DEVMAP,
00133         DEVMAN_CONNECT_TO_PARENTS_DEVICE
00134 } devman_interface_t;
00135 
00136 typedef enum {
00137         DEVMAN_DRIVER_REGISTER = IPC_FIRST_USER_METHOD,
00138         DEVMAN_ADD_FUNCTION,
00139         DEVMAN_ADD_MATCH_ID,
00140         DEVMAN_ADD_DEVICE_TO_CLASS
00141 
00142 } driver_to_devman_t;
00143 
00144 typedef enum {
00145         DRIVER_ADD_DEVICE = IPC_FIRST_USER_METHOD
00146 
00147 } devman_to_driver_t;
00148 
00149 typedef enum {
00150         DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
00151         DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
00152         DEVMAN_DEVICE_GET_DEVICE_PATH
00153 } client_to_devman_t;
00154 
00155 #endif
00156 

Generated on Thu Jun 2 07:45:46 2011 for HelenOS/USB by  doxygen 1.4.7