Dharmaray Kundargi | cd196d3 | 2011-01-16 15:47:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <VideoEditorClasses.h> |
| 18 | #include <VideoEditorJava.h> |
| 19 | #include <VideoEditorLogging.h> |
| 20 | #include <VideoEditorOsal.h> |
| 21 | |
| 22 | extern "C" { |
| 23 | #include <M4OSA_CharStar.h> |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | void |
| 28 | videoEditJava_checkAndThrowIllegalArgumentException( |
| 29 | bool* pResult, |
| 30 | JNIEnv* pEnv, |
| 31 | bool condition, |
| 32 | const char* pMessage) |
| 33 | { |
| 34 | // Check if the previous action succeeded. |
| 35 | if (*pResult) |
| 36 | { |
| 37 | // Check if the condition is true. |
| 38 | if (condition) |
| 39 | { |
| 40 | // Log the exception. |
| 41 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA",\ |
| 42 | "videoEditJava_checkAndThrowIllegalArgumentException, %s", pMessage); |
| 43 | |
| 44 | // Reset the result flag. |
| 45 | (*pResult) = false; |
| 46 | |
| 47 | // Throw an exception. |
| 48 | jniThrowException(pEnv, "java/lang/IllegalArgumentException", pMessage); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | videoEditJava_checkAndThrowRuntimeException( |
| 55 | bool* pResult, |
| 56 | JNIEnv* pEnv, |
| 57 | bool condition, |
| 58 | M4OSA_ERR result) |
| 59 | { |
| 60 | const char* pMessage = NULL; |
| 61 | |
| 62 | // Check if the previous action succeeded. |
| 63 | if (*pResult) |
| 64 | { |
| 65 | // Check if the condition is true. |
| 66 | if (condition) |
| 67 | { |
| 68 | // Get the error string. |
| 69 | pMessage = videoEditJava_getErrorName(result); |
| 70 | |
| 71 | // Log the exception. |
| 72 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 73 | "videoEditJava_checkAndThrowRuntimeException, %s", pMessage); |
| 74 | |
| 75 | // Reset the result flag. |
| 76 | (*pResult) = false; |
| 77 | |
| 78 | // Throw an exception. |
| 79 | jniThrowException(pEnv, "java/lang/RuntimeException", pMessage); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | videoEditJava_checkAndThrowIllegalStateException( |
| 86 | bool* pResult, |
| 87 | JNIEnv* pEnv, |
| 88 | bool condition, |
| 89 | const char* pMessage) |
| 90 | { |
| 91 | // Check if the previous action succeeded. |
| 92 | if (*pResult) |
| 93 | { |
| 94 | // Check if the condition is true. |
| 95 | if (condition) |
| 96 | { |
| 97 | // Log the exception. |
| 98 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 99 | "videoEditJava_checkAndThrowIllegalStateException, %s", pMessage); |
| 100 | |
| 101 | // Reset the result flag. |
| 102 | (*pResult) = false; |
| 103 | |
| 104 | // Throw an exception. |
| 105 | jniThrowException(pEnv, "java/lang/IllegalStateException", pMessage); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | videoEditJava_getClass( |
| 112 | bool* pResult, |
| 113 | JNIEnv* pEnv, |
| 114 | const char* pName, |
| 115 | jclass* pClazz) |
| 116 | { |
| 117 | // Only look for the class if locating the previous action succeeded. |
| 118 | if (*pResult) |
| 119 | { |
| 120 | // Log the function call. |
| 121 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 122 | "videoEditJava_getClass(%s)", pName); |
| 123 | |
| 124 | // Look up the class. |
| 125 | jclass clazz = pEnv->FindClass(pName); |
| 126 | |
| 127 | // Clear any resulting exceptions. |
| 128 | pEnv->ExceptionClear(); |
| 129 | |
| 130 | // Check if the class could be located. |
| 131 | if (NULL != clazz) |
| 132 | { |
| 133 | // Return the class. |
| 134 | (*pClazz) = clazz; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | // Reset the result flag. |
| 139 | (*pResult) = false; |
| 140 | |
| 141 | // Log the error. |
| 142 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 143 | "videoEditJava_getClass, error: unable to locate class %s", pName); |
| 144 | |
| 145 | // Throw an exception. |
| 146 | jniThrowException(pEnv, "java/lang/ClassNotFoundException", |
| 147 | "unable to locate class"); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void |
| 153 | videoEditJava_getMethodId( |
| 154 | bool* pResult, |
| 155 | JNIEnv* pEnv, |
| 156 | jclass clazz, |
| 157 | const char* pName, |
| 158 | const char* pType, |
| 159 | jmethodID* pMethodId) |
| 160 | { |
| 161 | // Only look for the class if locating the previous action succeeded. |
| 162 | if (*pResult) |
| 163 | { |
| 164 | // Log the function call. |
| 165 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 166 | "videoEditJava_getMethodId(%s,%s)", pName, pType); |
| 167 | |
| 168 | // Look up the method id. |
| 169 | jmethodID methodId = pEnv->GetMethodID(clazz, pName, pType); |
| 170 | |
| 171 | // Clear any resulting exceptions. |
| 172 | pEnv->ExceptionClear(); |
| 173 | |
| 174 | // Check if the method could be located. |
| 175 | if (NULL != methodId) |
| 176 | { |
| 177 | // Return the method id. |
| 178 | (*pMethodId) = methodId; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | // Reset the result flag. |
| 183 | (*pResult) = false; |
| 184 | |
| 185 | // Log the error. |
| 186 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 187 | "videoEditJava_getMethodId, error: unable to locate method %s with type %s", |
| 188 | pName, pType); |
| 189 | |
| 190 | // Throw an exception. |
| 191 | jniThrowException(pEnv, "java/lang/NoSuchMethodException", "unable to locate method"); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | videoEditJava_getFieldId( |
| 198 | bool* pResult, |
| 199 | JNIEnv* pEnv, |
| 200 | jclass clazz, |
| 201 | const char* pName, |
| 202 | const char* pType, |
| 203 | jfieldID* pFieldId) |
| 204 | { |
| 205 | // Only look for the class if locating the previous action succeeded. |
| 206 | if (*pResult) |
| 207 | { |
| 208 | // Log the function call. |
| 209 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 210 | "videoEditJava_getFieldId(%s,%s)", pName, pType); |
| 211 | |
| 212 | // Look up the field id. |
| 213 | jfieldID fieldId = pEnv->GetFieldID(clazz, pName, pType); |
| 214 | |
| 215 | // Clear any resulting exceptions. |
| 216 | pEnv->ExceptionClear(); |
| 217 | |
| 218 | // Check if the field could be located. |
| 219 | if (NULL != fieldId) |
| 220 | { |
| 221 | // Return the field id. |
| 222 | (*pFieldId) = fieldId; |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | // Reset the result flag. |
| 227 | (*pResult) = false; |
| 228 | |
| 229 | // Log the error. |
| 230 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 231 | "videoEditJava_getFieldId, error: unable to locate field %s with type %s", |
| 232 | pName, pType); |
| 233 | |
| 234 | // Throw an exception. |
| 235 | jniThrowException(pEnv, "java/lang/NoSuchFieldException", "unable to locate field"); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | void |
| 241 | videoEditJava_getObject( |
| 242 | bool* pResult, |
| 243 | JNIEnv* pEnv, |
| 244 | jobject object, |
| 245 | jfieldID objectFieldId, |
| 246 | jobject* pObject) |
| 247 | { |
| 248 | // Only retrieve the array object and size if the previous action succeeded. |
| 249 | if (*pResult) |
| 250 | { |
| 251 | // Log the function call. |
| 252 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 253 | "videoEditJava_getObject()"); |
| 254 | |
| 255 | // Retrieve the object. |
| 256 | (*pObject) = pEnv->GetObjectField(object, objectFieldId); |
| 257 | |
| 258 | // Clear any resulting exceptions. |
| 259 | pEnv->ExceptionClear(); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | void |
| 264 | videoEditJava_getArray( |
| 265 | bool* pResult, |
| 266 | JNIEnv* pEnv, |
| 267 | jobject object, |
| 268 | jfieldID arrayFieldId, |
| 269 | jobjectArray* pArray, |
| 270 | jsize* pArraySize) |
| 271 | { |
| 272 | // Only retrieve the array object and size if the previous action succeeded. |
| 273 | if (*pResult) |
| 274 | { |
| 275 | // Log the function call. |
| 276 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", "videoEditJava_getArray()"); |
| 277 | |
| 278 | // Retrieve the array object. |
| 279 | jobjectArray array = (jobjectArray)pEnv->GetObjectField(object, arrayFieldId); |
| 280 | jsize arraySize = 0; |
| 281 | |
| 282 | // Clear any resulting exceptions. |
| 283 | pEnv->ExceptionClear(); |
| 284 | |
| 285 | // Check if the array could be retrieved. |
| 286 | if (NULL != array) |
| 287 | { |
| 288 | // Retrieve the array size. |
| 289 | arraySize = pEnv->GetArrayLength(array); |
| 290 | } |
| 291 | |
| 292 | // Return the array and its size. |
| 293 | (*pArray) = array; |
| 294 | (*pArraySize) = arraySize; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void* |
| 299 | videoEditJava_getString( |
| 300 | bool* pResult, |
| 301 | JNIEnv* pEnv, |
| 302 | jobject object, |
| 303 | jfieldID stringFieldId, |
| 304 | M4OSA_UInt32* pLength) |
| 305 | { |
| 306 | void* pString = M4OSA_NULL; |
| 307 | jstring string = NULL; |
| 308 | M4OSA_UInt32 length = 0; |
| 309 | M4OSA_Char* pLocal = M4OSA_NULL; |
| 310 | M4OSA_ERR result = M4NO_ERROR; |
| 311 | |
| 312 | // Check if the previous action succeeded. |
| 313 | if (*pResult) |
| 314 | { |
| 315 | // Log the function call. |
| 316 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", "videoEditJava_getString()"); |
| 317 | |
| 318 | // Check if an object containing a string was specified. |
| 319 | if (NULL != stringFieldId) |
| 320 | { |
| 321 | // Retrieve the string object. |
| 322 | string = (jstring)pEnv->GetObjectField(object, stringFieldId); |
| 323 | |
| 324 | // Clear any resulting exceptions. |
| 325 | pEnv->ExceptionClear(); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | // The string itself was specified. |
| 330 | string = (jstring)object; |
| 331 | } |
| 332 | |
| 333 | // Check if the string could be retrieved. |
| 334 | if (NULL != string) |
| 335 | { |
| 336 | // Get a local copy of the string. |
| 337 | pLocal = (M4OSA_Char*)pEnv->GetStringUTFChars(string, M4OSA_NULL); |
| 338 | if (M4OSA_NULL != pLocal) |
| 339 | { |
| 340 | // Determine the length of the path |
| 341 | // (add one extra character for the zero terminator). |
Dheeraj Sharma | 7743fa6 | 2011-04-12 14:53:58 -0700 | [diff] [blame] | 342 | length = strlen((const char *)pLocal) + 1; |
Dharmaray Kundargi | cd196d3 | 2011-01-16 15:47:16 -0800 | [diff] [blame] | 343 | |
| 344 | // Allocate memory for the string. |
| 345 | pString = videoEditOsal_alloc(pResult, pEnv, length, "String"); |
| 346 | if (*pResult) |
| 347 | { |
| 348 | // Copy the string. |
| 349 | result = M4OSA_chrNCopy((M4OSA_Char*)pString, pLocal, length); |
| 350 | |
| 351 | // Check if the copy succeeded. |
| 352 | videoEditJava_checkAndThrowRuntimeException(pResult, pEnv, |
| 353 | (M4NO_ERROR != result), result); |
| 354 | |
| 355 | // Check if the string could not be copied. |
| 356 | if (!(*pResult)) |
| 357 | { |
| 358 | // Free the allocated memory. |
| 359 | videoEditOsal_free(pString); |
| 360 | pString = M4OSA_NULL; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | // Release the local copy of the string. |
| 365 | pEnv->ReleaseStringUTFChars(string, (const char *)pLocal); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | // Check if the string was empty or could be copied. |
| 370 | if (*pResult) |
| 371 | { |
| 372 | // Check if the length was requested. |
| 373 | if (M4OSA_NULL != pLength) |
| 374 | { |
| 375 | // Return the length. |
| 376 | (*pLength) = length; |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // Return the string. |
| 382 | return(pString); |
| 383 | } |
| 384 | |
| 385 | void |
| 386 | videoEditJava_getStaticIntField( |
| 387 | bool* pResult, |
| 388 | JNIEnv* pEnv, |
| 389 | jclass clazz, |
| 390 | const char* pName, |
| 391 | int* pValue) |
| 392 | { |
| 393 | // Only look for the class if locating the previous action succeeded. |
| 394 | if (*pResult) |
| 395 | { |
| 396 | // Log the function call. |
| 397 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 398 | "videoEditJava_getStaticIntField(%s)", pName); |
| 399 | |
| 400 | // Look up the field id. |
| 401 | jfieldID fieldId = pEnv->GetStaticFieldID(clazz, pName, "I"); |
| 402 | |
| 403 | // Clear any resulting exceptions. |
| 404 | pEnv->ExceptionClear(); |
| 405 | |
| 406 | // Check if the field could be located. |
| 407 | if (NULL != fieldId) |
| 408 | { |
| 409 | // Retrieve the field value. |
| 410 | (*pValue) = pEnv->GetStaticIntField(clazz, fieldId); |
| 411 | |
| 412 | // Log the value. |
Dharmaray Kundargi | 4e70320 | 2011-01-29 20:48:05 -0800 | [diff] [blame] | 413 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
Dharmaray Kundargi | cd196d3 | 2011-01-16 15:47:16 -0800 | [diff] [blame] | 414 | "videoEditJava_getStaticIntField, %s = %d", pName, (*pValue)); |
| 415 | } |
| 416 | else |
| 417 | { |
| 418 | // Reset the result flag. |
| 419 | (*pResult) = false; |
| 420 | |
| 421 | // Log the error. |
| 422 | VIDEOEDIT_LOG_EXCEPTION(ANDROID_LOG_ERROR, "VIDEO_EDITOR_JAVA", |
| 423 | "videoEditJava_getStaticIntField, error: unable to locate field %s", pName); |
| 424 | |
| 425 | // Throw an exception. |
| 426 | jniThrowException(pEnv, "java/lang/NoSuchFieldException", |
| 427 | "unable to locate static field"); |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | void |
| 433 | videoEditJava_initConstantClass( |
| 434 | bool* pResult, |
| 435 | JNIEnv* pEnv, |
| 436 | VideoEditJava_ConstantsClass* pClass) |
| 437 | { |
| 438 | bool gotten = true; |
| 439 | jclass clazz = NULL; |
| 440 | int index = 0; |
| 441 | |
| 442 | // Check if the previous action succeeded. |
| 443 | if (*pResult) |
| 444 | { |
| 445 | // Log the function call. |
| 446 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 447 | "videoEditJava_initConstantClass(%s)", pClass->pName); |
| 448 | |
| 449 | // Only initialize the class once. |
| 450 | if (!pClass->initialized) |
| 451 | { |
| 452 | // Look up the class. |
| 453 | videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz); |
| 454 | |
| 455 | // Loop over the constants. |
| 456 | for (index = 0; index < pClass->count; index++) |
| 457 | { |
| 458 | // Look up the constant. |
| 459 | videoEditJava_getStaticIntField(pResult, pEnv, clazz, |
| 460 | pClass->pConstants[index].pName, |
| 461 | &pClass->pConstants[index].java); |
| 462 | } |
| 463 | |
| 464 | // Check if all constants could be located. |
| 465 | if (*pResult) |
| 466 | { |
| 467 | // Set the initialized flag. |
| 468 | pClass->initialized = true; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | const char* |
| 475 | videoEditJava_getConstantClassName( |
| 476 | const VideoEditJava_ConstantsClass* pClass, |
| 477 | int value, |
| 478 | VideoEditJava_UnknownConstant unknown) |
| 479 | { |
| 480 | const char* pName = M4OSA_NULL; |
| 481 | int index = 0; |
| 482 | |
| 483 | // Loop over the list with constants. |
| 484 | for (index = 0; |
| 485 | ((M4OSA_NULL == pName) && (index < pClass->count)); |
| 486 | index++) |
| 487 | { |
| 488 | // Check if the specified value matches the c value of the constant. |
| 489 | if (value == pClass->pConstants[index].c) |
| 490 | { |
| 491 | // Set the name. |
| 492 | pName = pClass->pConstants[index].pName; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Check if no constant was found. |
| 497 | if (M4OSA_NULL == pName) |
| 498 | { |
| 499 | // Check if a function was specified to handle this case. |
| 500 | if (M4OSA_NULL != unknown) |
| 501 | { |
| 502 | // Pass the constant to the specified unknown function. |
| 503 | pName = unknown(value); |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | // Set the description to a default value. |
| 508 | pName = "<unknown>"; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Return the result. |
| 513 | return(pName); |
| 514 | } |
| 515 | |
| 516 | const char* |
| 517 | videoEditJava_getConstantClassString( |
| 518 | const VideoEditJava_ConstantsClass* pClass, |
| 519 | int value, |
| 520 | VideoEditJava_UnknownConstant unknown) |
| 521 | { |
| 522 | const char* pString = M4OSA_NULL; |
| 523 | int index = 0; |
| 524 | |
| 525 | // Loop over the list with constants. |
| 526 | for (index = 0; |
| 527 | ((M4OSA_NULL == pString) && (index < pClass->count)); |
| 528 | index++) |
| 529 | { |
| 530 | // Check if the specified value matches the c value of the constant. |
| 531 | if (value == pClass->pConstants[index].c) |
| 532 | { |
| 533 | // Set the description. |
| 534 | pString = pClass->pConstants[index].pDescription; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // Check if no constant was found. |
| 539 | if (M4OSA_NULL == pString) |
| 540 | { |
| 541 | // Check if a function was specified to handle this case. |
| 542 | if (M4OSA_NULL != unknown) |
| 543 | { |
| 544 | // Pass the constant to the specified unknown function. |
| 545 | pString = unknown(value); |
| 546 | } |
| 547 | else |
| 548 | { |
| 549 | // Set the description to a default value. |
| 550 | pString = "<unknown>"; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // Return the result. |
| 555 | return(pString); |
| 556 | } |
| 557 | |
| 558 | int |
| 559 | videoEditJava_getConstantClassJavaToC( |
| 560 | bool* pResult, |
| 561 | const VideoEditJava_ConstantsClass* pClass, |
| 562 | int value) |
| 563 | { |
| 564 | bool gotten = false; |
| 565 | int index = 0; |
| 566 | |
| 567 | // Check if the previous action succeeded. |
| 568 | if (*pResult) |
| 569 | { |
| 570 | // Loop over the list with constants. |
| 571 | for (index = 0; ((!gotten) && (index < pClass->count)); index++) |
| 572 | { |
| 573 | // Check if the specified value matches the java value of the constant. |
| 574 | if (value == pClass->pConstants[index].java) |
| 575 | { |
| 576 | // Set the value to the c value. |
| 577 | value = pClass->pConstants[index].c; |
| 578 | |
| 579 | // Set the gotten flag. |
| 580 | gotten = true; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | // Check if the value was not found. |
| 585 | if (!gotten) |
| 586 | { |
| 587 | (*pResult) = false; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | // Return the translated value. |
| 592 | return(value); |
| 593 | } |
| 594 | |
| 595 | int |
| 596 | videoEditJava_getConstantClassJavaToC( |
| 597 | bool* pResult, |
| 598 | const VideoEditJava_ConstantsClass* pClass, |
| 599 | int value, |
| 600 | int unknown) |
| 601 | { |
| 602 | bool gotten = false; |
| 603 | int index = 0; |
| 604 | |
| 605 | // Check if the previous action succeeded. |
| 606 | if (*pResult) |
| 607 | { |
| 608 | // Loop over the list with constants. |
| 609 | for (index = 0; ((!gotten) && (index < pClass->count)); index++) |
| 610 | { |
| 611 | // Check if the specified value matches the java value of the constant. |
| 612 | if (value == pClass->pConstants[index].java) |
| 613 | { |
| 614 | // Set the value to the c value. |
| 615 | value = pClass->pConstants[index].c; |
| 616 | |
| 617 | // Set the gotten flag. |
| 618 | gotten = true; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | // If the constant was not found, look for the specified unknown. |
| 623 | if (!gotten) |
| 624 | { |
| 625 | // Set the value to the c value. |
| 626 | value = unknown; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | // Return the translated value. |
| 631 | return(value); |
| 632 | } |
| 633 | |
| 634 | int |
| 635 | videoEditJava_getConstantClassCToJava( |
| 636 | const VideoEditJava_ConstantsClass* pClass, |
| 637 | int value) |
| 638 | { |
| 639 | bool gotten = false; |
| 640 | int index = 0; |
| 641 | |
| 642 | // Loop over the list with constants. |
| 643 | for (index = 0; ((!gotten) && (index < pClass->count)); index++) |
| 644 | { |
| 645 | // Check if the specified value matches the c value of the constant. |
| 646 | if (value == pClass->pConstants[index].c) |
| 647 | { |
| 648 | // Set the value to the java value. |
| 649 | value = pClass->pConstants[index].java; |
| 650 | |
| 651 | // Set the gotten flag. |
| 652 | gotten = true; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | // Return the translated value. |
| 657 | return(value); |
| 658 | } |
| 659 | |
| 660 | int |
| 661 | videoEditJava_getConstantClassCToJava( |
| 662 | const VideoEditJava_ConstantsClass* pClass, |
| 663 | int value, |
| 664 | int unknown) |
| 665 | { |
| 666 | bool gotten = false; |
| 667 | int index = 0; |
| 668 | |
| 669 | // Loop over the list with constants. |
| 670 | for (index = 0; ((!gotten) && (index < pClass->count)); index++) |
| 671 | { |
| 672 | // Check if the specified value matches the c value of the constant. |
| 673 | if (value == pClass->pConstants[index].c) |
| 674 | { |
| 675 | // Set the value to the java value. |
| 676 | value = pClass->pConstants[index].java; |
| 677 | |
| 678 | // Set the gotten flag. |
| 679 | gotten = true; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | // If the constant was not found, look for the specified unknown. |
| 684 | if (!gotten) |
| 685 | { |
| 686 | // Loop over the list with constants. |
| 687 | for (index = 0; ((!gotten) && (index < pClass->count)); index++) |
| 688 | { |
| 689 | // Check if the specified value matches the java value of the constant. |
| 690 | if (unknown == pClass->pConstants[index].c) |
| 691 | { |
| 692 | // Set the value to the c value. |
| 693 | value = pClass->pConstants[index].java; |
| 694 | |
| 695 | // Set the gotten flag. |
| 696 | gotten = true; |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // Return the translated value. |
| 702 | return(value); |
| 703 | } |
| 704 | |
| 705 | void |
| 706 | videoEditJava_initFieldClass( |
| 707 | bool* pResult, |
| 708 | JNIEnv* pEnv, |
| 709 | VideoEditJava_FieldsClass* pClass) |
| 710 | { |
| 711 | bool gotten = true; |
| 712 | jclass clazz = NULL; |
| 713 | int index = 0; |
| 714 | |
| 715 | // Check if the previous action succeeded. |
| 716 | if (*pResult) |
| 717 | { |
| 718 | // Log the function call. |
| 719 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 720 | "videoEditJava_initFieldClass(%s)", pClass->pName); |
| 721 | |
| 722 | // Only initialize the class once. |
| 723 | if (!pClass->initialized) |
| 724 | { |
| 725 | // Look up the class. |
| 726 | videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz); |
| 727 | |
| 728 | // Loop over the fields. |
| 729 | for (index = 0; index < pClass->count; index++) |
| 730 | { |
| 731 | // Look up the field id. |
| 732 | videoEditJava_getFieldId( |
| 733 | pResult, |
| 734 | pEnv, |
| 735 | clazz, |
| 736 | pClass->pFields[index].pName, |
| 737 | pClass->pFields[index].pType, |
| 738 | &pClass->pFields[index].fieldId); |
| 739 | } |
| 740 | |
| 741 | // Check if all fields could be located. |
| 742 | if (*pResult) |
| 743 | { |
| 744 | // Set the initialized flag. |
| 745 | pClass->initialized = true; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | void |
| 752 | videoEditJava_fieldClassClass( |
| 753 | bool* pResult, |
| 754 | JNIEnv* pEnv, |
| 755 | const VideoEditJava_FieldsClass* pClass, |
| 756 | jclass* pClazz) |
| 757 | { |
| 758 | // Check if the previous action succeeded. |
| 759 | if (*pResult) |
| 760 | { |
| 761 | // Check if the class is initialized. |
| 762 | videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized), |
| 763 | "field class not initialized"); |
| 764 | |
| 765 | // Get the class. |
| 766 | videoEditJava_getClass(pResult, pEnv, pClass->pName, pClazz); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | void |
| 771 | videoEditJava_fieldClassFieldIds( |
| 772 | bool* pResult, |
| 773 | JNIEnv* pEnv, |
| 774 | const VideoEditJava_FieldsClass* pClass, |
| 775 | int count, |
| 776 | VideoEditJava_FieldIds* pIds) |
| 777 | { |
| 778 | int index = 0; |
| 779 | |
| 780 | // Check if the previous action succeeded. |
| 781 | if (*pResult) |
| 782 | { |
| 783 | // Check if the class is initialized. |
| 784 | videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized), |
| 785 | "field class not initialized"); |
| 786 | |
| 787 | // Check if the number of fields matches. |
| 788 | videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, |
| 789 | (pClass->count != count), |
| 790 | "field class type mismatch"); |
| 791 | |
| 792 | // Check if the class and object are valid. |
| 793 | if (*pResult) |
| 794 | { |
| 795 | // Loop over the class fields. |
| 796 | for (index = 0; index < count; index++) |
| 797 | { |
| 798 | // Copy the field ids. |
| 799 | pIds->fieldIds[index] = pClass->pFields[index].fieldId; |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | void |
| 806 | videoEditJava_initMethodClass( |
| 807 | bool* pResult, |
| 808 | JNIEnv* pEnv, |
| 809 | VideoEditJava_MethodsClass* pClass) |
| 810 | { |
| 811 | bool gotten = true; |
| 812 | jclass clazz = NULL; |
| 813 | int index = 0; |
| 814 | |
| 815 | // Check if the previous action succeeded. |
| 816 | if (*pResult) |
| 817 | { |
| 818 | // Log the function call. |
| 819 | VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_JAVA", |
| 820 | "videoEditJava_initMethodClass(%s)", pClass->pName); |
| 821 | |
| 822 | // Only initialize the class once. |
| 823 | if (!pClass->initialized) |
| 824 | { |
| 825 | // Look up the class. |
| 826 | videoEditJava_getClass(pResult, pEnv, pClass->pName, &clazz); |
| 827 | |
| 828 | // Loop over the methods. |
| 829 | for (index = 0; index < pClass->count; index++) |
| 830 | { |
| 831 | // Look up the method id. |
| 832 | videoEditJava_getMethodId( |
| 833 | pResult, |
| 834 | pEnv, |
| 835 | clazz, |
| 836 | pClass->pMethods[index].pName, |
| 837 | pClass->pMethods[index].pType, |
| 838 | &pClass->pMethods[index].methodId); |
| 839 | } |
| 840 | |
| 841 | // Check if all methods could be located. |
| 842 | if (*pResult) |
| 843 | { |
| 844 | // Set the initialized flag. |
| 845 | pClass->initialized = true; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | void |
| 852 | videoEditJava_methodClassMethodIds( |
| 853 | bool* pResult, |
| 854 | JNIEnv* pEnv, |
| 855 | const VideoEditJava_MethodsClass* pClass, |
| 856 | int count, |
| 857 | VideoEditJava_MethodIds* pIds) |
| 858 | { |
| 859 | int index = 0; |
| 860 | |
| 861 | // Check if the previous action succeeded. |
| 862 | if (*pResult) |
| 863 | { |
| 864 | // Check if the class is initialized. |
| 865 | videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv, (!pClass->initialized), |
| 866 | "method class not initialized"); |
| 867 | |
| 868 | // Check if the number of methods matches. |
| 869 | videoEditJava_checkAndThrowIllegalArgumentException(pResult, pEnv,\ |
| 870 | (pClass->count != count), |
| 871 | "method class type mismatch"); |
| 872 | |
| 873 | // Check if the class and object are valid. |
| 874 | if (*pResult) |
| 875 | { |
| 876 | // Loop over the class methods. |
| 877 | for (index = 0; index < count; index++) |
| 878 | { |
| 879 | // Copy the method ids. |
| 880 | pIds->methodIds[index] = pClass->pMethods[index].methodId; |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | |