Beispiel #1
0
  public SixModelObject get_attribute_boxed(
      ThreadContext tc, SixModelObject class_handle, String name, long hint) {
    SixModelObject member = memberCache.get(name);
    if (member != null) return member;

    CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
    AttrInfo info = data.fieldTypes.get(name);

    Object o = storage.readField(name);
    if (info.inlined == 0) {
      if (info.argType == ArgType.CSTRUCT) {
        Class<?> structClass = ((CStructREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Structure.newInstance(structClass, ((Pointer) o));
      } else if (info.argType == ArgType.CPPSTRUCT) {
        Class<?> structClass = ((CPPStructREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Structure.newInstance(structClass, ((Pointer) o));
      } else if (info.argType == ArgType.CUNION) {
        Class<?> structClass = ((CUnionREPRData) info.type.st.REPRData).structureClass;
        o = (Object) Union.newInstance(structClass, ((Pointer) o));
      }
    }

    member = NativeCallOps.toNQPType(tc, info.argType, info.type, o);
    memberCache.put(name, member);
    return member;
  }
Beispiel #2
0
    public void read() {
      super.read();

      switch (ForestTrustType) {
        case NTSecApi.ForestTrustTopLevelName:
        case NTSecApi.ForestTrustTopLevelNameEx:
          u.setType(LSA_UNICODE_STRING.class);
          break;
        case NTSecApi.ForestTrustDomainInfo:
          u.setType(LSA_FOREST_TRUST_DOMAIN_INFO.class);
          break;
        default:
          u.setType(LSA_FOREST_TRUST_BINARY_DATA.class);
          break;
      }

      u.read();
    }
Beispiel #3
0
 public void bind_attribute_boxed(
     ThreadContext tc, SixModelObject class_handle, String name, long hint, SixModelObject value) {
   CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
   AttrInfo info = data.fieldTypes.get(name);
   /* XXX: This'll break if we try to set a callback member. OTOH, it's
    * broken on Parrot too, so it's not a NativeCall regression as
    * such... */
   ArgType type = info.argType;
   Object o = NativeCallOps.toJNAType(tc, value, type, null);
   if (info.inlined == 0) {
     if (type == ArgType.CSTRUCT || type == ArgType.CPPSTRUCT) {
       type = ArgType.CPOINTER;
       o = (Object) ((Structure) o).getPointer();
     } else if (type == ArgType.CUNION) {
       type = ArgType.CPOINTER;
       o = (Object) ((Union) o).getPointer();
     }
   }
   storage.writeField(name, o);
   memberCache.put(name, value);
 }
Beispiel #4
0
 public void bind_attribute_native(
     ThreadContext tc, SixModelObject class_handle, String name, long hint) {
   CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
   AttrInfo info = data.fieldTypes.get(name);
   Object value;
   switch (info.argType) {
     case CHAR:
       tc.native_type = ThreadContext.NATIVE_INT;
       value = new Byte((byte) tc.native_i);
       break;
     case SHORT:
       tc.native_type = ThreadContext.NATIVE_INT;
       value = new Short((short) tc.native_i);
       break;
     case INT:
       tc.native_type = ThreadContext.NATIVE_INT;
       value = new Integer((int) tc.native_i);
       break;
     case LONG:
       tc.native_type = ThreadContext.NATIVE_INT;
       value = new Long((long) tc.native_i);
       break;
     case FLOAT:
       tc.native_type = ThreadContext.NATIVE_NUM;
       value = new Float((float) tc.native_n);
       break;
     case DOUBLE:
       tc.native_type = ThreadContext.NATIVE_NUM;
       value = new Double((double) tc.native_n);
       break;
     default:
       ExceptionHandling.dieInternal(
           tc, String.format("CStruct.bind_attribute_native: Can't handle %s", info.argType));
       value = null;
   }
   storage.writeField(name, value);
 }
Beispiel #5
0
  public void get_attribute_native(
      ThreadContext tc, SixModelObject class_handle, String name, long hint) {
    CStructREPRData data = (CStructREPRData) class_handle.st.REPRData;
    AttrInfo info = data.fieldTypes.get(name);

    Object o = storage.readField(name);
    switch (info.argType) {
      case CHAR:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Byte) o).byteValue();
        break;
      case SHORT:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Short) o).shortValue();
        break;
      case INT:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Integer) o).intValue();
        break;
      case LONG:
        tc.native_type = ThreadContext.NATIVE_INT;
        tc.native_i = ((Long) o).longValue();
        break;
      case FLOAT:
        tc.native_type = ThreadContext.NATIVE_NUM;
        tc.native_n = ((Float) o).floatValue();
        break;
      case DOUBLE:
        tc.native_type = ThreadContext.NATIVE_NUM;
        tc.native_n = ((Double) o).doubleValue();
        break;
      default:
        ExceptionHandling.dieInternal(
            tc, String.format("CStruct.get_attribute_native: Can't handle %s", info.argType));
    }
  }
Beispiel #6
0
  // TODO: this method isn't very safe to leave public, perhaps some
  // setPropertyData[String/UInt32/etc.] methods would be better
  public static EdsError setPropertyDataAdvanced(
      final EdsBaseRef ref, final EdsPropertyID property, final long param, final Object value)
      throws IllegalStateException {

    final EdsDataType type = CanonUtils.getPropertyType(ref, property, param);

    final Pointer pointer;
    final int size;

    switch (type) {
      case kEdsDataType_String:
        { // EdsChar[]
          final String string = (String) value;
          size = string.length() + 1;
          pointer = new Memory(size);
          pointer.setString(0, string);
          break;
        }
      case kEdsDataType_Int8: // EdsInt8
      case kEdsDataType_UInt8:
        { // EdsUInt8
          size = 1;
          pointer = new Memory(size);
          pointer.setByte(0, (Byte) value);
          break;
        }
      case kEdsDataType_Int16: // EdsInt16
      case kEdsDataType_UInt16:
        { // EdsUInt16
          size = 2;
          pointer = new Memory(size);
          pointer.setShort(0, (Short) value);
          break;
        }
      case kEdsDataType_Int32: // EdsInt32
      case kEdsDataType_UInt32:
        { // EdsUInt32
          size = 4;
          pointer = new Memory(size);
          pointer.setNativeLong(0, new NativeLong((Long) value));
          break;
        }
      case kEdsDataType_Int64: // EdsInt64
      case kEdsDataType_UInt64:
        { // EdsUInt64
          size = 8;
          pointer = new Memory(size);
          pointer.setLong(0, (Long) value);
          break;
        }
      case kEdsDataType_Float:
        { // EdsFloat
          size = 4;
          pointer = new Memory(size);
          pointer.setFloat(0, (Float) value);
          break;
        }
      case kEdsDataType_Double:
        { // EdsDouble
          size = 8;
          pointer = new Memory(size);
          pointer.setDouble(0, (Double) value);
          break;
        }
      case kEdsDataType_ByteBlock:
        { // Byte Block // TODO: According to API, is either EdsInt8[] or EdsUInt32[], but perhaps
          // former is a typo or an old value
          final int[] array = (int[]) value;
          size = 4 * array.length;
          pointer = new Memory(size);
          pointer.write(0, array, 0, array.length);
          break;
        }
      case kEdsDataType_Rational: // EdsRational
      case kEdsDataType_Point: // EdsPoint
      case kEdsDataType_Rect: // EdsRect
      case kEdsDataType_Time: // EdsTime
      case kEdsDataType_FocusInfo: // EdsFocusInfo
      case kEdsDataType_PictureStyleDesc:
        { // EdsPictureStyleDesc
          final Structure structure = (Structure) value;
          structure.write();
          pointer = structure.getPointer();
          size = structure.size();
          break;
        }
      case kEdsDataType_Int8_Array: // EdsInt8[]
      case kEdsDataType_UInt8_Array:
        { // EdsUInt8[]
          final byte[] array = (byte[]) value;
          size = array.length;
          pointer = new Memory(size);
          pointer.write(0, array, 0, array.length);
          break;
        }
      case kEdsDataType_Int16_Array: // EdsInt16[]
      case kEdsDataType_UInt16_Array:
        { // EdsUInt16[]
          final short[] array = (short[]) value;
          size = 2 * array.length;
          pointer = new Memory(size);
          pointer.write(0, array, 0, array.length);
          break;
        }
      case kEdsDataType_Int32_Array: // EdsInt32[]
      case kEdsDataType_UInt32_Array:
        { // EdsUInt32[]
          final int[] array = (int[]) value;
          size = 4 * array.length;
          pointer = new Memory(size);
          pointer.write(0, array, 0, array.length);
          break;
        }
      case kEdsDataType_Bool:
        // EdsBool // TODO: implement
      case kEdsDataType_Bool_Array: // EdsBool[] // TODO: implement
      case kEdsDataType_Rational_Array: // EdsRational[] // TODO: implement
      case kEdsDataType_Unknown: // Unknown
      default:
        throw new IllegalStateException(
            type.description()
                + " ("
                + type.name()
                + ") is not currently supported by GetPropertyCommand");
    }
    return CanonUtils.setPropertyData(ref, property, param, size, pointer);
  }