summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
inline | side by side (from parent 1:
76672e2)
Let sigrokdecode_init() always load all decoders it can find in the
decoders directory, i.e., the user doesn't need to manually load decoders.
Instead he can just look up the list via sigrokdecode_list_decoders()
after sigrokdecode_init() has run.
This is not a problem, as sigrokdecode_init() is only run once per
sigrok-cli or sigrok-gui invocation, and even with many decoders this
should not take too long.
The list of decoders within libsigrokdecode is no longer a string, but
rather a list of 'struct sigrokdecode_decoder *' pointers.
Add sigrokdecode_get_decoder_by_id() API function which returns the
decoder with the specified ID (file name without ".py" suffix, for now),
or NULL if it cannot be found.
sigrokdecode_load_decoder() is now a private function and not exported
via the lib, i.e. not available to users of libsigrokdecode.
* Py_XDECREF()ing it (someone else will do it for you at some point).
*/
* Py_XDECREF()ing it (someone else will do it for you at some point).
*/
+static int sigrokdecode_load_decoder(const char *name,
+ struct sigrokdecode_decoder **dec);
+
/**
* Initialize libsigrokdecode.
*
/**
* Initialize libsigrokdecode.
*
{
DIR *dir;
struct dirent *dp;
{
DIR *dir;
struct dirent *dp;
+ char *decodername;
+ struct sigrokdecode_decoder *dec;
+ int ret;
/* Py_Initialize() returns void and usually cannot fail. */
Py_Initialize();
/* Py_Initialize() returns void and usually cannot fail. */
Py_Initialize();
while ((dp = readdir(dir)) != NULL) {
if (!g_str_has_suffix(dp->d_name, ".py"))
continue;
while ((dp = readdir(dir)) != NULL) {
if (!g_str_has_suffix(dp->d_name, ".py"))
continue;
- /* For now use the filename (without .py) as decoder name. */
- if ((tmp = g_strndup(dp->d_name, strlen(dp->d_name) - 3)))
- list_pds = g_slist_append(list_pds, tmp);
+
+ /* Decoder name == filename (without .py suffix). */
+ decodername = g_strndup(dp->d_name, strlen(dp->d_name) - 3);
+
+ /* TODO: Error handling. */
+ dec = malloc(sizeof(struct sigrokdecode_decoder));
+
+ /* Load the decoder. */
+ ret = sigrokdecode_load_decoder(decodername, &dec);
+
+ /* Append it to the list of supported/loaded decoders. */
+ list_pds = g_slist_append(list_pds, dec);
+/**
+ * Get the decoder with the specified ID.
+ *
+ * @param id The ID string of the decoder to return.
+ * @return The decoder with the specified ID, or NULL if not found.
+ */
+struct sigrokdecode_decoder *sigrokdecode_get_decoder_by_id(const char *id)
+{
+ GSList *l;
+ struct sigrokdecode_decoder *dec;
+
+ for (l = sigrokdecode_list_decoders(); l; l = l->next) {
+ dec = l->data;
+ if (!strcmp(dec->id, id))
+ return dec;
+ }
+
+ return NULL;
+}
+
/**
* Helper function to handle Python strings.
*
/**
* Helper function to handle Python strings.
*
*
* @return SIGROKDECODE_OK upon success, a (negative) error code otherwise.
*/
*
* @return SIGROKDECODE_OK upon success, a (negative) error code otherwise.
*/
-int sigrokdecode_load_decoder(const char *name,
+static int sigrokdecode_load_decoder(const char *name,
struct sigrokdecode_decoder **dec)
{
struct sigrokdecode_decoder *d;
struct sigrokdecode_decoder **dec)
{
struct sigrokdecode_decoder *d;
int sigrokdecode_init(void);
GSList *sigrokdecode_list_decoders(void);
int sigrokdecode_init(void);
GSList *sigrokdecode_list_decoders(void);
-int sigrokdecode_load_decoder(const char *name, struct sigrokdecode_decoder **dec);
+struct sigrokdecode_decoder *sigrokdecode_get_decoder_by_id(const char *id);
int sigrokdecode_run_decoder(struct sigrokdecode_decoder *dec,
uint8_t *inbuf, uint64_t inbuflen,
uint8_t **outbuf, uint64_t *outbuflen);
int sigrokdecode_run_decoder(struct sigrokdecode_decoder *dec,
uint8_t *inbuf, uint64_t inbuflen,
uint8_t **outbuf, uint64_t *outbuflen);