All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bugvm.apple.coreservices.CFNetServiceBrowser Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013-2015 RoboVM AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bugvm.apple.coreservices;

/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.corefoundation.*;
/**/

/**/
/**/
/**/@Library("CFNetwork")/**/
/**/public/**/ class /**/CFNetServiceBrowser/**/ 
    extends /**/CFType/**/ 
    /**//**/ {

    /**/public static class CFNetServiceBrowserPtr extends Ptr {}/**/
    
    public interface ClientCallback {
        void invoke(CFNetServiceBrowser browser, CFNetServiceBrowserFlags flags, CFType domainOrService, CFStreamError error);
    }
  
    private static final java.util.concurrent.atomic.AtomicLong refconId = new java.util.concurrent.atomic.AtomicLong();
    private long localRefconId;
    private static final LongMap callbacks = new LongMap<>();
    private static final java.lang.reflect.Method cbInvoke;
    
    static {
        try {
            cbInvoke = CFNetServiceBrowser.class.getDeclaredMethod("cbInvoke", CFNetServiceBrowser.class, CFNetServiceBrowserFlags.class, CFType.class, CFStreamError.CFStreamErrorPtr.class, long.class);
        } catch (Throwable e) {
            throw new Error(e);
        }
    }
    /**/static { Bro.bind(CFNetServiceBrowser.class); }/**/
    /**//**/
    /**/
    protected CFNetServiceBrowser() {}
    /**/
    /**//**/
    /**//**/
    @Callback
    private static void cbInvoke(CFNetServiceBrowser browser, CFNetServiceBrowserFlags flags, CFType domainOrService, CFStreamError.CFStreamErrorPtr error, @Pointer long refcon) {
        ClientCallback callback = null;
        synchronized (callbacks) {
            callback = callbacks.get(refcon);
        }
        CFStreamError err = null;
        if (error != null) err = error.get();
        callback.invoke(browser, flags, domainOrService, err);
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    public static CFNetServiceBrowser create(ClientCallback clientCB) {
        long refconId = CFNetServiceBrowser.refconId.getAndIncrement();
        CFNetServiceClientContext context = new CFNetServiceClientContext();
        context.setInfo(refconId);
        synchronized (callbacks) {
            callbacks.put(refconId, clientCB);
        }
        CFNetServiceBrowser service = create(null, new FunctionPtr(cbInvoke), context);
        if (service != null) service.localRefconId = refconId;
        return service;
    }
    
    /**
     * @since Available in iOS 2.0 and later.
     */
    public void scheduleInRunLoop(CFRunLoop runLoop, CFRunLoopMode runLoopMode) {
        scheduleInRunLoop(runLoop, runLoopMode.value().toString());
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    public void unscheduleFromRunLoop(CFRunLoop runLoop, CFRunLoopMode runLoopMode) {
        unscheduleFromRunLoop(runLoop, runLoopMode.value().toString());
    }
    /**/
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserGetTypeID", optional=true)
    public static native @MachineSizedUInt long getClassTypeID();
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserCreate", optional=true)
    private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFNetServiceBrowser create(CFAllocator alloc, FunctionPtr clientCB, CFNetServiceClientContext clientContext);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserInvalidate", optional=true)
    public native void invalidate();
    /**
     * @since Available in iOS 2.0 and later.
     */
    public boolean searchForDomains(boolean registrationDomains) throws CFStreamErrorException {
       CFStreamError.CFStreamErrorPtr ptr = new CFStreamError.CFStreamErrorPtr();
       boolean result = searchForDomains(registrationDomains, ptr);
       if (ptr.get() != null) { throw new CFStreamErrorException(ptr.get()); }
       return result;
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserSearchForDomains", optional=true)
    private native boolean searchForDomains(boolean registrationDomains, CFStreamError.CFStreamErrorPtr error);
    /**
     * @since Available in iOS 2.0 and later.
     */
    public boolean searchForServices(String domain, String serviceType) throws CFStreamErrorException {
       CFStreamError.CFStreamErrorPtr ptr = new CFStreamError.CFStreamErrorPtr();
       boolean result = searchForServices(domain, serviceType, ptr);
       if (ptr.get() != null) { throw new CFStreamErrorException(ptr.get()); }
       return result;
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserSearchForServices", optional=true)
    private native boolean searchForServices(String domain, String serviceType, CFStreamError.CFStreamErrorPtr error);
    /**
     * @since Available in iOS 2.0 and later.
     */
    public void stopSearch() throws CFStreamErrorException {
       CFStreamError.CFStreamErrorPtr ptr = new CFStreamError.CFStreamErrorPtr();
       stopSearch(ptr);
       if (ptr.get() != null) { throw new CFStreamErrorException(ptr.get()); }
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserStopSearch", optional=true)
    private native void stopSearch(CFStreamError.CFStreamErrorPtr error);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserScheduleWithRunLoop", optional=true)
    public native void scheduleInRunLoop(CFRunLoop runLoop, String runLoopMode);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceBrowserUnscheduleFromRunLoop", optional=true)
    public native void unscheduleFromRunLoop(CFRunLoop runLoop, String runLoopMode);
    /**/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy