Main.cxx 16.1 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 The Music Player Daemon Project
3
 * http://www.musicpd.org
Warren Dukes's avatar
Warren Dukes committed
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Warren Dukes's avatar
Warren Dukes committed
18 19
 */

20
#include "config.h"
Max Kellermann's avatar
Max Kellermann committed
21
#include "Main.hxx"
22
#include "Instance.hxx"
Max Kellermann's avatar
Max Kellermann committed
23
#include "CommandLine.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "PlaylistFile.hxx"
25
#include "MusicChunk.hxx"
26
#include "StateFile.hxx"
27
#include "player/Thread.hxx"
Max Kellermann's avatar
Max Kellermann committed
28
#include "Mapper.hxx"
29
#include "Permission.hxx"
Max Kellermann's avatar
Max Kellermann committed
30
#include "Listen.hxx"
31 32
#include "client/Client.hxx"
#include "client/ClientList.hxx"
33
#include "command/AllCommands.hxx"
34
#include "Partition.hxx"
35
#include "tag/TagConfig.hxx"
36
#include "ReplayGainConfig.hxx"
Max Kellermann's avatar
Max Kellermann committed
37
#include "Idle.hxx"
38
#include "Log.hxx"
39
#include "LogInit.hxx"
Max Kellermann's avatar
Max Kellermann committed
40
#include "input/Init.hxx"
41
#include "event/Loop.hxx"
42
#include "IOThread.hxx"
43
#include "fs/AllocatedPath.hxx"
44
#include "fs/Config.hxx"
45
#include "playlist/PlaylistRegistry.hxx"
46
#include "zeroconf/ZeroconfGlue.hxx"
47
#include "decoder/DecoderList.hxx"
48
#include "AudioConfig.hxx"
49
#include "pcm/PcmConvert.hxx"
50
#include "unix/SignalHandlers.hxx"
51
#include "system/FatalError.hxx"
52
#include "util/Error.hxx"
53
#include "thread/Slack.hxx"
54
#include "lib/icu/Init.hxx"
55
#include "config/ConfigGlobal.hxx"
56
#include "config/Param.hxx"
57 58
#include "config/ConfigDefaults.hxx"
#include "config/ConfigOption.hxx"
59
#include "config/ConfigError.hxx"
60
#include "Stats.hxx"
Max Kellermann's avatar
Max Kellermann committed
61

62 63 64 65
#ifdef ENABLE_DAEMON
#include "unix/Daemon.hxx"
#endif

66 67
#ifdef ENABLE_DATABASE
#include "db/update/Service.hxx"
68
#include "db/Configured.hxx"
69
#include "db/DatabasePlugin.hxx"
70
#include "db/plugins/simple/SimpleDatabasePlugin.hxx"
71
#include "storage/Configured.hxx"
72
#include "storage/CompositeStorage.hxx"
73 74 75
#ifdef ENABLE_INOTIFY
#include "db/update/InotifyUpdate.hxx"
#endif
76 77
#endif

78 79 80 81
#ifdef ENABLE_NEIGHBOR_PLUGINS
#include "neighbor/Glue.hxx"
#endif

82
#ifdef ENABLE_SQLITE
83
#include "sticker/StickerDatabase.hxx"
84 85
#endif

86
#ifdef ENABLE_ARCHIVE
87
#include "archive/ArchiveList.hxx"
88
#endif
Max Kellermann's avatar
Max Kellermann committed
89

Max Kellermann's avatar
Max Kellermann committed
90
#ifdef ANDROID
91 92
#include "java/Global.hxx"
#include "java/File.hxx"
93
#include "android/Environment.hxx"
94
#include "android/Context.hxx"
95
#include "fs/StandardDirectory.hxx"
96
#include "fs/FileSystem.hxx"
Max Kellermann's avatar
Max Kellermann committed
97 98 99
#include "org_musicpd_Bridge.h"
#endif

100 101 102 103
#ifdef ENABLE_SYSTEMD_DAEMON
#include <systemd/sd-daemon.h>
#endif

Max Kellermann's avatar
Max Kellermann committed
104
#include <stdlib.h>
105

106
#ifdef HAVE_LOCALE_H
107 108 109
#include <locale.h>
#endif

110 111 112 113 114
#ifdef WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif

115
#ifdef __BLOCKS__
116 117 118
#include <dispatch/dispatch.h>
#endif

119 120
#include <limits.h>

121
static constexpr unsigned DEFAULT_BUFFER_SIZE = 4096;
122
static constexpr unsigned DEFAULT_BUFFER_BEFORE_PLAY = 10;
Max Kellermann's avatar
Max Kellermann committed
123

124 125 126 127
#ifdef ANDROID
Context *context;
#endif

128
Instance *instance;
129

130
#ifdef ENABLE_DAEMON
131

132
static bool
133
glue_daemonize_init(const struct options *options, Error &error)
134
{
135
	auto pid_file = config_get_path(ConfigOption::PID_FILE, error);
136
	if (pid_file.IsNull() && error.IsDefined())
137 138
		return false;

139 140
	daemonize_init(config_get_string(ConfigOption::USER, nullptr),
		       config_get_string(ConfigOption::GROUP, nullptr),
141
		       std::move(pid_file));
142 143 144

	if (options->kill)
		daemonize_kill();
145 146

	return true;
147 148
}

149 150
#endif

151
static bool
152
glue_mapper_init(Error &error)
153
{
154
	auto playlist_dir = config_get_path(ConfigOption::PLAYLIST_DIR, error);
155
	if (playlist_dir.IsNull() && error.IsDefined())
156
		return false;
157

158 159 160
	mapper_init(std::move(playlist_dir));
	return true;
}
161

162 163
#ifdef ENABLE_DATABASE

164 165 166
static bool
InitStorage(Error &error)
{
167
	Storage *storage = CreateConfiguredStorage(io_thread_get(), error);
168 169 170 171 172 173 174 175 176
	if (storage == nullptr)
		return !error.IsDefined();

	assert(!error.IsDefined());

	CompositeStorage *composite = new CompositeStorage();
	instance->storage = composite;
	composite->Mount("", storage);
	return true;
177 178
}

179 180 181 182 183 184
/**
 * Returns the database.  If this function returns false, this has not
 * succeeded, and the caller should create the database after the
 * process has been daemonized.
 */
static bool
185
glue_db_init_and_load(void)
186
{
187
	Error error;
188
	instance->database =
189
		CreateConfiguredDatabase(instance->event_loop, *instance,
190
					 error);
191 192 193 194 195 196
	if (instance->database == nullptr) {
		if (error.IsDefined())
			FatalError(error);
		else
			return true;
	}
197

198 199 200
	if (instance->database->GetPlugin().flags & DatabasePlugin::FLAG_REQUIRE_STORAGE) {
		if (!InitStorage(error))
			FatalError(error);
201

202 203 204 205 206 207 208 209 210 211 212 213 214
		if (instance->storage == nullptr) {
			delete instance->database;
			instance->database = nullptr;
			LogDefault(config_domain,
				   "Found database setting without "
				   "music_directory - disabling database");
			return true;
		}
	} else {
		if (IsStorageConfigured())
			LogDefault(config_domain,
				   "Ignoring the storage configuration "
				   "because the database does not need it");
215 216
	}

217
	instance->database->Open();
218

219
	if (!instance->database->IsPlugin(simple_db_plugin))
220 221
		return true;

222
	SimpleDatabase &db = *(SimpleDatabase *)instance->database;
223
	instance->update = new UpdateService(instance->event_loop, db,
Max Kellermann's avatar
Max Kellermann committed
224
					     static_cast<CompositeStorage &>(*instance->storage),
225
					     *instance);
226

227
	/* run database update after daemonization? */
228
	return db.FileExists();
Warren Dukes's avatar
Warren Dukes committed
229
}
Warren Dukes's avatar
Warren Dukes committed
230

231 232 233 234 235 236 237
static bool
InitDatabaseAndStorage()
{
	const bool create_db = !glue_db_init_and_load();
	return create_db;
}

238 239
#endif

240 241 242 243 244 245 246
/**
 * Configure and initialize the sticker subsystem.
 */
static void
glue_sticker_init(void)
{
#ifdef ENABLE_SQLITE
247
	Error error;
248
	auto sticker_file = config_get_path(ConfigOption::STICKER_FILE, error);
249 250 251 252 253
	if (sticker_file.IsNull()) {
		if (error.IsDefined())
			FatalError(error);
		return;
	}
254

255
	if (!sticker_global_init(std::move(sticker_file), error))
256
		FatalError(error);
257 258 259
#endif
}

260
static bool
261
glue_state_file_init(Error &error)
262
{
263
	auto path_fs = config_get_path(ConfigOption::STATE_FILE, error);
264 265 266 267 268 269 270 271 272 273 274 275 276 277
	if (path_fs.IsNull()) {
		if (error.IsDefined())
			return false;

#ifdef ANDROID
		const auto cache_dir = GetUserCacheDir();
		if (cache_dir.IsNull())
			return true;

		path_fs = AllocatedPath::Build(cache_dir, "state");
#else
		return true;
#endif
	}
278

279 280 281
	const unsigned interval =
		config_get_unsigned(ConfigOption::STATE_FILE_INTERVAL,
				    StateFile::DEFAULT_INTERVAL);
282

283 284 285 286
	instance->state_file = new StateFile(std::move(path_fs), interval,
					     *instance->partition,
					     instance->event_loop);
	instance->state_file->Read();
287
	return true;
288 289
}

290 291 292 293 294
/**
 * Windows-only initialization of the Winsock2 library.
 */
static void winsock_init(void)
{
295
#ifdef WIN32
296 297
	WSADATA sockinfo;

298
	int retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
299
	if(retval != 0)
300 301
		FormatFatalError("Attempt to open Winsock2 failed; error code %d",
				 retval);
302 303

	if (LOBYTE(sockinfo.wVersion) != 2)
304 305
		FatalError("We use Winsock2 but your version is either too new "
			   "or old; please install Winsock 2.x");
306
#endif
307
}
308

Max Kellermann's avatar
Max Kellermann committed
309 310 311 312 313 314
/**
 * Initialize the decoder and player core, including the music pipe.
 */
static void
initialize_decoder_and_player(void)
{
315
	const struct config_param *param;
Max Kellermann's avatar
Max Kellermann committed
316

317
	size_t buffer_size;
318
	param = config_get_param(ConfigOption::AUDIO_BUFFER_SIZE);
319
	if (param != nullptr) {
320
		char *test;
321
		long tmp = strtol(param->value.c_str(), &test, 10);
322
		if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
323 324
			FormatFatalError("buffer size \"%s\" is not a "
					 "positive integer, line %i",
325
					 param->value.c_str(), param->line);
326
		buffer_size = tmp;
Max Kellermann's avatar
Max Kellermann committed
327 328 329 330 331
	} else
		buffer_size = DEFAULT_BUFFER_SIZE;

	buffer_size *= 1024;

332
	const unsigned buffered_chunks = buffer_size / CHUNK_SIZE;
Max Kellermann's avatar
Max Kellermann committed
333 334

	if (buffered_chunks >= 1 << 15)
335 336
		FormatFatalError("buffer size \"%lu\" is too big",
				 (unsigned long)buffer_size);
Max Kellermann's avatar
Max Kellermann committed
337

338
	float perc;
339
	param = config_get_param(ConfigOption::BUFFER_BEFORE_PLAY);
340
	if (param != nullptr) {
341
		char *test;
342
		perc = strtod(param->value.c_str(), &test);
Max Kellermann's avatar
Max Kellermann committed
343
		if (*test != '%' || perc < 0 || perc > 100) {
344 345 346
			FormatFatalError("buffered before play \"%s\" is not "
					 "a positive percentage and less "
					 "than 100 percent, line %i",
347
					 param->value.c_str(), param->line);
Max Kellermann's avatar
Max Kellermann committed
348 349 350 351
		}
	} else
		perc = DEFAULT_BUFFER_BEFORE_PLAY;

352
	unsigned buffered_before_play = (perc / 100) * buffered_chunks;
Max Kellermann's avatar
Max Kellermann committed
353 354 355
	if (buffered_before_play > buffered_chunks)
		buffered_before_play = buffered_chunks;

356
	const unsigned max_length =
357
		config_get_positive(ConfigOption::MAX_PLAYLIST_LENGTH,
358 359
				    DEFAULT_PLAYLIST_MAX_LENGTH);

360 361 362 363
	instance->partition = new Partition(*instance,
					    max_length,
					    buffered_chunks,
					    buffered_before_play);
Max Kellermann's avatar
Max Kellermann committed
364 365
}

366 367
void
Instance::OnIdle(unsigned flags)
368
{
Max Kellermann's avatar
Max Kellermann committed
369
	/* send "idle" notifications to all subscribed
370
	   clients */
371
	client_list->IdleAdd(flags);
372

373
	if (flags & (IDLE_PLAYLIST|IDLE_PLAYER|IDLE_MIXER|IDLE_OUTPUT) &&
374 375
	    state_file != nullptr)
		state_file->CheckModified();
376 377
}

Max Kellermann's avatar
Max Kellermann committed
378 379
#ifndef ANDROID

380
int main(int argc, char *argv[])
381 382 383 384 385 386 387 388
{
#ifdef WIN32
	return win32_main(argc, argv);
#else
	return mpd_main(argc, argv);
#endif
}

Max Kellermann's avatar
Max Kellermann committed
389 390
#endif

391 392
static int mpd_main_after_fork(struct options);

393 394 395
#ifdef ANDROID
static inline
#endif
396
int mpd_main(int argc, char *argv[])
397
{
Max Kellermann's avatar
Max Kellermann committed
398
	struct options options;
399
	Error error;
Warren Dukes's avatar
Warren Dukes committed
400

401
#ifdef ENABLE_DAEMON
402
	daemonize_close_stdin();
403
#endif
404

405
#ifndef ANDROID
406
#ifdef HAVE_LOCALE_H
407 408
	/* initialize locale */
	setlocale(LC_CTYPE,"");
409
	setlocale(LC_COLLATE, "");
410
#endif
411
#endif
Max Kellermann's avatar
Max Kellermann committed
412

413
	if (!IcuInit(error)) {
414 415 416 417
		LogError(error);
		return EXIT_FAILURE;
	}

418
	winsock_init();
419
	io_thread_init();
420
	config_global_init();
Warren Dukes's avatar
Warren Dukes committed
421

422
	try {
423
#ifdef ANDROID
424 425
		(void)argc;
		(void)argv;
426

427 428 429 430
		const auto sdcard = Environment::getExternalStorageDirectory();
		if (!sdcard.IsNull()) {
			const auto config_path =
				AllocatedPath::Build(sdcard, "mpd.conf");
431 432
			if (FileExists(config_path))
				ReadConfigFile(config_path);
433
		}
434
#else
435 436 437 438 439 440 441
		if (!parse_cmdline(argc, argv, &options, error)) {
			LogError(error);
			return EXIT_FAILURE;
		}
#endif
	} catch (const std::exception &e) {
		LogError(e);
442 443
		return EXIT_FAILURE;
	}
Warren Dukes's avatar
Warren Dukes committed
444

445
#ifdef ENABLE_DAEMON
446
	if (!glue_daemonize_init(&options, error)) {
447
		LogError(error);
448 449
		return EXIT_FAILURE;
	}
450
#endif
451

Max Kellermann's avatar
Max Kellermann committed
452
	stats_global_init();
453
	TagLoadConfig();
454

455
	if (!log_init(options.verbose, options.log_stderr, error)) {
456
		LogError(error);
457 458
		return EXIT_FAILURE;
	}
459

460 461
	instance = new Instance();

462 463 464 465 466 467 468 469 470 471 472 473 474
#ifdef ENABLE_NEIGHBOR_PLUGINS
	instance->neighbors = new NeighborGlue();
	if (!instance->neighbors->Init(io_thread_get(), *instance, error)) {
		LogError(error);
		return EXIT_FAILURE;
	}

	if (instance->neighbors->IsEmpty()) {
		delete instance->neighbors;
		instance->neighbors = nullptr;
	}
#endif

475 476
	const unsigned max_clients =
		config_get_positive(ConfigOption::MAX_CONN, 10);
477
	instance->client_list = new ClientList(max_clients);
478

479 480
	initialize_decoder_and_player();

481
	if (!listen_global_init(instance->event_loop, *instance->partition,
482
				error)) {
483
		LogError(error);
484 485
		return EXIT_FAILURE;
	}
486

487
#ifdef ENABLE_DAEMON
488
	daemonize_set_user();
489
	daemonize_begin(options.daemon);
490
#endif
Warren Dukes's avatar
Warren Dukes committed
491

492
#ifdef __BLOCKS__
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
	/* Runs the OS X native event loop in the main thread, and runs
	   the rest of mpd_main on a new thread. This lets CoreAudio receive
	   route change notifications (e.g. plugging or unplugging headphones).
	   All hardware output on OS X ultimately uses CoreAudio internally.
	   This must be run after forking; if dispatch is called before forking,
	   the child process will have a broken internal dispatch state. */
	dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
		exit(mpd_main_after_fork(options));
	});
	dispatch_main();
	return EXIT_FAILURE; // unreachable, because dispatch_main never returns
#else
	return mpd_main_after_fork(options);
#endif
}

static int mpd_main_after_fork(struct options options)
510
try {
511 512
	Error error;

513
	ConfigureFS();
514

515
	if (!glue_mapper_init(error)) {
516
		LogError(error);
517 518 519
		return EXIT_FAILURE;
	}

520
	initPermissions();
521
	spl_global_init();
522
#ifdef ENABLE_ARCHIVE
523
	archive_plugin_init_all();
524
#endif
525

526
	if (!pcm_convert_global_init(error)) {
527
		LogError(error);
528 529 530
		return EXIT_FAILURE;
	}

531
	decoder_plugin_init_all();
532

533
#ifdef ENABLE_DATABASE
534
	const bool create_db = InitDatabaseAndStorage();
535
#endif
536

537
	glue_sticker_init();
538

Max Kellermann's avatar
Max Kellermann committed
539
	command_init();
540
	initAudioConfig();
541
	instance->partition->outputs.Configure(instance->event_loop,
542
					       instance->partition->pc);
543
	client_manager_init();
544
	replay_gain_global_init();
545

546
	if (!input_stream_global_init(error)) {
547
		LogError(error);
548 549 550
		return EXIT_FAILURE;
	}

551
	playlist_list_global_init();
552

553
#ifdef ENABLE_DAEMON
554
	daemonize_commit();
555
#endif
556

557
#ifndef ANDROID
558
	setup_log_output(options.log_stderr);
Warren Dukes's avatar
Warren Dukes committed
559

560
	SignalHandlersInit(instance->event_loop);
561
#endif
562

563
	io_thread_start();
564

565 566 567 568 569 570
#ifdef ENABLE_NEIGHBOR_PLUGINS
	if (instance->neighbors != nullptr &&
	    !instance->neighbors->Open(error))
		FatalError(error);
#endif

571
	ZeroconfInit(instance->event_loop);
572

573
	StartPlayerThread(instance->partition->pc);
574

575
#ifdef ENABLE_DATABASE
576
	if (create_db) {
577 578
		/* the database failed to load: recreate the
		   database */
579
		unsigned job = instance->update->Enqueue("", true);
580
		if (job == 0)
581
			FatalError("directory update failed");
582
	}
583
#endif
584

585
	if (!glue_state_file_init(error)) {
586
		LogError(error);
587 588
		return EXIT_FAILURE;
	}
589

590
	instance->partition->outputs.SetReplayGainMode(replay_gain_get_real_mode(instance->partition->playlist.queue.random));
591

592
#ifdef ENABLE_DATABASE
593
	if (config_get_bool(ConfigOption::AUTO_UPDATE, false)) {
594
#ifdef ENABLE_INOTIFY
595
		if (instance->storage != nullptr &&
596
		    instance->update != nullptr)
597
			mpd_inotify_init(instance->event_loop,
598 599
					 *instance->storage,
					 *instance->update,
600
					 config_get_unsigned(ConfigOption::AUTO_UPDATE_DEPTH,
601
							     INT_MAX));
602
#else
603
		FormatWarning(config_domain,
604
			      "inotify: auto_update was disabled. enable during compilation phase");
605
#endif
606
	}
607
#endif
608

609 610
	config_global_check();

611 612
	/* enable all audio outputs (if not already done by
	   playlist_state_restore() */
613
	instance->partition->pc.LockUpdateAudio();
614

615 616 617
#ifdef WIN32
	win32_app_started();
#endif
618

619 620 621 622
	/* the MPD frontend does not care about timer slack; set it to
	   a huge value to allow the kernel to reduce CPU wakeups */
	SetThreadTimerSlackMS(100);

623 624 625 626
#ifdef ENABLE_SYSTEMD_DAEMON
	sd_notify(0, "READY=1");
#endif

627
	/* run the main loop */
628
	instance->event_loop.Run();
629

630 631 632 633
#ifdef WIN32
	win32_app_stopping();
#endif

634 635
	/* cleanup */

636
#if defined(ENABLE_DATABASE) && defined(ENABLE_INOTIFY)
637
	mpd_inotify_finish();
638 639 640

	if (instance->update != nullptr)
		instance->update->CancelAllAsync();
641
#endif
642

643 644 645
	if (instance->state_file != nullptr) {
		instance->state_file->Write();
		delete instance->state_file;
646 647
	}

648
	instance->partition->pc.Kill();
649
	ZeroconfDeinit();
Max Kellermann's avatar
Max Kellermann committed
650
	listen_global_finish();
651
	delete instance->client_list;
652

653 654 655 656 657 658 659
#ifdef ENABLE_NEIGHBOR_PLUGINS
	if (instance->neighbors != nullptr) {
		instance->neighbors->Close();
		delete instance->neighbors;
	}
#endif

660
#ifdef ENABLE_DATABASE
661
	delete instance->update;
662 663 664 665 666

	if (instance->database != nullptr) {
		instance->database->Close();
		delete instance->database;
	}
667 668

	delete instance->storage;
669
#endif
670

671 672 673 674
#ifdef ENABLE_SQLITE
	sticker_global_finish();
#endif

675
	playlist_list_global_finish();
676
	input_stream_global_finish();
677 678

#ifdef ENABLE_DATABASE
679
	mapper_finish();
680 681
#endif

682 683
	DeinitFS();

684
	delete instance->partition;
Max Kellermann's avatar
Max Kellermann committed
685
	command_finish();
686
	decoder_plugin_deinit_all();
687
#ifdef ENABLE_ARCHIVE
688
	archive_plugin_deinit_all();
689
#endif
690
	config_global_finish();
691
	io_thread_deinit();
692
#ifndef ANDROID
693
	SignalHandlersFinish();
694
#endif
695
	delete instance;
696
	instance = nullptr;
697 698

#ifdef ENABLE_DAEMON
699
	daemonize_finish();
700
#endif
701

702 703 704
#ifdef WIN32
	WSACleanup();
#endif
705

706
	IcuFinish();
707

708
	log_deinit();
709
	return EXIT_SUCCESS;
710 711 712
} catch (const std::exception &e) {
	LogError(e);
	return EXIT_FAILURE;
Warren Dukes's avatar
Warren Dukes committed
713
}
Max Kellermann's avatar
Max Kellermann committed
714 715 716 717 718

#ifdef ANDROID

gcc_visibility_default
JNIEXPORT void JNICALL
719
Java_org_musicpd_Bridge_run(JNIEnv *env, jclass, jobject _context)
Max Kellermann's avatar
Max Kellermann committed
720
{
721 722
	Java::Init(env);
	Java::File::Initialise(env);
723
	Environment::Initialise(env);
724

725 726
	context = new Context(env, _context);

Max Kellermann's avatar
Max Kellermann committed
727
	mpd_main(0, nullptr);
728

729
	delete context;
730
	Environment::Deinitialise(env);
Max Kellermann's avatar
Max Kellermann committed
731 732
}

733 734 735 736 737
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_musicpd_Bridge_shutdown(JNIEnv *, jclass)
{
	if (instance != nullptr)
738
		instance->Shutdown();
739 740
}

Max Kellermann's avatar
Max Kellermann committed
741
#endif