]> git.sesse.net Git - vlc/blob - bindings/java/src/core-jni.cc
better args handling
[vlc] / bindings / java / src / core-jni.cc
1 /*****************************************************************************
2  * vlc-libvlc-jni.cc: JNI interface for vlc Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *          Philippe Morin <phmorin@free.fr>
8  *
9  * $Id: core-jni.cc 156 2006-08-01 09:23:01Z littlejohn $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /* These are a must*/
27 #include <jni.h>
28 #include <vlc/libvlc.h>
29
30 #include <stdio.h>  // for printf
31 #include <stdlib.h> // for calloc
32 #include <string.h> // for strcmp
33 #include <unistd.h> // for usleep
34
35 /* JVLC internal imports, generated by gcjh */
36 #include "../includes/JVLC.h"
37
38 #include <jawt.h>
39 #include <jawt_md.h>
40
41 #include "utils.h"
42
43
44 jlong getClassInstance (JNIEnv *env, jobject _this);
45
46 JNIEXPORT jlong JNICALL Java_org_videolan_jvlc_JVLC_createInstance (JNIEnv *env, jobject _this, jobjectArray args) {
47
48     long res;
49     int argc;
50     const char **argv;
51
52     libvlc_exception_t *exception = ( libvlc_exception_t * ) malloc( sizeof( libvlc_exception_t ) );
53
54     libvlc_exception_init( exception );
55   
56     argc = (int) env->GetArrayLength((jarray) args) + 1;
57     argv = (const char **) malloc(argc * sizeof(char*));
58
59     for (int i = 0; i < argc; i++) {
60         argv[i] = env->GetStringUTFChars((jstring) env->GetObjectArrayElement(args, i),
61                                          0
62         );
63     }
64
65     res = (long) libvlc_new(argc, (char**) argv, exception );
66
67     free( exception );
68  
69     return res;
70
71 }
72
73 JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1destroy (JNIEnv *env, jobject _this) 
74 {
75     long instance;
76     
77     instance = getClassInstance( env, _this );
78
79     libvlc_destroy( (libvlc_instance_t *) instance, NULL);
80
81     return;
82 }
83
84
85 /*
86  * Utility functions
87  */
88 jlong getClassInstance (JNIEnv *env, jobject _this) {
89     /* get the id field of object */
90     jclass    cls   = env->GetObjectClass(_this);
91     jmethodID mid   = env->GetMethodID(cls, "getInstance", "()J");
92     jlong     field = env->CallLongMethod(_this, mid);
93     return field;
94 }