ns.c

00001 /*
00002  * Copyright (c) 2006 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00038 #include <ipc/ipc.h>
00039 #include <ipc/ns.h>
00040 #include <stdio.h>
00041 #include <errno.h>
00042 #include <macros.h>
00043 #include "ns.h"
00044 #include "service.h"
00045 #include "clonable.h"
00046 #include "task.h"
00047 
00048 int main(int argc, char **argv)
00049 {
00050         printf(NAME ": HelenOS IPC Naming Service\n");
00051         
00052         int rc = service_init();
00053         if (rc != EOK)
00054                 return rc;
00055         
00056         rc = clonable_init();
00057         if (rc != EOK)
00058                 return rc;
00059         
00060         rc = task_init();
00061         if (rc != EOK)
00062                 return rc;
00063         
00064         printf("%s: Accepting connections\n", NAME);
00065         
00066         while (true) {
00067                 process_pending_conn();
00068                 process_pending_wait();
00069                 
00070                 ipc_call_t call;
00071                 ipc_callid_t callid = ipc_wait_for_call(&call);
00072                 
00073                 task_id_t id;
00074                 sysarg_t retval;
00075                 
00076                 switch (IPC_GET_IMETHOD(call)) {
00077                 case IPC_M_PHONE_HUNGUP:
00078                         retval = ns_task_disconnect(&call);
00079                         break;
00080                 case IPC_M_CONNECT_TO_ME:
00081                         /*
00082                          * Server requests service registration.
00083                          */
00084                         if (service_clonable(IPC_GET_ARG1(call))) {
00085                                 register_clonable(IPC_GET_ARG1(call),
00086                                     IPC_GET_ARG5(call), &call, callid);
00087                                 continue;
00088                         } else {
00089                                 retval = register_service(IPC_GET_ARG1(call),
00090                                     IPC_GET_ARG5(call), &call);
00091                         }
00092                         break;
00093                 case IPC_M_CONNECT_ME_TO:
00094                         /*
00095                          * Client requests to be connected to a service.
00096                          */
00097                         if (service_clonable(IPC_GET_ARG1(call))) {
00098                                 connect_to_clonable(IPC_GET_ARG1(call),
00099                                     &call, callid);
00100                                 continue;
00101                         } else {
00102                                 connect_to_service(IPC_GET_ARG1(call), &call,
00103                                     callid);
00104                                 continue;
00105                         }
00106                         break;
00107                 case NS_PING:
00108                         retval = EOK;
00109                         break;
00110                 case NS_TASK_WAIT:
00111                         id = (task_id_t)
00112                             MERGE_LOUP32(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
00113                         wait_for_task(id, &call, callid);
00114                         continue;
00115                 case NS_ID_INTRO:
00116                         retval = ns_task_id_intro(&call);
00117                         break;
00118                 case NS_RETVAL:
00119                         retval = ns_task_retval(&call);
00120                         break;
00121                 default:
00122                         retval = ENOENT;
00123                         break;
00124                 }
00125                 
00126                 if (!(callid & IPC_CALLID_NOTIFICATION))
00127                         ipc_answer_0(callid, retval);
00128         }
00129         
00130         /* Not reached */
00131         return 0;
00132 }
00133 

Generated on Thu Jun 2 07:45:46 2011 for HelenOS/USB by  doxygen 1.4.7