java_class.mustache 6.17 KB
Newer Older
Sylvain Berfini's avatar
Sylvain Berfini committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
{{className}}.java
Copyright (C) 2010  Belledonne Communications, Grenoble, France

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

20
package {{packageName}};
Sylvain Berfini's avatar
Sylvain Berfini committed
21 22 23 24 25

{{#imports}}
import {{import}}
{{/imports}}
{{#isLinphoneFactory}}
26 27 28 29 30 31 32 33 34
import android.content.Context;
import android.os.Build;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.linphone.mediastream.Log;
Sylvain Berfini's avatar
Sylvain Berfini committed
35
import org.linphone.mediastream.Version;
36
import org.linphone.core.tools.OpenH264DownloadHelper;
Sylvain Berfini's avatar
Sylvain Berfini committed
37 38 39 40 41 42 43 44 45
{{/isLinphoneFactory}}

{{#doc}}
/**
    {{#lines}}
  * {{line}}
    {{/lines}}
  */
{{/doc}}
46
public {{#isLinphoneFactory}}abstract class{{/isLinphoneFactory}}{{#isNotLinphoneFactory}}interface{{/isNotLinphoneFactory}} {{className}} {
Sylvain Berfini's avatar
Sylvain Berfini committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
{{#enums}}
    enum {{className}} {
    {{#values}}
        {{#doc}}
        /**
            {{#lines}}
        * {{line}}
            {{/lines}}
        */
        {{/doc}}
        {{name}}({{value}}){{commarorsemicolon}}

    {{/values}}
        protected final int mValue;

        private {{className}} (int value) {
            mValue = value;
        }

66
        static public {{className}} fromInt(int value) throws RuntimeException {
Sylvain Berfini's avatar
Sylvain Berfini committed
67 68 69 70 71
            switch(value) {
            {{#values}}
            case {{value}}: return {{name}};
            {{/values}}
            default:
72
                throw new RuntimeException("Unhandled enum value " + value + " for {{className}}");
Sylvain Berfini's avatar
Sylvain Berfini committed
73 74
            }
        }
75 76 77 78

        public int toInt() {
            return mValue;
        }
Sylvain Berfini's avatar
Sylvain Berfini committed
79 80 81 82
    };

{{/enums}}
{{#isLinphoneFactory}}
83 84 85 86 87 88 89 90 91 92 93 94
    static Factory _Factory;

    public static final synchronized Factory instance() {
		try {
			if (_Factory == null) {
				_Factory = new FactoryImpl(0);
			}
		} catch (Exception e) {
			System.err.println("Cannot instanciate factory");
		}
		return _Factory;
	}
95 96

    abstract public OpenH264DownloadHelper createOpenH264DownloadHelper(Context context);
97 98

    abstract public void setDebugMode(boolean enable, String tag);
99 100 101

    abstract public Core createCore(CoreListener listener, String configPath, String factoryConfigPath);

Sylvain Berfini's avatar
Sylvain Berfini committed
102
{{/isLinphoneFactory}}
103 104 105 106 107 108
{{#isLinphoneCore}}
    /**
      * Gets the mediastreamer's factory
      */
    public org.linphone.mediastream.Factory getMediastreamerFactory();
{{/isLinphoneCore}}
Sylvain Berfini's avatar
Sylvain Berfini committed
109 110 111 112 113 114 115 116
{{#methods}}
    {{#doc}}
    /**
    {{#lines}}
      * {{line}}
    {{/lines}}
      */
    {{/doc}}
117
    {{#deprecated}}@Deprecated
118
    {{/deprecated}}{{#isLinphoneFactory}}abstract {{/isLinphoneFactory}}public {{return}} {{name}}({{params}});
Sylvain Berfini's avatar
Sylvain Berfini committed
119 120

{{/methods}}
121 122 123
    /**
      * Sets the object to store in this object user's data
      */
124
    {{#isLinphoneFactory}}abstract {{/isLinphoneFactory}}public void setUserData(Object data);
125 126 127 128

    /**
      * Gets the object stored in this object user's data
      */
129
    {{#isLinphoneFactory}}abstract {{/isLinphoneFactory}}public Object getUserData();
Sylvain Berfini's avatar
Sylvain Berfini committed
130 131
}

132
class {{classImplName}} {{#isLinphoneFactory}}extends{{/isLinphoneFactory}}{{#isNotLinphoneFactory}}implements{{/isNotLinphoneFactory}} {{className}} {
Sylvain Berfini's avatar
Sylvain Berfini committed
133 134

    protected long nativePtr = 0;
135
    protected Object userData = null;
Sylvain Berfini's avatar
Sylvain Berfini committed
136

137 138 139 140
    protected {{classImplName}}(long ptr) {
        nativePtr = ptr;
    }

Sylvain Berfini's avatar
Sylvain Berfini committed
141
{{#isLinphoneFactory}}
142
	private static boolean loadOptionalLibrary(String s) {
Sylvain Berfini's avatar
Sylvain Berfini committed
143 144 145 146
		try {
			System.loadLibrary(s);
			return true;
		} catch (Throwable e) {
147
			android.util.Log.w("FactoryImpl", "Unable to load optional library " + s + ": " + e.getMessage());
Sylvain Berfini's avatar
Sylvain Berfini committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161
		}
		return false;
	}

	static {
		System.loadLibrary("gnustl_shared");
		loadOptionalLibrary("ffmpeg-linphone");
		System.loadLibrary("bctoolbox");
		System.loadLibrary("ortp");
		System.loadLibrary("mediastreamer_base");
		System.loadLibrary("mediastreamer_voip");
		System.loadLibrary("linphone");
		Version.dumpCapabilities();
	}
162

163 164
    public OpenH264DownloadHelper createOpenH264DownloadHelper(Context context) {
		if (context == null) {
165
			new CoreException("Cannot create OpenH264DownloadHelper");
166
			return null;
167
		}
168
		return new OpenH264DownloadHelper(context);
169
	}
170 171 172

    @Override
    public native void setDebugMode(boolean enable, String tag);
173

Sylvain Berfini's avatar
Sylvain Berfini committed
174
    private native Core createCore(Factory factory, CoreListener listener, String configPath, String factoryConfigPath);
175 176
    @Override
    public Core createCore(CoreListener listener, String configPath, String factoryConfigPath) {
Sylvain Berfini's avatar
Sylvain Berfini committed
177
        return createCore(this, listener, configPath, factoryConfigPath);
178
    }
Sylvain Berfini's avatar
Sylvain Berfini committed
179 180 181 182
{{/isLinphoneFactory}}

{{#methods}}
    private native {{return_native}} {{name}}({{native_params}});
183
    @Override
184
    public {{return}} {{name}}({{params}}) {{#exception}}throws CoreException{{/exception}} {
185
        {{#exception}}int exceptionResult = {{/exception}}{{return_keyword}}{{#enumCast}}{{return}}.fromInt({{/enumCast}}{{#classCast}}({{return}}){{/classCast}}{{name}}(nativePtr{{native_params_impl}}){{#enumCast}}){{/enumCast}};{{#exception}}
186
        if (exceptionResult != 0) throw new CoreException("{{name}} returned value " + exceptionResult);{{/exception}}
Sylvain Berfini's avatar
Sylvain Berfini committed
187 188 189
    }

{{/methods}}
190 191 192 193 194 195 196
{{#isLinphoneCore}}
    private native org.linphone.mediastream.Factory getMediastreamerFactory(long nativePtr);
    public org.linphone.mediastream.Factory getMediastreamerFactory() {
        return getMediastreamerFactory(nativePtr);
    }

{{/isLinphoneCore}}
197
{{#isNotLinphoneFactory}}
198 199 200 201 202 203 204 205
    private native void unref(long ptr);
    protected void finalize() throws Throwable {
		if (nativePtr != 0) {
			unref(nativePtr);
			nativePtr = 0;
		}
		super.finalize();
	}
206
{{/isNotLinphoneFactory}}
207
    
208
    @Override
209 210 211 212
    public void setUserData(Object data) {
        userData = data;
    }

213
    @Override
214 215 216
    public Object getUserData() {
        return userData;
    }
Sylvain Berfini's avatar
Sylvain Berfini committed
217
}