1 /* 2 * libwebsockets - small server side websockets and web server implementation 3 * 4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com> 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 struct lws_state_notify_link; 26 struct lws_state_manager; 27 28 typedef int (*lws_state_notify_t)(struct lws_state_manager *mgr, 29 struct lws_state_notify_link *link, 30 int current, int target); 31 32 typedef struct lws_state_notify_link { 33 lws_dll2_t list; 34 lws_state_notify_t notify_cb; 35 const char *name; 36 } lws_state_notify_link_t; 37 38 typedef struct lws_state_manager { 39 lws_dll2_owner_t notify_list; 40 void *parent; 41 /**< optional opaque pointer to owning object... useful to make such 42 * a pointer available to a notification callback. Ignored by lws */ 43 const char **state_names; /* may be NULL */ 44 const char *name; 45 int state; 46 } lws_state_manager_t; 47 48 /** 49 * lws_state_reg_notifier() - add dep handler for state notifications 50 * 51 * \param context: the lws_context 52 * \param nl: the handler to add to the notifier linked-list 53 * 54 * Add \p notify_link to the context's list of notification handlers for system 55 * state changes. The handlers can defeat or take over responsibility for 56 * retrying the change after they have initiated some dependency. 57 */ 58 59 LWS_EXTERN LWS_VISIBLE void 60 lws_state_reg_notifier(lws_state_manager_t *mgr, lws_state_notify_link_t *nl); 61 62 /** 63 * lws_state_reg_deregister() - deregister a notifier 64 * 65 * \param nl: notification hardler to deregister 66 * 67 * Remove a notification handler from its state manager 68 */ 69 70 LWS_EXTERN LWS_VISIBLE void 71 lws_state_reg_deregister(lws_state_notify_link_t *nl); 72 73 /** 74 * lws_state_reg_notifier_list() - add dep handlers for state notifications 75 * 76 * \param context: the lws_context 77 * \param nl: list of notification handlers 78 * 79 * Add a NULL-terminated list of notification handler pointers to a notification 80 * manager object 81 */ 82 83 LWS_EXTERN LWS_VISIBLE void 84 lws_state_reg_notifier_list(lws_state_manager_t *mgr, 85 lws_state_notify_link_t * const *nl); 86 87 /** 88 * lws_state_transition_steps() - move to state via starting any deps 89 * 90 * \param mgr: the state manager object 91 * \param target: the state we wish to move to 92 * 93 * Advance state by state towards state \p target. At each state, notifiers 94 * may veto the change and be triggered to perform dependencies, stopping the 95 * advance towards the target state. 96 */ 97 LWS_EXTERN LWS_VISIBLE int 98 lws_state_transition_steps(lws_state_manager_t *mgr, int target); 99 100 /** 101 * lws_state_transition() - move to state via starting any deps 102 * 103 * \param mgr: the state manager object 104 * \param target: the state we wish to move to 105 * 106 * Jump to state target atomically. Notifiers may veto it. 107 */ 108 LWS_EXTERN LWS_VISIBLE int 109 lws_state_transition(lws_state_manager_t *mgr, int target); 110