content: // Generated by dart-wayland-scanner
  // https://github.com/your-repo/dart-wayland-scanner
  // XML file : https://gitlab.freedesktop.org/wayland/wayland-protocols/-/raw/main/staging/security-context/security-context-v1.xml
  //
  // security_context_v1 Protocol Copyright: 
  /// 
  /// Copyright © 2021 Simon Ser
  /// 
  /// Permission is hereby granted, free of charge, to any person obtaining a
  /// copy of this software and associated documentation files (the "Software"),
  /// to deal in the Software without restriction, including without limitation
  /// the rights to use, copy, modify, merge, publish, distribute, sublicense,
  /// and/or sell copies of the Software, and to permit persons to whom the
  /// Software is furnished to do so, subject to the following conditions:
  /// 
  /// The above copyright notice and this permission notice (including the next
  /// paragraph) shall be included in all copies or substantial portions of the
  /// Software.
  /// 
  /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  /// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  /// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  /// DEALINGS IN THE SOFTWARE.
  /// 
  
  library client;
  
  import 'package:wayland/wayland.dart';
  import 'package:wayland/protocols/wayland.dart';
  import 'dart:async';
  import 'dart:convert';
  import 'dart:typed_data';
  import 'package:result_dart/result_dart.dart';
  
  
  /// client security context manager
  /// 
  /// This interface allows a client to register a new Wayland connection to
  /// the compositor and attach a security context to it.
  /// 
  /// This is intended to be used by sandboxes. Sandbox engines attach a
  /// security context to all connections coming from inside the sandbox. The
  /// compositor can then restrict the features that the sandboxed connections
  /// can use.
  /// 
  /// Compositors should forbid nesting multiple security contexts by not
  /// exposing wp_security_context_manager_v1 global to clients with a security
  /// context attached, or by sending the nested protocol error. Nested
  /// security contexts are dangerous because they can potentially allow
  /// privilege escalation of a sandboxed client.
  /// 
  /// Warning! The protocol described in this file is currently in the testing
  /// phase. Backward compatible changes may be added together with the
  /// corresponding interface version bump. Backward incompatible changes can
  /// only be done by creating a new major version of the extension.
  /// 
  class WpSecurityContextManagerV1 extends Proxy{
    final Context innerContext;
    final version = 1;
  
    WpSecurityContextManagerV1(this.innerContext) : super(innerContext.allocateClientId()){
      innerContext.register(this);
    }
  
  
  @override
  toString(){
  return "WpSecurityContextManagerV1 {name: 'wp_security_context_manager_v1', id: '$objectId', version: '1',}";
  }
  
  /// destroy the manager object
  /// 
  /// Destroy the manager. This doesn't destroy objects created with the
  /// manager.
  /// 
    Result<void,Object> destroy() {
  innerContext.unRegister(this);
      logLn("WpSecurityContextManagerV1::destroy ");
  var arguments = [];var argTypes = <WaylandType>[];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 0]).buffer.asUint8List());
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextManagerV1::destroy: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  /// create a new security context
  /// 
  /// Creates a new security context with a socket listening FD.
  /// 
  /// The compositor will accept new client connections on listen_fd.
  /// listen_fd must be ready to accept new connections when this request is
  /// sent by the client. In other words, the client must call bind(2) and
  /// listen(2) before sending the FD.
  /// 
  /// close_fd is a FD closed by the client when the compositor should stop
  /// accepting new connections on listen_fd.
  /// 
  /// The compositor must continue to accept connections on listen_fd when
  /// the Wayland client which created the security context disconnects.
  /// 
  /// After sending this request, closing listen_fd and close_fd remains the
  /// only valid operation on them.
  /// 
  /// [id]:
  /// [listen_fd]: listening socket FD
  /// [close_fd]: FD closed when done
    Result<WpSecurityContextV1,Object> createListener(int listenFd, int closeFd) {
    var id =  WpSecurityContextV1(innerContext);
      logLn("WpSecurityContextManagerV1::createListener  id: $id listenFd: $listenFd closeFd: $closeFd");
  var arguments = [id];var argTypes = <WaylandType>[WaylandType.newId];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 1]).buffer.asUint8List());
      bytesBuilder.add(Uint32List.fromList([id.objectId]).buffer.asUint8List());
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), closeFd);
      }catch (e) {
        logLn("Exception in WpSecurityContextManagerV1::createListener: $e");
     return Failure(e);
      }
      return Success(id);
    }
  
  }
  
  /// 
  /// 
  
  enum WpSecurityContextManagerV1Error {
  /// listening socket FD is invalid
    invalidListenFd("invalid_listen_fd", 1),/// nested security contexts are forbidden
    nested("nested", 2);
  const WpSecurityContextManagerV1Error(this.enumName, this.enumValue);
  final int enumValue;
  final String enumName;
  @override
  toString(){
  return "WpSecurityContextManagerV1Error {name: $enumName, value: $enumValue}";
  }
  }
  
  
  
  /// client security context
  /// 
  /// The security context allows a client to register a new client and attach
  /// security context metadata to the connections.
  /// 
  /// When both are set, the combination of the application ID and the sandbox
  /// engine must uniquely identify an application. The same application ID
  /// will be used across instances (e.g. if the application is restarted, or
  /// if the application is started multiple times).
  /// 
  /// When both are set, the combination of the instance ID and the sandbox
  /// engine must uniquely identify a running instance of an application.
  /// 
  class WpSecurityContextV1 extends Proxy{
    final Context innerContext;
    final version = 1;
  
    WpSecurityContextV1(this.innerContext) : super(innerContext.allocateClientId()){
      innerContext.register(this);
    }
  
  
  @override
  toString(){
  return "WpSecurityContextV1 {name: 'wp_security_context_v1', id: '$objectId', version: '1',}";
  }
  
  /// destroy the security context object
  /// 
  /// Destroy the security context object.
  /// 
    Result<void,Object> destroy() {
  innerContext.unRegister(this);
      logLn("WpSecurityContextV1::destroy ");
  var arguments = [];var argTypes = <WaylandType>[];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 0]).buffer.asUint8List());
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextV1::destroy: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  /// set the sandbox engine
  /// 
  /// Attach a unique sandbox engine name to the security context. The name
  /// should follow the reverse-DNS style (e.g. "org.flatpak").
  /// 
  /// A list of well-known engines is maintained at:
  /// https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/security-context/engines.md
  /// 
  /// It is a protocol error to call this request twice. The already_set
  /// error is sent in this case.
  /// 
  /// [name]: the sandbox engine name
    Result<void,Object> setSandboxEngine(String name) {
      logLn("WpSecurityContextV1::setSandboxEngine  name: $name");
  var arguments = [name];var argTypes = <WaylandType>[WaylandType.string];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 1]).buffer.asUint8List());
      final nameBytes = utf8.encode(name);
      bytesBuilder.add(Uint32List.fromList([nameBytes.length + 1]).buffer.asUint8List());
      bytesBuilder.add(nameBytes);
      bytesBuilder.add([0]); // Null terminator
      while (bytesBuilder.length % 4 != 0) { bytesBuilder.add([0]); } // Padding
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextV1::setSandboxEngine: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  /// set the application ID
  /// 
  /// Attach an application ID to the security context.
  /// 
  /// The application ID is an opaque, sandbox-specific identifier for an
  /// application. See the well-known engines document for more details:
  /// https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/security-context/engines.md
  /// 
  /// The compositor may use the application ID to group clients belonging to
  /// the same security context application.
  /// 
  /// Whether this request is optional or not depends on the sandbox engine used.
  /// 
  /// It is a protocol error to call this request twice. The already_set
  /// error is sent in this case.
  /// 
  /// [app_id]: the application ID
    Result<void,Object> setAppId(String appId) {
      logLn("WpSecurityContextV1::setAppId  appId: $appId");
  var arguments = [appId];var argTypes = <WaylandType>[WaylandType.string];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 2]).buffer.asUint8List());
      final appIdBytes = utf8.encode(appId);
      bytesBuilder.add(Uint32List.fromList([appIdBytes.length + 1]).buffer.asUint8List());
      bytesBuilder.add(appIdBytes);
      bytesBuilder.add([0]); // Null terminator
      while (bytesBuilder.length % 4 != 0) { bytesBuilder.add([0]); } // Padding
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextV1::setAppId: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  /// set the instance ID
  /// 
  /// Attach an instance ID to the security context.
  /// 
  /// The instance ID is an opaque, sandbox-specific identifier for a running
  /// instance of an application. See the well-known engines document for
  /// more details:
  /// https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/security-context/engines.md
  /// 
  /// Whether this request is optional or not depends on the sandbox engine used.
  /// 
  /// It is a protocol error to call this request twice. The already_set
  /// error is sent in this case.
  /// 
  /// [instance_id]: the instance ID
    Result<void,Object> setInstanceId(String instanceId) {
      logLn("WpSecurityContextV1::setInstanceId  instanceId: $instanceId");
  var arguments = [instanceId];var argTypes = <WaylandType>[WaylandType.string];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 3]).buffer.asUint8List());
      final instanceIdBytes = utf8.encode(instanceId);
      bytesBuilder.add(Uint32List.fromList([instanceIdBytes.length + 1]).buffer.asUint8List());
      bytesBuilder.add(instanceIdBytes);
      bytesBuilder.add([0]); // Null terminator
      while (bytesBuilder.length % 4 != 0) { bytesBuilder.add([0]); } // Padding
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextV1::setInstanceId: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  /// register the security context
  /// 
  /// Atomically register the new client and attach the security context
  /// metadata.
  /// 
  /// If the provided metadata is inconsistent or does not match with out of
  /// band metadata (see
  /// https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/security-context/engines.md),
  /// the invalid_metadata error may be sent eventually.
  /// 
  /// It's a protocol error to send any request other than "destroy" after
  /// this request. In this case, the already_used error is sent.
  /// 
    Result<void,Object> commit() {
      logLn("WpSecurityContextV1::commit ");
  var arguments = [];var argTypes = <WaylandType>[];
  var calclulatedSize  = calculateSize(argTypes, arguments);
  final bytesBuilder = BytesBuilder();
  bytesBuilder.add(Uint32List.fromList([objectId, (calclulatedSize << 16) | 4]).buffer.asUint8List());
      try{
      innerContext.sendMessage(bytesBuilder.toBytes(), );
      }catch (e) {
        logLn("Exception in WpSecurityContextV1::commit: $e");
     return Failure(e);
      }
      return Success(Object());
    }
  
  }
  
  /// 
  /// 
  
  enum WpSecurityContextV1Error {
  /// security context has already been committed
    alreadyUsed("already_used", 1),/// metadata has already been set
    alreadySet("already_set", 2),/// metadata is invalid
    invalidMetadata("invalid_metadata", 3);
  const WpSecurityContextV1Error(this.enumName, this.enumValue);
  final int enumValue;
  final String enumName;
  @override
  toString(){
  return "WpSecurityContextV1Error {name: $enumName, value: $enumValue}";
  }
  }
  
  