-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: extract RzCorePlugins from RzCmd to RzCore
- Loading branch information
Showing
12 changed files
with
83 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,48 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
/* covardly copied from rz_cmd */ | ||
|
||
#include <config.h> | ||
#include <rz_core.h> | ||
#include <rz_cmd.h> | ||
#include <rz_list.h> | ||
#include <stdio.h> | ||
|
||
static RzCorePlugin *cmd_static_plugins[] = { | ||
static RzCorePlugin *core_static_plugins[] = { | ||
RZ_CORE_STATIC_PLUGINS | ||
}; | ||
|
||
RZ_API int rz_core_plugin_fini(RzCmd *cmd) { | ||
RZ_API bool rz_core_plugin_fini(RzCore *core) { | ||
rz_return_val_if_fail(core->plugins, false); | ||
|
||
RzListIter *iter; | ||
RzCorePlugin *plugin; | ||
if (!cmd->plist) { | ||
return false; | ||
} | ||
rz_list_foreach (cmd->plist, iter, plugin) { | ||
if (plugin && plugin->fini) { | ||
plugin->fini(cmd, NULL); | ||
rz_list_foreach (core->plugins, iter, plugin) { | ||
if (plugin->fini) { | ||
plugin->fini(core); | ||
} | ||
} | ||
/* empty the list */ | ||
rz_list_free(cmd->plist); | ||
cmd->plist = NULL; | ||
rz_list_free(core->plugins); | ||
core->plugins = NULL; | ||
return true; | ||
} | ||
|
||
RZ_API int rz_core_plugin_add(RzCmd *cmd, RzCorePlugin *plugin) { | ||
if (!cmd || (plugin && plugin->init && !plugin->init(cmd, NULL))) { | ||
RZ_API bool rz_core_plugin_add(RzCore *core, RzCorePlugin *plugin) { | ||
rz_return_val_if_fail(core, false); | ||
rz_return_val_if_fail(plugin && plugin->init && plugin->name && plugin->author && plugin->license, false); | ||
if (!plugin->init(core)) { | ||
return false; | ||
} | ||
rz_list_append(cmd->plist, plugin); | ||
rz_list_append(core->plugins, plugin); | ||
return true; | ||
} | ||
|
||
RZ_API int rz_core_plugin_init(RzCmd *cmd) { | ||
RZ_API bool rz_core_plugin_init(RzCore *core) { | ||
int i; | ||
cmd->plist = rz_list_newf(NULL); // memleak or dblfree | ||
for (i = 0; cmd_static_plugins[i]; i++) { | ||
if (!rz_core_plugin_add(cmd, cmd_static_plugins[i])) { | ||
eprintf("Error loading cmd plugin\n"); | ||
core->plugins = rz_list_newf(NULL); // memleak or dblfree | ||
for (i = 0; core_static_plugins[i]; i++) { | ||
if (!rz_core_plugin_add(core, core_static_plugins[i])) { | ||
eprintf("Error loading core plugin\n"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
RZ_API int rz_core_plugin_check(RzCmd *cmd, const char *a0) { | ||
RzListIter *iter; | ||
RzCorePlugin *cp; | ||
rz_list_foreach (cmd->plist, iter, cp) { | ||
if (cp->call(NULL, a0)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.