Files
checker_host/prot/prot_cmdline.h
2023-12-02 11:27:25 +08:00

67 lines
1.6 KiB
C++

#ifndef prot_cmdline_h__
#define prot_cmdline_h__
#include "QObject"
#include "base/base.h"
#include "QList"
#include "interface/codec.h"
#include "interface/interface.h"
#include "base/mycfg.h"
#include "QThread"
#include <QNetworkInterface>
#include <QUdpSocket>
// using namespace std;
// using namespace std::placeholders;
// typedef std::function<void(myarray data)> prot_cmdline_cb;
typedef void (*prot_cmdline_cb)(QList<myarray> data);
typedef struct
{
const char *cmd;
const char *help;
prot_cmdline_cb fun;
} cmdline_def;
#define cmdline_export(name_, fun_, help_) \
const static char __cmdline_##name_##_name[] __attribute__((section(".rodata.cmdlstr"))) = #name_; \
const static char __cmdline_##name_##_help[] __attribute__((section(".rodata.cmdlstr"))) = #help_; \
__attribute__((used)) static cmdline_def _cmdline_##name_ __attribute__((section("cmdldef"))) = { \
.cmd = __cmdline_##name_##_name, \
.help = __cmdline_##name_##_help, \
.fun = fun_, \
}
class command : public QObject
{
Q_OBJECT
public:
command()
{
socket_ = nullptr;
}
virtual ~command()
{
if (socket_ != nullptr)
delete socket_;
}
void send(QByteArray data);
void init_cb();
void ready_read_cb();
private:
QUdpSocket *socket_;
QByteArray recv_data;
QHostAddress host_addr;
quint16 port;
};
command *command_start();
#endif