Skip to content

Commit

Permalink
[Java.Interop] Rename JniValueMarshaler to JniValueManager.
Browse files Browse the repository at this point in the history
Context: dotnet/java-interop#8

Rename JniRuntime.JniValueMarshaler to JniRuntime.JniValueManager.

The reason for this is that the likely fix for issue 8
("Value Marshaling with Expressions") will involve adding a type named
JniValueMarshaler ("JniMarshalInfo" should die!), and having two
different JniValueMarshaler types running around would be confusing.

Added benefit: JniValueManager is more consistent with JniTypeManager.

:-)
  • Loading branch information
jonpryor committed Nov 27, 2015
1 parent eb69a47 commit 15fbb57
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ internal JniArgumentMarshalInfo (object value, Type valueType)
{
this = new JniArgumentMarshalInfo ();
var jvm = JniEnvironment.Runtime;
var info = jvm.ValueMarshaler.GetJniMarshalInfoForType (valueType);
var info = jvm.ValueManager.GetJniMarshalInfoForType (valueType);
if (info.CreateJniArgumentValue != null)
jvalue = info.CreateJniArgumentValue (value);
else if (info.CreateMarshalCollection != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override unsafe object Invoke (IJavaPeerable self, JniArgumentValue* argu
{
if (self == null) {
var h = members.InstanceMethods.StartCreateInstance (JniSignature, typeof (JavaInstanceProxy), arguments);
self = JniEnvironment.Runtime.ValueMarshaler.GetObject<JavaInstanceProxy> (ref h, JniObjectReferenceOptions.CopyAndDispose);
self = JniEnvironment.Runtime.ValueManager.GetObject<JavaInstanceProxy> (ref h, JniObjectReferenceOptions.CopyAndDispose);
}
members.InstanceMethods.FinishCreateInstance (JniSignature, self, arguments);
return new DynamicJavaInstance (self);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected virtual void Dispose (bool disposing)

protected static object ToReturnValue (ref JniObjectReference handle, string signature, int n)
{
var instance = JniEnvironment.Runtime.ValueMarshaler.GetObject (ref handle, JniObjectReferenceOptions.CopyAndDispose);
var instance = JniEnvironment.Runtime.ValueManager.GetObject (ref handle, JniObjectReferenceOptions.CopyAndDispose);
switch (signature [n]) {
case 'L':
return new DynamicJavaInstance (instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override DynamicMetaObject BindConvert (ConvertBinder binder)
return new DynamicMetaObject (typeE, BindingRestrictions.GetTypeRestriction (typeE, binder.Type), type);
}

var marshalInfo = vm.ValueMarshaler.GetJniMarshalInfoForType (binder.Type);
var marshalInfo = vm.ValueManager.GetJniMarshalInfoForType (binder.Type);
if (marshalInfo.GetValueFromJni == null)
return binder.FallbackConvert (this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ static Expression CreateDisposeJniEnvironment (ParameterExpression envp)
static Expression GetThis (Expression vm, Type targetType, Expression context)
{
return Expression.Call (
Expression.Property (vm, "ValueMarshaler"),
Expression.Property (vm, "ValueManager"),
"GetObject",
new[]{targetType},
context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void CreateMarshalFromJniMethodExpression_InstanceAction ()
ExportTest __this;
__jvm = JniEnvironment.Runtime;
__this = __jvm.ValueMarshaler.GetObject<ExportTest>(__context);
__this = __jvm.ValueManager.GetObject<ExportTest>(__context);
__this.InstanceAction();
}
catch (Exception __e)
Expand Down Expand Up @@ -304,7 +304,7 @@ public void CreateMarshalFromJniMethodExpression_FuncInt64 ()
long __mret;
__jvm = JniEnvironment.Runtime;
__this = __jvm.ValueMarshaler.GetObject<ExportTest>(__context);
__this = __jvm.ValueManager.GetObject<ExportTest>(__context);
__mret = __this.FuncInt64();
__jret = __mret;
return __jret;
Expand Down Expand Up @@ -343,7 +343,7 @@ public void CreateMarshalFromJniMethodExpression_FuncIJavaObject ()
JavaObject __mret;
__jvm = JniEnvironment.Runtime;
__this = __jvm.ValueMarshaler.GetObject<ExportTest>(__context);
__this = __jvm.ValueManager.GetObject<ExportTest>(__context);
__mret = __this.FuncIJavaObject();
__jret = References.NewReturnToJniRef(__mret);
return __jret;
Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</Compile>
<Compile Include="Java.Interop\JniReferenceSafeHandle.cs" />
<Compile Include="Java.Interop\JniRuntime.JniExportedMemberBuilder.cs" />
<Compile Include="Java.Interop\JniRuntime.JniValueMarshaler.cs" />
<Compile Include="Java.Interop\JniRuntime.JniValueManager.cs" />
<Compile Include="Java.Interop\JniSystem.cs" />
<Compile Include="Java.Interop\JniWeakGlobalReference.cs" />
<Compile Include="Java.Interop\ManagedPeer.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop/JavaArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ internal static JniObjectReference CreateLocalRef<TArray> (object value, Func<IL
internal static IList<T> GetValueFromJni<TArray> (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type targetType, ArrayCreator<TArray> creator)
where TArray : JavaArray<T>
{
var value = JniEnvironment.Runtime.ValueMarshaler.PeekObject (reference);
var value = JniEnvironment.Runtime.ValueManager.PeekObject (reference);
var array = value as TArray;
if (array != null) {
JniObjectReference.Dispose (ref reference, transfer);
Expand Down
8 changes: 4 additions & 4 deletions src/Java.Interop/Java.Interop/JavaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public JavaException (ref JniObjectReference reference, JniObjectReferenceOption

~JavaException ()
{
JniEnvironment.Runtime.ValueMarshaler.TryCollectObject (this);
JniEnvironment.Runtime.ValueManager.TryCollectObject (this);
}

public JniObjectReference PeerReference {
Expand Down Expand Up @@ -123,7 +123,7 @@ public override string StackTrace {

protected SetSafeHandleCompletion SetPeerReference (ref JniObjectReference handle, JniObjectReferenceOptions transfer)
{
return JniEnvironment.Runtime.ValueMarshaler.SetObjectPeerReference (
return JniEnvironment.Runtime.ValueManager.SetObjectPeerReference (
this,
ref handle,
transfer,
Expand All @@ -134,14 +134,14 @@ public void UnregisterFromRuntime ()
{
if (!PeerReference.IsValid)
throw new ObjectDisposedException (GetType ().FullName);
JniEnvironment.Runtime.ValueMarshaler.UnRegisterObject (this);
JniEnvironment.Runtime.ValueManager.UnRegisterObject (this);
}

public void Dispose ()
{
if (!PeerReference.IsValid)
return;
JniEnvironment.Runtime.ValueMarshaler.DisposeObject (this);
JniEnvironment.Runtime.ValueManager.DisposeObject (this);
var inner = InnerException as JavaException;
if (inner != null) {
inner.Dispose ();
Expand Down
8 changes: 4 additions & 4 deletions src/Java.Interop/Java.Interop/JavaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ unsafe public class JavaObject : IJavaPeerable, IJavaPeerableEx

~JavaObject ()
{
JniEnvironment.Runtime.ValueMarshaler.TryCollectObject (this);
JniEnvironment.Runtime.ValueManager.TryCollectObject (this);
}

public JniObjectReference PeerReference {
Expand Down Expand Up @@ -64,7 +64,7 @@ public unsafe JavaObject ()

protected SetPeerReferenceCompletion SetPeerReference (ref JniObjectReference handle, JniObjectReferenceOptions transfer)
{
return JniEnvironment.Runtime.ValueMarshaler.SetObjectPeerReference (
return JniEnvironment.Runtime.ValueManager.SetObjectPeerReference (
this,
ref handle,
transfer,
Expand All @@ -75,12 +75,12 @@ public void UnregisterFromRuntime ()
{
if (!PeerReference.IsValid)
throw new ObjectDisposedException (GetType ().FullName);
JniEnvironment.Runtime.ValueMarshaler.UnRegisterObject (this);
JniEnvironment.Runtime.ValueManager.UnRegisterObject (this);
}

public void Dispose ()
{
JniEnvironment.Runtime.ValueMarshaler.DisposeObject (this);
JniEnvironment.Runtime.ValueManager.DisposeObject (this);
}

public void DisposeUnlessRegistered ()
Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop/JavaPeerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static string GetJniTypeName (this IJavaPeerable self)

internal static object GetValue (ref JniObjectReference handle, JniObjectReferenceOptions transfer, Type targetType)
{
return JniEnvironment.Runtime.ValueMarshaler.GetObject (ref handle, transfer, targetType);
return JniEnvironment.Runtime.ValueManager.GetObject (ref handle, transfer, targetType);
}

internal static JniObjectReference CreateLocalRef (object value)
Expand Down
8 changes: 4 additions & 4 deletions src/Java.Interop/Java.Interop/JavaProxyObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ public static JavaProxyObject GetProxy (object value)

static bool _Equals (IntPtr jnienv, IntPtr n_self, IntPtr n_value)
{
var self = JniEnvironment.Runtime.ValueMarshaler.GetObject<JavaProxyObject> (n_self);
var value = JniEnvironment.Runtime.ValueMarshaler.GetObject (n_value);
var self = JniEnvironment.Runtime.ValueManager.GetObject<JavaProxyObject> (n_self);
var value = JniEnvironment.Runtime.ValueManager.GetObject (n_value);
return self.Equals (value);
}

static int _GetHashCode (IntPtr jnienv, IntPtr n_self)
{
var self = JniEnvironment.Runtime.ValueMarshaler.GetObject<JavaProxyObject> (n_self);
var self = JniEnvironment.Runtime.ValueManager.GetObject<JavaProxyObject> (n_self);
return self.GetHashCode ();
}

static IntPtr _ToString (IntPtr jnienv, IntPtr n_self)
{
var self = JniEnvironment.Runtime.ValueMarshaler.GetObject<JavaProxyObject> (n_self);
var self = JniEnvironment.Runtime.ValueManager.GetObject<JavaProxyObject> (n_self);
var s = self.ToString ();
var r = JniEnvironment.Strings.NewString (s);
try {
Expand Down
14 changes: 7 additions & 7 deletions src/Java.Interop/Java.Interop/JniMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static T GetValue<T> (ref JniObjectReference reference, JniObjectRefere
return default (T);

var jvm = JniEnvironment.Runtime;
var target = jvm.ValueMarshaler.PeekObject (reference);
var target = jvm.ValueManager.PeekObject (reference);
var proxy = target as JavaProxyObject;
if (proxy != null) {
JniObjectReference.Dispose (ref reference, transfer);
Expand All @@ -57,7 +57,7 @@ internal static T GetValue<T> (ref JniObjectReference reference, JniObjectRefere
return (T) target;
}

var info = jvm.ValueMarshaler.GetJniMarshalInfoForType (typeof (T));
var info = jvm.ValueManager.GetJniMarshalInfoForType (typeof (T));
if (info.GetValueFromJni != null) {
return (T) info.GetValueFromJni (ref reference, transfer, typeof (T));
}
Expand All @@ -66,11 +66,11 @@ internal static T GetValue<T> (ref JniObjectReference reference, JniObjectRefere
var targetType = jvm.TypeManager.GetType (signature);
if (targetType != null &&
typeof (T).GetTypeInfo ().IsAssignableFrom (targetType.GetTypeInfo ()) &&
(info = jvm.ValueMarshaler.GetJniMarshalInfoForType (targetType)).GetValueFromJni != null) {
(info = jvm.ValueManager.GetJniMarshalInfoForType (targetType)).GetValueFromJni != null) {
return (T) info.GetValueFromJni (ref reference, transfer, targetType);
}

return (T) jvm.ValueMarshaler.GetObject (ref reference, transfer, typeof (T));
return (T) jvm.ValueManager.GetObject (ref reference, transfer, typeof (T));
}

public static JniObjectReference CreateLocalRef<T> (T value)
Expand All @@ -79,17 +79,17 @@ public static JniObjectReference CreateLocalRef<T> (T value)

var info = new JniMarshalInfo ();
if (value != null)
info = jvm.ValueMarshaler.GetJniMarshalInfoForType (value.GetType ());
info = jvm.ValueManager.GetJniMarshalInfoForType (value.GetType ());
if (info.CreateLocalRef == null)
info = jvm.ValueMarshaler.GetJniMarshalInfoForType (typeof (T));
info = jvm.ValueManager.GetJniMarshalInfoForType (typeof (T));

if (info.CreateLocalRef != null) {
return info.CreateLocalRef (value);
}

var o = (value as IJavaPeerable) ??
JavaProxyObject.GetProxy (value);
return jvm.ValueMarshaler.GetJniMarshalInfoForType (typeof (IJavaPeerable)).CreateLocalRef (o);
return jvm.ValueManager.GetJniMarshalInfoForType (typeof (IJavaPeerable)).CreateLocalRef (o);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Java.Interop/Java.Interop/JniObjectReferenceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum JniObjectReferenceOptions
Copy = 1 << 0, // DoNotTransfer
// DisposeSource = 1 << 1, // See JniObjectReference.DisposeSource
CopyAndDispose = (1 << 1) + Copy, // Transfer
// DoNotRegisterTarget = 1 << 2, // See JniRuntime.JniValueMarshaler.DoNotRegisterTarget
// DoNotRegisterTarget = 1 << 2, // See JniRuntime.JniValueManager.DoNotRegisterTarget
CopyAndDoNotRegister = (1 << 2) + Copy,
}

Expand All @@ -18,7 +18,7 @@ partial struct JniObjectReference {
}

partial class JniRuntime {
partial class JniValueMarshaler {
partial class JniValueManager {
const JniObjectReferenceOptions DoNotRegisterTarget = (JniObjectReferenceOptions) (1 << 2);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal JniArgumentMarshalInfo (T value)
{
this = new JniArgumentMarshalInfo<T> ();
var jvm = JniEnvironment.Runtime;
var info = jvm.ValueMarshaler.GetJniMarshalInfoForType (typeof (T));
var info = jvm.ValueManager.GetJniMarshalInfoForType (typeof (T));
if (info.CreateJniArgumentValue != null)
jvalue = info.CreateJniArgumentValue (value);
else if (info.CreateMarshalCollection != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace Java.Interop
partial class JniRuntime
{
partial class CreationOptions {
public JniValueMarshaler ValueMarshaler {get; set;}
public JniValueManager ValueManager {get; set;}
}

public JniValueMarshaler ValueMarshaler {get; private set;}
public JniValueManager ValueManager {get; private set;}

partial void SetValueMarshaler (CreationOptions options)
partial void SetValueManager (CreationOptions options)
{
ValueMarshaler = SetRuntime (options.ValueMarshaler ?? new JniValueMarshaler ());
ValueManager = SetRuntime (options.ValueManager ?? new JniValueManager ());
}

public partial class JniValueMarshaler : ISetRuntime, IDisposable {
public partial class JniValueManager : ISetRuntime, IDisposable {

public JniRuntime Runtime { get; private set; }

Expand Down
10 changes: 5 additions & 5 deletions src/Java.Interop/Java.Interop/JniRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected JniRuntime (CreationOptions options)
ObjectReferenceManager = SetRuntime (options.ObjectReferenceManager ?? new JniObjectReferenceManager ());
TypeManager = SetRuntime (options.TypeManager ?? new JniTypeManager ());

SetValueMarshaler (options);
SetValueManager (options);
SetExportedMemberBuilder (options);

NewObjectRequired = options.NewObjectRequired;
Expand Down Expand Up @@ -228,7 +228,7 @@ T SetRuntime<T> (T value)
return value;
}

partial void SetValueMarshaler (CreationOptions options);
partial void SetValueManager (CreationOptions options);
partial void SetExportedMemberBuilder (CreationOptions options);

static unsafe JavaVMInterface CreateInvoker (IntPtr handle)
Expand Down Expand Up @@ -276,7 +276,7 @@ protected virtual void Dispose (bool disposing)
JniObjectReference.Dispose (ref ClassLoader);

#if !XA_INTEGRATION
ValueMarshaler.Dispose ();
ValueManager.Dispose ();
#endif // !XA_INTEGRATION
ClearTrackedReferences ();
JniRuntime _;
Expand Down Expand Up @@ -331,7 +331,7 @@ public virtual Exception GetExceptionForThrowable (ref JniObjectReference value,
#if XA_INTEGRATION
throw new NotSupportedException ("Do not know h ow to convert a JniObjectReference to a System.Exception!");
#else // !XA_INTEGRATION
var o = ValueMarshaler.PeekObject (value);
var o = ValueManager.PeekObject (value);
var e = o as JavaException;
if (e != null) {
JniObjectReference.Dispose (ref value, transfer);
Expand All @@ -340,7 +340,7 @@ public virtual Exception GetExceptionForThrowable (ref JniObjectReference value,
return p.Exception;
return e;
}
return ValueMarshaler.GetObject<JavaException> (ref value, transfer);
return ValueManager.GetObject<JavaException> (ref value, transfer);
#endif // !̣XA_INTEGRATION
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void CalledFromConstructor (int value)

static void CalledFromConstructorHandler (IntPtr jnienv, IntPtr n_self, int value)
{
var self = JniEnvironment.Runtime.ValueMarshaler.GetObject<CallVirtualFromConstructorDerived>(n_self);
var self = JniEnvironment.Runtime.ValueManager.GetObject<CallVirtualFromConstructorDerived>(n_self);
self.CalledFromConstructor (value);
self.DisposeUnlessRegistered ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void InvokeVirtualFromConstructor ()
{
using (var t = new CallVirtualFromConstructorDerived (42)) {
Assert.IsTrue (t.Called);
Assert.IsNotNull (JniRuntime.CurrentRuntime.ValueMarshaler.PeekObject (t.PeerReference));
Assert.IsNotNull (JniRuntime.CurrentRuntime.ValueManager.PeekObject (t.PeerReference));
}
}
}
Expand Down
Loading

0 comments on commit 15fbb57

Please sign in to comment.