mirror-chatterino2/src/providers/irc/AbstractIrcServer.hpp

79 lines
2.2 KiB
C++
Raw Normal View History

2018-02-05 15:11:50 +01:00
#pragma once
2018-06-26 14:09:39 +02:00
#include "providers/irc/IrcConnection2.hpp"
2018-04-01 16:43:30 +02:00
2018-02-05 15:11:50 +01:00
#include <IrcMessage>
#include <pajlada/signals/signal.hpp>
#include <functional>
2018-02-05 15:11:50 +01:00
#include <mutex>
namespace chatterino {
2018-04-01 16:43:30 +02:00
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
2018-02-05 15:11:50 +01:00
class AbstractIrcServer
{
public:
virtual ~AbstractIrcServer() = default;
2018-02-05 15:11:50 +01:00
// connection
void connect();
void disconnect();
void sendMessage(const QString &channelName, const QString &message);
void sendRawMessage(const QString &rawMessage);
2018-02-05 15:11:50 +01:00
// channels
std::shared_ptr<Channel> getOrAddChannel(const QString &dirtyChannelName);
std::shared_ptr<Channel> getChannelOrEmpty(const QString &dirtyChannelName);
2018-02-05 15:11:50 +01:00
// signals
pajlada::Signals::NoArgSignal connected;
pajlada::Signals::NoArgSignal disconnected;
2018-08-06 21:17:03 +02:00
// pajlada::Signals::Signal<Communi::IrcPrivateMessage *>
// onPrivateMessage;
2018-02-05 15:11:50 +01:00
void addFakeMessage(const QString &data);
// iteration
void forEachChannel(std::function<void(ChannelPtr)> func);
2018-02-05 15:11:50 +01:00
protected:
AbstractIrcServer();
2018-08-06 21:17:03 +02:00
virtual void initializeConnection(IrcConnection *connection, bool isRead,
bool isWrite) = 0;
virtual std::shared_ptr<Channel> createChannel(
const QString &channelName) = 0;
2018-02-05 15:11:50 +01:00
virtual void privateMessageReceived(Communi::IrcPrivateMessage *message);
virtual void messageReceived(Communi::IrcMessage *message);
virtual void writeConnectionMessageReceived(Communi::IrcMessage *message);
virtual void onConnected();
virtual void onDisconnected();
2018-08-06 21:17:03 +02:00
virtual std::shared_ptr<Channel> getCustomChannel(
const QString &channelName);
2018-02-05 15:11:50 +01:00
virtual bool hasSeparateWriteConnection() const = 0;
virtual QString cleanChannelName(const QString &dirtyChannelName);
QMap<QString, std::weak_ptr<Channel>> channels;
std::mutex channelMutex;
2018-02-05 15:11:50 +01:00
private:
void initConnection();
2018-06-22 23:24:45 +02:00
std::unique_ptr<IrcConnection> writeConnection_ = nullptr;
std::unique_ptr<IrcConnection> readConnection_ = nullptr;
2018-02-05 15:11:50 +01:00
2018-06-22 23:24:45 +02:00
std::mutex connectionMutex_;
2018-06-04 21:05:18 +02:00
2018-06-22 23:24:45 +02:00
// bool autoReconnect_ = false;
2018-02-05 15:11:50 +01:00
};
2018-04-01 16:43:30 +02:00
2018-02-05 15:11:50 +01:00
} // namespace chatterino