250 lines
11 KiB
D
250 lines
11 KiB
D
/++
|
|
The core context provided to a plugin during initialization and event handling.
|
|
+/
|
|
module wit.pumpkin.plugin.context.imports;
|
|
|
|
|
|
import wit.common;
|
|
|
|
public import wit.pumpkin.plugin.context.common;
|
|
|
|
static import wit.pumpkin.plugin.permission.imports;
|
|
static import wit.pumpkin.plugin.event.imports;
|
|
static import wit.pumpkin.plugin.server.imports;
|
|
static import wit.pumpkin.plugin.command.imports;
|
|
|
|
package (wit) void __wit_bindgen_component_type_force_link() pure @nogc nothrow => imported!"wit.pumpkin.plugin.plugin".__wit_bindgen_component_type_force_link();
|
|
|
|
/++
|
|
|
|
+/
|
|
alias Server = wit.pumpkin.plugin.server.imports.Server;
|
|
|
|
/++
|
|
|
|
+/
|
|
alias Command = wit.pumpkin.plugin.command.imports.Command;
|
|
|
|
/++
|
|
A contextual handle for plugin-related operations.
|
|
+/
|
|
struct Context {
|
|
package(wit) uint __handle = 0;
|
|
|
|
pragma(inline, true)
|
|
package(wit) this(uint handle) @safe @nogc nothrow {
|
|
__handle = handle;
|
|
}
|
|
|
|
|
|
pragma(inline, true) void witDrop() @trusted @nogc nothrow {
|
|
if (!__handle) return; __import_drop(__handle); __handle = 0;
|
|
}
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[resource-drop]context")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:resource_drop:context")
|
|
static private extern(C) void __import_drop(uint) @nogc nothrow;
|
|
|
|
pragma(inline, true) void witFree() @safe @nogc nothrow {}
|
|
pragma(inline, true) typeof(this) witClone() const @safe @nogc nothrow { return typeof(this)(__handle); }
|
|
// TODO: make RAII? disable copy for the own
|
|
|
|
Borrow borrow() => Borrow(__handle);
|
|
alias borrow this;
|
|
|
|
struct Borrow {
|
|
package(wit) uint __handle = 0;
|
|
|
|
pragma(inline, true)
|
|
package(wit) this(uint handle) @safe @nogc nothrow {
|
|
__handle = handle;
|
|
}
|
|
|
|
pragma(inline, true) void witFree() @safe @nogc nothrow {}
|
|
pragma(inline, true)
|
|
void witDrop() @trusted @nogc nothrow {
|
|
if (!__handle) return; __import_drop(__handle); __handle = 0;
|
|
}
|
|
pragma(inline, true) Borrow witClone() const @safe @nogc nothrow { return Borrow(__handle); }
|
|
|
|
/++
|
|
Registers a handler for a specific event.
|
|
|
|
* `handler-id`: Unique ID for the event handler.
|
|
* `event-type`: The type of event to listen for.
|
|
* `event-priority`: When this handler should be called relative to others.
|
|
* `blocking`: Whether the event should wait for this handler to finish.
|
|
+/
|
|
void registerEvent(uint handlerId, EventType eventType, EventPriority eventPriority, bool blocking) @trusted nothrow {
|
|
__import_registerEvent(this.__handle, handlerId, cast(uint)(eventType), cast(uint)(eventPriority), cast(uint)(blocking));
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.register-event")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.register_event")
|
|
static private extern(C) void __import_registerEvent(uint, uint, uint, uint, uint) nothrow;
|
|
|
|
/++
|
|
Registers a new command.
|
|
|
|
* `command`: The command definition.
|
|
* `permission`: The required permission node to execute this command.
|
|
+/
|
|
void registerCommand(Command command, in WitString permission) @trusted nothrow {
|
|
__import_registerCommand(this.__handle, command.__handle, cast(void*)(permission.ptr), permission.length);
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.register-command")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.register_command")
|
|
static private extern(C) void __import_registerCommand(uint, uint, void*, size_t) nothrow;
|
|
|
|
/++
|
|
Registers a permission node with the server.
|
|
+/
|
|
Result!(void, WitString) registerPermission(in Permission permission) @trusted nothrow {
|
|
align(size_t.sizeof) void[(3*size_t.sizeof)] _retArea = void;
|
|
wit.common.DeallocateBuffer deallocate;
|
|
uint _variantPart6 = void;
|
|
uint _variantPart7 = void;
|
|
alias _Tag8 = wit.pumpkin.plugin.permission.imports.PermissionDefault.Tag;
|
|
final switch (permission.default_.tag) {
|
|
case _Tag8.deny: {
|
|
_variantPart6 = 0;
|
|
_variantPart7 = 0;
|
|
break;
|
|
}
|
|
case _Tag8.allow: {
|
|
_variantPart6 = 1;
|
|
_variantPart7 = 0;
|
|
break;
|
|
}
|
|
case _Tag8.op: {
|
|
const ref wit.pumpkin.plugin.permission.imports.PermissionLevel _payload5 = permission.default_.getOp();
|
|
_variantPart6 = 2;
|
|
_variantPart7 = cast(uint)(_payload5);
|
|
break;
|
|
}
|
|
}
|
|
auto _listSrc10 = permission.children;
|
|
auto _list10 = _listSrc10.length ? wit.common.malloc(_listSrc10.length * ((3*size_t.sizeof))) : null;
|
|
assert(!_listSrc10.length || _list10);
|
|
if (_listSrc10.length) deallocate ~= _list10;
|
|
foreach (_elem9_idx, ref _elem9; _listSrc10) {
|
|
auto _base9 = _list10 + _elem9_idx * ((3*size_t.sizeof));
|
|
*cast(size_t*)(_base9 + size_t.sizeof) = cast(size_t)(_elem9.node.length);
|
|
*cast(void**)(_base9 + 0) = cast(void*)(cast(void*)(_elem9.node.ptr));
|
|
*cast(ubyte*)(_base9 + (2*size_t.sizeof)) = cast(ubyte)(cast(uint)(_elem9.value));
|
|
|
|
}
|
|
__import_registerPermission(this.__handle, cast(void*)(permission.node.ptr), permission.node.length, cast(void*)(permission.description.ptr), permission.description.length, _variantPart6, _variantPart7, _list10, permission.children.length, _retArea.ptr);
|
|
deallocate.purge();
|
|
Result!(void, WitString) _result15 = void;
|
|
bool _isErr15 = (cast(uint)(*(cast(ubyte*)(_retArea.ptr + 0)))) != 0;
|
|
if (_isErr15) {
|
|
auto _len13 = *(cast(size_t*)(_retArea.ptr + (2*size_t.sizeof)));
|
|
auto _ptr13 = _len13 ? cast(char*)(*(cast(void**)(_retArea.ptr + size_t.sizeof))) : null;
|
|
auto _list14 = WitString(_ptr13[0.._len13]);
|
|
|
|
_result15 = Result!(void, WitString).makeErr(_list14);
|
|
} else {
|
|
|
|
_result15 = Result!(void, WitString).makeOk();
|
|
}
|
|
auto _flush16 = _result15;
|
|
return _flush16;
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.register-permission")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.register_permission")
|
|
static private extern(C) void __import_registerPermission(uint, void*, size_t, void*, size_t, uint, uint, void*, size_t, void*) nothrow;
|
|
|
|
/++
|
|
Returns the path to the plugin's private data folder.
|
|
+/
|
|
WitString getDataFolder() @trusted nothrow {
|
|
align(size_t.sizeof) void[(2*size_t.sizeof)] _retArea = void;
|
|
__import_getDataFolder(this.__handle, _retArea.ptr);
|
|
auto _len0 = *(cast(size_t*)(_retArea.ptr + size_t.sizeof));
|
|
auto _ptr0 = _len0 ? cast(char*)(*(cast(void**)(_retArea.ptr + 0))) : null;
|
|
auto _list1 = WitString(_ptr0[0.._len0]);
|
|
auto _flush2 = _list1;
|
|
return _flush2;
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.get-data-folder")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.get_data_folder")
|
|
static private extern(C) void __import_getDataFolder(uint, void*) nothrow;
|
|
|
|
/++
|
|
Returns the global server instance.
|
|
+/
|
|
Server getServer() @trusted nothrow {
|
|
auto _ret = __import_getServer(this.__handle);
|
|
auto _handle0 = Server(_ret);
|
|
return _handle0;
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.get-server")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.get_server")
|
|
static private extern(C) uint __import_getServer(uint) nothrow;
|
|
|
|
/++
|
|
Returns verified marketplace metadata if this plugin binary is signed, or none if unsigned.
|
|
+/
|
|
Option!(MarketplaceMetadata) getMarketplaceMetadata() @trusted nothrow {
|
|
align(8) void[(48+12*size_t.sizeof)] _retArea = void;
|
|
__import_getMarketplaceMetadata(this.__handle, _retArea.ptr);
|
|
Option!(MarketplaceMetadata) _option18 = void;
|
|
bool _isSome18 = (cast(uint)(*(cast(ubyte*)(_retArea.ptr + 0)))) != 0;
|
|
if (_isSome18) {
|
|
auto _len2 = *(cast(size_t*)(_retArea.ptr + (8+1*size_t.sizeof)));
|
|
auto _ptr2 = _len2 ? cast(char*)(*(cast(void**)(_retArea.ptr + 8))) : null;
|
|
auto _list3 = WitString(_ptr2[0.._len2]);
|
|
auto _len4 = *(cast(size_t*)(_retArea.ptr + (16+3*size_t.sizeof)));
|
|
auto _ptr4 = _len4 ? cast(char*)(*(cast(void**)(_retArea.ptr + (16+2*size_t.sizeof)))) : null;
|
|
auto _list5 = WitString(_ptr4[0.._len4]);
|
|
auto _len6 = *(cast(size_t*)(_retArea.ptr + (16+5*size_t.sizeof)));
|
|
auto _ptr6 = _len6 ? cast(char*)(*(cast(void**)(_retArea.ptr + (16+4*size_t.sizeof)))) : null;
|
|
auto _list7 = WitString(_ptr6[0.._len6]);
|
|
auto _len8 = *(cast(size_t*)(_retArea.ptr + (24+7*size_t.sizeof)));
|
|
auto _ptr8 = _len8 ? cast(char*)(*(cast(void**)(_retArea.ptr + (24+6*size_t.sizeof)))) : null;
|
|
auto _list9 = WitString(_ptr8[0.._len8]);
|
|
Option!(WitString) _option14 = void;
|
|
bool _isSome14 = (cast(uint)(*(cast(ubyte*)(_retArea.ptr + (40+8*size_t.sizeof))))) != 0;
|
|
if (_isSome14) {
|
|
auto _len12 = *(cast(size_t*)(_retArea.ptr + (40+10*size_t.sizeof)));
|
|
auto _ptr12 = _len12 ? cast(char*)(*(cast(void**)(_retArea.ptr + (40+9*size_t.sizeof)))) : null;
|
|
auto _list13 = WitString(_ptr12[0.._len12]);
|
|
|
|
_option14 = Option!(WitString).makeSome(_list13);
|
|
} else {
|
|
_option14 = Option!(WitString).makeNone;
|
|
}
|
|
auto _len15 = *(cast(size_t*)(_retArea.ptr + (40+12*size_t.sizeof)));
|
|
auto _ptr15 = _len15 ? cast(char*)(*(cast(void**)(_retArea.ptr + (40+11*size_t.sizeof)))) : null;
|
|
auto _list16 = WitString(_ptr15[0.._len15]);
|
|
MarketplaceMetadata _record17 = {
|
|
marketplaceUrl: _list3,
|
|
pluginId: cast(long)(*(cast(ulong*)(_retArea.ptr + (8+2*size_t.sizeof)))),
|
|
pluginName: _list5,
|
|
version_: _list7,
|
|
devId: cast(long)(*(cast(ulong*)(_retArea.ptr + (16+6*size_t.sizeof)))),
|
|
devName: _list9,
|
|
isPaid: (cast(uint)(*(cast(ubyte*)(_retArea.ptr + (24+8*size_t.sizeof))))) != 0,
|
|
userId: cast(long)(*(cast(ulong*)(_retArea.ptr + (32+8*size_t.sizeof)))),
|
|
licenseKey: _option14,
|
|
issuedAt: _list16,
|
|
};
|
|
|
|
_option18 = Option!(MarketplaceMetadata).makeSome(_record17);
|
|
} else {
|
|
_option18 = Option!(MarketplaceMetadata).makeNone;
|
|
}
|
|
auto _flush19 = _option18;
|
|
return _flush19;
|
|
}
|
|
/// ditto
|
|
@wasmImport!("pumpkin:plugin/context@0.1.0", "[method]context.get-marketplace-metadata")
|
|
pragma(mangle, "__wit_import_pumpkin:plugin__context@0.1.0__:method:context.get_marketplace_metadata")
|
|
static private extern(C) void __import_getMarketplaceMetadata(uint, void*) nothrow;
|
|
}
|
|
}
|