123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #ifndef CLIENT_HPP
- #define CLIENT_HPP
- #include <QComboBox>
- #include <QDialog>
- #include <QLabel>
- #include <QLineEdit>
- #include <QMessageBox>
- #include <QMetaType>
- #include <QPushButton>
- #include <QQueue>
- #include <QString>
- #include <QThread>
- #include <QUuid>
- #include <QVector>
- #include <headers/util.hpp>
- #include <include/task/task.hpp>
- #include <string>
- #include <thread>
- #include <utility>
- static constexpr int MESSAGE_UPDATE_TYPE = 1;
- static constexpr int COMMANDS_UPDATE_TYPE = 2;
- static constexpr int EVENT_UPDATE_TYPE = 3;
- static constexpr int PROCESS_REQUEST_TYPE = 4;
- //using namespace Scheduler;
- namespace TaskCode {
- static constexpr uint32_t GENMSGBYTE = 0xFE;
- static constexpr uint32_t PINGBYTE = 0xFD;
- } // namespace TaskCode
- typedef std::map<int, std::string> CommandMap;
- typedef std::map<int, std::vector<std::string>> CommandArgMap;
- typedef QVector<QString> StringVec;
- struct SentFile {
- int timestamp;
- QString name;
- Scheduler::FileType type;
- };
- Q_DECLARE_METATYPE(StringVec)
- Q_DECLARE_METATYPE(QVector<QByteArray>);
- class Client : public QDialog {
- Q_OBJECT
- QThread workerThread;
- public:
- class MessageHandler {
- public:
- MessageHandler(std::function<void()> cb) : m_cb(cb) {}
- void operator()() { m_cb(); }
- private:
- std::function<void()> m_cb;
- };
- Client(QWidget* parent = nullptr);
- Client(QWidget* parent, int count, char** arguments);
- ~Client();
- void start();
- void closeConnection();
- void execute();
- QString getAppName(int mask);
- int getSelectedApp();
- // Move this to private after moving responsibilities to Client
- void scheduleTask(Scheduler::Task* task);
- MessageHandler createMessageHandler(std::function<void()> cb);
- public slots:
- void sendMessage(const QString& s);
- void setSelectedApp(std::vector<QString> app_names);
- void sendFiles(Scheduler::Task* task);
- void ping();
- void sendIPCMessage(const QString& s);
- signals:
- void messageReceived(int t, QString s, QVector<QString> args);
- void eventReceived(int t, std::string event, StringVec args);
- private:
- template <typename T>
- void sendEncoded(T message);
- void sendFileEncoded(QByteArray bytes);
- void sendTaskEncoded(Scheduler::Task* task);
- void processFileQueue();
- void handleMessages();
- void handleEvent(std::string data);
- void sendPackets(uint8_t* data, int size);
- int argc;
- char** argv;
- int m_client_socket_fd;
- bool executing;
- bool file_was_sent;
- Scheduler::Task* m_outbound_task;
- CommandMap m_commands;
- CommandArgMap m_command_arg_map;
- std::vector<int> selected_commands;
- std::vector<SentFile> sent_files;
- Scheduler::TaskQueue m_task_queue;
- QQueue<Scheduler::KFileData> outgoing_files;
- };
- #endif // CLIENT_HPP
|