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

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

/*
 * 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 /**/CFNetServiceMonitor/**/ 
    extends /**/CFType/**/ 
    /**//**/ {

    /**/public static class CFNetServiceMonitorPtr extends Ptr {}/**/
    
    public interface ClientCallback {
        void invoke(CFNetServiceMonitor monitor, CFNetService service, CFNetServiceMonitorType infoType, CFData data, 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 = CFNetServiceMonitor.class.getDeclaredMethod("cbInvoke", CFNetServiceMonitor.class, CFNetService.class, CFNetServiceMonitorType.class, CFData.class, CFStreamError.CFStreamErrorPtr.class, long.class);
        } catch (Throwable e) {
            throw new Error(e);
        }
    }
    /**/static { Bro.bind(CFNetServiceMonitor.class); }/**/
    /**//**/
    /**/
    protected CFNetServiceMonitor() {}
    /**/
    /**//**/
    /**//**/
    @Callback
    private static void cbInvoke(CFNetServiceMonitor monitor, CFNetService service, CFNetServiceMonitorType infoType, CFData data, 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(monitor, service, infoType, data, err);
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    public static CFNetServiceMonitor create(CFNetService theService, ClientCallback clientCB) {
        long refconId = CFNetServiceMonitor.refconId.getAndIncrement();
        CFNetServiceClientContext context = new CFNetServiceClientContext();
        context.setInfo(refconId);
        synchronized (callbacks) {
            callbacks.put(refconId, clientCB);
        }
        CFNetServiceMonitor service = create(null, theService, 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="CFNetServiceMonitorGetTypeID", optional=true)
    public static native @MachineSizedUInt long getClassTypeID();
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorCreate", optional=true)
    private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFNetServiceMonitor create(CFAllocator alloc, CFNetService theService, FunctionPtr clientCB, CFNetServiceClientContext clientContext);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorInvalidate", optional=true)
    public native void invalidate();
    /**
     * @since Available in iOS 2.0 and later.
     */
    public boolean start(CFNetServiceMonitorType recordType) throws CFStreamErrorException {
       CFStreamError.CFStreamErrorPtr ptr = new CFStreamError.CFStreamErrorPtr();
       boolean result = start(recordType, ptr);
       if (ptr.get() != null) { throw new CFStreamErrorException(ptr.get()); }
       return result;
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorStart", optional=true)
    private native boolean start(CFNetServiceMonitorType recordType, CFStreamError.CFStreamErrorPtr error);
    /**
     * @since Available in iOS 2.0 and later.
     */
    public void stop() throws CFStreamErrorException {
       CFStreamError.CFStreamErrorPtr ptr = new CFStreamError.CFStreamErrorPtr();
       stop(ptr);
       if (ptr.get() != null) { throw new CFStreamErrorException(ptr.get()); }
    }
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorStop", optional=true)
    private native void stop(CFStreamError.CFStreamErrorPtr error);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorScheduleWithRunLoop", optional=true)
    public native void scheduleInRunLoop(CFRunLoop runLoop, String runLoopMode);
    /**
     * @since Available in iOS 2.0 and later.
     */
    @Bridge(symbol="CFNetServiceMonitorUnscheduleFromRunLoop", optional=true)
    public native void unscheduleFromRunLoop(CFRunLoop runLoop, String runLoopMode);
    /**/
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy