int main(int argc, char **argv) { int listen_fd; sp_session *session; static sp_session_config config; static sp_session_callbacks callbacks = { .logged_in = &sess_callback_logged_in, .logged_out = &sess_callback_logged_out, .metadata_updated = &sess_callback_metadata_updated, .connection_error = NULL, .message_to_user = &sess_callback_message_to_user, .notify_main_thread = &sess_callback_notify, .music_delivery = &player_callback_frame_delivery, .play_token_lost = &player_callback_playtoken_lost, .log_message = &sess_callback_log_message, .end_of_track = &player_callback_end_of_track, .streaming_error = NULL, .userinfo_updated = NULL, .start_playback = &player_callback_start_playback, .stop_playback = &player_callback_stop_playback, .get_audio_buffer_stats = &player_callback_get_audio_buffer_stats, // libspotify 10 .offline_status_updated = &sess_callback_offline_status_updated, .offline_error = &sess_callback_offline_error, // libspotify 11 .credentials_blob_updated = sess_callback_credentials_blob_updated, // libspotify 12 .connectionstate_updated = &sess_callback_connectionstate_updated, .scrobble_error = NULL, .private_session_mode_changed = NULL, }; thread_main = pthread_self(); /* Setup logging to stderr */ openlog(LIBSPOTIFY_USERAGENT, LOG_PERROR, LOG_USER); /** * Filter logging with one of these * setlogmask(LOG_UPTO(LOG_WARNING)); setlogmask(LOG_UPTO(LOG_NOTICE)); setlogmask(LOG_UPTO(LOG_DEBUG)); */ setlogmask(LOG_UPTO(LOG_INFO)); config.api_version = SPOTIFY_API_VERSION; config.cache_location = LIBSPOTIFY_CACHE_DIR; config.settings_location = LIBSPOTIFY_CACHE_DIR; config.application_key = g_appkey; config.application_key_size = sizeof(g_appkey); config.user_agent = LIBSPOTIFY_USERAGENT; config.callbacks = &callbacks; config.userdata = app_create(); config.compress_playlists = 1; config.dont_save_metadata_for_playlists = 0; config.initially_unload_playlists = 0; config.device_id = NULL; syslog(LOG_DEBUG, "MAIN: Initializing libspotify"); if(sp_session_create(&config, &session) != SP_ERROR_OK) { syslog(LOG_ERR, "MAIN: Unable to initialize libspotify"); app_release(); return -1; } app_set_session(session); if(argc == 4) { sp_link *link = sp_link_create_from_string(argv[3]); app_set_link(link); } /* This program will be run on mobile internet connections */ sp_session_set_connection_type(session, SP_CONNECTION_TYPE_MOBILE_ROAMING); sp_session_set_connection_rules(session, SP_CONNECTION_RULE_NETWORK|SP_CONNECTION_RULE_NETWORK_IF_ROAMING|SP_CONNECTION_RULE_ALLOW_SYNC_OVER_MOBILE); sp_session_preferred_offline_bitrate(session, SP_BITRATE_160k, 0); if(argc < 2) { char username[256]; if(sp_session_remembered_user(session, username, sizeof(username)) > 0) syslog(LOG_DEBUG, "MAIN: Attempting to login using stored credentials for user '%s'", username); if(sp_session_relogin(session) == SP_ERROR_NO_CREDENTIALS) { syslog(LOG_ERR, "MAIN: No credentials stored. Please run: %s <username> <password>", argv[0]); app_release(); return -1; } } else { syslog(LOG_DEBUG, "MAIN: Attempting to login using command line credentials"); sp_session_login(session, argv[1], argc == 3? argv[2]: NULL, 1, get_auth_blob()); } if((listen_fd = net_create(CTRL_TCP_PORT)) < 0) { syslog(LOG_ERR, "MAIN: Failed to initialize external network"); app_release(); return -1; } mainloop(session, listen_fd); syslog(LOG_INFO, "MAIN: Outside main event loop, good bye!"); net_release(listen_fd); app_release(); return 0; }
int main(int argc, char** argv) { result_t r; memset(g_obj_barrels, 0x00, sizeof(g_obj_barrels)); /* Init core library */ r = core_init(CORE_INIT_ALL); /* After core init, you can set logging options */ log_outputconsole(TRUE); set_logfile(); /* load config file (json) */ init_params* params = app_config_default(); if (params == NULL) { err_sendtolog(FALSE); core_release(FALSE); return -1; } /* Add our stuff to init params * Engine's data directory must be changed */ params->flags |= (ENG_FLAG_CONSOLE | ENG_FLAG_DEV); /* Initialize application (graphics device and rendering window) * Application name will also, be the name of the main window */ r = app_init(APP_NAME, params); if (IS_FAIL(r)) { err_sendtolog(FALSE); core_release(FALSE); app_config_unload(params); return -1; } /* Initialize engine */ r = eng_init(params); /* init params isn't needed anymore */ app_config_unload(params); if (IS_FAIL(r)) { err_sendtolog(FALSE); eng_release(); app_release(); core_release(TRUE); return -1; } if (!init_scene()) { err_sendtolog(FALSE); eng_release(); app_release(); core_release(TRUE); return -1; } /* Set application callbacks */ app_window_setupdatefn(update_callback); app_window_setkeypressfn(keypress_callback); app_window_setactivefn(activate_callback); app_window_setresizefn(resize_callback); gfx_set_debug_renderfunc(debug_view_callback); /* Initialize ok: show the main window */ app_window_show(); /* Enter message loop and update engine */ app_window_run(); /* cleanup */ release_scene(); eng_release(); app_release(); core_release(TRUE); return 0; }