Skip to content

Commit 579d38c

Browse files
author
roman
committed
plugins UPDATE merge type/ext plugin find funcs
1 parent c22a49b commit 579d38c

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

src/plugins.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ plugins_iter(const struct ly_ctx *ctx, enum LYPLG type, uint32_t *index)
205205
/**
206206
* @brief Find the give @p type plugin record.
207207
*
208-
* @param[in] ctx The context for which the plugin record is searched for, NULL for built-in plugins.
208+
* @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins.
209209
* @param[in] type Type of the plugin record to find.
210210
* @param[in] module Module name of the plugin record.
211211
* @param[in] revision Revision of the @p module.
@@ -242,20 +242,31 @@ lyplg_record_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module,
242242
return NULL;
243243
}
244244

245-
uintptr_t
246-
lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name)
245+
/**
246+
* @brief Find the plugin of the given @p type.
247+
*
248+
* @param[in] ctx Context for which the plugin record is searched for, NULL for built-in plugins.
249+
* @param[in] type Type of the plugin record to find.
250+
* @param[in] module Module name of the plugin.
251+
* @param[in] revision Revision of the @p module.
252+
* @param[in] name Name of the plugin.
253+
* @return Accessor to the callbacks plugin structure, use ::lysc_get_type_plugin()
254+
* or ::lysc_get_ext_plugin() on the returned value to get the actual plugin. 0 if not found.
255+
*/
256+
static uintptr_t
257+
lyplg_plugin_find(const struct ly_ctx *ctx, enum LYPLG type, const char *module, const char *revision, const char *name)
247258
{
248259
struct lyplg_type_record *record = NULL;
249260
uint32_t record_idx = 0;
250261

251262
if (ctx) {
252263
/* try to find context specific plugin */
253-
record = lyplg_record_find(ctx, LYPLG_TYPE, module, revision, name, &record_idx);
264+
record = lyplg_record_find(ctx, type, module, revision, name, &record_idx);
254265
}
255266

256267
if (!record) {
257268
/* try to find shared plugin */
258-
record = lyplg_record_find(NULL, LYPLG_TYPE, module, revision, name, &record_idx);
269+
record = lyplg_record_find(NULL, type, module, revision, name, &record_idx);
259270
}
260271

261272
if (!record) {
@@ -273,33 +284,15 @@ lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char
273284
}
274285

275286
uintptr_t
276-
lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name)
287+
lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name)
277288
{
278-
struct lyplg_ext_record *record = NULL;
279-
uint32_t record_idx = 0;
280-
281-
if (ctx) {
282-
/* try to find context specific plugin */
283-
record = lyplg_record_find(ctx, LYPLG_EXTENSION, module, revision, name, &record_idx);
284-
}
285-
286-
if (!record) {
287-
/* try to find shared plugin */
288-
record = lyplg_record_find(NULL, LYPLG_EXTENSION, module, revision, name, &record_idx);
289-
}
290-
291-
if (!record) {
292-
/* not found */
293-
return 0;
294-
}
289+
return lyplg_plugin_find(ctx, LYPLG_TYPE, module, revision, name);
290+
}
295291

296-
if (!strncmp(record->plugin.id, "ly2 - ", 6)) {
297-
/* internal plugin, return an index with an offset of +1 in order to keep 0 as an invalid index (a NULL ptr) */
298-
return record_idx + 1;
299-
} else {
300-
/* external plugin, return the pointer */
301-
return (uintptr_t)&record->plugin;
302-
}
292+
uintptr_t
293+
lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name)
294+
{
295+
return lyplg_plugin_find(ctx, LYPLG_EXTENSION, module, revision, name);
303296
}
304297

305298
/**

0 commit comments

Comments
 (0)