* @brief load a dynamic module, and create a thread to excute the module main function. * * @param pgname path of the module to be loaded. * @param cmd the command string (with commandline options) for startup module. * @param cmd_size the command's length. * @return struct rt_dlmodule* On success, it returns a pointer to the module object. otherwise, RT_NULL is returned. */
| 564 | * @return struct rt_dlmodule* On success, it returns a pointer to the module object. otherwise, RT_NULL is returned. |
| 565 | */ |
| 566 | struct rt_dlmodule* dlmodule_exec(const char* pgname, const char* cmd, int cmd_size) |
| 567 | { |
| 568 | struct rt_dlmodule *module = RT_NULL; |
| 569 | |
| 570 | module = dlmodule_load(pgname); |
| 571 | if (module) |
| 572 | { |
| 573 | if (module->entry_addr) |
| 574 | { |
| 575 | /* exec this module */ |
| 576 | rt_thread_t tid; |
| 577 | |
| 578 | module->cmd_line = rt_strdup(cmd); |
| 579 | |
| 580 | /* check stack size and priority */ |
| 581 | if (module->priority > RT_THREAD_PRIORITY_MAX) module->priority = RT_THREAD_PRIORITY_MAX - 1; |
| 582 | if (module->stack_size < 2048 || module->stack_size > (1024 * 32)) module->stack_size = 2048; |
| 583 | |
| 584 | tid = rt_thread_create(module->parent.name, _dlmodule_thread_entry, (void*)module, |
| 585 | module->stack_size, module->priority, 10); |
| 586 | if (tid) |
| 587 | { |
| 588 | tid->parent.module_id= module; |
| 589 | module->main_thread = tid; |
| 590 | |
| 591 | rt_thread_startup(tid); |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | /* destory dl module */ |
| 596 | dlmodule_destroy(module); |
| 597 | module = RT_NULL; |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return module; |
| 603 | } |
| 604 | |
| 605 | #if defined(RT_USING_CUSTOM_DLMODULE) |
| 606 | struct rt_dlmodule* dlmodule_load_custom(const char* filename, struct rt_dlmodule_ops* ops) |
no test coverage detected