/branches/tracing/uspace/app/sctrace/proto.c |
---|
0,0 → 1,87 |
/** @addtogroup sctrace |
* @{ |
*/ |
/** @file |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#include <libadt/hash_table.h> |
#include "proto.h" |
#define SRV_PROTO_TABLE_CHAINS 32 |
hash_table_t srv_proto; |
typedef struct { |
int srv; |
proto_t *proto; |
link_t link; |
} srv_proto_t; |
hash_index_t srv_proto_hash(unsigned long key[]) |
{ |
return key[0] % SRV_PROTO_TABLE_CHAINS; |
} |
int srv_proto_compare(unsigned long key[], hash_count_t keys, |
link_t *item) |
{ |
srv_proto_t *sp; |
sp = hash_table_get_instance(item, srv_proto_t, link); |
return key[0] == sp->srv; |
} |
void srv_proto_remove_callback(link_t *item) |
{ |
} |
hash_table_operations_t srv_proto_ops = { |
.hash = srv_proto_hash, |
.compare = srv_proto_compare, |
.remove_callback = srv_proto_remove_callback |
}; |
void proto_init(void) |
{ |
hash_table_create(&srv_proto, SRV_PROTO_TABLE_CHAINS, 1, |
&srv_proto_ops); |
} |
void proto_cleanup(void) |
{ |
hash_table_destroy(&srv_proto); |
} |
void proto_register(int srv, proto_t *proto) |
{ |
srv_proto_t *sp; |
unsigned long key; |
sp = malloc(sizeof(srv_proto_t)); |
sp->srv = srv; |
sp->proto = proto; |
key = srv; |
hash_table_insert(&srv_proto, &key, &sp->link); |
} |
proto_t *proto_get_by_srv(int srv) |
{ |
unsigned long key; |
link_t *item; |
srv_proto_t *sp; |
key = srv; |
item = hash_table_find(&srv_proto, &key); |
if (item == NULL) return NULL; |
sp = hash_table_get_instance(item, srv_proto_t, link); |
return sp->proto; |
} |
/** @} |
*/ |
/branches/tracing/uspace/app/sctrace/sctrace.c |
---|
5,6 → 5,7 |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#include <unistd.h> |
#include <syscall.h> |
#include <ipc/ipc.h> |
13,6 → 14,9 |
#include <udebug.h> |
#include <async.h> |
#include "proto.h" |
#include <ipc/services.h> |
#include "syscalls.h" |
#include "ipcp.h" |
#include "errors.h" |
370,10 → 374,23 |
return; |
} |
int main(void) |
static void main_init(void) |
{ |
proto_t *p; |
next_thread_id = 1; |
proto_init(); |
p = malloc(sizeof(proto_t)); |
p->name = "vfs"; |
proto_register(SERVICE_VFS, p); |
} |
int main(void) |
{ |
main_init(); |
while (1) { |
trace_active_task(); |
} |
/branches/tracing/uspace/app/sctrace/proto.h |
---|
7,10 → 7,21 |
#ifndef PROTO_H_ |
#define PROTO_H_ |
#include <libadt/hash_table.h> |
typedef struct { |
char *name; |
} proto_t; |
/* Maps service number to protocol */ |
extern hash_table_t srv_proto; |
void proto_init(void); |
void proto_cleanup(void); |
void proto_register(int srv, proto_t *proto); |
proto_t *proto_get_by_srv(int srv); |
#endif |
/** @} |
/branches/tracing/uspace/app/sctrace/ipcp.c |
---|
9,6 → 9,7 |
#include <libadt/hash_table.h> |
#include "ipc_desc.h" |
#include "proto.h" |
#include "ipcp.h" |
#define IPCP_CALLID_SYNC 0 |
139,8 → 140,10 |
{ |
int phone; |
ipcarg_t method; |
ipcarg_t service; |
int retval; |
static proto_t proto = { .name = "unknown" }; |
static proto_t proto_unknown = { .name = "unknown" }; |
proto_t *proto; |
int cphone; |
// printf("parse_answer\n"); |
153,11 → 156,14 |
if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { |
/* Connected to a service (through NS) */ |
service = IPC_GET_ARG1(pcall->question); |
proto = proto_get_by_srv(service); |
if (proto == NULL) proto = &proto_unknown; |
cphone = IPC_GET_ARG5(*answer); |
printf("registering connection (phone %d)\n", cphone); |
connection_set(cphone, 0, &proto); |
} else { |
printf("unrecognized connection\n"); |
printf("registering connection (phone %d, protocol: %s)\n", cphone, |
proto->name); |
connection_set(cphone, 0, proto); |
} |
} |
/branches/tracing/uspace/app/sctrace/Makefile |
---|
45,6 → 45,7 |
syscalls.c \ |
ipcp.c \ |
ipc_desc.c \ |
proto.c \ |
errors.c \ |
debug_api.c |