00001 /* 00002 * Copyright (c) 2011 Martin Decky 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 <bool.h> 00039 #include <errno.h> 00040 #include <nil_skel.h> 00041 #include <net_interface.h> 00042 #include <net/modules.h> 00043 00050 static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall) 00051 { 00052 /* 00053 * Accept the connection by answering 00054 * the initial IPC_M_CONNECT_ME_TO call. 00055 */ 00056 async_answer_0(iid, EOK); 00057 00058 while (true) { 00059 ipc_call_t answer; 00060 size_t count; 00061 00062 /* Clear the answer structure */ 00063 refresh_answer(&answer, &count); 00064 00065 /* Fetch the next message */ 00066 ipc_call_t call; 00067 ipc_callid_t callid = async_get_call(&call); 00068 00069 /* Process the message */ 00070 int res = nil_module_message(callid, &call, &answer, 00071 &count); 00072 00073 /* 00074 * End if told to either by the message or the processing 00075 * result. 00076 */ 00077 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) || 00078 (res == EHANGUP)) 00079 return; 00080 00081 /* Answer the message */ 00082 answer_call(callid, res, &answer, count); 00083 } 00084 } 00085 00102 int nil_module_start(int service) 00103 { 00104 async_set_client_connection(nil_client_connection); 00105 int net_phone = net_connect_module(); 00106 if (net_phone < 0) 00107 return net_phone; 00108 00109 int rc = pm_init(); 00110 if (rc != EOK) 00111 return rc; 00112 00113 rc = nil_initialize(net_phone); 00114 if (rc != EOK) 00115 goto out; 00116 00117 rc = async_connect_to_me(PHONE_NS, service, 0, 0, NULL); 00118 if (rc != EOK) 00119 goto out; 00120 00121 async_manager(); 00122 00123 out: 00124 pm_destroy(); 00125 return rc; 00126 } 00127