Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_sm.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
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 are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * Generic state machine framework declarations.
36  */
37 
38 #ifndef _OCS_SM_H
39 #define _OCS_SM_H
40 
41 /**
42  * State Machine (SM) IDs.
43  */
44 enum {
50 };
51 
52 #define OCS_SM_EVENT_SHIFT 24
53 #define OCS_SM_EVENT_START(id) ((id) << OCS_SM_EVENT_SHIFT)
54 
55 extern const char *ocs_sm_id[]; /**< String format of the above enums. */
56 
57 /**
58  * State Machine events.
59  */
60 typedef enum {
61  /* Common Events */
69 
70  /* Domain Events */
73 
85 
86  /* Sport Events */
100 
101  /* Login Events */
114  OCS_EVT_ABORT_ELS, /**< request an ELS IO be aborted */
115  OCS_EVT_ELS_ABORT_CMPL, /**< ELS abort process complete */
116 
118 
119  OCS_EVT_NODE_MISSING, /**< node is not in the GID_PT payload */
120  OCS_EVT_NODE_REFOUND, /**< node is allocated and in the GID_PT payload */
121  OCS_EVT_SHUTDOWN_IMPLICIT_LOGO, /**< node shutting down due to PLOGI recvd (implicit logo) */
122  OCS_EVT_SHUTDOWN_EXPLICIT_LOGO, /**< node shutting down due to LOGO recvd/sent (explicit logo) */
123 
136 
138 
139  /* Used by fabric emulation */
156 
158 
159  /* SCSI Target Server events */
175 
176  /* Loopback events */
179 
180  /* Must be last */
183 
184 /* Declare ocs_sm_ctx_s */
185 typedef struct ocs_sm_ctx_s ocs_sm_ctx_t;
186 
187 /* State machine state function */
188 typedef void *(*ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
189 
190 /* State machine context header */
191 struct ocs_sm_ctx_s {
193  const char *description;
194  void *app; /** Application-specific handle. */
195 };
196 
197 extern int ocs_sm_post_event(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
198 extern void ocs_sm_transition(ocs_sm_ctx_t *, ocs_sm_function_t, void *);
199 extern void ocs_sm_disable(ocs_sm_ctx_t *ctx);
200 extern const char *ocs_sm_event_name(ocs_sm_event_t evt);
201 
202 #if 0
203 #define smtrace(sm) ocs_log_debug(NULL, "%s: %-20s --> %s\n", sm, ocs_sm_event_name(evt), __func__)
204 #else
205 #define smtrace(...)
206 #endif
207 
208 #endif /* ! _OCS_SM_H */
void * app
Definition: ocs_sm.h:194
const char * ocs_sm_id[]
Definition: ocs_sm.c:41
const char * ocs_sm_event_name(ocs_sm_event_t evt)
Definition: ocs_sm.c:92
void *(* ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *)
Definition: ocs_sm.h:188
void ocs_sm_transition(ocs_sm_ctx_t *ctx, ocs_sm_function_t state, void *data)
Transition to a new state.
Definition: ocs_sm.c:72
int ocs_sm_post_event(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *data)
Post an event to a context.
Definition: ocs_sm.c:58
#define OCS_SM_EVENT_START(id)
Definition: ocs_sm.h:53
ocs_sm_function_t current_state
Definition: ocs_sm.h:192
const char * description
Definition: ocs_sm.h:193
ocs_sm_event_t
Definition: ocs_sm.h:60
void ocs_sm_disable(ocs_sm_ctx_t *ctx)
Disable further state machine processing.
Definition: ocs_sm.c:87