BitLab 0.1.0
BitLab: A Browser for the Bitcoin P2P Network and Blockchain
Loading...
Searching...
No Matches
bitlab.h File Reference

Go to the source code of this file.

Enumerations

enum  bitlab_result { BITLAB_RESULT_SUCCESS , BITLAB_RESULT_FAILURE }
 

Functions

bitlab_result run_bitlab (int argc, char *argv[])
 Run the BitLab program.
 

Enumeration Type Documentation

◆ bitlab_result

Enumerator
BITLAB_RESULT_SUCCESS 
BITLAB_RESULT_FAILURE 

Definition at line 4 of file bitlab.h.

5{
bitlab_result
Definition bitlab.h:5
@ BITLAB_RESULT_SUCCESS
Definition bitlab.h:6
@ BITLAB_RESULT_FAILURE
Definition bitlab.h:7

Function Documentation

◆ run_bitlab()

bitlab_result run_bitlab ( int  argc,
char *  argv[] 
)

Run the BitLab program.

Parameters
argcThe number of arguments.
argvThe arguments.
Returns
The result of the BitLab program.

Definition at line 13 of file bitlab.c.

14{
15 // init
21 pthread_t cli_thread = thread_runner(handle_cli, "CLI", NULL);
22 pthread_t peer_discovery_thread = thread_runner(handle_peer_discovery, "Peer discovery", NULL);
23
24 // execute command line arguments
25 if (argc > 1 && argv != NULL)
26 {
28 int total_length = 0;
29 for (int i = 1; i < argc; ++i)
30 total_length += strlen(argv[i]) + 1;
31
32 char* line = (char*)malloc(total_length * sizeof(char));
33 if (line == NULL)
34 log_message(LOG_ERROR, BITLAB_LOG, __FILE__, "Failed to allocate memory for command line arguments");
35 else
36 {
37 line[0] = '\0';
38 for (int i = 1; i < argc; ++i)
39 {
40 strcat(line, argv[i]);
41 if (i < argc - 1)
42 strcat(line, " ");
43 }
44
45 if (argv[1] && strcmp(argv[1], "exit") == 0)
46 log_message(LOG_WARN, BITLAB_LOG, __FILE__, "Starting BitLab with \"%s\" parameter", line);
47
48 cli_exec_line(line);
49 free(line);
50 }
51 guarded_print_line("Close BitLab using \"exit\"");
52 }
53
54 // main loop
55 while (!get_exit_flag(&state))
56 usleep(100000); // 100 ms
57
58 // cleanup
59 pthread_join(cli_thread, NULL);
60 pthread_join(peer_discovery_thread, NULL);
66}
void * handle_cli(void *arg)
CLI handler thread.
Definition cli.c:1278
int cli_exec_line(char *line)
Execute command.
Definition cli.c:1163
void finish_logging()
Finish logging used to finish logging and close the log file.
Definition log.c:199
void log_message(log_level level, const char *filename, const char *source_file, const char *format,...)
Log a message used to log a message to the console or a file.
Definition log.c:89
#define LOG_BITLAB_FINISHED
Definition log.h:13
#define LOG_BITLAB_STARTED
Definition log.h:12
void init_logging(const char *filename)
Initialize logging used to initialize the logging system, open and preserve the log file.
Definition log.c:34
#define BITLAB_LOG
Definition log.h:11
@ LOG_ERROR
Definition log.h:32
@ LOG_INFO
Definition log.h:30
@ LOG_WARN
Definition log.h:31
void * handle_peer_discovery(void *arg)
Peer discovery handler thread.
void destroy_program_state()
Destroy the program state.
Definition state.c:95
void destroy_program_operation()
Clear all program operations.
Definition state.c:247
program_state state
The program state used to store the state of the program.
Definition state.c:19
void mark_started_with_parameters()
Mark the program as started with parameters.
Definition state.c:88
int init_program_operation()
Initialize the program operation.
Definition state.c:100
program_operation operation
The program operation used to store all current operations of the program.
Definition state.c:40
sig_atomic_t get_exit_flag()
Get the exit flag.
Definition state.c:80
void init_program_state()
Initialize the program state.
Definition state.c:52
pthread_t thread_runner(void *(*start_routine)(void *), const char *name, void *arg)
Thread runner function.
Definition thread.c:9
void guarded_print_line(const char *format,...)
Guarded print line function.
Definition utils.c:65
void usleep(unsigned int usec)
int init_config_dir()
Initialize the configuration directory.
Definition utils.c:38

References BITLAB_LOG, BITLAB_RESULT_SUCCESS, cli_exec_line(), destroy_program_operation(), destroy_program_state(), finish_logging(), get_exit_flag(), guarded_print_line(), handle_cli(), handle_peer_discovery(), init_config_dir(), init_logging(), init_program_operation(), init_program_state(), LOG_BITLAB_FINISHED, LOG_BITLAB_STARTED, LOG_ERROR, LOG_INFO, log_message(), LOG_WARN, mark_started_with_parameters(), operation, state, thread_runner(), and usleep().

Referenced by main().