Ignore:
Timestamp:
Sep 29, 2012, 3:59:06 PM (8 years ago)
Author:
djay
Message:

Update to make ZOO-Kernel able to compile and run from Windows Platforms. A special thanks to Espen Messel, Knut Landmark and Benrd Härtwig for providing many patches that I can successfully apply on the SVN source tree and to Farkas for continuing requesting for ZOO-Kernel to run on Windows platforms privately and through the ZOO-Discuss mailing list.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal_java.c

    r360 r364  
    4040      classpath=(char*) malloc((strlen(ntmp)+strlen(tmp->value)+strlen(cclasspath)+4)*sizeof(char));
    4141      oclasspath=(char*) malloc((strlen(ntmp)+strlen(tmp->value)+strlen(cclasspath)+22)*sizeof(char));
     42#ifndef WIN32
    4243      sprintf(classpath,"%s/%s/:%s",ntmp,tmp->value,cclasspath);
     44#else
     45      sprintf(classpath,"%s/%s/;%s",ntmp,tmp->value,cclasspath);
     46#endif
    4347    }
    4448    else{
     
    5458#endif
    5559
     60#ifdef WIN32
     61  JavaVMOption options[2];
     62#else
    5663  JavaVMOption options[1];
     64#endif
    5765  JavaVMInitArgs vm_args;
    5866  JavaVM *jvm;
     
    6270  jfieldID fid;
    6371  jobject jobj;
    64   jclass cls,cls_gr;
     72  jclass cls;
     73#ifdef JAVA7
     74  jobject cls_gr;
     75#else
     76  jclass cls_gr;
     77#endif
    6578  int i;
    6679
    6780  options[0].optionString = strdup(oclasspath);
     81#ifdef WIN32
     82  options[1].optionString = "-Xmx512M";
     83#endif
    6884
    6985  JNI_GetDefaultJavaVMInitArgs(&vm_args);
    7086  vm_args.version = JNI_VERSION_1_6;
    7187  vm_args.options = options;
     88#ifdef WIN32
     89  vm_args.nOptions = 2;
     90#else
    7291  vm_args.nOptions = 1;
    73   vm_args.ignoreUnrecognized = JNI_FALSE;
     92#endif
     93  vm_args.ignoreUnrecognized = JNI_TRUE;
    7494
    7595  result = JNI_CreateJavaVM(&jvm,(void **)&env, &vm_args);
     
    7999  }
    80100#ifdef DEBUG
    81   else 
     101  else
    82102    fprintf(stderr,"JAVA VM Started\n");
    83103#endif
    84104
    85105  tmp=getMap(s->content,"serviceProvider");
     106#ifdef JAVA7
     107  cls = env->FindClass(tmp->value);
     108  cls_gr = env->NewGlobalRef(cls);
     109#else
    86110  cls = (*env)->FindClass(env,tmp->value);
    87111  cls_gr = (*env)->NewGlobalRef(env, cls);
     112#endif
    88113  if( cls == NULL ) {
    89114    char pbt[10240];
    90115    sprintf(pbt,"can't find class %s\n",tmp->value);
     116    fprintf(stderr,pbt);
     117    fflush(stderr);
    91118    map* err=createMap("text",pbt);
    92119    addToMap(err,"code","NoApplicableCode");
     
    94121    freeMap(&err);
    95122    free(err);
     123#ifdef JAVA7
     124    (*jvm).DestroyJavaVM();
     125#else
    96126    (*jvm)->DestroyJavaVM(jvm);
     127#endif
    97128    return -1;
    98129  }
     
    104135
    105136  if (cls != NULL) {
     137#ifdef JAVA7
     138    (*env).ExceptionClear();
     139    pmid=(*env).GetStaticMethodID(cls, s->name, "(Ljava/util/HashMap;Ljava/util/HashMap;Ljava/util/HashMap;)I");
     140#else
    106141    (*env)->ExceptionClear(env);
    107142    pmid=(*env)->GetStaticMethodID(env,cls_gr, s->name, "(Ljava/util/HashMap;Ljava/util/HashMap;Ljava/util/HashMap;)I");
     143#endif
    108144    if (pmid!=0){
    109145#ifdef DEBUG
     
    112148      jclass scHashMapClass,scHashMap_class;
    113149      jmethodID scHashMap_constructor;
     150#ifdef JAVA7
     151      scHashMapClass = (*env).FindClass("java/util/HashMap");
     152      scHashMap_class = (jclass)(*env).NewGlobalRef(scHashMapClass);
     153      scHashMap_constructor = (*env).GetMethodID(scHashMap_class, "<init>", "()V");
     154#else
    114155      scHashMapClass = (*env)->FindClass(env, "java/util/HashMap");
    115156      scHashMap_class = (*env)->NewGlobalRef(env, scHashMapClass);
    116157      scHashMap_constructor = (*env)->GetMethodID(env, scHashMap_class, "<init>", "()V");
     158#endif
    117159      /**
    118160       * The 3 standard parameter for each services
     
    123165      jint pValue=0;
    124166
     167#ifdef JAVA7
     168      pValue=(*env).CallStaticIntMethod(cls,pmid,arg1,arg2,arg3);
     169#else
    125170      pValue=(*env)->CallStaticIntMethod(env,cls,pmid,arg1,arg2,arg3);
     171#endif
    126172      if (pValue != (jint)NULL){
    127173        res=pValue;
     
    146192        FILE* new_stdout=fopen(tmps,"w+");
    147193        dup2(fileno(new_stdout),fileno(stdout));
     194#ifdef JAVA7
     195        (*env).ExceptionDescribe();
     196#else
    148197        (*env)->ExceptionDescribe(env);
     198#endif
    149199        fflush(stdout);
    150200        dup2(old_stdout,fileno(stdout));
     
    152202        long flen=ftell(new_stdout);
    153203        rewind(new_stdout);
    154         char tmps1[flen];
     204        char *tmps1=(char*)malloc((flen+1)*sizeof(char));
    155205        fread(tmps1,flen,1,new_stdout);
    156206        fclose(new_stdout);
    157         char pbt[100+flen];
     207        char *pbt=(char*)malloc((100+flen+1)*sizeof(char));
    158208        sprintf(pbt,"Unable to run your java process properly. Server returns : %s",tmps1);
    159209        map* err=createMap("text",pbt);
     
    162212        freeMap(&err);
    163213        free(err);
     214#ifdef JAVA7
     215        (*jvm).DestroyJavaVM();
     216#else
    164217        (*jvm)->DestroyJavaVM(jvm);
     218#endif
    165219        return -1;
    166220      }
     
    173227      freeMap(&err);
    174228      free(err);
     229#ifdef JAVA7
     230      (*jvm).DestroyJavaVM();
     231#else
    175232      (*jvm)->DestroyJavaVM(jvm);
     233#endif
    176234      return -1;
    177235    }
     
    183241    freeMap(&err);
    184242    free(err);
     243#ifdef JAVA7
     244    (*jvm).DestroyJavaVM();
     245#else
    185246    (*jvm)->DestroyJavaVM(jvm);
     247#endif
    186248    return -1;
    187249  }
     250#ifdef JAVA7
     251      (*jvm).DestroyJavaVM();
     252#else
    188253  (*jvm)->DestroyJavaVM(jvm);
     254#endif
    189255  return res;
    190256}
     
    193259  jobject scObject,scObject1;
    194260  if(scHashMap_constructor!=NULL){
     261#ifdef JAVA7
     262    scObject = (*env).NewObject(scHashMap_class, scHashMap_constructor);
     263#else
    195264    scObject = (*env)->NewObject(env, scHashMap_class, scHashMap_constructor);
     265#endif
    196266    jmethodID put_mid = 0;
    197267
     268#ifdef JAVA7
     269    put_mid = (*env).GetMethodID(scHashMapClass, "put",
     270                                  "(Ljava/lang/Object;Ljava/lang/Object;)"
     271                                  "Ljava/lang/Object;");
     272#else
    198273    put_mid = (*env)->GetMethodID(env,scHashMapClass, "put",
    199274                                  "(Ljava/lang/Object;Ljava/lang/Object;)"
    200275                                  "Ljava/lang/Object;");
     276#endif
    201277    maps* tmp=t;
    202278    while(tmp!=NULL){
    203279      map* tmap=getMapType(tmp->content);
    204280      map* tmp1=tmp->content;
     281#ifdef JAVA7
     282      scObject1 = (*env).NewObject(scHashMap_class, scHashMap_constructor);
     283#else
    205284      scObject1 = (*env)->NewObject(env, scHashMap_class, scHashMap_constructor);
     285#endif
    206286      map* sizeV=getMap(tmp1,"size");
    207287      map* isArray=getMap(tmp1,"isArray");
     
    211291          if(isArray==NULL){
    212292            if(sizeV!=NULL && strcmp(tmp1->name,"value")==0){
     293#ifdef JAVA7
     294              jbyteArray tmpData=(*env).NewByteArray(atoi(sizeV->value));
     295              (*env).SetByteArrayRegion(tmpData,0,atoi(sizeV->value),(const jbyte *)tmp1->value);
     296              (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), tmpData);
     297#else
    213298              jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sizeV->value));
    214299              (*env)->SetByteArrayRegion(env,tmpData,0,atoi(sizeV->value),tmp1->value);
    215300              (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), tmpData);
     301#endif
    216302            }else
     303#ifdef JAVA7
     304              (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), (*env).NewStringUTF(tmp1->value));
     305#else
    217306              (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), (*env)->NewStringUTF(env,tmp1->value));
     307#endif
    218308          }
    219309          else{
     
    224314            jmethodID scArrayList_constructor;
    225315            jobject scObject2,scObject3,scObject4;
     316#ifdef JAVA7
     317            scArrayListClass = (*env).FindClass("java/util/ArrayList");
     318            scArrayList_class = (jclass)(*env).NewGlobalRef(scArrayListClass);
     319            scArrayList_constructor = (*env).GetMethodID(scArrayList_class, "<init>", "()V");
     320            jmethodID add_mid = 0;
     321            scObject2 = (*env).NewObject(scArrayList_class, scArrayList_constructor);
     322            scObject3 = (*env).NewObject(scArrayList_class, scArrayList_constructor);
     323            scObject4 = (*env).NewObject(scArrayList_class, scArrayList_constructor);
     324
     325            add_mid = (*env).GetMethodID(scArrayListClass,
     326                                          "add","(Ljava/lang/Object;)Z");
     327#else
    226328            scArrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
    227329            scArrayList_class = (*env)->NewGlobalRef(env, scArrayListClass);
     
    234336            add_mid = (*env)->GetMethodID(env,scArrayListClass,
    235337                                          "add","(Ljava/lang/Object;)Z");
    236            
     338#endif     
    237339            int i;
    238340           
     
    243345             
    244346              if(sMap!=NULL && vMap!=NULL && strncmp(vMap->name,"value",5)==0){
     347#ifdef JAVA7
     348                jbyteArray tmpData=(*env).NewByteArray(atoi(sMap->value));
     349                (*env).SetByteArrayRegion(tmpData,0,atoi(sMap->value),(const jbyte *)vMap->value);
     350                (*env).CallObjectMethod(scObject2, add_mid, tmpData);
     351#else
    245352                jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sMap->value));
    246353                (*env)->SetByteArrayRegion(env,tmpData,0,atoi(sMap->value),vMap->value);
    247354                (*env)->CallObjectMethod(env,scObject2, add_mid, tmpData);
     355#endif
    248356              }else{
     357#ifdef JAVA7
     358                jobject tmpData=(*env).NewStringUTF(vMap->value);
     359                (*env).CallObjectMethod(scObject2, add_mid, tmpData);
     360#else
    249361                jobject tmpData=(*env)->NewStringUTF(env,vMap->value);
    250362                (*env)->CallObjectMethod(env,scObject2, add_mid, tmpData);
     363#endif
    251364              }
    252365             
    253366            }
    254            
     367
     368#ifdef JAVA7
     369            (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), scObject2);
     370#else       
    255371            (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), scObject2);
    256            
     372#endif
     373
    257374          }
    258375        }
    259376        else
     377#ifdef JAVA7
     378          (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), (*env).NewStringUTF(tmp1->value));
     379#else
    260380          (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), (*env)->NewStringUTF(env,tmp1->value));
     381#endif
    261382        tmp1=tmp1->next;
    262383      }
     384#ifdef JAVA7
     385      (*env).CallObjectMethod(scObject, put_mid, (*env).NewStringUTF(tmp->name), scObject1);
     386#else
    263387      (*env)->CallObjectMethod(env,scObject, put_mid, (*env)->NewStringUTF(env,tmp->name), scObject1);
     388#endif
    264389      tmp=tmp->next;
    265390    }
     
    292417    return NULL;
    293418  }
     419#ifdef JAVA7
     420  entrySet_mid = (*env).GetMethodID(scHashMapClass, "entrySet", "()Ljava/util/Set;");
     421  containsKey_mid = (*env).GetMethodID(scHashMapClass, "containsKey", "(Ljava/lang/Object;)Z");
     422  get_mid = (*env).GetMethodID(scHashMapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
     423#else
    294424  entrySet_mid = (*env)->GetMethodID(env, scHashMapClass, "entrySet", "()Ljava/util/Set;");
    295425  containsKey_mid = (*env)->GetMethodID(env, scHashMapClass, "containsKey", "(Ljava/lang/Object;)Z");
    296426  get_mid = (*env)->GetMethodID(env, scHashMapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
     427#endif
    297428
    298429  if(containsKey_mid==0){
     
    319450#endif
    320451
     452#ifdef JAVA7
     453  scSetClass = (*env).FindClass("java/util/Set");
     454  iterator_mid = (*env).GetMethodID(scSetClass, "iterator", "()Ljava/util/Iterator;");
     455#else
    321456  scSetClass = (*env)->FindClass(env, "java/util/Set");
    322457  iterator_mid = (*env)->GetMethodID(env, scSetClass, "iterator", "()Ljava/util/Iterator;");
     458#endif
    323459#ifdef DEBUG
    324460  fprintf(stderr,"mapsFromHashMap 1 (%d) \n",iterator_mid);
    325461#endif
    326462
     463#ifdef JAVA7
     464  scIteratorClass = (*env).FindClass("java/util/Iterator");
     465  hasNext_mid = (*env).GetMethodID(scIteratorClass, "hasNext", "()Z");
     466#else
    327467  scIteratorClass = (*env)->FindClass(env, "java/util/Iterator");
    328468  hasNext_mid = (*env)->GetMethodID(env, scIteratorClass, "hasNext", "()Z");
     469#endif
     470
    329471#ifdef DEBUG
    330472  fprintf(stderr,"mapsFromHashMap 2 (%d)\n",hasNext_mid);
    331473#endif
     474
     475#ifdef JAVA7
     476  next_mid = (*env).GetMethodID(scIteratorClass, "next", "()Ljava/lang/Object;");
     477#else
    332478  next_mid = (*env)->GetMethodID(env, scIteratorClass, "next", "()Ljava/lang/Object;");
     479#endif
    333480#ifdef DEBUG
    334481  fprintf(stderr,"mapsFromHashMap 3 (%d)\n",next_mid);
    335482#endif
    336483
     484#ifdef JAVA7
     485  scMapEntryClass = (*env).FindClass("java/util/Map$Entry");
     486  getKey_mid = (*env).GetMethodID(scMapEntryClass, "getKey", "()Ljava/lang/Object;");
     487#else
    337488  scMapEntryClass = (*env)->FindClass(env, "java/util/Map$Entry");
    338489  getKey_mid = (*env)->GetMethodID(env, scMapEntryClass, "getKey", "()Ljava/lang/Object;");
     490#endif
    339491#ifdef DEBUG
    340492  fprintf(stderr,"mapsFromHashMap 4 (%d)\n",getKey_mid);
    341493#endif
     494#ifdef JAVA7
     495  getValue_mid = (*env).GetMethodID(scMapEntryClass, "getValue", "()Ljava/lang/Object;");
     496#else
    342497  getValue_mid = (*env)->GetMethodID(env, scMapEntryClass, "getValue", "()Ljava/lang/Object;");
     498#endif
    343499#ifdef DEBUG
    344500  fprintf(stderr,"mapsFromHashMap 5 (%d)\n",getValue_mid);
    345501#endif
    346502
     503#ifdef JAVA7
     504  jobject final_set=(*env).CallObjectMethod(t,entrySet_mid);
     505  jobject final_iterator=(*env).CallObjectMethod(final_set,iterator_mid);
     506#else
    347507  jobject final_set=(*env)->CallObjectMethod(env,t,entrySet_mid);
    348508  jobject final_iterator=(*env)->CallObjectMethod(env,final_set,iterator_mid);
    349 
     509#endif
    350510
    351511  maps* final_res=NULL;
    352512  map* res=NULL;
     513#ifdef JAVA7
     514  while((*env).CallBooleanMethod(final_iterator,hasNext_mid)){
     515    jobject tmp=(*env).CallObjectMethod(final_iterator,next_mid);
     516
     517    jobject imap=(*env).CallObjectMethod(tmp,getValue_mid);
     518    jobject set=(*env).CallObjectMethod(imap,entrySet_mid);
     519    jobject iterator=(*env).CallObjectMethod(set,iterator_mid);
     520
     521#else
    353522  while((*env)->CallBooleanMethod(env,final_iterator,hasNext_mid)){
    354523    jobject tmp=(*env)->CallObjectMethod(env,final_iterator,next_mid);
     
    358527    jobject iterator=(*env)->CallObjectMethod(env,set,iterator_mid);
    359528
     529#endif
    360530    int size=-1;
     531#ifdef JAVA7
     532    if((*env).CallBooleanMethod(imap,containsKey_mid,(*env).NewStringUTF("size"))){
     533      jobject sizeV=(*env).CallObjectMethod(imap, get_mid,(*env).NewStringUTF("size"));
     534      const char* sizeVS=(*env).GetStringUTFChars((jstring)sizeV, NULL);
     535#else
    361536    if((*env)->CallBooleanMethod(env,imap,containsKey_mid,(*env)->NewStringUTF(env,"size"))){
    362537      jobject sizeV=(*env)->CallObjectMethod(env, imap, get_mid,(*env)->NewStringUTF(env,"size"));
    363538      const char* sizeVS=(*env)->GetStringUTFChars(env, sizeV, NULL);
     539#endif
    364540      size=atoi(sizeVS);
    365541      fprintf(stderr,"SIZE : %s\n",sizeVS);
     542#ifdef JAVA7
     543      (*env).ReleaseStringUTFChars((jstring)sizeV, sizeVS);
     544#else
    366545      (*env)->ReleaseStringUTFChars(env, sizeV, sizeVS);
     546#endif
    367547    }
    368548   
     549#ifdef JAVA7
     550    while((*env).CallBooleanMethod(iterator,hasNext_mid)){
     551      jobject tmp1=(*env).CallObjectMethod(iterator,next_mid);
     552      jobject jk=(*env).CallObjectMethod(tmp1,getKey_mid);
     553      jobject jv=(*env).CallObjectMethod(tmp1,getValue_mid);
     554
     555      const char* jkd=(*env).GetStringUTFChars((jstring)jk, NULL);
     556#else
    369557    while((*env)->CallBooleanMethod(env,iterator,hasNext_mid)){
    370558      jobject tmp1=(*env)->CallObjectMethod(env,iterator,next_mid);
     
    373561
    374562      const char* jkd=(*env)->GetStringUTFChars(env, jk, NULL);
     563#endif
    375564      if(size>=0 && strcmp(jkd,"value")==0){
     565#ifdef JAVA7
     566        jobject value=(jobject)(*env).GetByteArrayElements((jbyteArray)jv, NULL);
     567#else
    376568        jobject value=(*env)->GetByteArrayElements(env, jv, NULL);
     569#endif
    377570        if(res==NULL){
    378571          res=createMap(jkd,"");
     
    390583      }
    391584      else{
     585#ifdef JAVA7
     586        const char* jvd=(*env).GetStringUTFChars((jstring)jv, NULL);
     587#else
    392588        const char* jvd=(*env)->GetStringUTFChars(env, jv, NULL);
     589#endif
    393590        if(res==NULL){
    394591          res=createMap(jkd,jvd);
     
    396593          addToMap(res,jkd,jvd);
    397594        }
     595#ifdef JAVA7
     596        (*env).ReleaseStringUTFChars((jstring)jv, jvd);
     597#else
    398598        (*env)->ReleaseStringUTFChars(env, jv, jvd);
     599#endif
    399600      }
    400601
     602#ifdef JAVA7
     603      (*env).ReleaseStringUTFChars((jstring)jk, jkd);
     604#else
    401605      (*env)->ReleaseStringUTFChars(env, jk, jkd);
     606#endif
    402607
    403608    }
     609#ifdef JAVA7
     610    jobject jk=(*env).CallObjectMethod(tmp,getKey_mid);
     611#else
    404612    jobject jk=(*env)->CallObjectMethod(env,tmp,getKey_mid);
     613#endif
    405614    maps* cmap=(maps*)malloc(sizeof(maps));
     615#ifdef JAVA7
     616    cmap->name=(char*)(*env).GetStringUTFChars((jstring)jk, NULL);
     617#else
    406618    cmap->name=(*env)->GetStringUTFChars(env, jk, NULL);
     619#endif
    407620#ifdef DEBUG
    408621    fprintf(stderr," / %s \n",cmap->name);
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png