FileDocCategorySizeDatePackage
MarshalRegistry.javaAPI DocAndroid 5.1 API5331Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.marshal

MarshalRegistry

public class MarshalRegistry extends Object
Registry of supported marshalers; add new query-able marshalers or lookup existing ones.

Fields Summary
private static List
sRegisteredMarshalQueryables
private static HashMap
sMarshalerMap
Constructors Summary
private MarshalRegistry()


      
        throw new AssertionError();
    
Methods Summary
public static MarshalergetMarshaler(android.hardware.camera2.utils.TypeReference typeToken, int nativeType)
Lookup a marshaler between {@code T} and {@code nativeType}.

Marshalers are looked up in the order they were registered; earlier registered marshal queriers get priority.

param
typeToken The compile-time type reference for {@code T}
param
nativeType The native type, e.g. {@link CameraMetadataNative#TYPE_BYTE TYPE_BYTE}
return
marshaler a non-{@code null} marshaler that supports marshaling the type combo
throws
UnsupportedOperationException If no marshaler matching the args could be found

        // TODO: can avoid making a new token each time by code-genning
        // the list of type tokens and native types from the keys (at the call sites)
        MarshalToken<T> marshalToken = new MarshalToken<T>(typeToken, nativeType);

        /*
         * Marshalers are instantiated lazily once they are looked up; successive lookups
         * will not instantiate new marshalers.
         */
        Marshaler<T> marshaler =
                (Marshaler<T>) sMarshalerMap.get(marshalToken);

        if (sRegisteredMarshalQueryables.size() == 0) {
            throw new AssertionError("No available query marshalers registered");
        }

        if (marshaler == null) {
            // Query each marshaler to see if they support the native/managed type combination
            for (MarshalQueryable<?> potentialMarshaler : sRegisteredMarshalQueryables) {

                MarshalQueryable<T> castedPotential =
                        (MarshalQueryable<T>)potentialMarshaler;

                if (castedPotential.isTypeMappingSupported(typeToken, nativeType)) {
                    marshaler = castedPotential.createMarshaler(typeToken, nativeType);
                    break;
                }
            }

            if (marshaler == null) {
                throw new UnsupportedOperationException(
                        "Could not find marshaler that matches the requested " +
                                "combination of type reference " +
                                typeToken + " and native type " +
                                MarshalHelpers.toStringNativeType(nativeType));
            }

            // Only put when no cached version exists to avoid +0.5ms lookup per call.
            sMarshalerMap.put(marshalToken, marshaler);
        }

        return marshaler;
    
public static voidregisterMarshalQueryable(MarshalQueryable queryable)
Register a marshal queryable for the managed type {@code T}.

Multiple marshal queryables for the same managed type {@code T} may be registered; this is desirable if they support different native types (e.g. marshaler 1 supports {@code Integer <-> TYPE_INT32}, marshaler 2 supports {@code Integer <-> TYPE_BYTE}.

param
queryable a non-{@code null} marshal queryable that supports marshaling {@code T}

        sRegisteredMarshalQueryables.add(queryable);