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  * @brief State Machine (SM) ID's
43  */
44 enum {
49 };
50 
51 #define OCS_SM_EVENT_SHIFT 24
52 #define OCS_SM_EVENT_START(id) ((id) << OCS_SM_EVENT_SHIFT)
53 
54 extern const char *ocs_sm_id[]; /** string format of above enums */
55 
56 /**
57  * @brief State Machine Events
58  */
59 typedef enum {
60  /* Common Events */
66 
67  /* Domain Events */
71 
72  /* Connection Events */
84 
85  /* SCSI Target Server events */
98 
99  /* Must be last */
102 
103 /* Declare ocs_sm_ctx_s */
104 typedef struct ocs_sm_ctx_s ocs_sm_ctx_t;
105 
106 /* State machine state function */
107 typedef void *(*ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
108 
109 /**
110  * @brief State machine context header.
111  */
112 struct ocs_sm_ctx_s {
114  const char *description;
115  void *app; /** Application specific handle */
116 };
117 
118 extern int ocs_sm_post_event(ocs_sm_ctx_t *, ocs_sm_event_t, void *);
119 extern void ocs_sm_transition(ocs_sm_ctx_t *, ocs_sm_function_t, void *);
120 extern void ocs_sm_disable(ocs_sm_ctx_t *ctx);
121 extern const char *ocs_sm_event_name(ocs_sm_event_t evt);
122 #if 0
123 #define smtrace(sm) ocs_log_debug(NULL, "%s: %-20s --> %s\n", sm, ocs_sm_event_name(evt), __func__)
124 #else
125 #define smtrace(...)
126 #endif
127 
128 #endif /* ! _OCS_SM_H */
void * app
Definition: ocs_sm.h:115
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:93
void *(* ocs_sm_function_t)(ocs_sm_ctx_t *, ocs_sm_event_t, void *)
Definition: ocs_sm.h:107
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:73
State machine context header.
Definition: ocs_sm.h:112
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:59
#define OCS_SM_EVENT_START(id)
Definition: ocs_sm.h:52
ocs_sm_function_t current_state
Definition: ocs_sm.h:113
const char * description
Definition: ocs_sm.h:114
ocs_sm_event_t
State Machine Events.
Definition: ocs_sm.h:59
void ocs_sm_disable(ocs_sm_ctx_t *ctx)
Disable further state machine processing.
Definition: ocs_sm.c:88