70 lines
2.4 KiB
C++
70 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <lock/rw_mutex.h>
|
|
#include <stdint.h>
|
|
#include <cstdlib>
|
|
#include "Properties.h"
|
|
#include "PermissionRegister.h"
|
|
#include "BasicChannel.h"
|
|
#include <memory>
|
|
#include <sql/SqlQuery.h>
|
|
|
|
namespace ts {
|
|
namespace server {
|
|
class VirtualServer;
|
|
class ConnectedClient;
|
|
}
|
|
|
|
class ServerChannelTree;
|
|
class ServerChannel : public BasicChannel {
|
|
friend class ServerChannelTree;
|
|
public:
|
|
ServerChannel(ChannelId parentId, ChannelId channelId);
|
|
|
|
~ServerChannel();
|
|
void setProperties(const std::shared_ptr<Properties> &ptr) override;
|
|
|
|
std::shared_mutex client_lock;
|
|
std::deque<std::weak_ptr<server::ConnectedClient>> clients;
|
|
|
|
void unregister_client(const std::shared_ptr<server::ConnectedClient>& /* client */);
|
|
void register_client(const std::shared_ptr<server::ConnectedClient>& /* client */);
|
|
|
|
bool deleted = false;
|
|
size_t client_count();
|
|
};
|
|
|
|
class ServerChannelTree : public BasicChannelTree {
|
|
public:
|
|
ServerChannelTree(const std::shared_ptr<server::VirtualServer>&, sql::SqlManager*);
|
|
virtual ~ServerChannelTree();
|
|
void loadChannelsFromDatabase();
|
|
|
|
virtual std::shared_ptr<BasicChannel> createChannel(ChannelId parentId, ChannelId orderId, const std::string &name) override;
|
|
virtual std::deque<ChannelId> deleteChannelRoot(const std::shared_ptr<BasicChannel> &channel);
|
|
|
|
void deleteSemiPermanentChannels();
|
|
|
|
[[nodiscard]] std::shared_ptr<LinkedTreeEntry> tree_head() { return this->head; }
|
|
protected:
|
|
virtual ChannelId generateChannelId() override;
|
|
|
|
virtual void on_channel_entry_deleted(const std::shared_ptr<BasicChannel> &channel) override;
|
|
|
|
std::shared_ptr<BasicChannel> allocateChannel(const std::shared_ptr<BasicChannel> &parent, ChannelId channelId) override;
|
|
|
|
private:
|
|
std::weak_ptr<server::VirtualServer> server;
|
|
ServerId getServerId();
|
|
sql::SqlManager* sql;
|
|
|
|
std::deque<std::shared_ptr<TreeView::LinkedTreeEntry>> tmpChannelList;
|
|
|
|
bool initializeTempParents();
|
|
bool buildChannelTreeFromTemp();
|
|
bool updateOrderIds();
|
|
bool validateChannelNames();
|
|
bool validateChannelIcons();
|
|
int loadChannelFromData(int argc, char** data, char** column);
|
|
};
|
|
} |