librw/src/rwplg.h

71 lines
2.2 KiB
C
Raw Normal View History

namespace rw {
2014-12-18 17:26:57 +01:00
#define PLUGINOFFSET(type, base, offset) \
((type*)((char*)(base) + (offset)))
typedef void *(*Constructor)(void *object, int32 offset, int32 size);
typedef void *(*Destructor)(void *object, int32 offset, int32 size);
typedef void *(*CopyConstructor)(void *dst, void *src, int32 offset, int32 size);
2016-06-17 16:20:02 +02:00
typedef Stream *(*StreamRead)(Stream *stream, int32 length, void *object, int32 offset, int32 size);
typedef Stream *(*StreamWrite)(Stream *stream, int32 length, void *object, int32 offset, int32 size);
typedef int32 (*StreamGetSize)(void *object, int32 offset, int32 size);
2015-01-10 22:13:27 +01:00
typedef void (*RightsCallback)(void *object, int32 offset, int32 size, uint32 data);
2014-12-18 17:26:57 +01:00
struct Plugin
{
int32 offset;
int32 size;
uint32 id;
2014-12-18 17:26:57 +01:00
Constructor constructor;
Destructor destructor;
CopyConstructor copy;
StreamRead read;
StreamWrite write;
StreamGetSize getSize;
2015-01-10 22:13:27 +01:00
RightsCallback rightsCallback;
2014-12-18 17:26:57 +01:00
Plugin *next;
Plugin *prev;
2014-12-18 17:26:57 +01:00
};
struct PluginList
2014-12-18 17:26:57 +01:00
{
int32 size;
int32 defaultSize;
Plugin *first;
Plugin *last;
void construct(void *);
void destruct(void *);
void copy(void *dst, void *src);
bool streamRead(Stream *stream, void *);
void streamWrite(Stream *stream, void *);
int streamGetSize(void *);
void assertRights(void *, uint32 pluginID, uint32 data);
int32 registerPlugin(int32 size, uint32 id,
Constructor, Destructor, CopyConstructor);
int32 registerStream(uint32 id, StreamRead, StreamWrite, StreamGetSize);
int32 setStreamRightsCallback(uint32 id, RightsCallback cb);
int32 getPluginOffset(uint32 id);
2014-12-18 17:26:57 +01:00
};
#define PLUGINBASE \
static PluginList s_plglist; \
static int32 registerPlugin(int32 size, uint32 id, Constructor ctor, \
Destructor dtor, CopyConstructor copy){ \
return s_plglist.registerPlugin(size, id, ctor, dtor, copy); \
} \
static int32 registerPluginStream(uint32 id, StreamRead read, \
StreamWrite write, StreamGetSize getSize){ \
return s_plglist.registerStream(id, read, write, getSize); \
} \
static int32 setStreamRightsCallback(uint32 id, RightsCallback cb){ \
return s_plglist.setStreamRightsCallback(id, cb); \
} \
static int32 getPluginOffset(uint32 id){ \
return s_plglist.getPluginOffset(id); \
}
2014-12-18 17:26:57 +01:00
}