2014-01-18 16:36:42 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 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.
|
|
|
|
*/
|
|
|
|
|
2019-02-05 21:56:20 +01:00
|
|
|
#include "ConfigGlue.hxx"
|
2014-01-18 16:36:42 +01:00
|
|
|
#include "neighbor/Listener.hxx"
|
|
|
|
#include "neighbor/Info.hxx"
|
|
|
|
#include "neighbor/Glue.hxx"
|
|
|
|
#include "fs/Path.hxx"
|
|
|
|
#include "event/Loop.hxx"
|
2018-06-04 17:42:47 +02:00
|
|
|
#include "ShutdownHandler.hxx"
|
2018-07-17 21:56:43 +02:00
|
|
|
#include "util/PrintException.hxx"
|
2014-01-18 16:36:42 +01:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
class MyNeighborListener final : public NeighborListener {
|
|
|
|
public:
|
|
|
|
/* virtual methods from class NeighborListener */
|
2020-02-01 04:37:53 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2020-02-01 04:37:53 +01:00
|
|
|
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 */
|
|
|
|
|
2014-02-04 23:56:24 +01:00
|
|
|
EventLoop loop;
|
2018-06-04 17:42:47 +02:00
|
|
|
const ShutdownHandler shutdown_handler(loop);
|
2014-01-18 16:36:42 +01:00
|
|
|
|
2017-08-18 14:19:03 +02:00
|
|
|
/* read configuration file (mpd.conf) */
|
|
|
|
|
2019-02-05 21:56:20 +01:00
|
|
|
const auto config = AutoLoadConfigFile(config_path);
|
2017-08-18 14:19:03 +02:00
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
/* initialize neighbor plugins */
|
|
|
|
|
|
|
|
MyNeighborListener listener;
|
|
|
|
NeighborGlue neighbor;
|
2018-08-19 22:41:58 +02:00
|
|
|
neighbor.Init(config, loop, listener);
|
2016-09-05 10:53:54 +02:00
|
|
|
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;
|
2018-07-17 21:56:43 +02:00
|
|
|
} catch (...) {
|
|
|
|
PrintException(std::current_exception());
|
2015-12-16 11:12:30 +01:00
|
|
|
return EXIT_FAILURE;
|
2016-09-05 10:53:54 +02:00
|
|
|
}
|