Changes in uspace/app/trace/proto.c [9d58539:4e00f87] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/trace/proto.c
r9d58539 r4e00f87 40 40 #include "proto.h" 41 41 42 #define SRV_PROTO_TABLE_CHAINS 32 43 #define METHOD_OPER_TABLE_CHAINS 32 44 45 hash_table_t srv_proto; 42 43 /* Maps service number to protocol */ 44 static hash_table_t srv_proto; 46 45 47 46 typedef struct { 48 unsignedsrv;47 int srv; 49 48 proto_t *proto; 50 link_t link;49 ht_link_t link; 51 50 } srv_proto_t; 52 51 53 52 typedef struct { 54 sysarg_t method;53 int method; 55 54 oper_t *oper; 56 link_t link;55 ht_link_t link; 57 56 } method_oper_t; 58 57 59 static hash_index_t srv_proto_hash(unsigned long key[]); 60 static int srv_proto_compare(unsigned long key[], hash_count_t keys, 61 link_t *item); 62 static void srv_proto_remove_callback(link_t *item); 63 64 hash_table_operations_t srv_proto_ops = { 58 /* Hash table operations. */ 59 60 static size_t srv_proto_key_hash(void *key) 61 { 62 return *(int *)key; 63 } 64 65 static size_t srv_proto_hash(const ht_link_t *item) 66 { 67 srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link); 68 return sp->srv; 69 } 70 71 static bool srv_proto_key_equal(void *key, const ht_link_t *item) 72 { 73 srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link); 74 return sp->srv == *(int *)key; 75 } 76 77 static hash_table_ops_t srv_proto_ops = { 65 78 .hash = srv_proto_hash, 66 .compare = srv_proto_compare, 67 .remove_callback = srv_proto_remove_callback 79 .key_hash = srv_proto_key_hash, 80 .key_equal = srv_proto_key_equal, 81 .equal = NULL, 82 .remove_callback = NULL 68 83 }; 69 84 70 static hash_index_t method_oper_hash(unsigned long key[]); 71 static int method_oper_compare(unsigned long key[], hash_count_t keys, 72 link_t *item); 73 static void method_oper_remove_callback(link_t *item); 74 75 hash_table_operations_t method_oper_ops = { 85 86 static size_t method_oper_key_hash(void *key) 87 { 88 return *(int *)key; 89 } 90 91 static size_t method_oper_hash(const ht_link_t *item) 92 { 93 method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link); 94 return mo->method; 95 } 96 97 static bool method_oper_key_equal(void *key, const ht_link_t *item) 98 { 99 method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link); 100 return mo->method == *(int *)key; 101 } 102 103 static hash_table_ops_t method_oper_ops = { 76 104 .hash = method_oper_hash, 77 .compare = method_oper_compare, 78 .remove_callback = method_oper_remove_callback 105 .key_hash = method_oper_key_hash, 106 .key_equal = method_oper_key_equal, 107 .equal = NULL, 108 .remove_callback = NULL 79 109 }; 80 110 81 static hash_index_t srv_proto_hash(unsigned long key[]) 82 { 83 return key[0] % SRV_PROTO_TABLE_CHAINS; 84 } 85 86 static int srv_proto_compare(unsigned long key[], hash_count_t keys, 87 link_t *item) 111 112 void proto_init(void) 113 { 114 /* todo: check return value. */ 115 bool ok = hash_table_create(&srv_proto, 0, 0, &srv_proto_ops); 116 assert(ok); 117 } 118 119 void proto_cleanup(void) 120 { 121 hash_table_destroy(&srv_proto); 122 } 123 124 void proto_register(int srv, proto_t *proto) 88 125 { 89 126 srv_proto_t *sp; 90 91 sp = hash_table_get_instance(item, srv_proto_t, link);92 93 return key[0] == sp->srv;94 }95 96 static void srv_proto_remove_callback(link_t *item)97 {98 }99 100 static hash_index_t method_oper_hash(unsigned long key[])101 {102 return key[0] % METHOD_OPER_TABLE_CHAINS;103 }104 105 static int method_oper_compare(unsigned long key[], hash_count_t keys,106 link_t *item)107 {108 method_oper_t *mo;109 110 mo = hash_table_get_instance(item, method_oper_t, link);111 112 return key[0] == mo->method;113 }114 115 static void method_oper_remove_callback(link_t *item)116 {117 }118 119 120 void proto_init(void)121 {122 hash_table_create(&srv_proto, SRV_PROTO_TABLE_CHAINS, 1,123 &srv_proto_ops);124 }125 126 void proto_cleanup(void)127 {128 hash_table_destroy(&srv_proto);129 }130 131 void proto_register(int srv, proto_t *proto)132 {133 srv_proto_t *sp;134 unsigned long key;135 127 136 128 sp = malloc(sizeof(srv_proto_t)); 137 129 sp->srv = srv; 138 130 sp->proto = proto; 139 key = srv; 140 141 hash_table_insert(&srv_proto, &key, &sp->link); 131 132 hash_table_insert(&srv_proto, &sp->link); 142 133 } 143 134 144 135 proto_t *proto_get_by_srv(int srv) 145 136 { 146 unsigned long key; 147 link_t *item; 148 srv_proto_t *sp; 149 150 key = srv; 151 item = hash_table_find(&srv_proto, &key); 137 ht_link_t *item = hash_table_find(&srv_proto, &srv); 152 138 if (item == NULL) return NULL; 153 139 154 s p = hash_table_get_instance(item, srv_proto_t, link);140 srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link); 155 141 return sp->proto; 156 142 } … … 159 145 { 160 146 proto->name = name; 161 hash_table_create(&proto->method_oper, SRV_PROTO_TABLE_CHAINS, 1, 162 &method_oper_ops); 147 /* todo: check return value. */ 148 bool ok = hash_table_create(&proto->method_oper, 0, 0, &method_oper_ops); 149 assert(ok); 163 150 } 164 151 … … 181 168 { 182 169 method_oper_t *mo; 183 unsigned long key;184 170 185 171 mo = malloc(sizeof(method_oper_t)); 186 172 mo->method = method; 187 173 mo->oper = oper; 188 key = method; 189 190 hash_table_insert(&proto->method_oper, &key, &mo->link); 174 175 hash_table_insert(&proto->method_oper, &mo->link); 191 176 } 192 177 193 178 oper_t *proto_get_oper(proto_t *proto, int method) 194 179 { 195 unsigned long key; 196 link_t *item; 197 method_oper_t *mo; 198 199 key = method; 200 item = hash_table_find(&proto->method_oper, &key); 180 ht_link_t *item = hash_table_find(&proto->method_oper, &method); 201 181 if (item == NULL) return NULL; 202 182 203 m o = hash_table_get_instance(item, method_oper_t, link);183 method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link); 204 184 return mo->oper; 205 185 }
Note:
See TracChangeset
for help on using the changeset viewer.