OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Native.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #include <jni.h>
22 #include <android/log.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 
26 #define LOG_TAG "libNative"
27 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
28 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
29 
30 static int PRIVATE_FILE_SIZE = 82;
31 static int PUBLIC_FILE_SIZE = 105;
32 static int CACHE_FILE_SIZE = 146;
33 
34 extern "C"
35 {
36  /* [initFunctionNativePrototype] */
38  JNIEnv * env, jobject obj, jstring privateFile, jstring publicFile, jstring cacheFile);
39  /* [initFunctionNativePrototype] */
40 };
41 
42 /* [readFile] */
43 void readFile(const char * fileName, int size)
44 {
45  FILE * file = fopen(fileName, "r");
46  char * fileContent =(char *) malloc(sizeof(char) * size);
47 
48  if(file == NULL)
49  {
50  LOGE("Failure to load the file");
51  return;
52  }
53  fread(fileContent, size, 1, file);
54  LOGI("%s",fileContent);
55  free(fileContent);
56  fclose(file);
57 }
58 /* [readFile] */
59 
60 /*[nativeInitFunction]*/
62  JNIEnv * env, jobject obj, jstring privateFile, jstring publicFile, jstring cacheFile )
63 {
64  const char* privateFileC = env->GetStringUTFChars(privateFile, NULL);
65  const char* publicFileC = env->GetStringUTFChars(publicFile, NULL);
66  const char* cacheFileC = env->GetStringUTFChars(cacheFile, NULL);
67 
68  readFile(privateFileC, PRIVATE_FILE_SIZE);
69  readFile(publicFileC, PUBLIC_FILE_SIZE);
70  readFile(cacheFileC, CACHE_FILE_SIZE);
71 
72  env->ReleaseStringUTFChars(privateFile, privateFileC);
73  env->ReleaseStringUTFChars(publicFile, publicFileC);
74  env->ReleaseStringUTFChars(cacheFile, cacheFileC);
75 }
76 /*[nativeInitFunction]*/
#define LOGE(...)
Definition: Native.cpp:28
#define LOGI(...)
Definition: Native.cpp:27
static int PUBLIC_FILE_SIZE
Definition: Native.cpp:31
static int CACHE_FILE_SIZE
Definition: Native.cpp:32
JNIEXPORT void JNICALL Java_com_arm_malideveloper_openglessdk_fileloading_NativeLibrary_init(JNIEnv *env, jobject obj, jstring privateFile, jstring publicFile, jstring cacheFile)
Definition: Native.cpp:61
static int PRIVATE_FILE_SIZE
Definition: Native.cpp:30
GLenum GLuint GLintptr GLsizeiptr size
Definition: gl2ext.h:629
void readFile(const char *fileName, int size)
Definition: Native.cpp:43