tl_skel.c

Go to the documentation of this file.
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 <tl_skel.h>
00041 #include <net_interface.h>
00042 #include <net/modules.h>
00043 
00050 static void tl_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         /* Per-connection initialization */
00059         tl_connection();
00060         
00061         while (true) {
00062                 ipc_call_t answer;
00063                 size_t count;
00064                 
00065                 /* Clear the answer structure */
00066                 refresh_answer(&answer, &count);
00067                 
00068                 /* Fetch the next message */
00069                 ipc_call_t call;
00070                 ipc_callid_t callid = async_get_call(&call);
00071                 
00072                 /* Process the message */
00073                 int res = tl_message(callid, &call, &answer, &count);
00074                 
00075                 /*
00076                  * End if told to either by the message or the processing
00077                  * result.
00078                  */
00079                 if ((IPC_GET_IMETHOD(call) == IPC_M_PHONE_HUNGUP) ||
00080                     (res == EHANGUP))
00081                         return;
00082                 
00083                 /* Answer the message */
00084                 answer_call(callid, res, &answer, count);
00085         }
00086 }
00087 
00104 int tl_module_start(int service)
00105 {
00106         async_set_client_connection(tl_client_connection);
00107         int net_phone = net_connect_module();
00108         if (net_phone < 0)
00109                 return net_phone;
00110         
00111         int rc = pm_init();
00112         if (rc != EOK)
00113                 return rc;
00114         
00115         rc = tl_initialize(net_phone);
00116         if (rc != EOK)
00117                 goto out;
00118         
00119         rc = async_connect_to_me(PHONE_NS, service, 0, 0, NULL);
00120         if (rc != EOK)
00121                 goto out;
00122         
00123         async_manager();
00124         
00125 out:
00126         pm_destroy();
00127         return rc;
00128 }
00129 

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