2 * Copyright (c) 2012, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of Intel Corporation nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __SRS_DAEMON_PLUGIN_H__
31 #define __SRS_DAEMON_PLUGIN_H__
33 #include "src/daemon/context.h"
35 #define SRS_PLUGIN_API_VERSION ((0 << 24) | (0 << 16) | 1)
37 /* Type definition for an SRS plugin. */
38 typedef struct srs_plugin_s srs_plugin_t;
39 typedef struct srs_plugin_api_s srs_plugin_api_t;
42 * SRS plugin API functions
44 typedef srs_plugin_api_t *(*srs_plugin_query_t)(const char **name,
45 const char **description,
50 struct srs_plugin_api_s {
51 /* perform basic plugin initialization, memory allocations, etc. */
52 int (*create)(srs_plugin_t *plugin);
53 /* perform plugin configuration, hook up with SRS infra */
54 int (*config)(srs_plugin_t *plugin, srs_cfg_t *settings);
55 /* perform remaining plugin startup steps if any */
56 int (*start)(srs_plugin_t *plugin);
57 /* initiate plugin shutdown sequence */
58 void (*stop)(srs_plugin_t *plugin);
59 /* perform final plugin cleanup, free memory, etc. */
60 void (*destroy)(srs_plugin_t *plugin);
63 /** Macro to declare a plugin. */
64 #define SRS_DESCRIBE_PLUGIN_FUNC "__srs_describe_plugin"
66 #define SRS_DECLARE_PLUGIN(_name, _descr, _authors, _version, ...) \
67 srs_plugin_api_t *__srs_describe_plugin(const char **name, \
68 const char **description, \
69 const char **authors, \
70 const char **version, \
73 static srs_plugin_api_t api = { __VA_ARGS__ }; \
76 *description = _descr; \
77 *authors = _authors; \
78 *version = _version; \
79 *srs_version = SRS_PLUGIN_API_VERSION; \
90 SRS_PLUGIN_UNKNOWN = 0,
91 SRS_PLUGIN_CREATED, /* plugin successfully created */
92 SRS_PLUGIN_CONFIGURED, /* plugin successfully configured */
93 SRS_PLUGIN_STARTED, /* plugin successfully started */
94 SRS_PLUGIN_STOPPED, /* plugin successfully stopped */
100 struct srs_plugin_s {
101 mrp_list_hook_t hook; /* hook to list of plugins */
102 srs_context_t *srs; /* SRS context */
103 char *name; /* plugin name */
104 const char *description; /* verbose plugin description */
105 const char *authors; /* plugin authors */
106 void *plugin_data; /* opaque plugin data */
107 srs_plugin_api_t *api; /* plugin API functions */
108 void *h; /* plugin (DSO) handle */
109 srs_plugin_state_t state; /* plugin state */
113 /** Create (ie. load and initialize) a plugin. */
114 srs_plugin_t *srs_create_plugin(srs_context_t *srs, const char *name);
116 /** Configure the given plugin plugin. */
117 int srs_configure_plugin(srs_plugin_t *plugin, srs_cfg_t *settings);
119 /** Start the given plugin. */
120 int srs_start_plugin(srs_plugin_t *plugin);
122 /** Stop the given plugin. */
123 void srs_stop_plugin(srs_plugin_t *plugin);
125 /** Destroy the given plugin. */
126 void srs_destroy_plugin(srs_plugin_t *plugin);
128 /** Configure all loaded plugins. */
129 int srs_configure_plugins(srs_context_t *srs);
131 /** Start all loaded plugins. */
132 int srs_start_plugins(srs_context_t *srs);
134 /** Stop all loaded plugins. */
135 void srs_stop_plugins(srs_context_t *srs);
137 /** Destroy all loaded plugins. */
138 void srs_destroy_plugins(srs_context_t *srs);
140 #endif /* __SRS_DAEMON_PLUGIN_H__ */