Example #1
0
    static void Init(GType gType, Type type)
    {
        var ptr = gType.GetClassPtr();

        gst_element_class_set_metadata(ptr, LONGNAME, CLASSIFICATION, DESCRIPTION, AUTHOR);
        PadTemplate srcTmpl  = new PadTemplate("src", PadDirection.Src, PadPresence.Always, Caps.NewAny());
        PadTemplate sinkTmpl = new PadTemplate("sink", PadDirection.Sink, PadPresence.Always, Caps.NewAny());

        gst_element_class_add_pad_template(ptr, srcTmpl.OwnedHandle);
        gst_element_class_add_pad_template(ptr, sinkTmpl.OwnedHandle);
    }
Example #2
0
		void InitForProperty (GType gtype, string name)
		{
			IntPtr p_name = Marshaller.StringToPtrGStrdup (name);
			IntPtr spec_ptr = g_object_class_find_property (gtype.GetClassPtr (), p_name);
			Marshaller.Free (p_name);

			if (spec_ptr == IntPtr.Zero)
				throw new Exception (String.Format ("No property with name '{0}' in type '{1}'", name, gtype.ToString()));
			
			ParamSpec spec = new ParamSpec (spec_ptr);
			g_value_init (ref this, spec.ValueType.Val);
		}
Example #3
0
		static void AddProperties (GType gtype, System.Type t, bool register_instance_prop)
		{
			uint idx = 1;
			
			if (register_instance_prop) {
				IntPtr declaring_class = gtype.GetClassPtr ();
				ParamSpec pspec = new ParamSpec ("gtk-sharp-managed-instance", "", "", GType.Pointer, ParamFlags.Writable | ParamFlags.ConstructOnly);
				g_object_class_install_property (declaring_class, idx, pspec.Handle);
				idx++;				
			}

			bool handlers_overridden = register_instance_prop;
			foreach (PropertyInfo pinfo in t.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) {
				foreach (object attr in pinfo.GetCustomAttributes (typeof (PropertyAttribute), false)) {
					if(pinfo.GetIndexParameters().Length > 0)
						throw(new InvalidOperationException(String.Format("Gst.GLib.RegisterPropertyAttribute cannot be applied to property {0} of type {1} because the property expects one or more indexed parameters", pinfo.Name, t.FullName)));
					
					if (!handlers_overridden) {
						IntPtr class_ptr = gtype.GetClassPtr ();
						GObjectClass gobject_class = (GObjectClass) Marshal.PtrToStructure (class_ptr, typeof (GObjectClass));
						gobject_class.get_prop_cb = GetPropertyHandler;
						gobject_class.set_prop_cb = SetPropertyHandler;
						Marshal.StructureToPtr (gobject_class, class_ptr, false);
						handlers_overridden = true;
					}
					PropertyAttribute property_attr = attr as PropertyAttribute;
					try {
						IntPtr param_spec = RegisterProperty (gtype, property_attr.Name, property_attr.Nickname, property_attr.Blurb, idx, (GType) pinfo.PropertyType, pinfo.CanRead, pinfo.CanWrite);
						Properties.Add (param_spec, pinfo);
						idx++;
					} catch (ArgumentException) {
						throw new InvalidOperationException (String.Format ("Gst.GLib.PropertyAttribute cannot be applied to property {0} of type {1} because the return type of the property is not supported", pinfo.Name, t.FullName));
					}
				}
			}
		}
Example #4
0
		static IntPtr RegisterProperty (GType type, string name, string nick, string blurb, uint property_id, GType property_type, bool can_read, bool can_write)
		{
			IntPtr declaring_class = type.GetClassPtr ();
			ParamSpec pspec = new ParamSpec (name, nick, blurb, property_type, can_read, can_write);

			g_object_class_install_property (declaring_class, property_id, pspec.Handle);
			return pspec.Handle;
		}