コード例 #1
0
JNIEXPORT void JNICALL
Java_io_jxcore_node_jxcore_prepareEngine(JNIEnv *env, jobject thiz,
                                         jstring home, jstring files) {
  static bool initialized = false;

  const char *hfiles = env->GetStringUTFChars(files, 0);
  const char *hfolder = env->GetStringUTFChars(home, 0);

  if (!initialized) {  // silly but does the job
    initialized = true;
    JX_Initialize(hfolder, callback);
  }

  JX_InitializeNewEngine();
  files_json = hfiles;

  env->ReleaseStringUTFChars(home, hfolder);
  env->ReleaseStringUTFChars(files, hfiles);

  JX_DefineExtension("assetExistsSync", assetExistsSync);
  JX_DefineExtension("assetReadSync", assetReadSync);
  JX_DefineExtension("assetReadDirSync", assetReadDirSync);
  JX_DefineExtension("defineEventCB", defineEventCB);
  JX_DefineExtension("callJXcoreNative", callJXcoreNative);
}
コード例 #2
0
ファイル: test-posix.cpp プロジェクト: Andrepuel/jxcore
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("crashMe", crashMe);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  while (JX_LoopOnce() != 0) usleep(1);

  JX_StopEngine();
}
コード例 #3
0
ファイル: test-posix.cpp プロジェクト: makelivedotnet/jxcore
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  while (JX_LoopOnce() != 0) usleep(1);

  JXValue *params[2] = {param1, param2};
  JXValue out;

  // call fnc -> JS side function
  // we had made this variable persistent inside sampleMethod
  JX_CallFunction(fnc, *params, 2, &out);

  // we need to clear persistent and then free whenever we
  // are done with persistent values to not to leak
  JX_ClearPersistent(fnc);
  JX_Free(fnc);
  JX_ClearPersistent(param1);
  JX_Free(param1);
  JX_ClearPersistent(param2);
  JX_Free(param2);

  assert(JX_GetDataLength(&out) == 11 &&
         "Expected return value was 'test{\"a\":3}");
  JX_Free(&out);
  assert(out.data_ == NULL && out.size_ == 0 && "JX_FreeResultData leaks?");

  JX_StopEngine();
}
コード例 #4
0
JNIEXPORT void JNICALL
Java_org_capriza_jxcore_jxcore_prepareEngine(JNIEnv *env, jobject thiz,
                                                  jstring home, jstring files) {
  static bool initialized = false;

  const char *hfiles = env->GetStringUTFChars(files, 0);
  const char *hfolder = env->GetStringUTFChars(home, 0);

  std::thread::id thread_id = std::this_thread::get_id();


  try {
    int* isAlive = (int*) pthread_getspecific(tlsKey);

      std::ostringstream oss;
      oss << "prepareEngineOri called thread id: " << thread_id << " isAlive is: " << isAlive;
      std::string var = oss.str();

      __android_log_print(ANDROID_LOG_DEBUG, APPNAME, var.c_str(), 1);
  }
  catch (int e) {
    __android_log_print(ANDROID_LOG_ERROR, APPNAME, "EXCEPTION in prepare. yes Ori.", 1);
  }


  if (!initialized) {  // silly but does the job
    __android_log_print(ANDROID_LOG_DEBUG, APPNAME, "Initializing engine capriza", 1);
    initialized = true;
    JX_Initialize(hfolder, callback);
  }
  else {
    __android_log_print(ANDROID_LOG_DEBUG, APPNAME, "NOT!! Initializing engine capriza", 1);
  }



  JX_InitializeNewEngine();
  files_json = hfiles;

  env->ReleaseStringUTFChars(home, hfolder);
  env->ReleaseStringUTFChars(files, hfiles);

  JX_DefineExtension("assetExistsSync", assetExistsSync);
  JX_DefineExtension("assetReadSync", assetReadSync);
  JX_DefineExtension("assetReadDirSync", assetReadDirSync);
  JX_DefineExtension("stopBGS", stopBGS);
  JX_DefineExtension("getTaskOptions", getTaskOptions);
  JX_DefineExtension("defineEventCB", defineEventCB);

  bool isSpider = JX_IsSpiderMonkey();
  bool isV8 = JX_IsV8();

  std::ostringstream oss2;
  oss2 << "prepareEngineOri ended spidermonkey?: " << isSpider << " v8?: " << isV8;
  std::string var2 = oss2.str();
  __android_log_print(ANDROID_LOG_DEBUG, APPNAME, var2.c_str(), 1);

}
コード例 #5
0
ファイル: test-posix.cpp プロジェクト: JarshChen/jxcore
int main(int argc, char **args) {
  JX_Initialize(args[0], callback);
  JX_InitializeNewEngine();

  JX_DefineMainFile(contents);
  JX_DefineExtension("sampleMethod", sampleMethod);
  JX_StartEngine();

  // loop for possible IO
  // or JX_Loop() without usleep / while
  while (JX_LoopOnce() != 0) usleep(1);

  JXValue result;
  JX_Evaluate(eval_str, "myscript", &result);
  JX_Free(&result);

  // loop for possible IO
  // or JX_Loop() without usleep / while
  while (JX_LoopOnce() != 0) usleep(1);

  JX_StopEngine();

  assert(counter == 3 && "sampleMethod is expected to recive 3 calls (2 sub instance, 1 main)");
}