Exemplo n.º 1
0
        static void RaiseException(TextWriter o, JniFunction entry, HandleStyle style)
        {
            if (!entry.Throws)
            {
                return;
            }

            o.WriteLine();
            o.WriteLine("\t\t\tException __e = JniEnvironment.GetExceptionForLastThrowable ({0});",
                        style == HandleStyle.JIIntPtrPinvokeWithErrors ? "thrown" : "");
            o.WriteLine("\t\t\tif (__e != null)");
            o.WriteLine("\t\t\t\tExceptionDispatchInfo.Capture (__e).Throw ();");
            o.WriteLine();
        }
Exemplo n.º 2
0
        static void CreateDelegate(TextWriter o, JniFunction entry, HandleStyle style)
        {
            StringBuilder builder        = new StringBuilder();
            bool          has_char_array = false;

            string name = entry.GetDelegateTypeName(style);

            if (name == null)
            {
                return;
            }

            builder.AppendFormat("\tunsafe delegate {0} {1} ({2} env", entry.GetMarshalReturnType(style), name, GetJniEnvironmentPointerType(style));
            for (int i = 0; i < entry.Parameters.Length; i++)
            {
                if (i >= 0)
                {
                    builder.Append(", ");
                    builder.AppendFormat("{0} {1}",
                                         entry.Parameters [i].Type.GetMarshalType(style, isReturn: false, isPinvoke: true),
                                         Escape(entry.Parameters [i].Name));
                }

                var ptype = entry.Parameters [i].Type.GetManagedType(style, isReturn: false, isPinvoke: true);
                if (ptype == "va_list")
                {
                    return;
                }
                if (ptype == "char[]")
                {
                    has_char_array = true;
                }
            }
            builder.Append(");");

            if (created_delegates.Contains(name))
            {
                return;
            }

            created_delegates.Add(name);
            if (entry.Name == "NewString" || has_char_array)
            {
                o.WriteLine("\t[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl, CharSet=CharSet.Unicode)]");
            }
            o.WriteLine(builder.ToString());
        }
Exemplo n.º 3
0
 public override string[] GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
 {
     return(new string[] {
         string.Format("return (JniReleaseArrayElementsMode) {0};", variable),
     });
 }
Exemplo n.º 4
0
        public override string[] GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
        {
            switch (style)
            {
            case HandleStyle.SafeHandle:
            case HandleStyle.XAIntPtr:
                return(new [] {
                    string.Format("JniEnvironment.LogCreateLocalRef ({0});", variable),
                    string.Format("return {0};", variable),
                });

            case HandleStyle.JIIntPtr:
            case HandleStyle.JIIntPtrPinvokeWithErrors:
                return(new [] {
                    string.Format("JniEnvironment.LogCreateLocalRef ({0});", variable),
                    string.Format("return new JniObjectReference ({0}, JniObjectReferenceType.Local);", variable),
                });
            }
            return(null);
        }
Exemplo n.º 5
0
 public override string[] GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
 {
     return(new string[] {
         string.Format("return ({0} != 0) ? true : false;", variable),
     });
 }
Exemplo n.º 6
0
 public virtual string[]    GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
 {
     return(new[] {
         string.Format("return {0};", variable),
     });
 }
Exemplo n.º 7
0
 static string Initialize(JniFunction e, string prefix, string delegateType)
 {
     return(string.Format("{0}{1} = ({2}) Marshal.GetDelegateForFunctionPointer (env.{1}, typeof ({2}));",
                          prefix, e.Name, delegateType));
 }
Exemplo n.º 8
0
        public override string[] GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
        {
            switch (style)
            {
            case HandleStyle.SafeHandle:
            case HandleStyle.JIIntPtr:
            case HandleStyle.JIIntPtrPinvokeWithErrors:
                return(new [] {
                    string.Format("return new JniObjectReference ({0}, {1});", variable, refType),
                });

            case HandleStyle.XAIntPtr:
                return(new[] {
                    string.Format("return {0};", variable),
                });
            }
            return(new string [0]);
        }
Exemplo n.º 9
0
        public override string[] GetMarshalToManagedStatements(HandleStyle style, string variable, JniFunction entry)
        {
            switch (style)
            {
            case HandleStyle.SafeHandle:
            case HandleStyle.JIIntPtr:
            case HandleStyle.JIIntPtrPinvokeWithErrors:
                return(new[] {
                    string.Format("if ({0} == IntPtr.Zero)", variable),
                    string.Format("\treturn null;"),
                    string.Format("return new {0} ({1}, {2}, {3}, isStatic: {4});", type, entry.Parameters [1].Name, entry.Parameters [2].Name, variable, IsStatic ? "true" : "false"),
                });

            case HandleStyle.XAIntPtr:
                return(new[] {
                    string.Format("return {0};", variable),
                });
            }
            return(new string [0]);
        }