4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef SPDK_INTERNAL_EVENT_H
35 #define SPDK_INTERNAL_EVENT_H
37 #include "spdk/stdinc.h"
39 #include "spdk/event.h"
40 #include "spdk/json.h"
41 #include "spdk/thread.h"
50 int spdk_reactors_init(void);
51 void spdk_reactors_fini(void);
53 void spdk_reactors_start(void);
54 void spdk_reactors_stop(void *arg1
);
56 struct spdk_subsystem
{
58 /* User must call spdk_subsystem_init_next() when they are done with their initialization. */
61 void (*config
)(FILE *fp
);
64 * Write JSON configuration handler.
66 * \param w JSON write context
68 void (*write_config_json
)(struct spdk_json_write_ctx
*w
);
69 TAILQ_ENTRY(spdk_subsystem
) tailq
;
72 TAILQ_HEAD(spdk_subsystem_list
, spdk_subsystem
);
73 extern struct spdk_subsystem_list g_subsystems
;
75 struct spdk_subsystem
*spdk_subsystem_find(struct spdk_subsystem_list
*list
, const char *name
);
77 struct spdk_subsystem_depend
{
79 const char *depends_on
;
80 TAILQ_ENTRY(spdk_subsystem_depend
) tailq
;
83 TAILQ_HEAD(spdk_subsystem_depend_list
, spdk_subsystem_depend
);
84 extern struct spdk_subsystem_depend_list g_subsystems_deps
;
86 void spdk_add_subsystem(struct spdk_subsystem
*subsystem
);
87 void spdk_add_subsystem_depend(struct spdk_subsystem_depend
*depend
);
89 void spdk_subsystem_init(spdk_msg_fn cb_fn
, void *cb_arg
);
90 void spdk_subsystem_fini(spdk_msg_fn cb_fn
, void *cb_arg
);
91 void spdk_subsystem_init_next(int rc
);
92 void spdk_subsystem_fini_next(void);
93 void spdk_subsystem_config(FILE *fp
);
96 * Save pointed \c subsystem configuration to the JSON write context \c w. In case of
97 * error \c null is written to the JSON context.
99 * \param w JSON write context
100 * \param subsystem the subsystem to query
102 void spdk_subsystem_config_json(struct spdk_json_write_ctx
*w
, struct spdk_subsystem
*subsystem
);
104 void spdk_rpc_initialize(const char *listen_addr
);
105 void spdk_rpc_finish(void);
108 * \brief Register a new subsystem
110 #define SPDK_SUBSYSTEM_REGISTER(_name) \
111 __attribute__((constructor)) static void _name ## _register(void) \
113 spdk_add_subsystem(&_name); \
117 * \brief Declare that a subsystem depends on another subsystem.
119 #define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on) \
120 static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \
122 .depends_on = #_depends_on, \
124 __attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \
126 spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \
129 #endif /* SPDK_INTERNAL_EVENT_H */