Gobject decorator -> How to deal with properties

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Gobject decorator -> How to deal with properties

Gonzalo Aguilar Delgado

Hello,

I'm writting a decorator pattern for a protocol in Thrift that's based on c_glib. One of the cases I found is that you can have this:

// From Thrift code:


/*!
 * Thrift Protocol Decorator instance.
 */
struct _ThriftProtocolDecorator
{
  ThriftProtocol parent;

  ThriftProtocol *concrete_protocol;
};

typedef struct _ThriftProtocolDecoratorClass ThriftProtocolDecoratorClass;


That's a class that implements an interface but when a method is called, it really calls the concrete_protocol method. That's nice. It works but when dealing with properties that's a new history.


For example you can decorate a concrete_protocol that has a property called "transport" but when the code does something like:


g_object_get(decorated_protocol, "transport", &transportvar, NULL);

glib will search over the decorator class installed properties that's not what I want. I resolved hacking a known property install and trying to find its values on
concrete_protocol.

Something like this:


In the init class

  // TODO Ugly hack, in theory we must override all properties from underlaying
  // protocol
  thrift_stored_message_protocol_obj_properties[PROP_THRIFT_STORED_MESSAGE_PROTOCOL_TRANSPORT] =
      g_param_spec_pointer ("transport",
            "Transport on the underlaying implementation",
            "Transport of decorated protocol",
            G_PARAM_READABLE);


In the getter function

    case PROP_THRIFT_STORED_MESSAGE_PROTOCOL_TRANSPORT:
      // FIXME Since we don't override properties in the decorator as it should
      // we just override the properties that we know are used
      g_object_get(decorator->concrete_protocol,pspec->name, &transport, NULL);
      g_value_set_pointer (value, transport);
      break;


But it will fail if it asks for other property of the concrete_protocol instance. So the question is:

Is there any way to install all properties installed on the concrete_protocol? So I can override the "Getter" and "Setter" and fordward the request to the decorated instance?


Best regards,



_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list