UiConnection * ui_connection_new(const gchar *hostname, int internal_port, int external_port) { UiConnection *self = g_new(UiConnection, 1); self->connection = NULL; self->main_network = NULL; self->network_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)network_free); self->hostname = g_strdup(hostname); self->registry = registry_new(runtime_info_new_from_env(hostname, external_port)); self->component_lib = library_new(); setup_log_handlers(self); self->server = soup_server_new(SOUP_SERVER_SERVER_HEADER, "imgflo-runtime", NULL); if (!self->server) { g_free(self); return NULL; } soup_server_add_handler(self->server, NULL, server_callback, self, NULL); soup_server_add_websocket_handler(self->server, NULL, NULL, NULL, websocket_callback, self, NULL); soup_server_listen_all(self->server, internal_port, SOUP_SERVER_LISTEN_IPV4_ONLY, NULL); return self; }
int main(char *argv[],int argc) { mc_init(); el_bool stop = el_false; hre_t re_load = hre_compile("^load(&play)?\\s+(.*)$","i"); hre_t re_play = hre_compile("^play$","i"); hre_t re_pause = hre_compile("^pause$","i"); hre_t re_next = hre_compile("^next$","i"); hre_t re_previous = hre_compile("^prev(ious)?$","i"); hre_t re_track = hre_compile("^track\\s+([0-9]+)$","i"); hre_t re_quhit = hre_compile("^quit$","i"); hre_t re_seek = hre_compile("^seek\\s([0-9]+([.][0-9]+)?)$","i"); hre_t re_quit = hre_compile("^quit$","i"); hre_t re_repeat = hre_compile("^repeat\\s+(off|list|track)$","i"); hre_t re_again = hre_compile("^again$","i"); hre_t re_scan = hre_compile("^scan\\s+(.*)$","i"); file_info_t *history_file = mc_take_over(file_info_new_home(".btb_playlist")); printf("history file: %s\n", file_info_absolute_path(history_file)); printf("history file: %s\n", file_info_path(history_file)); if (file_info_exists(history_file)) { read_history(file_info_absolute_path(history_file)); } i18n_set_language("nl"); printf(_("Starting btb_playlist\n")); playlist_player_t *player = playlist_player_new(); while (!stop) { char* line = readln(">", player); hre_trim(line); if (hre_has_match(re_quit, line)) { stop = el_true; } else if (hre_has_match(re_load, line)) { hre_matches m = hre_match(re_load, line); hre_match_t *mplay = hre_matches_get(m, 1); hre_match_t *match = hre_matches_get(m, 2); char* file = mc_strdup(hre_match_str(match)); char* play = mc_strdup(hre_match_str(mplay)); hre_matches_destroy(m); printf("loading '%s', '%s'\n", file, play); file_info_t *info = file_info_new(file); if (file_info_exists(info)) { if (file_info_is_file(info)) { if (file_info_can_read(info)) { const char *mediafile = NULL; track_array array; if (strcasecmp(file_info_ext(info),"cue") == 0) { array = tracks_from_cue(file_info_absolute_path(info)); track_t* t = track_array_get(array, 0); } else { array = tracks_from_media(file_info_absolute_path(info)); } playlist_t* pl = playlist_new("playlist"); int i; for(i=0; i < track_array_count(array); ++i) { playlist_append(pl, track_array_get(array, i)); } playlist_player_set_playlist(player, pl); track_array_destroy(array); } } } file_info_destroy(info); if (strcasecmp(play,"&play")==0) { playlist_player_play(player); } mc_free(file); mc_free(play); } else if (hre_has_match(re_play, line)) { playlist_player_play(player); } else if (hre_has_match(re_pause, line)) { playlist_player_pause(player); } else if (hre_has_match(re_seek, line)) { hre_matches m = hre_match(re_seek, line); hre_match_t* match = hre_matches_get(m, 1); char* position = mc_strdup(hre_match_str(match)); hre_matches_destroy(m); double s = atof(position); int ms = s * 1000; mc_free(position); playlist_player_seek(player, ms); } else if (hre_has_match(re_next, line)) { playlist_player_next(player); } else if (hre_has_match(re_previous, line)) { playlist_player_previous(player); } else if (hre_has_match(re_track, line)) { hre_matches m = hre_match(re_track, line); hre_match_t* match = hre_matches_get(m, 1); char* nr = mc_strdup(hre_match_str(match)); hre_matches_destroy(m); int index = atoi(nr); mc_free(nr); printf("setting track %d\n",index); playlist_player_set_track(player, index); } else if (hre_has_match(re_repeat, line)) { hre_matches m = hre_match(re_repeat, line); hre_match_t* match = hre_matches_get(m, 1); if (strcasecmp(hre_match_str(match),"track") == 0) { playlist_player_set_repeat(player, PLP_TRACK_REPEAT); } else if (strcasecmp(hre_match_str(match),"list") == 0) { playlist_player_set_repeat(player, PLP_LIST_REPEAT); } else { playlist_player_set_repeat(player, PLP_NO_REPEAT); } hre_matches_destroy(m); } else if (hre_has_match(re_again, line)) { playlist_player_again(player); } else if (hre_has_match(re_scan, line)) { hre_matches m = hre_match(re_scan, line); hre_match_t* match = hre_matches_get(m, 1); printf("scanning %s\n", hre_match_str(match)); library_t* library = library_new(); printf("calling scan_library\n"); //scan_library(library, hre_match_str(match), library_cb); printf("\n"); printf("library: %d tracks\n", library_count(library)); printf("done scanning, destroying library\n"); library_destroy(library); printf("library destroyed\n"); hre_matches_destroy(m); printf("matches destroyed\n"); } mc_free(line); } playlist_player_destroy(player); printf("%d\n",write_history(file_info_absolute_path(history_file))); file_info_destroy(history_file); hre_destroy(re_load); hre_destroy(re_play); hre_destroy(re_pause); hre_destroy(re_quit); hre_destroy(re_seek); hre_destroy(re_track); hre_destroy(re_next); hre_destroy(re_previous); hre_destroy(re_again); hre_destroy(re_repeat); hre_destroy(re_scan); return 0; }