//uspace/trunk/ns/ns.c |
---|
16,28 → 16,26 |
printf("NS:Name service started.\n"); |
while (1) { |
call.taskid = -1; |
callid = ipc_wait_for_call(&call, 0); |
printf("NS:Call task=%llX,phone=%lX..", |
call.taskid,call.data.phoneid); |
switch (IPC_GET_METHOD(call.data)) { |
printf("NS:Call phone=%lX..", call.phoneid); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
printf("Phone hung up.\n"); |
retval = 0; |
break; |
case IPC_M_CONNECT_TO_ME: |
printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call.data)); |
service = IPC_GET_ARG3(call.data); |
printf("Somebody connecting phid=%zd.\n", IPC_GET_ARG3(call)); |
service = IPC_GET_ARG3(call); |
retval = 0; |
break; |
case IPC_M_CONNECT_ME_TO: |
printf("Connectmeto: %zd\n", |
IPC_GET_ARG1(call.data)); |
printf("Connectme(%P)to: %zd\n", |
IPC_GET_ARG3(call), IPC_GET_ARG1(call)); |
retval = 0; |
break; |
case NS_PING: |
printf("Ping...%P %P\n", IPC_GET_ARG1(call.data), |
IPC_GET_ARG2(call.data)); |
printf("Ping...%P %P\n", IPC_GET_ARG1(call), |
IPC_GET_ARG2(call)); |
retval = 0; |
arg1 = 0xdead; |
arg2 = 0xbeef; |
52,7 → 50,7 |
printf("NS:Got pong\n"); |
break; |
default: |
printf("Unknown method: %zd\n", IPC_GET_METHOD(call.data)); |
printf("Unknown method: %zd\n", IPC_GET_METHOD(call)); |
retval = ENOENT; |
break; |
} |
//uspace/trunk/libipc/include/ipc.h |
---|
35,18 → 35,13 |
typedef sysarg_t ipcarg_t; |
typedef struct { |
sysarg_t args[IPC_CALL_LEN]; |
sysarg_t phoneid; |
} ipc_data_t ; |
typedef struct { |
unsigned long long taskid; |
ipc_data_t data; |
}ipc_call_t; |
ipcarg_t args[IPC_CALL_LEN]; |
ipcarg_t phoneid; |
} ipc_call_t ; |
typedef sysarg_t ipc_callid_t; |
typedef void (* ipc_async_callback_t)(void *private, |
int retval, |
ipc_data_t *data); |
typedef void (* ipc_async_callback_t)(void *private, int retval, |
ipc_call_t *data); |
#define ipc_call_sync_2(phoneid, method, arg1, arg2, res1, res2) ipc_call_sync_3((phoneid), (method), (arg1), (arg2), 0, (res1), (res2), 0) |
extern int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1, |
65,8 → 60,7 |
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1, |
ipcarg_t arg2, void *private, |
ipc_async_callback_t callback); |
int ipc_connect_to_me(int phoneid, int arg1, int arg2, |
unsigned long long *taskid); |
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone); |
int ipc_connect_me_to(int phoneid, int arg1, int arg2); |
int ipc_hangup(int phoneid); |
//uspace/trunk/libipc/generic/ipc.c |
---|
46,8 → 46,8 |
union { |
ipc_callid_t callid; |
struct { |
ipc_call_t data; |
int phoneid; |
ipc_data_t data; |
} msg; |
}u; |
} async_call_t; |
58,7 → 58,7 |
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1, |
ipcarg_t *result) |
{ |
ipc_data_t resdata; |
ipc_call_t resdata; |
int callres; |
callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, |
74,7 → 74,7 |
ipcarg_t arg2, ipcarg_t arg3, |
ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3) |
{ |
ipc_data_t data; |
ipc_call_t data; |
int callres; |
IPC_SET_METHOD(data, method); |
97,7 → 97,7 |
} |
/** Syscall to send asynchronous message */ |
static ipc_callid_t _ipc_call_async(int phoneid, ipc_data_t *data) |
static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data) |
{ |
return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t)data); |
} |
154,14 → 154,6 |
__SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2); |
} |
/** Call syscall function sys_ipc_wait_for_call */ |
static inline ipc_callid_t _ipc_wait_for_call(ipc_call_t *call, int flags) |
{ |
return __SYSCALL3(SYS_IPC_WAIT, (sysarg_t)&call->data, |
(sysarg_t)&call->taskid, flags); |
} |
/** Try to dispatch queed calls from async queue */ |
static void try_dispatch_queued_calls(void) |
{ |
193,7 → 185,7 |
* |
* @param callid Callid (with first bit set) of the answered call |
*/ |
static void handle_answer(ipc_callid_t callid, ipc_data_t *data) |
static void handle_answer(ipc_callid_t callid, ipc_call_t *data) |
{ |
link_t *item; |
async_call_t *call; |
229,27 → 221,39 |
do { |
try_dispatch_queued_calls(); |
callid = _ipc_wait_for_call(call, flags); |
callid = __SYSCALL2(SYS_IPC_WAIT, (sysarg_t)call, flags); |
/* Handle received answers */ |
if (callid & IPC_CALLID_ANSWERED) |
handle_answer(callid, &call->data); |
handle_answer(callid, call); |
} while (callid & IPC_CALLID_ANSWERED); |
return callid; |
} |
/** Ask destination to do a callback connection */ |
int ipc_connect_to_me(int phoneid, int arg1, int arg2, |
unsigned long long *taskid) |
/** Ask destination to do a callback connection |
* |
* @return 0 - OK, error code |
*/ |
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phone) |
{ |
return __SYSCALL4(SYS_IPC_CONNECT_TO_ME, phoneid, arg1, arg2, |
(sysarg_t) taskid); |
return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, |
arg2, 0, 0, 0, phone); |
} |
/** Ask through phone for a new connection to some service */ |
/** Ask through phone for a new connection to some service |
* |
* @return new phoneid - OK, error code |
*/ |
int ipc_connect_me_to(int phoneid, int arg1, int arg2) |
{ |
return __SYSCALL3(SYS_IPC_CONNECT_ME_TO, phoneid, arg1, arg2); |
int newphid; |
int res; |
res = ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, |
arg2, 0, 0, 0, &newphid); |
if (res) |
return res; |
return newphid; |
} |
/* Hang up specified phone */ |
//uspace/trunk/init/init.c |
---|
112,11 → 112,12 |
ipcarg_t result; |
int retval; |
printf("Pinging\n"); |
retval = ipc_call_sync(PHONE_NS, NS_PING, 0xbeef,&result); |
printf("Retval: %d - received: %P\n", retval, result); |
} |
static void got_answer(void *private, int retval, ipc_data_t *data) |
static void got_answer(void *private, int retval, ipc_call_t *data) |
{ |
printf("Retval: %d...%s...%zX, %zX\n", retval, private, |
IPC_GET_ARG1(*data), IPC_GET_ARG2(*data)); |
148,7 → 149,7 |
} |
static void got_answer_2(void *private, int retval, ipc_data_t *data) |
static void got_answer_2(void *private, int retval, ipc_call_t *data) |
{ |
printf("Pong\n"); |
} |
155,14 → 156,14 |
static void test_advanced_ipc(void) |
{ |
int res; |
unsigned long long taskid; |
ipcarg_t phonead; |
ipc_callid_t callid; |
ipc_call_t data; |
int i; |
printf("Asking 0 to connect to me...\n"); |
res = ipc_connect_to_me(0, 1, 2, &taskid); |
printf("Result: %d - taskid: %llu\n", res, taskid); |
res = ipc_connect_to_me(0, 1, 2, &phonead); |
printf("Result: %d - phonead: %llu\n", res, phonead); |
for (i=0; i < 100; i++) { |
printf("----------------\n"); |
ipc_call_async(PHONE_NS, NS_PING_SVC, 0, "prov", |
178,6 → 179,7 |
{ |
int res; |
ipcarg_t result; |
int phoneid; |
printf("Starting connect...\n"); |
res = ipc_connect_me_to(PHONE_NS, 10, 20); |
252,10 → 254,10 |
// test_advanced_ipc(); |
// test_connection_ipc(); |
// test_hangup(); |
test_slam(); |
// test_slam(); |
// if ((tid = thread_create(utest, NULL, "utest") != -1)) { |
// printf("Created thread tid=%d\n", tid); |
// } |
if ((tid = thread_create(utest, NULL, "utest") != -1)) { |
printf("Created thread tid=%d\n", tid); |
} |
return 0; |
} |