MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / srd_init

Function srd_init

libsigrokdecode4DSL/srd.c:188–268  ·  view source on GitHub ↗

* Initialize libsigrokdecode. * * This initializes the Python interpreter, and creates and initializes * a "sigrokdecode" Python module. * * Then, it searches for sigrok protocol decoders in the "decoders" * subdirectory of the the libsigrokdecode installation directory. * All decoders that are found are loaded into memory and added to an * internal list of decoders, which can be queried v

Source from the content-addressed store, hash-verified

186 * @since 0.1.0
187 */
188SRD_API int srd_init(const char *path)
189{
190 const char *const *sys_datadirs;
191 size_t i;
192 int ret;
193 const char *env_path;
194
195 srd_log_init(); //init log
196
197 if (max_session_id != -1) {
198 srd_err("libsigrokdecode is already initialized.");
199 return SRD_ERR;
200 }
201
202 srd_dbg("Initializing libsigrokdecode.");
203
204 /* Add our own module to the list of built-in modules. */
205 PyImport_AppendInittab("sigrokdecode", PyInit_sigrokdecode);
206
207 /* Initialize the Python interpreter. */
208 Py_InitializeEx(0);
209
210#ifdef DECODERS_DIR
211 /* Hardcoded decoders install location, if defined. */
212 if ((ret = srd_decoder_searchpath_add(DECODERS_DIR)) != SRD_OK) {
213 Py_Finalize();
214 return ret;
215 }
216#endif
217
218 /* Path specified by the user. */
219 if (path) {
220 if ((ret = srd_decoder_searchpath_add(path)) != SRD_OK) {
221 Py_Finalize();
222 return ret;
223 }
224 }
225 else{
226 /* Locations relative to the XDG system data directories. */
227 sys_datadirs = g_get_system_data_dirs();
228 for (i = g_strv_length((char **)sys_datadirs); i > 0; i--)
229 {
230 ret = searchpath_add_xdg_dir(sys_datadirs[i - 1]);
231 if (ret != SRD_OK)
232 {
233 Py_Finalize();
234 return ret;
235 }
236 }
237
238 /* Location relative to the XDG user data directory. */
239 ret = searchpath_add_xdg_dir(g_get_user_data_dir());
240 if (ret != SRD_OK)
241 {
242 Py_Finalize();
243 return ret;
244 }
245

Callers 1

InitMethod · 0.85

Calls 4

srd_log_initFunction · 0.85
searchpath_add_xdg_dirFunction · 0.85
print_searchpathsFunction · 0.85

Tested by

no test coverage detected