unit Macapi.ServiceManagement;
{$MODE Delphi}
{$modeswitch objectivec1}
interface
uses
Macapi.ObjectiveC, Macapi.CoreFoundation, Macapi.CocoaTypes, Macapi.Foundation, Macapi.Security;
const
{ TODO : Macro probably use invalid symbol "kSMRightBlessPrivilegedHelper": }
(* kSMRightBlessPrivilegedHelper "com.apple.ServiceManagement.blesshelper" *)
{ TODO : Macro probably use invalid symbol "kSMRightModifySystemDaemons": }
(* kSMRightModifySystemDaemons "com.apple.ServiceManagement.daemons.modify" *)
kSMErrorInternalFailure = 2;
kSMErrorInvalidSignature = 3;
kSMErrorAuthorizationFailure = 4;
kSMErrorToolNotValid = 5;
kSMErrorJobNotFound = 6;
kSMErrorServiceUnavailable = 7;
kSMErrorJobPlistNotFound = 8;
kSMErrorJobMustBeEnabled = 9;
kSMErrorInvalidPlist = 10;
kSMErrorLaunchDeniedByUser = 11;
kSMErrorAlreadyRegistered = 12;
SMAppServiceStatusNotRegistered = 0;
SMAppServiceStatusEnabled = 1;
SMAppServiceStatusRequiresApproval = 2;
SMAppServiceStatusNotFound = 3;
type
SMAppService = interface;
SMAppServiceStatus = NSInteger;
TSMAppServiceBlockMethod1 = procedure(error: NSError) of object;
SMAppServiceClass = objcclass(NSObject)
SMAppServiceClass = interface(NSObjectClass)
['{A4BDE3B3-3167-43B5-A5B3-4D441AFC9FC4}']
{class} function agentServiceWithPlistName(plistName: NSString): Pointer; cdecl;
{class} function daemonServiceWithPlistName(plistName: NSString): Pointer; cdecl;
{class} function loginItemServiceWithIdentifier(identifier: NSString): Pointer; cdecl;
{class} function mainAppService: SMAppService; cdecl;
{class} procedure openSystemSettingsLoginItems; cdecl;
{class} function statusForLegacyURL(url: NSURL): SMAppServiceStatus; cdecl;
end;
SMAppService = interface(NSObject)
['{997656A2-2E6A-4BAE-B2F3-248CD99993AD}']
function registerAndReturnError(error: PPointer): Boolean; cdecl;
function status: SMAppServiceStatus; cdecl;
function unregisterAndReturnError(error: PPointer): Boolean; cdecl;
procedure unregisterWithCompletionHandler(handler: TSMAppServiceBlockMethod1); cdecl;
end;
TSMAppService = class(TOCGenericImport<SMAppServiceClass, SMAppService>) end;
const
libServiceManagement = '/System/Library/Frameworks/ServiceManagement.framework/ServiceManagement';
function SMLoginItemSetEnabled(identifier: CFStringRef; enabled: Boolean): Boolean; cdecl;
external libServiceManagement name _PU + 'SMLoginItemSetEnabled';
function SMJobCopyDictionary(domain: CFStringRef; jobLabel: CFStringRef): CFDictionaryRef; cdecl;
external libServiceManagement name _PU + 'SMJobCopyDictionary';
function SMCopyAllJobDictionaries(domain: CFStringRef): CFArrayRef; cdecl;
external libServiceManagement name _PU + 'SMCopyAllJobDictionaries';
function SMJobSubmit(domain: CFStringRef; job: CFDictionaryRef; auth: AuthorizationRef; outError: PCFErrorRef): Boolean; cdecl;
external libServiceManagement name _PU + 'SMJobSubmit';
function SMJobRemove(domain: CFStringRef; jobLabel: CFStringRef; auth: AuthorizationRef; wait: Boolean; outError: PCFErrorRef): Boolean; cdecl;
external libServiceManagement name _PU + 'SMJobRemove';
function SMJobBless(domain: CFStringRef; executableLabel: CFStringRef; auth: AuthorizationRef; outError: PCFErrorRef): Boolean; cdecl;
external libServiceManagement name _PU + 'SMJobBless';
implementation
uses
System.SysUtils;
var
ServiceManagementModule: THandle;
initialization
ServiceManagementModule := LoadLibrary(libServiceManagement);
finalization
if ServiceManagementModule <> 0 then
FreeLibrary(ServiceManagementModule);
end.