1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#include <stdio.h> 14#include <stdbool.h> 15#include <refos/share.h> 16#include <refos-rpc/proc_client.h> 17#include <refos-rpc/proc_common.h> 18#include "dispatch.h" 19#include "../state.h" 20#include "../badge.h" 21 22/*! @file 23 @brief Client watch dispatcher module. */ 24 25/*! @brief Handles client death notifications. 26 @param notification Structure containing the notification message, read from the notification 27 ring buffer. 28 @return DISPATCH_SUCCESS if success, DISPATCHER_ERROR otherwise. 29*/ 30static int 31handle_timeserver_death_notification(struct proc_notification *notification) 32{ 33 dprintf(COLOUR_B "## Timer server Handling death notification...\n" COLOUR_RESET); 34 dprintf(" Label: PROCSERV_NOTIFY_DEATH\n"); 35 dprintf(" deathID: %d\n", notification->arg[0]); 36 37 /* Find the client and queue it for deletion. */ 38 int error = client_queue_delete_deathID(&timeServCommon->clientTable, notification->arg[0]); 39 40 if (error) { 41 ROS_ERROR("Unknown deathID. timer server book-keeping error."); 42 assert(!"timer server book-keeping bug."); 43 return DISPATCH_ERROR; 44 } 45 return DISPATCH_SUCCESS; 46} 47 48int dispatch_client_watch(srv_msg_t *m) 49{ 50 if ((m->badge & TIMESERV_ASYNC_BADGE_MASK) == 0) { 51 return DISPATCH_PASS; 52 } 53 if ((m->badge & TIMESERV_ASYNC_NOTIFY_BADGE) == 0) { 54 return DISPATCH_PASS; 55 } 56 57 srv_common_notify_handler_callbacks_t cb = { 58 .handle_server_fault = NULL, 59 .handle_server_content_init = NULL, 60 .handle_server_death_notification = handle_timeserver_death_notification 61 }; 62 63 return srv_dispatch_notification(timeServCommon, cb); 64} 65