package link.anyauto.smartkey.sdks.targets;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;

/**
 * A wrapper or just say a target of service, all generated service targets will inherit this class.
 * @param <T>
 *     the type of generated class.
 */
public abstract class ServiceTarget<T> extends Target<T> {

    /**
     * The class of the service.
     * @return
     *  the class.
     */
    protected abstract Class<? extends Service> getServiceClass();

    /**
     * Start the wrapping service.
     * @param src
     */
    public void start(Context src) {
        Intent in = prepare(src);
        in.setClass(src, getServiceClass());
        src.startService(in);
    }

    /**
     * Bind the wrapping service.
     * @param src
     *  the context
     * @param conn
     *  the service connection
     * @param flags
     *  the flags.
     */
    public void bind(Context src, ServiceConnection conn, int flags) {
        Intent in = prepare(src);
        in.setClass(src, getServiceClass());
        src.bindService(in, conn, flags);
    }
}

@@ -1138,11 +1138,194 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Stop the service.%0A     * @param src%0A     *  the context%0A     */%0A    public void stop(Context src) %7B%0A        src.stopService(new Intent(src, getServiceClass()));%0A    %7D
 %0A%7D%0A

add stop method to ServiceTarget