MateComponentObject

## MateComponentObject MateComponentObject — Base object for wrapping MateComponent::Unknown derived objects. Implements Figure 2, “The MateComponent::Unknown interface”. |

## Synopsis

    #define             MATECOMPONENT_OBJECT_TYPE
    #define             MATECOMPONENT_OBJREF                       (o)
    void                (*MateComponentObjectPOAFn)                (PortableServer_Servant servant,
                                                             CORBA_Environment *ev);
                        MateComponentObject;
                        MateComponentObjectClass;
    void                matecomponent_object_add_interface         (MateComponentObject *object,
                                                             MateComponentObject *newobj);
    MateComponentObject *      matecomponent_object_query_local_interface (MateComponentObject *object,
                                                             const char *repo_id);
    MateComponent_Unknown      matecomponent_object_query_interface       (MateComponentObject *object,
                                                             const char *repo_id,
                                                             CORBA_Environment *opt_ev);
    MateComponent_Unknown      matecomponent_object_query_remote          (MateComponent_Unknown unknown,
                                                             const char *repo_id,
                                                             CORBA_Environment *opt_ev);
    MateComponent_Unknown      matecomponent_object_corba_objref          (MateComponentObject *object);
    MateComponent_Unknown      matecomponent_object_dup_ref               (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);
    MateComponent_Unknown      matecomponent_object_release_unref         (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);
    gpointer            matecomponent_object_ref                   (gpointer obj);
    void                matecomponent_object_idle_unref            (gpointer obj);
    gpointer            matecomponent_object_unref                 (gpointer obj);
    void                matecomponent_object_set_immortal          (MateComponentObject *object,
                                                             gboolean immortal);
    gpointer            matecomponent_object_trace_refs            (gpointer obj,
                                                             const char *fn,
                                                             int line,
                                                             gboolean ref);
    void                matecomponent_object_dump_interfaces       (MateComponentObject *object);
    void                matecomponent_object_check_env             (MateComponentObject *object,
                                                             CORBA_Object corba_object,
                                                             CORBA_Environment *ev);
    #define             MATECOMPONENT_OBJECT_CHECK                 (o,
                                                             c,
                                                             e)
    gboolean            matecomponent_unknown_ping                 (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);
    void                matecomponent_object_list_unref_all        (GList **list);
    void                matecomponent_object_slist_unref_all       (GSList **list);
    MateComponentObject *      matecomponent_object                       (gpointer p);
    #define             matecomponent_object_fast                  (o)
    #define             matecomponent_object_from_servant          (s)
    #define             matecomponent_object_get_servant           (o)
    PortableServer_POA  matecomponent_object_get_poa               (MateComponentObject *object);
    GType               matecomponent_type_unique                  (GType parent_type,
                                                             MateComponentObjectPOAFn init_fn,
                                                             MateComponentObjectPOAFn fini_fn,
                                                             int epv_struct_offset,
                                                             const GTypeInfo *info,
                                                             const gchar *type_name);
    gboolean            matecomponent_type_setup                   (GType type,
                                                             MateComponentObjectPOAFn init_fn,
                                                             MateComponentObjectPOAFn fini_fn,
                                                             int epv_struct_offset);
    #define             MATECOMPONENT_TYPE_FUNC_FULL               (class_name,
                                                             corba_name,
                                                             parent,
                                                             prefix)
    #define             MATECOMPONENT_TYPE_FUNC                    (class_name,
                                                             parent,
                                                             prefix)

## Object Hierarchy

      GObject
       +----MateComponentObject
             +----MateComponentGenericFactory
             +----MateComponentPersist
             +----MateComponentMonikerExtender
             +----MateComponentItemContainer
             +----MateComponentStreamMem
             +----MateComponentItemHandler
             +----MateComponentListener
             +----MateComponentMoniker

## Properties

      "poa"                      gpointer              : Read / Write / Construct Only

## Signals

      "destroy"                                        : Run Last
      "system-exception"                               : Run Last

## Description

MateComponentObject provides an easy to use way of writing CORBA servers. It drastically simplifies the issues of epv and vepv construction by automating these, and automatically instantiates a CORBA_Object on g_object_new. This removes clutter from construction time. For libmatecomponent-2.0, it strongly deprecates MateComponentXObject.

Figure 2. The MateComponent::Unknown interface

The `MateComponent::Unknown` interface (wrapped by MateComponentObject) is the foundation for the component system: it provides life cycle management for objects as well as service discovery.

The MateComponent interfaces are all based on the `MateComponent::Unknown` interface. This interface is very simple and provides two basic services: object lifetime management and object functionality-discovery. This interface only contains three methods, here it is:

      module MateComponent {
          interface Unknown {
              void void ref ();
              void void unref ();
              Object query_interface (in string repoid);
          };
      };

The ``ref()`` and ``unref()`` methods are used to control the lifetime of an object. The `query_interface` method is used to discover optional functionality provided by the object implementation.

The lifetime management is based on reference counting: when a component is initially launched, it starts life with a reference count of one. This reference is held by the component invoker. Each time a reference is kept to this object (say, you store a copy of the object in an array), the reference count is incremented. Every time a reference goes out of scope, the reference count needs to be decremented. When the reference count reaches zero, the component knows that there are no outstanding references to it, and it is safe to shutdown. At this point, the component shuts down.

It is possible to ask an object which implements the `MateComponent::Unknown` interface if it supports other CORBA interfaces. For example, it would be possible to ask an object whether it supports the "IDL:MateComponent/EmbeddablePrint:1.0" interface to find out if it is possible to print its contents. If the return value from invoking the `query_interface` method on the interface is CORBA_OBJECT_NIL, then we know that the requested interface is not supported. Otherwise, we can invoke IDL:MateComponent/EmbeddablePrint:1.0 methods on the returned CORBA Object.

Clients of the `query_interface` method use it to discover dynamically if a component supports a given interface. Sometimes the client code would require a specific interface to exist, but many times it is possible to operate in a "downgraded" mode. You should design your code to be able to cope with the lack of interfaces in objects. This will allow your program to deal with more components, and this also allows components to work in more situations.

For example, a help browser can load an HTML renderer component and ask this component which sort of features are supported by it:

    stop_animations (BrowserHTML html)
    {
      BrowserControl control
      control = html->query_interface ("IDL:Browser/Control:1.0");
      if (control)
              control->stop_animations ();
    }

The return value of the query_interface invocation contains a reference to a CORBA object that is derived from the `MateComponent::Unknown` interface or CORBA_OBJECT_NIL if the interface is not supported by the object. And this interface would have been already ``ref()``ed before it was returned. It is up to the caller to call ``unref()`` when they are done using the interface.

MateComponentObject implements the MateComponent::Unknown interface and exports the implementations of the methods in this class to simplify creating new objects that inherit from MateComponent::Unknown. This base object provides default implementations for the ref, unref and query_interface methods.

Other implementations reuse this implementation by listing on their VEPV tables the matecomponent_object_epv entry point vector.

The `MateComponent::Unknown` interface is inspired by the Microsoft COM `IUnknown` interface but it has been translated into the CORBA world.

## Details

### MATECOMPONENT_OBJECT_TYPE

    #define MATECOMPONENT_OBJECT_TYPE        MATECOMPONENT_TYPE_OBJECT /* deprecated, you should use MATECOMPONENT_TYPE_OBJECT */

Returns the GtkType for the MateComponentObject object.

### MATECOMPONENT_OBJREF()

    #define MATECOMPONENT_OBJREF(o)          (matecomponent_object_corba_objref(MATECOMPONENT_OBJECT(o)))

This macro returns the CORBA object reference inside a MateComponentObject.

`o` : | a MateComponentObject

### MateComponentObjectPOAFn ()

    void                (*MateComponentObjectPOAFn)                (PortableServer_Servant servant,
                                                             CORBA_Environment *ev);

Signature of POA initialization and finalization functions

`servant` : | the object's servant
`ev` : | CORBA environment

### MateComponentObject

    typedef struct _MateComponentObject MateComponentObject;

Implements MateComponent::Unknown.

### MateComponentObjectClass

    typedef struct {
    	GObjectClass parent_class;

    	/* signals. */
    	void         (*destroy)          (MateComponentObject *object);
    	void         (*system_exception) (MateComponentObject *object,
    					  CORBA_Object  cobject,
    					  CORBA_Environment *ev);

    	MateComponentObjectPOAFn          poa_init_fn;
    	MateComponentObjectPOAFn          poa_fini_fn;

    	POA_MateComponent_Unknown__vepv       *vepv;

    	/* The offset of this class' additional epv */
    	int                             epv_struct_offset;

    	PortableServer_ServantBase__epv base_epv;
    	POA_MateComponent_Unknown__epv         epv;

    	gpointer                        dummy[4];
    } MateComponentObjectClass;

MateComponentObject's class.

### matecomponent_object_add_interface ()

    void                matecomponent_object_add_interface         (MateComponentObject *object,
                                                             MateComponentObject *newobj);

Adds the interfaces supported by `newobj` to the list of interfaces for `object`. This function adds the interfaces supported by `newobj` to the list of interfaces support by `object`. It should never be used when the object has been exposed to the world. This is a firm part of the contract.

`object` : | The MateComponentObject to which an interface is going to be added.
`newobj` : | The MateComponentObject containing the new interface to be added.

### matecomponent_object_query_local_interface ()

    MateComponentObject *      matecomponent_object_query_local_interface (MateComponentObject *object,
                                                             const char *repo_id);

`object` : | A MateComponentObject which is the aggregate of multiple objects.
`repo_id` : | The id of the interface being queried.
Returns : | A MateComponentObject for the requested interface.

### matecomponent_object_query_interface ()

    MateComponent_Unknown      matecomponent_object_query_interface       (MateComponentObject *object,
                                                             const char *repo_id,
                                                             CORBA_Environment *opt_ev);

`object` : | A MateComponentObject to be queried for a given interface.
`repo_id` : | The name of the interface to be queried.
`opt_ev` : | optional exception environment
Returns : | The CORBA interface named `repo_id` for `object`.

### matecomponent_object_query_remote ()

    MateComponent_Unknown      matecomponent_object_query_remote          (MateComponent_Unknown unknown,
                                                             const char *repo_id,
                                                             CORBA_Environment *opt_ev);

A helper wrapper for query interface

`unknown` : | an unknown object ref ( or NIL )
`repo_id` : | the interface to query for
`opt_ev` : | an optional exception environment
Returns : | the interface or CORBA_OBJECT_NIL

### matecomponent_object_corba_objref ()

    MateComponent_Unknown      matecomponent_object_corba_objref          (MateComponentObject *object);

`object` : | A MateComponentObject whose CORBA object is requested.
Returns : | The CORBA interface object for which `object` is a wrapper.

### matecomponent_object_dup_ref ()

    MateComponent_Unknown      matecomponent_object_dup_ref               (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);

This function returns a duplicated CORBA Object reference; it also bumps the ref count on the object. This is ideal to use in any method returning a MateComponent_Object in a CORBA impl. If object is CORBA_OBJECT_NIL it is returned unaffected.

`object` : | a MateComponent_Unknown corba object
`opt_ev` : | an optional exception environment
Returns : | duplicated & ref'd corba object reference.

### matecomponent_object_release_unref ()

    MateComponent_Unknown      matecomponent_object_release_unref         (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);

This function releases a CORBA Object reference; it also decrements the ref count on the matecomponent object. This is the converse of matecomponent_object_dup_ref. We tolerate object == CORBA_OBJECT_NIL silently.

`object` : | a MateComponent_Unknown corba object
`opt_ev` : | an optional exception environment
Returns : | `CORBA_OBJECT_NIL`.

### matecomponent_object_ref ()

    gpointer            matecomponent_object_ref                   (gpointer obj);

Increments the reference count for the aggregate MateComponentObject.

`obj` : | A MateComponentObject you want to ref-count
Returns : | `object`

### matecomponent_object_idle_unref ()

    void                matecomponent_object_idle_unref            (gpointer obj);

`obj` : |

### matecomponent_object_unref ()

    gpointer            matecomponent_object_unref                 (gpointer obj);

Decrements the reference count for the aggregate MateComponentObject.

`obj` : | A MateComponentObject you want to unref.
Returns : | `NULL`.

### matecomponent_object_set_immortal ()

    void                matecomponent_object_set_immortal          (MateComponentObject *object,
                                                             gboolean immortal);

`object` : |
`immortal` : |

### matecomponent_object_trace_refs ()

    gpointer            matecomponent_object_trace_refs            (gpointer obj,
                                                             const char *fn,
                                                             int line,
                                                             gboolean ref);

`obj` : |
`fn` : |
`line` : |
`ref` : |
Returns : |

### matecomponent_object_dump_interfaces ()

    void                matecomponent_object_dump_interfaces       (MateComponentObject *object);

`object` : |

### matecomponent_object_check_env ()

    void                matecomponent_object_check_env             (MateComponentObject *object,
                                                             CORBA_Object corba_object,
                                                             CORBA_Environment *ev);

This routine verifies the `ev` environment for any fatal system exceptions. If a system exception occurs, the object raises a "system_exception" signal. The idea is that GObjects which are used to wrap a CORBA interface can use this function to notify the user if a fatal exception has occurred, causing the object to become defunct.

`object` : | The object on which we operate
`corba_object` : |
`ev` : | CORBA Environment to check

### MATECOMPONENT_OBJECT_CHECK()

    #define             MATECOMPONENT_OBJECT_CHECK(o,c,e)

Checks if the exception in `e` needs to be signaled. If so, then the proper exception signal is generated on the MateComponentObject object `o` for the CORBA reference `c`.

`o` : |
`c` : |
`e` : |

### matecomponent_unknown_ping ()

    gboolean            matecomponent_unknown_ping                 (MateComponent_Unknown object,
                                                             CORBA_Environment *opt_ev);

Pings the object `object` using the ref/unref methods from MateComponent::Unknown. You can use this one to see if a remote object has gone away.

`object` : | a CORBA object reference of type MateComponent::Unknown
`opt_ev` : | optional exception environment
Returns : | `TRUE` if the MateComponent::Unknown `object` is alive.

### matecomponent_object_list_unref_all ()

    void                matecomponent_object_list_unref_all        (GList **list);

This routine unrefs all valid objects in the list and then removes them from `list` if they have not already been so removed.

`list` : | A list of MateComponentObjects *s

### matecomponent_object_slist_unref_all ()

    void                matecomponent_object_slist_unref_all       (GSList **list);

`list` : |

### matecomponent_object ()

    MateComponentObject *      matecomponent_object                       (gpointer p);

This function can be passed a MateComponentObject * or a PortableServer_Servant, and it will return a MateComponentObject *.

`p` : | a pointer to something
Returns : | a MateComponentObject or NULL on error.

### matecomponent_object_fast()

    #define             matecomponent_object_fast(o)

`o` : |

### matecomponent_object_from_servant()

    #define       matecomponent_object_from_servant(s) ((MateComponentObject *)(((guchar *) (s)) - MATECOMPONENT_OBJECT_HEADER_SIZE))

`s` : |
Returns : |

### matecomponent_object_get_servant()

    #define       matecomponent_object_get_servant(o)  ((PortableServer_Servant)((guchar *)(o) + MATECOMPONENT_OBJECT_HEADER_SIZE))

`o` : |
Returns : |

### matecomponent_object_get_poa ()

    PortableServer_POA  matecomponent_object_get_poa               (MateComponentObject *object);

Gets the POA associated with this part of the MateComponentObject aggregate it is possible to have different POAs per interface.

`object` : | the object associated with an interface
Returns : | the poa, never NIL.

### matecomponent_type_unique ()

    GType               matecomponent_type_unique                  (GType parent_type,
                                                             MateComponentObjectPOAFn init_fn,
                                                             MateComponentObjectPOAFn fini_fn,
                                                             int epv_struct_offset,
                                                             const GTypeInfo *info,
                                                             const gchar *type_name);

This function is the main entry point for deriving matecomponent server interfaces.

`parent_type` : | the parent GType
`init_fn` : | a POA initialization function
`fini_fn` : | a POA finialization function or NULL
`epv_struct_offset` : | the offset into the struct that the epv commences at, or 0 if we are inheriting a plain GObject from a MateComponentObject, adding no new CORBA interfaces
`info` : | the standard GTypeInfo.
`type_name` : | the name of the type being registered.
Returns : | the constructed GType.

### matecomponent_type_setup ()

    gboolean            matecomponent_type_setup                   (GType type,
                                                             MateComponentObjectPOAFn init_fn,
                                                             MateComponentObjectPOAFn fini_fn,
                                                             int epv_struct_offset);

This function initializes a type derived from MateComponentObject, such that when you instantiate a new object of this type with g_type_new the CORBA object will be correctly created and embedded.

`type` : | The type to initialize
`init_fn` : | the POA_init function for the CORBA interface or NULL
`fini_fn` : | NULL or a custom POA free fn.
`epv_struct_offset` : | the offset in the class structure where the epv is or 0
Returns : | TRUE on success, FALSE on error.

### MATECOMPONENT_TYPE_FUNC_FULL()

    #define             MATECOMPONENT_TYPE_FUNC_FULL(class_name, corba_name, parent, prefix)

Macro that includes all the boilerplate code need to register a new MateComponentObject-derived class. The programmer has to define two functions only: `prefix_init` and `prefix_class_init`. As a result of the macro expansion, a function named @`prefix_get_type()` is defined.

`class_name` : | Name of the GObject class, LikeThis
`corba_name` : | Name of the CORBA interface, with IDL-to-C mapping, Like_This
`parent` : | GType of the parent class, LIKE_TYPE_THIS
`prefix` : | prefix of the implementation functions

### MATECOMPONENT_TYPE_FUNC()

    #define             MATECOMPONENT_TYPE_FUNC(class_name, parent, prefix)

Like MATECOMPONENT_TYPE_FUNC, but doesn't set POA ini and fini functions.

`class_name` : |
`parent` : |
`prefix` : |

## Property Details

### The `"poa"` property

      "poa"                      gpointer              : Read / Write / Construct Only

Pass this property during construction to specify a custom POA for a MateComponentObject. Example:

    1
    2
    3
    4
    5
    6
    7
    MateComponentObject * my_matecomponent_object_new (void)
    {
        MateComponentObject *object;
        object = g_object_new (MY_TYPE_MATECOMPONENT_OBJECT, "poa",
                       matecomponent_poa_get_threaded (MATECOMPONENT_POA_ALL_AT_IDLE), NULL);
        return object;
    }

## Signal Details

### The `"destroy"` signal

    void                user_function                      (MateComponentObject *matecomponentobject,
                                                            gpointer      user_data)         : Run Last

Signal emitted when the last reference of a MateComponentObject has been lost and the object is being destroyed / finalized / deactivated.

`matecomponentobject` : | the object which received the signal.
`user_data` : | user data set when the signal handler was connected.

### The `"system-exception"` signal

    void                user_function                      (MateComponentObject         *matecomponentobject,
                                                            CorbaObject          *arg1,
                                                            MateComponentCorbaException *arg2,
                                                            gpointer              user_data)         : Run Last

Signal emitted from matecomponent_object_check_env if a system exception is identified.

`matecomponentobject` : | the MateComponentObject which received the signal.
`arg1` : | the CORBA_Object contained in `matecomponentobject`.
`arg2` : | the exception that has just occurred.
`user_data` : | user data set when the signal handler was connected.

## See Also

GObject