#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 #include #include "QTimer" // using namespace std; // using namespace std::placeholders; // typedef std::function prot_cmdline_cb; typedef void (*prot_cmdline_cb)(QList 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; timer_=nullptr; networt_state=0; } virtual ~command() { if (socket_ != nullptr) delete socket_; } void send(QByteArray data); void init_cb(); void timer_cb(); void ready_read_cb(); private: QUdpSocket *socket_; QByteArray recv_data; QHostAddress host_addr; quint16 port; QTimer *timer_; int networt_state; }; command *command_start(); #endif