Function

CFNetServiceMonitorCreate(_:_:_:_:)

Creates an instance of a NetServiceMonitor object that watches for record changes.

Declaration

func CFNetServiceMonitorCreate(_ alloc: CFAllocator?, _ theService: CFNetService, _ clientCB: CFNetServiceMonitorClientCallBack, _ clientContext: UnsafeMutablePointer<CFNetServiceClientContext>) -> Unmanaged<CFNetServiceMonitor>

Parameters

alloc

The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

theService

CFNetService to be monitored.

clientCB

Pointer to callback function that is to be called when a record associated with theService changes; cannot be NULL.

clientContext

Pointer to user-defined contextual information that is to be passed to the callback specified by clientCB when the callback is called; cannot be NULL. For details, see CFNetServiceClientContext.

Return Value

A new instance of a CFNetServiceMonitor, or NULL if the monitor could not be created. Ownership follows the The Create Rule.

Discussion

This function creates a CFNetServiceMonitor that watches for changes in records associated with theService.

If the CFNetServiceMonitor is to run in asynchronous mode, call CFNetServiceMonitorScheduleWithRunLoop(_:_:_:) to schedule the monitor on a run loop. Then call CFNetServiceMonitorStart(_:_:_:) to start monitoring. When a change occurs, the callback function specified by clientCB will be called. For details, see CFNetServiceMonitorClientCallBack.

If the CFNetServiceMonitor is to run in synchronous mode, call CFNetServiceMonitorStart(_:_:_:).

To stop a monitor that is running in asynchronous mode, call CFNetServiceMonitorStop(_:_:) and CFNetServiceMonitorUnscheduleFromRunLoop(_:_:_:).

To stop a monitor that is running in synchronous mode, call CFNetServiceMonitorStop(_:_:).

If you no longer need to monitor record changes, call CFNetServiceMonitorStop(_:_:) to stop the monitor and then call CFNetServiceMonitorInvalidate(_:)to invalidate the monitor so it cannot be used again. Then call CFRelease to release the memory associated with CFNetServiceMonitorRef.

Special Considerations

This function is thread safe.

See Also

Network Services

class CFNetService

An opaque reference representing a CFNetService.

class CFNetServiceBrowser

An opaque reference representing a CFNetServiceBrowser.

class CFNetServiceMonitor

An opaque reference for a service monitor.

enum CFNetServiceMonitorType

Record type specifier used to tell a service monitor the type of record changes to watch for.

struct CFNetServiceClientContext

A structure provided when a CFNetService is associated with a callback function or when a CFNetServiceBrowser is created.

enum CFNetServicesError

Error codes that may be returned by CFNetServices functions or passed to CFNetServices callback functions.

func CFNetServiceBrowserInvalidate(CFNetServiceBrowser)

Invalidates an instance of a Network Service browser object.

func CFNetServiceBrowserGetTypeID() -> CFTypeID

Gets the Core Foundation type identifier for the Network Service browser object.

func CFNetServiceBrowserUnscheduleFromRunLoop(CFNetServiceBrowser, CFRunLoop, CFString)

Unschedules a CFNetServiceBrowser from a run loop and mode.

func CFNetServiceCancel(CFNetService)

Cancels a service registration or a service resolution.

func CFNetServiceGetPortNumber(CFNetService) -> Int32

This function gets the port number from a CFNetService.

func CFNetServiceGetTXTData(CFNetService) -> Unmanaged<CFData>?

Queries a network service for the contents of its TXT records.

func CFNetServiceGetTypeID() -> CFTypeID

Gets the Core Foundation type identifier for the Network Service object.

func CFNetServiceMonitorGetTypeID() -> CFTypeID

Gets the Core Foundation type identifier for all CFNetServiceMonitor instances.

func CFNetServiceMonitorInvalidate(CFNetServiceMonitor)

Invalidates an instance of a Network Service monitor object.

func CFNetServiceSetClient(CFNetService, CFNetServiceClientCallBack?, UnsafeMutablePointer<CFNetServiceClientContext>?) -> Bool

Associates a callback function with a CFNetService or disassociates a callback function from a CFNetService.

func CFNetServiceSetTXTData(CFNetService, CFData) -> Bool

Sets the TXT record for a CFNetService.