remote_hw_res.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Lenka Trochtova
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 
00035 #include <async.h>
00036 #include <errno.h>
00037 
00038 #include "ops/hw_res.h"
00039 #include "ddf/driver.h"
00040 
00041 static void remote_hw_res_get_resource_list(ddf_fun_t *, void *, ipc_callid_t,
00042     ipc_call_t *);
00043 static void remote_hw_res_enable_interrupt(ddf_fun_t *, void *, ipc_callid_t,
00044     ipc_call_t *);
00045 
00046 static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
00047         &remote_hw_res_get_resource_list,
00048         &remote_hw_res_enable_interrupt
00049 };
00050 
00051 remote_iface_t remote_hw_res_iface = {
00052         .method_count = sizeof(remote_hw_res_iface_ops) /
00053             sizeof(remote_iface_func_ptr_t),
00054         .methods = remote_hw_res_iface_ops
00055 };
00056 
00057 static void remote_hw_res_enable_interrupt(ddf_fun_t *fun, void *ops,
00058     ipc_callid_t callid, ipc_call_t *call)
00059 {
00060         hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
00061         
00062         if (hw_res_ops->enable_interrupt == NULL)
00063                 async_answer_0(callid, ENOTSUP);
00064         else if (hw_res_ops->enable_interrupt(fun))
00065                 async_answer_0(callid, EOK);
00066         else
00067                 async_answer_0(callid, EREFUSED);
00068 }
00069 
00070 static void remote_hw_res_get_resource_list(ddf_fun_t *fun, void *ops,
00071     ipc_callid_t callid, ipc_call_t *call)
00072 {
00073         hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
00074 
00075         if (hw_res_ops->get_resource_list == NULL) {
00076                 async_answer_0(callid, ENOTSUP);
00077                 return;
00078         }
00079         
00080         hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(fun);
00081         if (hw_resources == NULL){
00082                 async_answer_0(callid, ENOENT);
00083                 return;
00084         }
00085         
00086         async_answer_1(callid, EOK, hw_resources->count);
00087 
00088         size_t len;
00089         if (!async_data_read_receive(&callid, &len)) {
00090                 /* Protocol error - the recipient is not accepting data */
00091                 return;
00092         }
00093         async_data_read_finalize(callid, hw_resources->resources, len);
00094 }
00095 

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