package ai.pai.lensman.dslr;

import com.android.common.utils.LogHelper;

import java.util.Random;

import ai.pai.lensman.BuildConfig;

public class CameraJNIInterface {


    static {
        try {
            System.loadLibrary("hello_jni");
        }catch (Throwable e){
            LogHelper.d("czy","load library error-->"+e);
            e.printStackTrace();
        }
    }

    private static CameraJNIInterface instance;

    private CameraJNIInterface(){

    }

    public static synchronized CameraJNIInterface getInstance(){
        if(instance==null){
            instance = new CameraJNIInterface();
        }
        return instance;
    }

    public native  int  mygpcamerainit();
    public native  int  mygpcameraexit();
    public native  String  mygpcameragetsummary();
    public native  String  mygpcamerawaitforevent(String  foldr_path);

    public int java_mygpcamerainit(){
        try {
            return mygpcamerainit();
        }catch (Throwable t){
            t.printStackTrace();
        }
        if(BuildConfig.isTestMode){
            return 0;
        }else{
            return -1;
        }
    }
    public int java_mygpcameraexit(){
        try {
            return mygpcameraexit();
        }catch (Throwable t){
            t.printStackTrace();
        }
        if(BuildConfig.isTestMode){
            return 0;
        }else{
            return -1;
        }
    }

    public String java_mygpcamerawaitforevent(String folder_path){
        try{
            return mygpcamerawaitforevent(folder_path);
        }catch (Throwable t){
            t.printStackTrace();
        }
        if(BuildConfig.isTestMode){
            return new Random().nextInt(100)%2==0 ?"1.jpg":"2.jpg";
        }else{
            return "init error";
        }
    }

}
