Exemplo n.º 1
0
int et_event_setendian(et_event *pe, int endian)
{
  int err, myendian;
  
  if ( (err = etNetLocalByteOrder(&myendian)) != ET_OK) {
      return err;
  }
  
  if ((endian != ET_ENDIAN_BIG)      &&
      (endian != ET_ENDIAN_LITTLE)   &&
      (endian != ET_ENDIAN_LOCAL)    &&
      (endian != ET_ENDIAN_NOTLOCAL) &&
      (endian != ET_ENDIAN_SWITCH))     {
    return ET_ERROR;
  }
  
  if ((endian == ET_ENDIAN_BIG) || (endian == ET_ENDIAN_LITTLE)) {
    pe->byteorder = (myendian == endian) ? 0x04030201 : 0x01020304;
  }
  else if (endian == ET_ENDIAN_LOCAL) {
    pe->byteorder = 0x04030201;
  }
  else if (endian == ET_ENDIAN_NOTLOCAL) {
    pe->byteorder = 0x01020304;
  }
  else {
    pe->byteorder = ET_SWAP32(pe->byteorder);
  }

  return ET_OK;
}
Exemplo n.º 2
0
int et_event_getendian(et_event *pe, int *endian)
{ 
  int err, myendian, notmyendian;
  
  if (endian == NULL) {
    return ET_ERROR;
  }
  
  if ( (err = etNetLocalByteOrder(&myendian)) != ET_OK) {
      return err;
  }
  
  notmyendian = (myendian == ET_ENDIAN_BIG) ? ET_ENDIAN_LITTLE : ET_ENDIAN_BIG;
  *endian = (pe->byteorder == 0x04030201) ? myendian : notmyendian;
  
  return ET_OK;
}
Exemplo n.º 3
0
/*
 * Class:     org_jlab_coda_et_EtJniAccess
 * Method:    openLocalEtSystem
 * Signature: (Ljava/lang/String;)J
 */
JNIEXPORT void JNICALL Java_org_jlab_coda_et_EtJniAccess_openLocalEtSystem
        (JNIEnv *env, jobject thisObj, jstring fileName)
{
    int err;
    const char* mappedFile;
    et_sys_id id; /* (void *) */
    et_openconfig openconfig;
    jclass clazz, class1, classEventImpl;
    jmethodID mid;

    /* get C string from java arg */
    mappedFile = (*env)->GetStringUTFChars(env, fileName, NULL);
    if (mappedFile == NULL) {
        /* pending exception already thrown, need to return for it to complete */
        (*env)->ReleaseStringUTFChars(env, fileName, mappedFile);
        return;
    }
    
    /* open ET system */
    et_open_config_init(&openconfig);
    et_open_config_sethost(openconfig, ET_HOST_LOCAL); /* must be local host */
    err = et_open(&id, mappedFile, openconfig);
    if (err != ET_OK) {
        if (err == ET_ERROR_TIMEOUT) {
            clazz = (*env)->FindClass(env, "org/jlab/coda/et/exception/EtTimeoutException");
        }
        else {
            clazz = (*env)->FindClass(env, "org/jlab/coda/et/exception/EtException");
        }
        (*env)->ThrowNew(env, clazz, "openLocalEtSystem: cannot open ET system in native code");
        return;
    }
    et_open_config_destroy(openconfig);

    /* store byte order of local system */
    err = etNetLocalByteOrder(&localByteOrder);
    if (err != ET_OK) {
        localByteOrder = ET_ENDIAN_LITTLE;
    }

    /* store et id in object by calling this native method */
    class1 = (*env)->GetObjectClass(env, thisObj);
    mid    = (*env)->GetMethodID(env, class1, "setLocalEtId", "(J)V");
    (*env)->CallVoidMethod(env, thisObj, mid, (jlong)id);

    /*******************************************/
    /* cache objects for efficient, future use */
    /*******************************************/
    classEventImpl = (*env)->FindClass(env, "org/jlab/coda/et/EtEventImpl");
    eventImplClass = (*env)->NewGlobalRef(env, classEventImpl);
 
    /* find id's of all the fields that we'll read/write directly to */
    fid[0] = (*env)->GetFieldID(env, classEventImpl, "id",         "I");
    fid[1] = (*env)->GetFieldID(env, classEventImpl, "length",     "I");
    fid[2] = (*env)->GetFieldID(env, classEventImpl, "byteOrder",  "I");
    fid[3] = (*env)->GetFieldID(env, classEventImpl, "control",    "[I");

    /* methods to get event's enum values */
    getPriorityVal   = (*env)->GetMethodID(env, classEventImpl, "getPriorityValue",   "()I");
    getDataStatusVal = (*env)->GetMethodID(env, classEventImpl, "getDataStatusValue", "()I");

    /* get id's of a few different constructors */
    constrMethodId2 = (*env)->GetMethodID(env, classEventImpl, "<init>", "(IIIIIIIIZLjava/nio/ByteBuffer;)V");
    constrMethodId3 = (*env)->GetMethodID(env, classEventImpl, "<init>", "(IIIIIIIIII[IZLjava/nio/ByteBuffer;)V");
    
    if (debug) printf("\nopenLocalEtSystem (native) : done, opened ET system\n\n");
}