source: mainline/uspace/lib/c/generic/task_event.c@ e7faeba

Last change on this file since e7faeba was 338a1a76, checked in by Matthieu Riolo <matthieu.riolo@…>, 5 years ago

Correcting sysman registering a port

  • Correcting port handler - the new API does not need to accept the call
  • Allowing multiple registration of event handler
  • removing global variable holding the handler
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2015 Michal Koutny
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <errno.h>
36#include <ipc/taskman.h>
37#include <macros.h>
38#include <task.h>
39#include <assert.h>
40
41#include "private/taskman.h"
42
43static void taskman_task_event(ipc_call_t *icall, task_event_handler_t handler)
44{
45 task_id_t tid = (task_id_t)
46 MERGE_LOUP32(ipc_get_arg1(icall), ipc_get_arg2(icall));
47 int flags = ipc_get_arg3(icall);
48 task_exit_t texit = ipc_get_arg4(icall);
49 int retval = ipc_get_arg5(icall);
50
51 handler(tid, flags, texit, retval);
52
53 async_answer_0(icall, EOK);
54}
55
56static void taskman_event_conn(ipc_call_t *icall, void *arg)
57{
58 while (true) {
59 ipc_call_t call;
60
61 if (!async_get_call(&call) || !ipc_get_imethod(&call)) {
62 /* Hangup, end of game */
63 async_answer_0(&call, EOK);
64 return;
65 }
66
67 switch (ipc_get_imethod(&call)) {
68 case TASKMAN_EV_TASK:
69 taskman_task_event(&call, (task_event_handler_t)arg);
70 break;
71 default:
72 async_answer_0(&call, ENOTSUP);
73 break;
74 }
75 }
76}
77
78/**
79 * Blocks, calls handler in another fibril
80 */
81errno_t task_register_event_handler(task_event_handler_t handler, bool past_events)
82{
83 assert(handler != NULL); /* no support for "unregistration" */
84
85 async_exch_t *exch = taskman_exchange_begin();
86 aid_t req = async_send_1(exch, TASKMAN_EVENT_CALLBACK, past_events, NULL);
87
88 port_id_t port;
89 errno_t rc = async_create_callback_port(exch, INTERFACE_TASKMAN_CB, 0, 0,
90 taskman_event_conn, handler, &port);
91 taskman_exchange_end(exch);
92
93 if (rc != EOK) {
94 return rc;
95 }
96
97 errno_t retval;
98 async_wait_for(req, &retval);
99 return retval;
100}
101
102/** @}
103 */
Note: See TracBrowser for help on using the repository browser.