Files
checker_host/interface/interface.h

49 lines
1.2 KiB
C
Raw Normal View History

2023-11-21 20:28:23 +08:00
#ifndef INTERFACE_H
#define INTERFACE_H
#include <QObject>
#include "base/base.h"
2023-11-26 23:05:35 +08:00
#include "interface/codec.h"
2023-11-21 20:28:23 +08:00
using namespace std;
using namespace std::placeholders;
2023-11-26 23:05:35 +08:00
typedef std::function<void(myarray data)> irq_cb;
2023-11-21 20:28:23 +08:00
class InterFace : public QObject
{
Q_OBJECT
public:
2023-11-27 14:31:00 +08:00
InterFace() { irq_fun = nullptr; }
2023-11-21 20:28:23 +08:00
virtual ~InterFace() {}
virtual void init() = 0;
virtual int write(myarray data) = 0;
2023-11-27 14:31:00 +08:00
virtual void set_irq(irq_cb fun)
{
this->irq_fun = fun;
2023-11-26 23:05:35 +08:00
}
2023-11-29 15:36:45 +08:00
virtual int write(int dst,myarray data){
return write(data);
}
2023-11-27 14:31:00 +08:00
2023-11-26 23:05:35 +08:00
protected:
irq_cb irq_fun;
2023-11-21 20:28:23 +08:00
};
InterFace *interFaceFind(const char *name);
2023-11-27 14:31:00 +08:00
typedef struct
{
const char *name;
InterFace *(*if_get_fun)();
} if_def;
2023-11-26 23:05:35 +08:00
2023-11-27 14:31:00 +08:00
#define if_export(name_, fun_) \
2023-11-26 23:05:35 +08:00
const static char __if_##name_##_name[] __attribute__((section(".rodata.ifstr"))) = #name_; \
2023-11-27 14:31:00 +08:00
__attribute__((used)) static if_def _if_##name_ __attribute__((section("ifdef"))) = { \
.name = __if_##name_##_name, \
.if_get_fun = fun_, \
}
2023-11-26 23:05:35 +08:00
2023-11-21 20:28:23 +08:00
#endif // INTERFACE_H