Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1088 → Rev 1089

/uspace/trunk/ns/ns.c
14,18 → 14,24
ipcarg_t retval, arg1, arg2;
 
printf("Name service started.\n");
printf("NS:Name service started.\n");
while (1) {
call.taskid = -1;
callid = ipc_wait_for_call(&call, 0);
printf("Received call from: %P..%llX\n", &call.taskid,call.taskid);
printf("NS:Call task=%llX,phone=%lX..",
call.taskid,call.data.phoneid);
switch (IPC_GET_METHOD(call.data)) {
case IPC_M_CONNECTTOME:
printf("Somebody wants to connect with phoneid %zd...accepting\n", IPC_GET_ARG3(call.data));
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);
retval = 0;
break;
case IPC_M_CONNECTMETO:
printf("Somebody wants to connect to: %zd\n",
case IPC_M_CONNECT_ME_TO:
printf("Connectmeto: %zd\n",
IPC_GET_ARG1(call.data));
retval = 0;
break;
36,10 → 42,14
arg1 = 0xdead;
arg2 = 0xbeef;
break;
case NS_HANGUP:
printf("Closing connection.\n");
retval = EHANGUP;
break;
case NS_PING_SVC:
printf("Pinging service %d\n", service);
printf("NS:Pinging service %d\n", service);
ipc_call_sync(service, NS_PING, 0xbeef, 0);
printf("Got pong\n");
printf("NS:Got pong\n");
break;
default:
printf("Unknown method: %zd\n", IPC_GET_METHOD(call.data));
/uspace/trunk/libipc/include/ipc.h
34,8 → 34,11
#include <types.h>
 
typedef sysarg_t ipcarg_t;
typedef sysarg_t ipc_data_t[IPC_CALL_LEN];
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;
65,5 → 68,6
int ipc_connect_to_me(int phoneid, int arg1, int arg2,
unsigned long long *taskid);
int ipc_connect_me_to(int phoneid, int arg1, int arg2);
int ipc_hangup(int phoneid);
 
#endif
/uspace/trunk/libipc/include/ns.h
31,5 → 31,6
 
#define NS_PING 1024
#define NS_PING_SVC 1025
#define NS_HANGUP 1026
 
#endif
/uspace/trunk/libipc/generic/ipc.c
252,3 → 252,8
return __SYSCALL3(SYS_IPC_CONNECT_ME_TO, phoneid, arg1, arg2);
}
 
/* Hang up specified phone */
int ipc_hangup(int phoneid)
{
return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
}
/uspace/trunk/init/init.c
34,6 → 34,8
#include <ns.h>
#include <thread.h>
 
int a;
 
extern void utest(void *arg);
void utest(void *arg)
{
169,7 → 171,7
printf("Received ping\n");
ipc_answer(callid, 0, 0, 0);
}
callid = ipc_wait_for_call(&data, NULL);
// callid = ipc_wait_for_call(&data, NULL);
}
 
static void test_connection_ipc(void)
182,10 → 184,63
printf("Connected: %d\n", res);
printf("pinging.\n");
res = ipc_call_sync(res, NS_PING, 0xbeef,&result);
printf("Retval: %d - received: %zd\n", res, result);
printf("Retval: %d - received: %X\n", res, result);
}
 
static void test_hangup(void)
{
int phoneid;
ipc_call_t data;
ipc_callid_t callid;
int i;
 
printf("Starting connect...\n");
phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
printf("Phoneid: %d, pinging\n", phoneid);
ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
"Pong1", got_answer);
printf("Hangin up\n");
ipc_hangup(phoneid);
printf("Connecting\n");
phoneid = ipc_connect_me_to(PHONE_NS, 10, 20);
printf("Newphid: %d\n", phoneid);
for (i=0; i < 1000; i++) {
if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
printf("callid: %d\n");
}
printf("New new phoneid: %d\n", ipc_connect_me_to(PHONE_NS, 10, 20));
}
 
static void test_slam(void)
{
int i;
ipc_call_t data;
ipc_callid_t callid;
 
printf("ping");
ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
"Pong1", got_answer);
printf("slam");
ipc_call_async_2(PHONE_NS, NS_HANGUP, 1, 0xbeefbee2,
"Hang", got_answer);
printf("ping2\n");
ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
"Ping2", got_answer);
for (i=0; i < 1000; i++) {
if ((callid=ipc_wait_for_call(&data, IPC_WAIT_NONBLOCKING)))
printf("callid: %d\n");
}
ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
"Pong1", got_answer);
printf("Closing file\n");
ipc_hangup(PHONE_NS);
ipc_call_async_2(PHONE_NS, NS_PING, 1, 0xbeefbee2,
"Pong1", got_answer);
ipc_wait_for_call(&data, 0);
}
 
int main(int argc, char *argv[])
{
int tid;
195,11 → 250,12
// test_ping();
// test_async_ipc();
// test_advanced_ipc();
test_connection_ipc();
if ((tid = thread_create(utest, NULL, "utest") != -1)) {
printf("Created thread tid=%d\n", tid);
}
// test_connection_ipc();
// test_hangup();
test_slam();
 
// if ((tid = thread_create(utest, NULL, "utest") != -1)) {
// printf("Created thread tid=%d\n", tid);
// }
return 0;
}