NUGU SDK Linux  1.7.6
nugu_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 SK Telecom Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __NUGU_PLUGIN_H__
18 #define __NUGU_PLUGIN_H__
19 
20 #include <nugu.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
43 #define NUGU_PLUGIN_PRIORITY_HIGH 10
44 
48 #define NUGU_PLUGIN_PRIORITY_DEFAULT 100
49 
53 #define NUGU_PLUGIN_PRIORITY_LOW 900
54 
58 #define NUGU_PLUGIN_SYMBOL "nugu_plugin_define_desc"
59 
63 #ifdef NUGU_PLUGIN_BUILTIN
64 #define NUGU_PLUGIN_DEFINE(p_name, p_prio, p_ver, p_load, p_unload, p_init) \
65  NUGU_API_EXPORT struct nugu_plugin_desc _builtin_plugin_##p_name = { \
66  .name = #p_name, \
67  .priority = p_prio, \
68  .version = p_ver, \
69  .load = p_load, \
70  .unload = p_unload, \
71  .init = p_init \
72  }
73 #else
74 #define NUGU_PLUGIN_DEFINE(p_name, p_prio, p_ver, p_load, p_unload, p_init) \
75  NUGU_API_EXPORT struct nugu_plugin_desc nugu_plugin_define_desc = { \
76  .name = #p_name, \
77  .priority = p_prio, \
78  .version = p_ver, \
79  .load = p_load, \
80  .unload = p_unload, \
81  .init = p_init \
82  }
83 #endif
84 
88 typedef struct _plugin NuguPlugin;
89 
97  const char *name;
98 
102  unsigned int priority;
103 
107  const char *version;
108 
112  int (*load)(void);
113 
117  void (*unload)(NuguPlugin *p);
118 
123  int (*init)(NuguPlugin *p);
124 };
125 
134 
142 NUGU_API NuguPlugin *nugu_plugin_new_from_file(const char *filepath);
143 
148 NUGU_API void nugu_plugin_free(NuguPlugin *p);
149 
160 NUGU_API int nugu_plugin_add(NuguPlugin *p);
161 
172 
180 NUGU_API NuguPlugin *nugu_plugin_find(const char *name);
181 
191 NUGU_API int nugu_plugin_set_data(NuguPlugin *p, void *data);
192 
199 NUGU_API void *nugu_plugin_get_data(NuguPlugin *p);
200 
207 NUGU_API void *nugu_plugin_get_symbol(NuguPlugin *p, const char *symbol_name);
208 
214 NUGU_API const struct nugu_plugin_desc *
216 
223 NUGU_API int nugu_plugin_load_directory(const char *dirpath);
224 
230 NUGU_API int nugu_plugin_load_builtin(void);
231 
236 NUGU_API int nugu_plugin_initialize(void);
237 
241 NUGU_API void nugu_plugin_deinitialize(void);
242 
247 #ifdef __cplusplus
248 }
249 #endif
250 
251 #endif
NUGU_API const struct nugu_plugin_desc * nugu_plugin_get_description(NuguPlugin *p)
Get the plugin description.
NUGU_API int nugu_plugin_initialize(void)
Initialize plugin.
NUGU_API void nugu_plugin_deinitialize(void)
De-initialize plugin.
NUGU_API int nugu_plugin_load_builtin(void)
Load all built-in plugins.
NUGU_API void * nugu_plugin_get_data(NuguPlugin *p)
Get private data from plugin.
NUGU_API int nugu_plugin_add(NuguPlugin *p)
Add the plugin to managed list.
NUGU_API void * nugu_plugin_get_symbol(NuguPlugin *p, const char *symbol_name)
Get dlsym result from plugin.
struct _plugin NuguPlugin
Plugin object.
Definition: nugu_plugin.h:88
NUGU_API NuguPlugin * nugu_plugin_find(const char *name)
Find a plugin by name in the managed list.
NUGU_API NuguPlugin * nugu_plugin_new_from_file(const char *filepath)
Create new plugin object from file.
NUGU_API NuguPlugin * nugu_plugin_new(struct nugu_plugin_desc *desc)
Create new plugin object.
NUGU_API int nugu_plugin_set_data(NuguPlugin *p, void *data)
Set private data to plugin.
NUGU_API int nugu_plugin_load_directory(const char *dirpath)
Load all plugin files from directory.
NUGU_API int nugu_plugin_remove(NuguPlugin *p)
Remove the plugin to managed list.
NUGU_API void nugu_plugin_free(NuguPlugin *p)
Destroy the plugin.
Plugin description.
Definition: nugu_plugin.h:93
const char * name
Name of plugin.
Definition: nugu_plugin.h:97
int(* init)(NuguPlugin *p)
Function called by priority after all plugins have finished loading.
Definition: nugu_plugin.h:123
unsigned int priority
Priority used in the init call order.
Definition: nugu_plugin.h:102
const char * version
Version of plugin.
Definition: nugu_plugin.h:107
void(* unload)(NuguPlugin *p)
Function to be called after unloading.
Definition: nugu_plugin.h:117
int(* load)(void)
Function to be called after loading.
Definition: nugu_plugin.h:112