Exemple #1
1
 public GObjectVM(XmlElement elem, ObjectBase container_type)
     : base(elem, container_type)
 {
     parms.HideData = false;
     this.Protection = "protected";
     class_struct_name = container_type.ClassStructName;
 }
Exemple #2
0
		protected virtual bool CanGenerate (GenerationInfo gen_info, ObjectBase implementor)
		{
			if (implementor != null || this.CName.Length == 0 || CodeType == VMCodeType.None || (CodeType == VMCodeType.Glue && !gen_info.GlueEnabled))
				return false;
			else
				return true;
		}
		protected override void GenerateUnmanagedInvocation (GenerationInfo gen_info, ObjectBase implementor)
		{
			if (!base.CanGenerate (gen_info, implementor))
				GenerateChainVirtualMethod (gen_info.Writer, implementor);
			else
				base.GenerateUnmanagedInvocation (gen_info, implementor);
		}
		public VirtualMethod (XmlElement elem, ObjectBase container_type) : base (elem, container_type)
		{
			if (container_type.ParserVersion == 1) {
				// The old pre 2.14 parser didn't drop the 1st parameter in all <signal> and <virtual_method> elements
				parms = new Parameters (elem ["parameters"], true);
			}
			retval = new ReturnValue (elem ["return-type"]);
		}
Exemple #5
0
 public Signal(XmlElement elem, ObjectBase container_type)
 {
     this.elem = elem;
     name = elem.GetAttribute ("name");
     marshaled = elem.GetAttribute ("manual") == "true";
     retval = new ReturnValue (elem ["return-type"]);
     parms = new Parameters (elem["parameters"], container_type.ParserVersion == 1 ? true : false);
     this.container_type = container_type;
 }
Exemple #6
0
		public void Generate (GenerationInfo gen_info, ObjectBase implementor)
		{
			if (!CanGenerate (gen_info, implementor))
				throw new NotSupportedException (String.Format ("Cannot generate virtual method {0}.{1}. Make sure a writable glue path was provided to the generator.", container_type.Name, this.CallString));

			GenerateOverride (gen_info, implementor);
			GenerateCallback (gen_info.Writer, implementor);
			if (!IsStatic)
				GenerateUnmanagedInvocation (gen_info, implementor);
		}
		protected override void GenerateOverride (GenerationInfo gen_info, ObjectBase implementor)
		{
			StreamWriter sw = gen_info.Writer;

			if (!base.CanGenerate (gen_info, implementor)) {
				GenerateOverrideBody (sw);
				sw.WriteLine ("\t\t\tOverrideVirtualMethod (gtype, \"{0}\", callback);", signal_name);
				sw.WriteLine ("\t\t}");
			} else
				base.GenerateOverride (gen_info, implementor);
		}
		private void GenerateChainVirtualMethod (StreamWriter sw, ObjectBase implementor)
		{
			GenerateMethodBody (sw, implementor);
			if (retval.IsVoid)
				sw.WriteLine ("\t\t\tGst.GLib.Value ret = Gst.GLib.Value.Empty;");
			else
				sw.WriteLine ("\t\t\tGst.GLib.Value ret = new Gst.GLib.Value (" + ReturnGType + ");");

			sw.WriteLine ("\t\t\tGst.GLib.ValueArray inst_and_params = new Gst.GLib.ValueArray (" + (parms.Count + 1) + ");");
			sw.WriteLine ("\t\t\tGst.GLib.Value[] vals = new Gst.GLib.Value [" + (parms.Count + 1) + "];");
			sw.WriteLine ("\t\t\tvals [0] = new Gst.GLib.Value (this);");
			sw.WriteLine ("\t\t\tinst_and_params.Append (vals [0]);");
			string cleanup = "";
			for (int i = 0; i < parms.Count; i++) {
				Parameter p = parms [i];
				if (p.PassAs != "") {
					if (SymbolTable.Table.IsBoxed (p.CType)) {
						if (p.PassAs == "ref")
							sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new Gst.GLib.Value (" + p.Name + ");");
						else
							sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new Gst.GLib.Value ((Gst.GLib.GType)typeof (" + p.CSType + "));");
						cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
					} else {
						if (p.PassAs == "ref")
							sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Gst.GLib.Marshaller.StructureToPtrAlloc (" + p.Generatable.CallByName (p.Name) + ");");
						else
							sw.WriteLine ("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.MarshalType + ")));");

						sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new Gst.GLib.Value (" + p.Name + "_ptr);");
						cleanup += "\t\t\t" + p.Name + " = " + p.FromNative ("(" + p.MarshalType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.MarshalType + "))") + ";\n";
						cleanup += "\t\t\tMarshal.FreeHGlobal (" + p.Name + "_ptr);\n";
					}
				} else if (p.IsLength && i > 0 && parms [i - 1].IsString)
					sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new Gst.GLib.Value (System.Text.Encoding.UTF8.GetByteCount (" + parms [i-1].Name + "));");
				else
					sw.WriteLine ("\t\t\tvals [" + (i + 1) + "] = new Gst.GLib.Value (" + p.Name + ");");

				sw.WriteLine ("\t\t\tinst_and_params.Append (vals [" + (i + 1) + "]);");
			}

			sw.WriteLine ("\t\t\tg_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
			if (cleanup != "")
				sw.WriteLine (cleanup);
			sw.WriteLine ("\t\t\tforeach (Gst.GLib.Value v in vals)");
			sw.WriteLine ("\t\t\t\tv.Dispose ();");
			if (!retval.IsVoid) {
				IGeneratable igen = SymbolTable.Table [retval.CType];
				sw.WriteLine ("\t\t\t" + retval.CSType + " result = (" + (igen is EnumGen ? retval.CSType + ") (Enum" : retval.CSType) + ") ret;");
				sw.WriteLine ("\t\t\tret.Dispose ();");
				sw.WriteLine ("\t\t\treturn result;");
			}
			sw.WriteLine ("\t\t}\n");
		}
Exemple #9
0
 public void GenSignals(GenerationInfo gen_info, ObjectBase implementor)
 {
     foreach (Signal sig in sigs.Values)
         sig.Generate (gen_info, implementor);
 }
Exemple #10
0
        private void GenerateChainVirtualMethod(StreamWriter sw, ObjectBase implementor)
        {
            GenerateMethodBody(sw, implementor);
            if (retval.IsVoid)
            {
                sw.WriteLine("\t\t\tGLib.Value ret = GLib.Value.Empty;");
            }
            else
            {
                sw.WriteLine("\t\t\tGLib.Value ret = new GLib.Value (" + ReturnGType + ");");
            }

            sw.WriteLine("\t\t\tGLib.ValueArray inst_and_params = new GLib.ValueArray (" + (parms.Count + 1) + ");");
            sw.WriteLine("\t\t\tGLib.Value[] vals = new GLib.Value [" + (parms.Count + 1) + "];");
            sw.WriteLine("\t\t\tvals [0] = new GLib.Value (this);");
            sw.WriteLine("\t\t\tinst_and_params.Append (vals [0]);");
            string cleanup = "";

            for (int i = 0; i < parms.Count; i++)
            {
                Parameter p = parms [i];
                if (p.PassAs != "")
                {
                    if (SymbolTable.Table.IsBoxed(p.CType))
                    {
                        if (p.PassAs == "ref")
                        {
                            sw.WriteLine("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + ");");
                        }
                        else
                        {
                            sw.WriteLine("\t\t\tvals [" + (i + 1) + "] = new GLib.Value ((GLib.GType)typeof (" + p.CSType + "));");
                        }
                        cleanup += "\t\t\t" + p.Name + " = (" + p.CSType + ") vals [" + i + "];\n";
                    }
                    else
                    {
                        if (p.PassAs == "ref")
                        {
                            sw.WriteLine("\t\t\tIntPtr " + p.Name + "_ptr = GLib.Marshaller.StructureToPtrAlloc (" + p.Generatable.CallByName(p.Name) + ");");
                        }
                        else
                        {
                            sw.WriteLine("\t\t\tIntPtr " + p.Name + "_ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (" + p.MarshalType + ")));");
                        }

                        sw.WriteLine("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + "_ptr);");
                        cleanup += "\t\t\t" + p.Name + " = " + p.FromNative("(" + p.MarshalType + ") Marshal.PtrToStructure (" + p.Name + "_ptr, typeof (" + p.MarshalType + "))") + ";\n";
                        cleanup += "\t\t\tMarshal.FreeHGlobal (" + p.Name + "_ptr);\n";
                    }
                }
                else if (p.IsLength && i > 0 && parms [i - 1].IsString)
                {
                    sw.WriteLine("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (System.Text.Encoding.UTF8.GetByteCount (" + parms [i - 1].Name + "));");
                }
                else
                {
                    sw.WriteLine("\t\t\tvals [" + (i + 1) + "] = new GLib.Value (" + p.Name + ");");
                }

                sw.WriteLine("\t\t\tinst_and_params.Append (vals [" + (i + 1) + "]);");
            }

            sw.WriteLine("\t\t\tg_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);");
            if (cleanup != "")
            {
                sw.WriteLine(cleanup);
            }
            sw.WriteLine("\t\t\tforeach (GLib.Value v in vals)");
            sw.WriteLine("\t\t\t\tv.Dispose ();");
            if (!retval.IsVoid)
            {
                IGeneratable igen = SymbolTable.Table [retval.CType];
                sw.WriteLine("\t\t\t" + retval.CSType + " result = (" + (igen is EnumGen ? retval.CSType + ") (Enum" : retval.CSType) + ") ret;");
                sw.WriteLine("\t\t\tret.Dispose ();");
                sw.WriteLine("\t\t\treturn result;");
            }
            sw.WriteLine("\t\t}\n");
        }
Exemple #11
0
 protected virtual void GenerateUnmanagedInvocation(GenerationInfo gen_info, ObjectBase implementor)
 {
     if (CodeType == VMCodeType.Glue)
         GenerateUnmanagedInvocation_glue (gen_info);
     else
         GenerateUnmanagedInvocation_managed (gen_info);
 }
Exemple #12
0
 protected virtual void GenerateOverride(GenerationInfo gen_info, ObjectBase implementor)
 {
     if (CodeType == VMCodeType.Glue)
         GenerateOverride_glue (gen_info);
     else
         GenerateOverride_managed (gen_info.Writer);
 }
Exemple #13
0
 private bool NeedNew(ObjectBase implementor)
 {
     return elem.HasAttribute ("new_flag") ||
         (container_type != null && container_type.GetSignalRecursively (Name) != null) ||
         (implementor != null && implementor.GetSignalRecursively (Name) != null);
 }
Exemple #14
0
        public void Generate(GenerationInfo gen_info, ObjectBase implementor)
        {
            StreamWriter sw = gen_info.Writer;

            if (implementor == null)
                GenEventHandler (gen_info);

            GenEvent (sw, implementor, "this");

            Statistics.SignalCount++;
        }
Exemple #15
0
 protected override bool CanGenerate(GenerationInfo gen_info, ObjectBase implementor)
 {
     return(true);
 }
Exemple #16
0
		protected override bool CanGenerate (GenerationInfo gen_info, ObjectBase implementor)
		{
			return true;
		}
Exemple #17
0
		public DefaultSignalHandler (XmlElement elem, ObjectBase container_type) : base (elem, container_type)
		{
			signal_name = elem.GetAttribute ("cname");
		}
Exemple #18
0
 public GObjectVM(XmlElement elem, ObjectBase container_type) : base(elem, container_type)
 {
     parms.HideData    = false;
     this.Protection   = "protected";
     class_struct_name = container_type.ClassStructName;
 }
Exemple #19
0
 public ClassField(XmlElement elem, ObjectBase container_type) : base(elem, container_type)
 {
     this.container_type = container_type;
 }
Exemple #20
0
 public InterfaceVM(XmlElement elem, Method target, ObjectBase container_type) : base(elem, container_type)
 {
     this.target     = target;
     parms.HideData  = true;
     this.Protection = "public";
 }
Exemple #21
0
 public void GenVirtualMethods(GenerationInfo gen_info, ObjectBase implementor)
 {
     foreach (GObjectVM vm in virtual_methods)
         vm.Generate (gen_info, implementor);
 }
Exemple #22
0
 private bool NeedNew(ObjectBase implementor)
 {
     return(elem.HasAttribute("new_flag") ||
            (container_type != null && container_type.GetSignalRecursively(Name) != null) ||
            (implementor != null && implementor.GetSignalRecursively(Name) != null));
 }
Exemple #23
0
		public void GenEvent (StreamWriter sw, ObjectBase implementor, string target)
		{
			string args_type = IsEventHandler ? "" : ", typeof (" + EventArgsQualifiedName + ")";
			
			if (Marshaled) {
				GenCallback (sw);
				args_type = ", new " + DelegateName + "(" + CallbackName + ")";
			}

			sw.WriteLine("\t\t[GLib.Signal("+ CName + ")]");
			sw.Write("\t\tpublic ");
			if (NeedNew (implementor))
				sw.Write("new ");
			sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
			sw.WriteLine("\t\t\tadd {");
			sw.WriteLine("\t\t\t\t{0}.AddSignalHandler ({1}, value{2});", target, CName, args_type);
			sw.WriteLine("\t\t\t}");
			sw.WriteLine("\t\t\tremove {");
			sw.WriteLine("\t\t\t\t{0}.RemoveSignalHandler ({1}, value);", target, CName);
			sw.WriteLine("\t\t\t}");
			sw.WriteLine("\t\t}");
			sw.WriteLine();
		}
Exemple #24
0
        public void GenEvent(StreamWriter sw, ObjectBase implementor, string target)
        {
            string args_type = IsEventHandler ? "" : ", typeof (" + EventArgsQualifiedName + ")";

            if (Marshaled) {
                GenCallback (sw);
                args_type = ", new " + DelegateName + "(" + CallbackName + ")";
            }

            sw.WriteLine("\t\t[GLib.Signal("+ CName + ")]");
            sw.Write("\t\tpublic ");
            if (NeedNew (implementor))
                sw.Write("new ");
            sw.WriteLine("event " + EventHandlerQualifiedName + " " + Name + " {");
            sw.WriteLine("\t\t\tadd {");
            sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");");
            sw.WriteLine("\t\t\t\tsig.AddDelegate (value);");
            sw.WriteLine("\t\t\t}");
            sw.WriteLine("\t\t\tremove {");
            sw.WriteLine("\t\t\t\tGLib.Signal sig = GLib.Signal.Lookup (" + target + ", " + CName + args_type + ");");
            sw.WriteLine("\t\t\t\tsig.RemoveDelegate (value);");
            sw.WriteLine("\t\t\t}");
            sw.WriteLine("\t\t}");
            sw.WriteLine();
        }
Exemple #25
0
		public ClassField (XmlElement elem, ObjectBase container_type) : base (elem, container_type) {
			this.container_type = container_type;
		}
Exemple #26
0
 public DefaultSignalHandler(XmlElement elem, ObjectBase container_type) : base(elem, container_type)
 {
     signal_name = elem.GetAttribute("cname");
 }
Exemple #27
0
		public InterfaceVM (XmlElement elem, Method target, ObjectBase container_type) : base (elem, container_type)
		{
			this.target = target;
			parms.HideData = true;
			this.Protection = "public";
		}