THE ONE OF IoT,YOUR ONLY CHOICE!
How to Write a Infairy Bundle
 

Bundle


This section will lead you into Infairy Cocina Bundle develop world. the Infairy is a OSGi based platform which integrate many object to build a whole IoT platform, so, let getting start from bundle.

Infairy Bundle is a base object for everything, it's simple and easy to write...
Fig-1-1-1:What is bunlde?

package com.mycompany.App.myBundle;

import java.util.Dictionary;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.infairy.cocina.SDK.device.DevicePool;
import com.infairy.cocina.SDK.gene.InfairyInterface;
import com.infairy.cocina.SDK.property.Property;
import com.infairy.smarthome.tools.Tools;


public class myFirstBundle implements BundleActivator{

    /*
     * declare bundle context
     */
    BundleContext context;

    /*
     * declare device sdk
     */
    DevicePool device;

    /*
     * declare property sdk
     */
     Property property;

    /*
     * entry point
     */
    public void start(BundleContext context) throws Exception {
        this.context=context;

        /*
         * get property service
         */
        property=(Property)Tools.getService(context, Property.class.getName(), "(Property=Setting)");

        /*
         * get device service
         */
        device=(DevicePool)Tools.getService(context, DevicePool.class.getName(), property.getDeviceService());

        /**
         * Register bundle
         */
        Dictionary props = new Hashtable();
        props.put(InfairyInterface.BundleAlias, "MyInfairyBundle");
        boolean TF=device.registerBundle(context, this, props);

    }


    /*
     * exit bundle
     */
    public void stop(BundleContext context) throws Exception {
        device.stopInfairyBundle(context, this,  "", "");
    }


}
function start() is entry point of Infairy bundle, function stop() is exit point.