--------------------------------------------------------------------------------
-- <auto-generated>                                                           --
--     This code was generated by a tool.                                     --
--                                                                            --
--     Changes to this file may cause incorrect behavior and will be lost if  --
--     the code is regenerated.                                               --
-- </auto-generated>                                                          --
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--                                                                            --
--    Copyright(c) 2018 Alexander Gamper, All Rights Reserved.                --
--                                                                            --
--    Ada-WinRT                                                               --
--                                                                            --
-- This program is free software: you can redistribute it and / or modify     --
-- it under the terms of the GNU Lesser General Public License as published by--
-- the Free Software Foundation, either version 3 of the License, or          --
-- (at your option) any later version.                                        --
--                                                                            --
-- This program is distributed in the hope that it will be useful,            --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               --
-- GNU Lesser General Public License for more details.                        --
--                                                                            --
-- You should have received a copy of the GNU Lesser General Public License   --
-- along with this program.If not, see http://www.gnu.org/licenses            --
--                                                                            --
--------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
--------------------------------------------------------------------------------
package body Windows.Security.Isolation is

   ------------------------------------------------------------------------
   -- Delegates/Events
   ------------------------------------------------------------------------
   
   function Invoke
   (
      This       : access AsyncOperationCompletedHandler_IIsolatedWindowsEnvironmentLaunchFileResult_Interface
      ; asyncInfo : Windows.Security.Isolation.IAsyncOperation_IIsolatedWindowsEnvironmentLaunchFileResult
      ; asyncStatus : Windows.Foundation.AsyncStatus
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(asyncInfo, asyncStatus);
      return Hr;
   end;
   
   function Invoke
   (
      This       : access AsyncOperationCompletedHandler_IIsolatedWindowsEnvironmentShareFolderResult_Interface
      ; asyncInfo : Windows.Security.Isolation.IAsyncOperation_IIsolatedWindowsEnvironmentShareFolderResult
      ; asyncStatus : Windows.Foundation.AsyncStatus
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(asyncInfo, asyncStatus);
      return Hr;
   end;
   
   function Invoke
   (
      This       : access AsyncOperationCompletedHandler_IIsolatedWindowsEnvironmentStartProcessResult_Interface
      ; asyncInfo : Windows.Security.Isolation.IAsyncOperation_IIsolatedWindowsEnvironmentStartProcessResult
      ; asyncStatus : Windows.Foundation.AsyncStatus
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(asyncInfo, asyncStatus);
      return Hr;
   end;
   
   function Invoke
   (
      This       : access MessageReceivedCallback_Interface
      ; receiverId : Windows.Guid
      ; message : Windows.Foundation.Collections.IVectorView_Object
   )
   return Windows.HRESULT is
      Hr : Windows.HRESULT := S_OK;
   begin
      This.Callback(receiverId, message);
      return Hr;
   end;
   
   ------------------------------------------------------------------------
   -- Create functions (for activatable classes)
   ------------------------------------------------------------------------
   
   function Create return Windows.Security.Isolation.IIsolatedWindowsEnvironmentOptions is
      Hr            : Windows.HResult := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentOptions");
      Instance      : aliased IInspectable := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased IUnknown := null;
      function Convert is new Ada.Unchecked_Conversion(IUnknown , Windows.Security.Isolation.IIsolatedWindowsEnvironmentOptions) with inline;
   begin
      Hr := RoActivateInstance(m_hString, Instance'Address);
      if Hr = 0 then
         Hr := Instance.QueryInterface(Windows.Security.Isolation.IID_IIsolatedWindowsEnvironmentOptions'Access, RetVal'access);
         RefCount := Instance.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return Convert(RetVal);
   end;
   
   function Create return Windows.Security.Isolation.IIsolatedWindowsEnvironmentOwnerRegistrationData is
      Hr            : Windows.HResult := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentOwnerRegistrationData");
      Instance      : aliased IInspectable := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased IUnknown := null;
      function Convert is new Ada.Unchecked_Conversion(IUnknown , Windows.Security.Isolation.IIsolatedWindowsEnvironmentOwnerRegistrationData) with inline;
   begin
      Hr := RoActivateInstance(m_hString, Instance'Address);
      if Hr = 0 then
         Hr := Instance.QueryInterface(Windows.Security.Isolation.IID_IIsolatedWindowsEnvironmentOwnerRegistrationData'Access, RetVal'access);
         RefCount := Instance.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return Convert(RetVal);
   end;
   
   function Create return Windows.Security.Isolation.IIsolatedWindowsEnvironmentShareFolderRequestOptions is
      Hr            : Windows.HResult := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentShareFolderRequestOptions");
      Instance      : aliased IInspectable := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased IUnknown := null;
      function Convert is new Ada.Unchecked_Conversion(IUnknown , Windows.Security.Isolation.IIsolatedWindowsEnvironmentShareFolderRequestOptions) with inline;
   begin
      Hr := RoActivateInstance(m_hString, Instance'Address);
      if Hr = 0 then
         Hr := Instance.QueryInterface(Windows.Security.Isolation.IID_IIsolatedWindowsEnvironmentShareFolderRequestOptions'Access, RetVal'access);
         RefCount := Instance.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return Convert(RetVal);
   end;
   
   function Create return Windows.Security.Isolation.IIsolatedWindowsEnvironmentTelemetryParameters is
      Hr            : Windows.HResult := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentTelemetryParameters");
      Instance      : aliased IInspectable := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased IUnknown := null;
      function Convert is new Ada.Unchecked_Conversion(IUnknown , Windows.Security.Isolation.IIsolatedWindowsEnvironmentTelemetryParameters) with inline;
   begin
      Hr := RoActivateInstance(m_hString, Instance'Address);
      if Hr = 0 then
         Hr := Instance.QueryInterface(Windows.Security.Isolation.IID_IIsolatedWindowsEnvironmentTelemetryParameters'Access, RetVal'access);
         RefCount := Instance.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return Convert(RetVal);
   end;
   
   ------------------------------------------------------------------------
   -- Override Implementations
   ------------------------------------------------------------------------
   
   ------------------------------------------------------------------------
   -- Static procedures/functions
   ------------------------------------------------------------------------
   
   function CreateAsync
   (
      options : Windows.Security.Isolation.IIsolatedWindowsEnvironmentOptions
   )
   return Windows.Address is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironment");
      m_Factory     : IIsolatedWindowsEnvironmentFactory := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Address;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentFactory'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.CreateAsync(options, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function CreateWithTelemetryAsync
   (
      options : Windows.Security.Isolation.IIsolatedWindowsEnvironmentOptions
      ; telemetryParameters : Windows.Security.Isolation.IIsolatedWindowsEnvironmentTelemetryParameters
   )
   return Windows.Address is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironment");
      m_Factory     : IIsolatedWindowsEnvironmentFactory := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Address;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentFactory'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.CreateWithTelemetryAsync(options, telemetryParameters, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function FindByOwnerId
   (
      environmentOwnerId : Windows.String
   )
   return Windows.Security.Isolation.IVectorView_IIsolatedWindowsEnvironment is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironment");
      m_Factory     : IIsolatedWindowsEnvironmentFactory := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Security.Isolation.IVectorView_IIsolatedWindowsEnvironment;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentFactory'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.FindByOwnerId(environmentOwnerId, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function GetById
   (
      environmentId : Windows.String
   )
   return Windows.Security.Isolation.IIsolatedWindowsEnvironment is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironment");
      m_Factory     : IIsolatedWindowsEnvironmentFactory := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Security.Isolation.IIsolatedWindowsEnvironment;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentFactory'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.GetById(environmentId, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function get_HostErrors
   return Windows.Security.Isolation.IVectorView_IsolatedWindowsEnvironmentHostError is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentHost");
      m_Factory     : IIsolatedWindowsEnvironmentHostStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Security.Isolation.IVectorView_IsolatedWindowsEnvironmentHostError;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentHostStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.get_HostErrors(RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function get_IsReady
   return Windows.Boolean is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentHost");
      m_Factory     : IIsolatedWindowsEnvironmentHostStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Boolean;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentHostStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.get_IsReady(RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   function Register
   (
      ownerName : Windows.String
      ; ownerRegistrationData : Windows.Security.Isolation.IIsolatedWindowsEnvironmentOwnerRegistrationData
   )
   return Windows.Security.Isolation.IIsolatedWindowsEnvironmentOwnerRegistrationResult is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentOwnerRegistration");
      m_Factory     : IIsolatedWindowsEnvironmentOwnerRegistrationStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Security.Isolation.IIsolatedWindowsEnvironmentOwnerRegistrationResult;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentOwnerRegistrationStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.Register(ownerName, ownerRegistrationData, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   procedure Unregister
   (
      ownerName : Windows.String
   )
   is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsEnvironmentOwnerRegistration");
      m_Factory     : IIsolatedWindowsEnvironmentOwnerRegistrationStatics := null;
      RefCount      : Windows.UInt32 := 0;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsEnvironmentOwnerRegistrationStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.Unregister(ownerName);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
   end;
   
   function GetFileId
   (
      filePath : Windows.String
   )
   return Windows.Guid is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsHostMessenger");
      m_Factory     : IIsolatedWindowsHostMessengerStatics := null;
      RefCount      : Windows.UInt32 := 0;
      RetVal        : aliased Windows.Guid;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsHostMessengerStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.GetFileId(filePath, RetVal'Access);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
      return RetVal;
   end;
   
   procedure PostMessageToReceiver
   (
      receiverId : Windows.Guid
      ; message : Windows.Foundation.Collections.IVectorView_Object
   )
   is
      Hr            : Windows.HRESULT := S_OK;
      m_hString     : Windows.String := To_String("Windows.Security.Isolation.IsolatedWindowsHostMessenger");
      m_Factory     : IIsolatedWindowsHostMessengerStatics := null;
      RefCount      : Windows.UInt32 := 0;
   begin
      Hr := RoGetActivationFactory(m_hString, IID_IIsolatedWindowsHostMessengerStatics'Access , m_Factory'Address);
      if Hr = 0 then
         Hr := m_Factory.PostMessageToReceiver(receiverId, message);
         RefCount := m_Factory.Release;
      end if;
      Hr := WindowsDeleteString(m_hString);
   end;
   
end;
