Adding console I/O via the `SHELL`. Demonstration of [http_tcp_demo.c](https://git.kolibrios.org/KolibriOS/kolibrios/src/branch/main/programs/develop/ktcc/libc.obj/samples/http_tcp_demo.c): <video src="attachments/847d7d19-3d67-480d-80c8-6d678af61a43" title="Запись экрана от 2026-03-07 13-55-50.mp4" controls></video> - [x] output - [x] multithread - [x] add mutex - [x] multithread tests Reviewed-on: #354 Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com> Reviewed-by: Kiril Lipatov <lipatov.kiril@gmail.com> Co-authored-by: Egor00f <y.yarin@inbox.ru>
68 lines
1.4 KiB
C
68 lines
1.4 KiB
C
#include <sys/ksys.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <shell_api.h>
|
|
|
|
char app_name[13];
|
|
char __shell_shm_name[32];
|
|
char *__shell_shm = NULL;
|
|
enum __SHELL_INIT_STATE __shell_is_init = __SHELL_NOT_LOADED;
|
|
|
|
int __shell_shm_init()
|
|
{
|
|
__shell_is_init = __SHELL_LOADING;
|
|
ksys_thread_t proc_info;
|
|
unsigned PID;
|
|
|
|
_ksys_thread_info(&proc_info, -1);
|
|
PID = proc_info.pid;
|
|
strncpy(app_name, (&proc_info)->name, 12);
|
|
|
|
itoa(PID, __shell_shm_name);
|
|
strcat(__shell_shm_name, "-SHELL");
|
|
|
|
return _ksys_shm_open(__shell_shm_name, KSYS_SHM_OPEN_ALWAYS | KSYS_SHM_WRITE, SHELL_SHM_MAX, &__shell_shm);
|
|
}
|
|
|
|
void __shell_init()
|
|
{
|
|
switch (__shell_is_init)
|
|
{
|
|
case __SHELL_NOT_LOADED:
|
|
if (__shell_shm_init())
|
|
{
|
|
debug_printf("%s: shell problems detected!\n", app_name);
|
|
goto __shell_init_err;
|
|
}
|
|
|
|
if (!shell_ping())
|
|
{
|
|
goto __shell_init_err;
|
|
}
|
|
|
|
__shell_is_init = __SHELL_INIT_OK; // The shell is being pinged, so it's working.
|
|
break;
|
|
case __SHELL_LOADING:
|
|
while (__shell_is_init == __SHELL_LOADING)
|
|
{
|
|
_ksys_thread_yield();
|
|
}
|
|
case __SHELL_INIT_OK:
|
|
if (!shell_ping())
|
|
{
|
|
goto __shell_init_err;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return;
|
|
|
|
__shell_init_err:
|
|
__shell_is_init = __SHELL_INIT_FAILED;
|
|
shell_exit();
|
|
return;
|
|
}
|