22 #include "libsigrokdecode-internal.h"
130 if (max_session_id != -1) {
131 srd_err(
"libsigrokdecode is already initialized.");
135 srd_dbg(
"Initializing libsigrokdecode.");
138 PyImport_AppendInittab(
"sigrokdecode", PyInit_sigrokdecode);
144 if ((ret = srd_decoder_searchpath_add(DECODERS_DIR)) !=
SRD_OK) {
151 if ((ret = srd_decoder_searchpath_add(path)) !=
SRD_OK) {
158 if ((env_path = getenv(
"SIGROKDECODE_DIR"))) {
159 if ((ret = srd_decoder_searchpath_add(env_path)) !=
SRD_OK) {
188 srd_dbg(
"Exiting libsigrokdecode.");
190 for (l = sessions; l; l = l->next)
194 g_slist_free_full(searchpaths, g_free);
224 SRD_PRIV int srd_decoder_searchpath_add(
const char *path)
226 PyObject *py_cur_path, *py_item;
229 wchar_t *wc_new_path;
232 srd_dbg(
"Adding '%s' to module path.", path);
234 new_path = g_string_sized_new(256);
235 g_string_assign(new_path, path);
236 py_cur_path = PySys_GetObject(
"path");
237 for (i = 0; i < PyList_Size(py_cur_path); i++) {
238 g_string_append(new_path, G_SEARCHPATH_SEPARATOR_S);
239 py_item = PyList_GetItem(py_cur_path, i);
240 if (!PyUnicode_Check(py_item))
243 if (py_str_as_str(py_item, &item) !=
SRD_OK)
245 g_string_append(new_path, item);
250 wc_len =
sizeof(wchar_t) * (new_path->len + 1);
251 if (!(wc_new_path = g_try_malloc(wc_len))) {
252 srd_dbg(
"malloc failed");
255 mbstowcs(wc_new_path, new_path->str, wc_len);
256 PySys_SetPath(wc_new_path);
257 g_string_free(new_path, TRUE);
259 searchpaths = g_slist_append(searchpaths, g_strdup(path));
int srd_session_destroy(struct srd_session *sess)
Destroy a decoding session.
int srd_exit(void)
Shutdown libsigrokdecode.
The public libsigrokdecode header file to be used by frontends.
int srd_decoder_unload_all(void)
Unload all loaded protocol decoders.
Generic/unspecified error.
Malloc/calloc/realloc error.
int srd_init(const char *path)
Initialize libsigrokdecode.