2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2014-01-18 16:36:42 +01:00
|
|
|
|
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
|
|
|
}
|