Client: make almost all attributes `private`
This commit is contained in:
parent
380f73c112
commit
a9cb12b745
|
@ -56,7 +56,6 @@ class Client final
|
|||
|
||||
Partition *partition;
|
||||
|
||||
public:
|
||||
unsigned permission;
|
||||
|
||||
/** the uid of the client process, or -1 if unknown */
|
||||
|
@ -76,11 +75,14 @@ public:
|
|||
/** idle flags that the client wants to receive */
|
||||
unsigned idle_subscriptions;
|
||||
|
||||
public:
|
||||
// TODO: make this attribute "private"
|
||||
/**
|
||||
* The tags this client is interested in.
|
||||
*/
|
||||
TagMask tag_mask = TagMask::All();
|
||||
|
||||
private:
|
||||
/**
|
||||
* A list of channel names this client is subscribed to.
|
||||
*/
|
||||
|
@ -97,6 +99,7 @@ public:
|
|||
*/
|
||||
std::list<ClientMessage> messages;
|
||||
|
||||
public:
|
||||
Client(EventLoop &loop, Partition &partition,
|
||||
UniqueSocketDescriptor fd, int uid,
|
||||
unsigned _permission,
|
||||
|
@ -175,11 +178,23 @@ public:
|
|||
return subscriptions.find(channel_name) != subscriptions.end();
|
||||
}
|
||||
|
||||
const auto &GetSubscriptions() const noexcept {
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
SubscribeResult Subscribe(const char *channel) noexcept;
|
||||
bool Unsubscribe(const char *channel) noexcept;
|
||||
void UnsubscribeAll() noexcept;
|
||||
bool PushMessage(const ClientMessage &msg) noexcept;
|
||||
|
||||
template<typename F>
|
||||
void ConsumeMessages(F &&f) {
|
||||
while (!messages.empty()) {
|
||||
f(messages.front());
|
||||
messages.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this client allowed to use the specified local file?
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2018 The Music Player Daemon Project
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -70,14 +70,15 @@ client_new(EventLoop &loop, Partition &partition,
|
|||
|
||||
(void)fd.Write(GREETING, sizeof(GREETING) - 1);
|
||||
|
||||
const unsigned num = next_client_num++;
|
||||
Client *client = new Client(loop, partition, std::move(fd), uid,
|
||||
permission,
|
||||
next_client_num++);
|
||||
num);
|
||||
|
||||
client_list.Add(*client);
|
||||
|
||||
FormatInfo(client_domain, "[%u] opened from %s",
|
||||
client->num, remote.c_str());
|
||||
num, remote.c_str());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2018 The Music Player Daemon Project
|
||||
* Copyright 2003-2019 The Music Player Daemon Project
|
||||
* http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -78,9 +78,11 @@ handle_channels(Client &client, gcc_unused Request args, Response &r)
|
|||
assert(args.empty());
|
||||
|
||||
std::set<std::string> channels;
|
||||
for (const auto &c : *client.GetInstance().client_list)
|
||||
channels.insert(c.subscriptions.begin(),
|
||||
c.subscriptions.end());
|
||||
for (const auto &c : *client.GetInstance().client_list) {
|
||||
const auto &subscriptions = c.GetSubscriptions();
|
||||
channels.insert(subscriptions.begin(),
|
||||
subscriptions.end());
|
||||
}
|
||||
|
||||
for (const auto &channel : channels)
|
||||
r.Format("channel: %s\n", channel.c_str());
|
||||
|
@ -94,13 +96,10 @@ handle_read_messages(Client &client,
|
|||
{
|
||||
assert(args.empty());
|
||||
|
||||
while (!client.messages.empty()) {
|
||||
const ClientMessage &msg = client.messages.front();
|
||||
|
||||
client.ConsumeMessages([&r](const auto &msg){
|
||||
r.Format("channel: %s\nmessage: %s\n",
|
||||
msg.GetChannel(), msg.GetMessage());
|
||||
client.messages.pop_front();
|
||||
}
|
||||
});
|
||||
|
||||
return CommandResult::OK;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue