/* * Class: com_example_pmxota_OtaLoadJNI * Method: deconnectClient * Signature: ()I */ JNIEXPORT jint JNICALL Java_com_example_pmxota_OtaLoadJNI_deconnectClient(JNIEnv *env, jobject obj) { // Remove the HID service from sdp server //sdp_remove(); // Kill hid interrupt and control channels quit_thread(); // Finish bt sockets quit_serv(); return 0; }
void MDLHandleProcess(MDL_HANDLER_ARG* inputVolatile) { MDL_HANDLER_ARG input; memcpy(&input, inputVolatile, sizeof(MDL_HANDLER_ARG)); free(inputVolatile); if(input.todoList == NULL || input.todoList->datas == NULL) { *(input.currentState) = MDL_CODE_INTERNAL_ERROR; MDLUpdateIcons(input.selfCode, input.todoList); quit_thread(0); } void **listDL; size_t *listSizeDL; PROXY_DATA_LOADED todoListTmp; DATA_MOD_DL argument; bool isTome = input.todoList->listChapitreOfTome != NULL, DLAborted; uint posTomeInStruct = ERROR_CHECK, nbElemToInstall = 0, nbElement = isTome ? input.todoList->nbElemList : 1, selfCode = input.selfCode; bool didElemGotDownloaded[nbElement]; argument.todoList = &todoListTmp; todoListTmp.datas = input.todoList->datas; listDL = calloc(nbElement, sizeof(void*)); listSizeDL = calloc(nbElement, sizeof(size_t)); if(isTome && todoListTmp.datas->volumesFull != NULL) //We find the tome position { posTomeInStruct = getPosForID(*todoListTmp.datas, false, input.todoList->identifier); if(posTomeInStruct == UINT_MAX) posTomeInStruct = ERROR_CHECK; } if(listDL == NULL || listSizeDL == NULL) { free(listDL); free(listSizeDL); *(input.currentState) = MDL_CODE_INTERNAL_ERROR; MDLUpdateIcons(selfCode, input.todoList); quit_thread(0); } *(input.currentState) = MDL_CODE_DL; MDLUpdateIcons(selfCode, input.todoList); for(uint i = 0; i < nbElement; i++) { didElemGotDownloaded[i] = false; todoListTmp.listChapitreOfTome = NULL; if(!isTome) { todoListTmp.chapitre = input.todoList->identifier; todoListTmp.subFolder = false; todoListTmp.partOfTome = INVALID_VALUE; todoListTmp.tomeName = NULL; } else { todoListTmp.tomeName = input.todoList->tomeName; todoListTmp.chapitre = input.todoList->listChapitreOfTome[i].ID; todoListTmp.subFolder = input.todoList->listChapitreOfTome[i].isPrivate; todoListTmp.partOfTome = input.todoList->identifier; } todoListTmp.rowViewResponsible = &input.todoList->rowViewResponsible; todoListTmp.curlHandler = &input.todoList->curlHandler; todoListTmp.downloadSuspended = &input.todoList->downloadSuspended; todoListTmp.metadata = &input.todoList->metadata; switch (MDL_isAlreadyInstalled(*todoListTmp.datas, todoListTmp.subFolder, todoListTmp.chapitre, &posTomeInStruct)) { case NOT_INSTALLED: { didElemGotDownloaded[i] = true; argument.buf = NULL; argument.length = 0; if(MDLTelechargement(&argument, i, nbElement)) { if(i + 1 == nbElement) *(input.currentState) = nbElemToInstall ? MDL_CODE_DL_OVER : MDL_CODE_ERROR_DL; } else if(quit) { *(input.currentState) = MDL_CODE_DEFAULT; } else { listDL[i] = argument.buf; listSizeDL[i] = argument.length; nbElemToInstall++; if(i + 1 == nbElement) *(input.currentState) = MDL_CODE_DL_OVER; } break; } case ALTERNATIVE_INSTALLED: //Le chapitre existe et à été installé par un tome { if(!isTome && posTomeInStruct != ERROR_CHECK) //chapitre, il va falloir le copier ailleurs { char oldPath[2*LENGTH_PROJECT_NAME + 384], newPath[2*LENGTH_PROJECT_NAME + 256], *encodedPath = getPathForProject(*todoListTmp.datas); if(encodedPath == NULL) continue; if(todoListTmp.chapitre % 10) { snprintf(oldPath, sizeof(oldPath), PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"VOLUME_PRESHARED_DIR"/"CHAPTER_PREFIX"%u.%u", encodedPath, todoListTmp.datas->volumesFull[posTomeInStruct].ID, todoListTmp.chapitre / 10, todoListTmp.chapitre % 10); snprintf(newPath, sizeof(newPath), PROJECT_ROOT"%s/"CHAPTER_PREFIX"%u.%u", encodedPath, todoListTmp.chapitre / 10, todoListTmp.chapitre % 10); } else { snprintf(oldPath, sizeof(oldPath), PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"VOLUME_PRESHARED_DIR"/"CHAPTER_PREFIX"%u", encodedPath, todoListTmp.datas->volumesFull[posTomeInStruct].ID, todoListTmp.chapitre / 10); snprintf(newPath, sizeof(newPath), PROJECT_ROOT"%s/"CHAPTER_PREFIX"%u", encodedPath, todoListTmp.chapitre / 10); } free(encodedPath); rename(oldPath, newPath); MDL_createSharedFile(*todoListTmp.datas, todoListTmp.chapitre, posTomeInStruct, true); } if(i + 1 == nbElement && *(input.currentState) == MDL_CODE_DL) { *(input.currentState) = nbElemToInstall ? MDL_CODE_DL_OVER : MDL_CODE_INSTALL_OVER; } break; } case ALREADY_INSTALLED: //Le chapitre est déjà installé indépendament { if(isTome) { MDL_createSharedFile(*todoListTmp.datas, todoListTmp.chapitre, posTomeInStruct, true); } if(i + 1 == nbElement && *(input.currentState) == MDL_CODE_DL) { *(input.currentState) = nbElemToInstall ? MDL_CODE_DL_OVER : MDL_CODE_INSTALL_OVER; } break; } } } DLAborted = (input.todoList->downloadSuspended & DLSTATUS_ABORT) != 0; if(!DLAborted) { #if TARGET_OS_IPHONE MDLUpdateIcons(selfCode, input.todoList); #endif MDLDownloadOver(false); } else *(input.currentState) = MDL_CODE_ABORTED; if(!DLAborted && nbElemToInstall) //On lance l'installation { int error = 0; if(!MDLStartNextInstallation()) //Si le controlleur central s'est arrêté, dans le cas où on est les derniers *(input.currentState) = MDL_CODE_INSTALL; MDLUpdateIcons(input.selfCode, input.todoList); MUTEX_LOCK(installSharedMemoryReadWrite); while(*(input.currentState) != MDL_CODE_INSTALL) { MUTEX_UNLOCK(installSharedMemoryReadWrite); usleep(25000); MUTEX_LOCK(installSharedMemoryReadWrite); } MUTEX_UNLOCK(installSharedMemoryReadWrite); for(uint i = 0; i < nbElement; i++) { if(didElemGotDownloaded[i] && (listDL[i] == NULL || !MDLInstallation(listDL[i], listSizeDL[i], input.todoList->datas, isTome ? input.todoList->listChapitreOfTome[i].ID : input.todoList->identifier, isTome ? input.todoList->identifier : INVALID_VALUE, isTome ? input.todoList->listChapitreOfTome[i].isPrivate : false, (input.todoList->listChapitreOfTome != NULL && i == nbElement-1)) ) ) { error++; } if(listDL[i] != NULL) { free(((DATA_DL_OBFS*) listDL[i])->data); free(((DATA_DL_OBFS*) listDL[i])->mask); free(listDL[i]); } } if(error) *(input.currentState) = MDL_CODE_ERROR_INSTALL; else { *(input.currentState) = MDL_CODE_INSTALL_OVER; setInstalled(input.todoList->datas->cacheDBID); addRecentEntry(*(input.todoList->datas), true); MDLInstallOver(*input.todoList->datas); } } else { for(uint i = 0; i < nbElement; free(listDL[i++])); if(!DLAborted && isTome && !nbElemToInstall && *(input.currentState) == MDL_CODE_INSTALL_OVER) { setTomeReadable(*input.todoList->datas, input.todoList->identifier); setInstalled(input.todoList->datas->cacheDBID); addRecentEntry(*(input.todoList->datas), true); } MDLInstallOver(*input.todoList->datas); } //On lance les éventuelles installations en attente MDLStartNextInstallation(); if(!quit && !DLAborted) MDLUpdateIcons(input.selfCode, input.todoList); free(listSizeDL); free(listDL); quit_thread(0); }