Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2879 → Rev 2880

/branches/tracing/uspace/app/sctrace/proto.c
6,11 → 6,13
 
#include <stdio.h>
#include <stdlib.h>
#include <ipc/ipc.h>
#include <libadt/hash_table.h>
 
#include "proto.h"
 
#define SRV_PROTO_TABLE_CHAINS 32
#define METHOD_OPER_TABLE_CHAINS 32
 
hash_table_t srv_proto;
 
20,6 → 22,12
link_t link;
} srv_proto_t;
 
typedef struct {
ipcarg_t method;
oper_t *oper;
link_t link;
} method_oper_t;
 
hash_index_t srv_proto_hash(unsigned long key[])
{
return key[0] % SRV_PROTO_TABLE_CHAINS;
45,6 → 53,32
.remove_callback = srv_proto_remove_callback
};
 
hash_index_t method_oper_hash(unsigned long key[])
{
return key[0] % METHOD_OPER_TABLE_CHAINS;
}
 
int method_oper_compare(unsigned long key[], hash_count_t keys,
link_t *item)
{
method_oper_t *mo;
 
mo = hash_table_get_instance(item, method_oper_t, link);
 
return key[0] == mo->method;
}
 
void method_oper_remove_callback(link_t *item)
{
}
 
hash_table_operations_t method_oper_ops = {
.hash = method_oper_hash,
.compare = method_oper_compare,
.remove_callback = method_oper_remove_callback
};
 
 
void proto_init(void)
{
hash_table_create(&srv_proto, SRV_PROTO_TABLE_CHAINS, 1,
83,5 → 117,49
return sp->proto;
}
 
static void proto_struct_init(proto_t *proto, char *name)
{
proto->name = name;
hash_table_create(&proto->method_oper, SRV_PROTO_TABLE_CHAINS, 1,
&method_oper_ops);
}
 
proto_t *proto_new(char *name)
{
proto_t *p;
 
p = malloc(sizeof(proto_t));
proto_struct_init(p, name);
 
return p;
}
 
void proto_add_oper(proto_t *proto, int method, oper_t *oper)
{
method_oper_t *mo;
unsigned long key;
 
mo = malloc(sizeof(method_oper_t));
mo->method = method;
mo->oper = oper;
key = method;
 
hash_table_insert(&proto->method_oper, &key, &mo->link);
}
 
oper_t *proto_get_oper(proto_t *proto, int method)
{
unsigned long key;
link_t *item;
method_oper_t *mo;
 
key = method;
item = hash_table_find(&proto->method_oper, &key);
if (item == NULL) return NULL;
 
mo = hash_table_get_instance(item, method_oper_t, link);
return mo->oper;
}
 
/** @}
*/
/branches/tracing/uspace/app/sctrace/sctrace.c
14,8 → 14,10
#include <udebug.h>
#include <async.h>
 
// Temporary: service and method names
#include "proto.h"
#include <ipc/services.h>
#include "../../srv/vfs/vfs.h"
 
#include "syscalls.h"
#include "ipcp.h"
377,13 → 379,18
static void main_init(void)
{
proto_t *p;
oper_t *o;
 
next_thread_id = 1;
 
proto_init();
 
p = malloc(sizeof(proto_t));
p->name = "vfs";
o = malloc(sizeof(oper_t));
o->name = "mount";
 
p = proto_new("vfs");
proto_add_oper(p, VFS_MOUNT, o);
 
proto_register(SERVICE_VFS, p);
}
 
/branches/tracing/uspace/app/sctrace/proto.h
11,6 → 11,14
 
typedef struct {
char *name;
} oper_t;
 
typedef struct {
/** Protocol name */
char *name;
 
/** Maps method number to operation */
hash_table_t method_oper;
} proto_t;
 
/* Maps service number to protocol */
18,10 → 26,13
 
void proto_init(void);
void proto_cleanup(void);
 
void proto_register(int srv, proto_t *proto);
proto_t *proto_get_by_srv(int srv);
proto_t *proto_new(char *name);
void proto_add_oper(proto_t *proto, int method, oper_t *oper);
oper_t *proto_get_oper(proto_t *proto, int method);
 
 
#endif
 
/** @}
/branches/tracing/uspace/app/sctrace/ipcp.c
78,9 → 78,10
connections[phone].proto = NULL;
}
 
static void ipc_m_print(ipcarg_t method)
static void ipc_m_print(proto_t *proto, ipcarg_t method)
{
ipc_m_desc_t *desc;
oper_t *oper;
 
/* FIXME: too slow */
desc = ipc_methods;
93,6 → 94,14
++desc;
}
 
if (proto != NULL) {
oper = proto_get_oper(proto, method);
if (oper != NULL) {
printf("%s (%d)", oper->name, method);
return;
}
}
 
printf("%d", method);
}
 
109,15 → 118,15
void ipcp_call_out(int phone, ipc_call_t *call, ipc_callid_t hash)
{
pending_call_t *pcall;
char *proto_name;
proto_t *proto;
 
if (have_conn[phone]) proto_name = connections[phone].proto->name;
else proto_name = "n/a";
if (have_conn[phone]) proto = connections[phone].proto;
else proto = NULL;
 
// printf("ipcp_call_out()\n");
printf("call id: 0x%x, phone: %d, proto: %s, method: ", hash, phone,
proto_name);
ipc_m_print(IPC_GET_METHOD(*call));
(proto ? proto->name : "n/a"));
ipc_m_print(proto, IPC_GET_METHOD(*call));
printf(" args: (%u, %u, %u, %u, %u)\n",
IPC_GET_ARG1(*call),
IPC_GET_ARG2(*call),