2014-01-18 16:36:42 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2014-01-18 16:36:42 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "config/ConfigGlobal.hxx"
|
|
|
|
#include "neighbor/Listener.hxx"
|
|
|
|
#include "neighbor/Info.hxx"
|
|
|
|
#include "neighbor/Glue.hxx"
|
|
|
|
#include "fs/Path.hxx"
|
|
|
|
#include "event/Loop.hxx"
|
|
|
|
#include "Log.hxx"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-08-18 14:19:03 +02:00
|
|
|
class GlobalInit {
|
|
|
|
public:
|
|
|
|
GlobalInit() {
|
|
|
|
config_global_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
~GlobalInit() {
|
|
|
|
config_global_finish();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
class MyNeighborListener final : public NeighborListener {
|
|
|
|
public:
|
|
|
|
/* virtual methods from class NeighborListener */
|
2018-01-02 16:58:14 +01:00
|
|
|
virtual void FoundNeighbor(const NeighborInfo &info) noexcept override {
|
2014-01-18 16:36:42 +01:00
|
|
|
printf("found '%s' (%s)\n",
|
|
|
|
info.display_name.c_str(), info.uri.c_str());
|
|
|
|
}
|
|
|
|
|
2018-01-02 16:58:14 +01:00
|
|
|
virtual void LostNeighbor(const NeighborInfo &info) noexcept override {
|
2014-01-18 16:36:42 +01:00
|
|
|
printf("lost '%s' (%s)\n",
|
|
|
|
info.display_name.c_str(), info.uri.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2015-12-16 11:12:30 +01:00
|
|
|
try {
|
2014-01-18 16:36:42 +01:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: run_neighbor_explorer CONFIG\n");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Path config_path = Path::FromFS(argv[1]);
|
|
|
|
|
|
|
|
/* initialize the core */
|
|
|
|
|
2017-08-18 14:19:03 +02:00
|
|
|
GlobalInit init;
|
2014-02-04 23:56:24 +01:00
|
|
|
EventLoop loop;
|
2014-01-18 16:36:42 +01:00
|
|
|
|
2017-08-18 14:19:03 +02:00
|
|
|
/* read configuration file (mpd.conf) */
|
|
|
|
|
|
|
|
ReadConfigFile(config_path);
|
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
/* initialize neighbor plugins */
|
|
|
|
|
|
|
|
MyNeighborListener listener;
|
|
|
|
NeighborGlue neighbor;
|
2016-09-05 10:53:54 +02:00
|
|
|
neighbor.Init(loop, listener);
|
|
|
|
neighbor.Open();
|
2014-01-18 16:36:42 +01:00
|
|
|
|
2018-05-31 13:05:59 +02:00
|
|
|
/* dump initial list */
|
|
|
|
|
|
|
|
for (const auto &info : neighbor.GetList())
|
|
|
|
printf("have '%s' (%s)\n",
|
|
|
|
info.display_name.c_str(), info.uri.c_str());
|
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
/* run */
|
|
|
|
|
|
|
|
loop.Run();
|
|
|
|
neighbor.Close();
|
|
|
|
return EXIT_SUCCESS;
|
2016-09-05 10:53:54 +02:00
|
|
|
} catch (const std::exception &e) {
|
2015-12-16 11:12:30 +01:00
|
|
|
LogError(e);
|
|
|
|
return EXIT_FAILURE;
|
2016-09-05 10:53:54 +02:00
|
|
|
}
|